aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2010-11-06 16:36:31 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2010-11-09 16:35:32 -0500
commitf8585fe1fc6f0830f900dad7c8ccc40e17f79644 (patch)
treea89c87d7f2b2002e4ac77ca34b63209ed98d66a1
parent42e747e4fe5648967c1ead5ae327b5fbbe66f2e5 (diff)
refactor: use architecture-specific includes for cycles.h
-rw-r--r--arch/sparc64/include/asm/cycles.h16
-rw-r--r--arch/x86/include/asm/cycles.h30
-rw-r--r--bin/cycles.c2
-rw-r--r--bin/null_call.c1
-rw-r--r--include/cycles.h63
-rw-r--r--include/litmus.h2
6 files changed, 48 insertions, 66 deletions
diff --git a/arch/sparc64/include/asm/cycles.h b/arch/sparc64/include/asm/cycles.h
new file mode 100644
index 0000000..ce0e8ce
--- /dev/null
+++ b/arch/sparc64/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/bin/cycles.c b/bin/cycles.c
index a6b9308..babd073 100644
--- a/bin/cycles.c
+++ b/bin/cycles.c
@@ -2,7 +2,7 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <unistd.h> 3#include <unistd.h>
4 4
5#include "cycles.h" 5#include "asm/cycles.h"
6 6
7int main(int argc, char** argv) 7int main(int argc, char** argv)
8{ 8{
diff --git a/bin/null_call.c b/bin/null_call.c
index 94ba866..61c4629 100644
--- a/bin/null_call.c
+++ b/bin/null_call.c
@@ -5,7 +5,6 @@
5#include <math.h> 5#include <math.h>
6 6
7#include "litmus.h" 7#include "litmus.h"
8#include "cycles.h"
9 8
10static void time_null_call(void) 9static void time_null_call(void)
11{ 10{
diff --git a/include/cycles.h b/include/cycles.h
deleted file mode 100644
index e9b0e11..0000000
--- a/include/cycles.h
+++ /dev/null
@@ -1,63 +0,0 @@
1#ifndef CYCLES_H
2#define CYCLES_H
3
4#ifdef __x86_64__
5
6#define rdtscll(val) do { \
7 unsigned int __a,__d; \
8 __asm__ __volatile__("rdtsc" : "=a" (__a), "=d" (__d)); \
9 (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
10} while(0)
11
12static __inline__ unsigned long long native_read_tsc(void)
13{
14 unsigned long long val;
15
16 __asm__ __volatile__("mfence":::"memory");
17 rdtscll(val);
18 __asm__ __volatile__("mfence":::"memory");
19
20 return val;
21}
22
23
24#define CYCLES_FMT "llu"
25
26typedef unsigned long long cycles_t;
27
28static inline cycles_t get_cycles(void)
29{
30 return native_read_tsc();
31}
32#elif defined __i386__
33static inline unsigned long long native_read_tsc(void) {
34 unsigned long long val;
35 __asm__ __volatile__("rdtsc" : "=A" (val));
36 return val;
37}
38
39typedef unsigned long long cycles_t;
40
41#define CYCLES_FMT "llu"
42
43static inline cycles_t get_cycles(void)
44{
45 return native_read_tsc();
46}
47#elif defined __sparc__
48
49#define NPT_BIT 63
50
51typedef unsigned long cycles_t;
52
53#define CYCLES_FMT "lu"
54
55static inline cycles_t get_cycles(void) {
56 unsigned long cycles = 0;
57 __asm__ __volatile__("rd %%asr24, %0" : "=r" (cycles));
58 return cycles & ~(1UL << NPT_BIT);
59}
60
61#endif
62
63#endif
diff --git a/include/litmus.h b/include/litmus.h
index c4c4129..2a26a4a 100644
--- a/include/litmus.h
+++ b/include/litmus.h
@@ -13,7 +13,7 @@ extern "C" {
13 */ 13 */
14#include "litmus/rt_param.h" 14#include "litmus/rt_param.h"
15 15
16#include "cycles.h" /* for null_call() */ 16#include "asm/cycles.h" /* for null_call() */
17 17
18typedef int pid_t; /* PID of a task */ 18typedef int pid_t; /* PID of a task */
19 19