s390/percpu: remove this_cpu_cmpxchg_double_4
[deliverable/linux.git] / arch / s390 / include / asm / cputime.h
CommitLineData
1da177e4 1/*
a53c8fab 2 * Copyright IBM Corp. 2004
1da177e4
LT
3 *
4 * Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
5 */
6
7#ifndef _S390_CPUTIME_H
8#define _S390_CPUTIME_H
9
76d4e00a 10#include <linux/types.h>
1da177e4
LT
11#include <asm/div64.h>
12
8461b63c
FW
13#define CPUTIME_PER_USEC 4096ULL
14#define CPUTIME_PER_SEC (CPUTIME_PER_USEC * USEC_PER_SEC)
a7e1a9e3 15
aa5e97ce 16/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
1da177e4 17
64861634
MS
18typedef unsigned long long __nocast cputime_t;
19typedef unsigned long long __nocast cputime64_t;
1da177e4 20
347abad9
RR
21#define cmpxchg_cputime(ptr, old, new) cmpxchg64(ptr, old, new)
22
64861634 23static inline unsigned long __div(unsigned long long n, unsigned long base)
1da177e4 24{
64861634 25 return n / base;
1da177e4
LT
26}
27
64861634 28#define cputime_one_jiffy jiffies_to_cputime(1)
1da177e4 29
64861634
MS
30/*
31 * Convert cputime to jiffies and back.
32 */
33static inline unsigned long cputime_to_jiffies(const cputime_t cputime)
1da177e4 34{
8461b63c 35 return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / HZ);
1da177e4
LT
36}
37
64861634
MS
38static inline cputime_t jiffies_to_cputime(const unsigned int jif)
39{
8461b63c 40 return (__force cputime_t)(jif * (CPUTIME_PER_SEC / HZ));
64861634 41}
1da177e4 42
64861634
MS
43static inline u64 cputime64_to_jiffies64(cputime64_t cputime)
44{
45 unsigned long long jif = (__force unsigned long long) cputime;
8461b63c 46 do_div(jif, CPUTIME_PER_SEC / HZ);
64861634
MS
47 return jif;
48}
49
50static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
51{
8461b63c 52 return (__force cputime64_t)(jif * (CPUTIME_PER_SEC / HZ));
1da177e4
LT
53}
54
55/*
d57af9b2 56 * Convert cputime to microseconds and back.
1da177e4 57 */
64861634 58static inline unsigned int cputime_to_usecs(const cputime_t cputime)
1da177e4 59{
64861634 60 return (__force unsigned long long) cputime >> 12;
1da177e4
LT
61}
62
64861634 63static inline cputime_t usecs_to_cputime(const unsigned int m)
1da177e4 64{
8461b63c 65 return (__force cputime_t)(m * CPUTIME_PER_USEC);
1da177e4
LT
66}
67
34845636
AS
68#define usecs_to_cputime64(m) usecs_to_cputime(m)
69
1da177e4
LT
70/*
71 * Convert cputime to milliseconds and back.
72 */
64861634 73static inline unsigned int cputime_to_secs(const cputime_t cputime)
1da177e4 74{
8461b63c 75 return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / 2) >> 1;
1da177e4
LT
76}
77
64861634 78static inline cputime_t secs_to_cputime(const unsigned int s)
1da177e4 79{
8461b63c 80 return (__force cputime_t)(s * CPUTIME_PER_SEC);
1da177e4
LT
81}
82
83/*
84 * Convert cputime to timespec and back.
85 */
64861634 86static inline cputime_t timespec_to_cputime(const struct timespec *value)
1da177e4 87{
8461b63c 88 unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
35199781 89 return (__force cputime_t)(ret + __div(value->tv_nsec * CPUTIME_PER_USEC, NSEC_PER_USEC));
1da177e4
LT
90}
91
64861634
MS
92static inline void cputime_to_timespec(const cputime_t cputime,
93 struct timespec *value)
1da177e4 94{
64861634 95 unsigned long long __cputime = (__force unsigned long long) cputime;
8461b63c
FW
96 value->tv_nsec = (__cputime % CPUTIME_PER_SEC) * NSEC_PER_USEC / CPUTIME_PER_USEC;
97 value->tv_sec = __cputime / CPUTIME_PER_SEC;
1da177e4
LT
98}
99
100/*
101 * Convert cputime to timeval and back.
102 * Since cputime and timeval have the same resolution (microseconds)
103 * this is easy.
104 */
64861634 105static inline cputime_t timeval_to_cputime(const struct timeval *value)
1da177e4 106{
8461b63c
FW
107 unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
108 return (__force cputime_t)(ret + value->tv_usec * CPUTIME_PER_USEC);
1da177e4
LT
109}
110
64861634
MS
111static inline void cputime_to_timeval(const cputime_t cputime,
112 struct timeval *value)
1da177e4 113{
64861634 114 unsigned long long __cputime = (__force unsigned long long) cputime;
8461b63c
FW
115 value->tv_usec = (__cputime % CPUTIME_PER_SEC) / CPUTIME_PER_USEC;
116 value->tv_sec = __cputime / CPUTIME_PER_SEC;
1da177e4
LT
117}
118
119/*
120 * Convert cputime to clock and back.
121 */
64861634 122static inline clock_t cputime_to_clock_t(cputime_t cputime)
1da177e4 123{
64861634 124 unsigned long long clock = (__force unsigned long long) cputime;
8461b63c 125 do_div(clock, CPUTIME_PER_SEC / USER_HZ);
64861634 126 return clock;
1da177e4
LT
127}
128
64861634 129static inline cputime_t clock_t_to_cputime(unsigned long x)
1da177e4 130{
8461b63c 131 return (__force cputime_t)(x * (CPUTIME_PER_SEC / USER_HZ));
1da177e4
LT
132}
133
134/*
135 * Convert cputime64 to clock.
136 */
64861634 137static inline clock_t cputime64_to_clock_t(cputime64_t cputime)
1da177e4 138{
64861634 139 unsigned long long clock = (__force unsigned long long) cputime;
8461b63c 140 do_div(clock, CPUTIME_PER_SEC / USER_HZ);
64861634 141 return clock;
1da177e4
LT
142}
143
b5f87f15 144cputime64_t arch_cpu_idle_time(int cpu);
76d4e00a 145
b5f87f15 146#define arch_idle_time(cpu) arch_cpu_idle_time(cpu)
3c5d92a0 147
1da177e4 148#endif /* _S390_CPUTIME_H */
This page took 0.696759 seconds and 5 git commands to generate.