ckrm-E15 memory controller
[linux-2.6.git] / include / asm-i386 / relay.h
1 #ifndef _ASM_I386_RELAY_H
2 #define _ASM_I386_RELAY_H
3 /*
4  * linux/include/asm-i386/relay.h
5  *
6  * Copyright (C) 2002, 2003 - Tom Zanussi (zanussi@us.ibm.com), IBM Corp
7  * Copyright (C) 2002 - Karim Yaghmour (karim@opersys.com)
8  *
9  * i386 definitions for relayfs
10  */
11
12 #include <linux/relayfs_fs.h>
13
14 #ifdef CONFIG_X86_TSC
15 #include <asm/msr.h>
16
17 /**
18  *      get_time_delta - utility function for getting time delta
19  *      @now: pointer to a timeval struct that may be given current time
20  *      @rchan: the channel
21  *
22  *      Returns either the TSC if TSCs are being used, or the time and the
23  *      time difference between the current time and the buffer start time 
24  *      if TSCs are not being used.
25  */
26 static inline u32
27 get_time_delta(struct timeval *now, struct rchan *rchan)
28 {
29         u32 time_delta;
30
31         if ((using_tsc(rchan) == 1) && cpu_has_tsc)
32                 rdtscl(time_delta);
33         else {
34                 do_gettimeofday(now);
35                 time_delta = calc_time_delta(now, &rchan->buf_start_time);
36         }
37
38         return time_delta;
39 }
40
41 /**
42  *      get_timestamp - utility function for getting a time and TSC pair
43  *      @now: current time
44  *      @tsc: the TSC associated with now
45  *      @rchan: the channel
46  *
47  *      Sets the value pointed to by now to the current time and the value
48  *      pointed to by tsc to the tsc associated with that time, if the 
49  *      platform supports TSC.
50  */
51 static inline void 
52 get_timestamp(struct timeval *now,
53               u32 *tsc,
54               struct rchan *rchan)
55 {
56         do_gettimeofday(now);
57
58         if ((using_tsc(rchan) == 1) && cpu_has_tsc)
59                 rdtscl(*tsc);
60 }
61
62 /**
63  *      get_time_or_tsc - utility function for getting a time or a TSC
64  *      @now: current time
65  *      @tsc: current TSC
66  *      @rchan: the channel
67  *
68  *      Sets the value pointed to by now to the current time or the value
69  *      pointed to by tsc to the current tsc, depending on whether we're
70  *      using TSCs or not.
71  */
72 static inline void 
73 get_time_or_tsc(struct timeval *now,
74                 u32 *tsc,
75                 struct rchan *rchan)
76 {
77         if ((using_tsc(rchan) == 1) && cpu_has_tsc)
78                 rdtscl(*tsc);
79         else
80                 do_gettimeofday(now);
81 }
82
83 /**
84  *      have_tsc - does this platform have a useable TSC?
85  *
86  *      Returns 1 if this platform has a useable TSC counter for
87  *      timestamping purposes, 0 otherwise.
88  */
89 static inline int
90 have_tsc(void)
91 {
92         if (cpu_has_tsc)
93                 return 1;
94         else
95                 return 0;
96 }
97
98 #else /* No TSC support (#ifdef CONFIG_X86_TSC) */
99 #include <asm-generic/relay.h>
100 #endif /* #ifdef CONFIG_X86_TSC */
101 #endif