]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/ia64/include/asm/cputime.h
ia64, sched/cputime: Move the nsecs based cputime headers to the last arch using it
[linux.git] / arch / ia64 / include / asm / cputime.h
1 /*
2  * Definitions for measuring cputime on ia64 machines.
3  *
4  * Based on <asm-powerpc/cputime.h>.
5  *
6  * Copyright (C) 2007 FUJITSU LIMITED
7  * Copyright (C) 2007 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version
12  * 2 of the License, or (at your option) any later version.
13  *
14  * If we have CONFIG_VIRT_CPU_ACCOUNTING_NATIVE, we measure cpu time in nsec.
15  * Otherwise we measure cpu time in jiffies using the generic definitions.
16  */
17
18 #ifndef __IA64_CPUTIME_H
19 #define __IA64_CPUTIME_H
20
21 #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
22 # include <asm-generic/cputime.h>
23
24 #else
25
26 #include <asm/processor.h>
27 #include <linux/math64.h>
28
29 typedef u64 __nocast cputime_t;
30 typedef u64 __nocast cputime64_t;
31
32 #define cmpxchg_cputime(ptr, old, new) cmpxchg64(ptr, old, new)
33
34 #define cputime_one_jiffy               jiffies_to_cputime(1)
35
36 #define cputime_div(__ct, divisor)  div_u64((__force u64)__ct, divisor)
37 #define cputime_div_rem(__ct, divisor, remainder) \
38         div_u64_rem((__force u64)__ct, divisor, remainder);
39
40 /*
41  * Convert cputime <-> jiffies (HZ)
42  */
43 #define cputime_to_jiffies(__ct)        \
44         cputime_div(__ct, NSEC_PER_SEC / HZ)
45 #define jiffies_to_cputime(__jif)       \
46         (__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ))
47 #define cputime64_to_jiffies64(__ct)    \
48         cputime_div(__ct, NSEC_PER_SEC / HZ)
49 #define jiffies64_to_cputime64(__jif)   \
50         (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ))
51
52
53 /*
54  * Convert cputime <-> nanoseconds
55  */
56 #define cputime_to_nsecs(__ct)          \
57         (__force u64)(__ct)
58 #define nsecs_to_cputime(__nsecs)       \
59         (__force cputime_t)(__nsecs)
60 #define nsecs_to_cputime64(__nsecs)     \
61         (__force cputime64_t)(__nsecs)
62
63
64 /*
65  * Convert cputime <-> microseconds
66  */
67 #define cputime_to_usecs(__ct)          \
68         cputime_div(__ct, NSEC_PER_USEC)
69 #define usecs_to_cputime(__usecs)       \
70         (__force cputime_t)((__usecs) * NSEC_PER_USEC)
71 #define usecs_to_cputime64(__usecs)     \
72         (__force cputime64_t)((__usecs) * NSEC_PER_USEC)
73
74 /*
75  * Convert cputime <-> seconds
76  */
77 #define cputime_to_secs(__ct)           \
78         cputime_div(__ct, NSEC_PER_SEC)
79 #define secs_to_cputime(__secs)         \
80         (__force cputime_t)((__secs) * NSEC_PER_SEC)
81
82 /*
83  * Convert cputime <-> timespec (nsec)
84  */
85 static inline cputime_t timespec_to_cputime(const struct timespec *val)
86 {
87         u64 ret = (u64)val->tv_sec * NSEC_PER_SEC + val->tv_nsec;
88         return (__force cputime_t) ret;
89 }
90 static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val)
91 {
92         u32 rem;
93
94         val->tv_sec = cputime_div_rem(ct, NSEC_PER_SEC, &rem);
95         val->tv_nsec = rem;
96 }
97
98 /*
99  * Convert cputime <-> timeval (msec)
100  */
101 static inline cputime_t timeval_to_cputime(const struct timeval *val)
102 {
103         u64 ret = (u64)val->tv_sec * NSEC_PER_SEC +
104                         val->tv_usec * NSEC_PER_USEC;
105         return (__force cputime_t) ret;
106 }
107 static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val)
108 {
109         u32 rem;
110
111         val->tv_sec = cputime_div_rem(ct, NSEC_PER_SEC, &rem);
112         val->tv_usec = rem / NSEC_PER_USEC;
113 }
114
115 /*
116  * Convert cputime <-> clock (USER_HZ)
117  */
118 #define cputime_to_clock_t(__ct)        \
119         cputime_div(__ct, (NSEC_PER_SEC / USER_HZ))
120 #define clock_t_to_cputime(__x)         \
121         (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ))
122
123 /*
124  * Convert cputime64 to clock.
125  */
126 #define cputime64_to_clock_t(__ct)      \
127         cputime_to_clock_t((__force cputime_t)__ct)
128
129
130 extern void arch_vtime_task_switch(struct task_struct *tsk);
131 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
132
133 #endif /* __IA64_CPUTIME_H */