[PATCH V2 1/2] mips: add hp-timing support for MIPS R2
Huang Pei
huangpei@loongson.cn
Wed Dec 2 03:33:28 GMT 2020
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
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 */
--
2.17.1
More information about the Libc-alpha
mailing list