diff mbox series

[V2,1/2] mips: add hp-timing support for MIPS R2

Message ID 20201202033329.21759-2-huangpei@loongson.cn
State Changes Requested
Headers show
Series [V2,1/2] mips: add hp-timing support for MIPS R2 | expand

Commit Message

Huang Pei Dec. 2, 2020, 3:33 a.m. UTC
MIPS R2 only support 32 bit TSC(AKA "rdhwr %0, $2"), but it should be
enough for glibc.

DO remember Linux/MIPS added emulation for 'rdhwr %0, $2',when disabled
or not supported, which would make the precision worse. If you got
unreasonable result, check your CPU Manual for whether your CPU
implemented it or not
---
 sysdeps/mips/hp-timing.h | 44 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 sysdeps/mips/hp-timing.h

Comments

Adhemerval Zanella Dec. 3, 2020, 12:39 p.m. UTC | #1
On 02/12/2020 00:33, Huang Pei wrote:
> MIPS R2 only support 32 bit TSC(AKA "rdhwr %0, $2"), but it should be
> enough for glibc.
> 
> DO remember Linux/MIPS added emulation for 'rdhwr %0, $2',when disabled
> or not supported, which would make the precision worse. If you got
> unreasonable result, check your CPU Manual for whether your CPU
> implemented it or not

Could you confirm that all MIPS R2 machine do implement this instruction?
I don't want to slow down the loader for such machine, if they exists.

Patch looks ok, some indentation fixes below.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/mips/hp-timing.h | 44 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
>  create mode 100644 sysdeps/mips/hp-timing.h
> 
> diff --git a/sysdeps/mips/hp-timing.h b/sysdeps/mips/hp-timing.h
> new file mode 100644
> index 0000000000..43cb695f2f
> --- /dev/null
> +++ b/sysdeps/mips/hp-timing.h
> @@ -0,0 +1,44 @@
> +/* High precision, low overhead timing functions. MIPS version.
> +   Copyright (C) 2020 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +   Contributed by Huang Pei <huangpei@loongson.cn>, 2020.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef _HP_TIMING_MIPS_H
> +#define _HP_TIMING_MIPS_H	1
> +
> +#if IS_IN(rtld) && __mips_isa_rev >= 2
> +/* MIPS R2 always have the timestamp register. but it's got only 8 seconds
> + * range, assuming half of cpu frequence 800Mhz . Use it for ld.so
> + * profiling only*/
> +#define HP_TIMING_INLINE	(1)

Missing onne space indentation for preprocessor. 

> +
> +/* We use 32bit values for the times.  */
> +typedef unsigned int hp_timing_t;
> +
> +/* Read the cp0 count, this maybe inaccurate.  */
> +#define HP_TIMING_NOW(Var) \
> +  ({ unsigned int _count; \
> +     asm volatile ("rdhwr\t%0,$2" : "=r" (_count)); \
> +     (Var) = _count; })

Same as before.

> +
> +# include <hp-timing-common.h>
> +
> +#else
> +# include <sysdeps/generic/hp-timing.h>
> +#endif /* IS_IN(rtld) && __mips_isa_rev >= 2 */
> +
> +#endif /* hp-timing.h */
>
Maciej W. Rozycki Dec. 4, 2020, 11:05 a.m. UTC | #2
On Wed, 2 Dec 2020, Huang Pei wrote:

> MIPS R2 only support 32 bit TSC(AKA "rdhwr %0, $2"), but it should be
> enough for glibc.
> 
> DO remember Linux/MIPS added emulation for 'rdhwr %0, $2',when disabled
> or not supported, which would make the precision worse. If you got
> unreasonable result, check your CPU Manual for whether your CPU
> implemented it or not

 As discussed previously please rewrite the change description so as not 
to mislead with irrelevant information.

  Maciej
Huang Pei Dec. 5, 2020, 2:26 a.m. UTC | #3
On Fri, Dec 04, 2020 at 11:05:54AM +0000, Maciej W. Rozycki wrote:
> On Wed, 2 Dec 2020, Huang Pei wrote:
> 
> > MIPS R2 only support 32 bit TSC(AKA "rdhwr %0, $2"), but it should be
> > enough for glibc.
> > 
> > DO remember Linux/MIPS added emulation for 'rdhwr %0, $2',when disabled
> > or not supported, which would make the precision worse. If you got
> > unreasonable result, check your CPU Manual for whether your CPU
> > implemented it or not
> 
>  As discussed previously please rewrite the change description so as not 
> to mislead with irrelevant information.
> 
>   Maciej

What about this one?

......

MIPS R2 only support 32 bit TSC(AKA "rdhwr %0, $2"), but it should be
enough for glibc.

"rhdwr/CP0 Hwena and kerel/hypervisor emulation" makes userspace CAN NOT
tell whether rdhwr is not enabled(AKA CP0 Hwena bit[2] is not set, so 
kernel/hypervisor emulated it) or not implemented but still emulated by
kernel/hypervisor, however, it DO "feel something is wrong with rdhwr" by
specific test(like computing the difference between the results of two
nearby rdhwr)

If you get unreasonable result, check your environment(CPU manual,
kernel, hypervisor)
......
diff mbox series

Patch

diff --git a/sysdeps/mips/hp-timing.h b/sysdeps/mips/hp-timing.h
new file mode 100644
index 0000000000..43cb695f2f
--- /dev/null
+++ b/sysdeps/mips/hp-timing.h
@@ -0,0 +1,44 @@ 
+/* High precision, low overhead timing functions. MIPS version.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Huang Pei <huangpei@loongson.cn>, 2020.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _HP_TIMING_MIPS_H
+#define _HP_TIMING_MIPS_H	1
+
+#if IS_IN(rtld) && __mips_isa_rev >= 2
+/* MIPS R2 always have the timestamp register. but it's got only 8 seconds
+ * range, assuming half of cpu frequence 800Mhz . Use it for ld.so
+ * profiling only*/
+#define HP_TIMING_INLINE	(1)
+
+/* We use 32bit values for the times.  */
+typedef unsigned int hp_timing_t;
+
+/* Read the cp0 count, this maybe inaccurate.  */
+#define HP_TIMING_NOW(Var) \
+  ({ unsigned int _count; \
+     asm volatile ("rdhwr\t%0,$2" : "=r" (_count)); \
+     (Var) = _count; })
+
+# include <hp-timing-common.h>
+
+#else
+# include <sysdeps/generic/hp-timing.h>
+#endif /* IS_IN(rtld) && __mips_isa_rev >= 2 */
+
+#endif /* hp-timing.h */