Merge tag 'pm+acpi-4.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux/fpc-iii.git] / arch / s390 / include / asm / cputime.h
blob221b454c734a24481c02aee8e0168d0e11f1fec7
1 /*
2 * Copyright IBM Corp. 2004
4 * Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
5 */
7 #ifndef _S390_CPUTIME_H
8 #define _S390_CPUTIME_H
10 #include <linux/types.h>
11 #include <asm/div64.h>
13 #define CPUTIME_PER_USEC 4096ULL
14 #define CPUTIME_PER_SEC (CPUTIME_PER_USEC * USEC_PER_SEC)
16 /* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
18 typedef unsigned long long __nocast cputime_t;
19 typedef unsigned long long __nocast cputime64_t;
21 #define cmpxchg_cputime(ptr, old, new) cmpxchg64(ptr, old, new)
23 static inline unsigned long __div(unsigned long long n, unsigned long base)
25 return n / base;
28 #define cputime_one_jiffy jiffies_to_cputime(1)
31 * Convert cputime to jiffies and back.
33 static inline unsigned long cputime_to_jiffies(const cputime_t cputime)
35 return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / HZ);
38 static inline cputime_t jiffies_to_cputime(const unsigned int jif)
40 return (__force cputime_t)(jif * (CPUTIME_PER_SEC / HZ));
43 static inline u64 cputime64_to_jiffies64(cputime64_t cputime)
45 unsigned long long jif = (__force unsigned long long) cputime;
46 do_div(jif, CPUTIME_PER_SEC / HZ);
47 return jif;
50 static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
52 return (__force cputime64_t)(jif * (CPUTIME_PER_SEC / HZ));
56 * Convert cputime to microseconds and back.
58 static inline unsigned int cputime_to_usecs(const cputime_t cputime)
60 return (__force unsigned long long) cputime >> 12;
63 static inline cputime_t usecs_to_cputime(const unsigned int m)
65 return (__force cputime_t)(m * CPUTIME_PER_USEC);
68 #define usecs_to_cputime64(m) usecs_to_cputime(m)
71 * Convert cputime to milliseconds and back.
73 static inline unsigned int cputime_to_secs(const cputime_t cputime)
75 return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / 2) >> 1;
78 static inline cputime_t secs_to_cputime(const unsigned int s)
80 return (__force cputime_t)(s * CPUTIME_PER_SEC);
84 * Convert cputime to timespec and back.
86 static inline cputime_t timespec_to_cputime(const struct timespec *value)
88 unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
89 return (__force cputime_t)(ret + __div(value->tv_nsec * CPUTIME_PER_USEC, NSEC_PER_USEC));
92 static inline void cputime_to_timespec(const cputime_t cputime,
93 struct timespec *value)
95 unsigned long long __cputime = (__force unsigned long long) cputime;
96 value->tv_nsec = (__cputime % CPUTIME_PER_SEC) * NSEC_PER_USEC / CPUTIME_PER_USEC;
97 value->tv_sec = __cputime / CPUTIME_PER_SEC;
101 * Convert cputime to timeval and back.
102 * Since cputime and timeval have the same resolution (microseconds)
103 * this is easy.
105 static inline cputime_t timeval_to_cputime(const struct timeval *value)
107 unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
108 return (__force cputime_t)(ret + value->tv_usec * CPUTIME_PER_USEC);
111 static inline void cputime_to_timeval(const cputime_t cputime,
112 struct timeval *value)
114 unsigned long long __cputime = (__force unsigned long long) cputime;
115 value->tv_usec = (__cputime % CPUTIME_PER_SEC) / CPUTIME_PER_USEC;
116 value->tv_sec = __cputime / CPUTIME_PER_SEC;
120 * Convert cputime to clock and back.
122 static inline clock_t cputime_to_clock_t(cputime_t cputime)
124 unsigned long long clock = (__force unsigned long long) cputime;
125 do_div(clock, CPUTIME_PER_SEC / USER_HZ);
126 return clock;
129 static inline cputime_t clock_t_to_cputime(unsigned long x)
131 return (__force cputime_t)(x * (CPUTIME_PER_SEC / USER_HZ));
135 * Convert cputime64 to clock.
137 static inline clock_t cputime64_to_clock_t(cputime64_t cputime)
139 unsigned long long clock = (__force unsigned long long) cputime;
140 do_div(clock, CPUTIME_PER_SEC / USER_HZ);
141 return clock;
144 cputime64_t arch_cpu_idle_time(int cpu);
146 #define arch_idle_time(cpu) arch_cpu_idle_time(cpu)
148 #endif /* _S390_CPUTIME_H */