diff mbox series

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

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

Commit Message

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

Linux/MIPS kernel added emulation for 'rdhwr %0, $2',uncondionally.
Userspace CAN NOT tell directly whether 'rdhwr' is not implemented, or
disabled (by clear bit[2] of CP0 Hwena). If you had any doubt on the
precision of 'rdhwr %0, $2', DO check both your hardware and software
environment(such as in a para-virtualized guest).
---
 sysdeps/mips/hp-timing.h | 44 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 sysdeps/mips/hp-timing.h
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 */