aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/include/asm/cycles.h23
-rw-r--r--arch/sparc/include/asm/cycles.h16
-rw-r--r--arch/x86/include/asm/cycles.h30
-rw-r--r--arch/x86/include/asm/irq.h15
4 files changed, 84 insertions, 0 deletions
diff --git a/arch/arm/include/asm/cycles.h b/arch/arm/include/asm/cycles.h
new file mode 100644
index 0000000..73632f8
--- /dev/null
+++ b/arch/arm/include/asm/cycles.h
@@ -0,0 +1,23 @@
1#ifndef ASM_CYCLES_H
2#define ASM_CYCLES_H
3
4typedef unsigned long cycles_t;
5
6#define CYCLES_FMT "lu"
7
8/* system call wrapper */
9int null_call(cycles_t *timestamp);
10
11static inline cycles_t get_cycles(void)
12{
13 cycles_t c;
14 /* On the ARM11 MPCore chips, userspace cannot access the cycle counter
15 * directly. So ask the kernel to read it instead. Eventually, this
16 * should support newer ARM chips that do allow accessing the cycle
17 * counter in userspace.
18 */
19 null_call(&c);
20 return c;
21}
22
23#endif
diff --git a/arch/sparc/include/asm/cycles.h b/arch/sparc/include/asm/cycles.h
new file mode 100644
index 0000000..ce0e8ce
--- /dev/null
+++ b/arch/sparc/include/asm/cycles.h
@@ -0,0 +1,16 @@
1#ifndef ASM_CYCLES_H
2#define ASM_CYCLES_H
3
4#define NPT_BIT 63
5
6typedef unsigned long cycles_t;
7
8#define CYCLES_FMT "lu"
9
10static inline cycles_t get_cycles(void) {
11 cycles_t cycles = 0;
12 __asm__ __volatile__("rd %%asr24, %0" : "=r" (cycles));
13 return cycles & ~(1UL << NPT_BIT);
14}
15
16#endif
diff --git a/arch/x86/include/asm/cycles.h b/arch/x86/include/asm/cycles.h
new file mode 100644
index 0000000..00a7593
--- /dev/null
+++ b/arch/x86/include/asm/cycles.h
@@ -0,0 +1,30 @@
1#ifndef ASM_CYCLES_H
2#define ASM_CYCLES_H
3
4#define rdtscll(val) do { \
5 unsigned int __a,__d; \
6 __asm__ __volatile__("rdtsc" : "=a" (__a), "=d" (__d)); \
7 (val) = ((unsigned long long)__a) | (((unsigned long long)__d)<<32); \
8} while(0)
9
10static __inline__ unsigned long long native_read_tsc(void)
11{
12 unsigned long long val;
13
14 __asm__ __volatile__("mfence":::"memory");
15 rdtscll(val);
16 __asm__ __volatile__("mfence":::"memory");
17
18 return val;
19}
20
21#define CYCLES_FMT "llu"
22
23typedef unsigned long long cycles_t;
24
25static inline cycles_t get_cycles(void)
26{
27 return native_read_tsc();
28}
29
30#endif
diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h
new file mode 100644
index 0000000..23f47fd
--- /dev/null
+++ b/arch/x86/include/asm/irq.h
@@ -0,0 +1,15 @@
1#ifndef ASM_IRQ_H
2#define ASM_IRQ_H
3
4/* please, use these only if you _really_ know what you're doing
5 * ... and remember iopl(3) first!! (include sys/io.h)
6 */
7static inline void cli(void) {
8 asm volatile("cli": : :"memory");
9}
10
11static inline void sti(void) {
12 asm volatile("sti": : :"memory");
13}
14
15#endif