Skip to content

Commit 8461b63

Browse files
fweisbecMartin Schwidefsky
authored andcommitted
s390: translate cputime magic constants to macros
Make the code more self-explanatory by naming magic constants. Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 1ce2180 commit 8461b63

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

‎arch/s390/include/asm/cputime.h‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <linux/types.h>
1111
#include <asm/div64.h>
1212

13+
#define CPUTIME_PER_USEC 4096ULL
14+
#define CPUTIME_PER_SEC (CPUTIME_PER_USEC * USEC_PER_SEC)
1315

1416
/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
1517

@@ -38,24 +40,24 @@ static inline unsigned long __div(unsigned long long n, unsigned long base)
3840
*/
3941
static inline unsigned long cputime_to_jiffies(const cputime_t cputime)
4042
{
41-
return __div((__force unsigned long long) cputime, 4096000000ULL / HZ);
43+
return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / HZ);
4244
}
4345

4446
static inline cputime_t jiffies_to_cputime(const unsigned int jif)
4547
{
46-
return (__force cputime_t)(jif * (4096000000ULL / HZ));
48+
return (__force cputime_t)(jif * (CPUTIME_PER_SEC / HZ));
4749
}
4850

4951
static inline u64 cputime64_to_jiffies64(cputime64_t cputime)
5052
{
5153
unsigned long long jif = (__force unsigned long long) cputime;
52-
do_div(jif, 4096000000ULL / HZ);
54+
do_div(jif, CPUTIME_PER_SEC / HZ);
5355
return jif;
5456
}
5557

5658
static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
5759
{
58-
return (__force cputime64_t)(jif * (4096000000ULL / HZ));
60+
return (__force cputime64_t)(jif * (CPUTIME_PER_SEC / HZ));
5961
}
6062

6163
/*
@@ -68,7 +70,7 @@ static inline unsigned int cputime_to_usecs(const cputime_t cputime)
6870

6971
static inline cputime_t usecs_to_cputime(const unsigned int m)
7072
{
71-
return (__force cputime_t)(m * 4096ULL);
73+
return (__force cputime_t)(m * CPUTIME_PER_USEC);
7274
}
7375

7476
#define usecs_to_cputime64(m) usecs_to_cputime(m)
@@ -78,21 +80,21 @@ static inline cputime_t usecs_to_cputime(const unsigned int m)
7880
*/
7981
static inline unsigned int cputime_to_secs(const cputime_t cputime)
8082
{
81-
return __div((__force unsigned long long) cputime, 2048000000) >> 1;
83+
return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / 2) >> 1;
8284
}
8385

8486
static inline cputime_t secs_to_cputime(const unsigned int s)
8587
{
86-
return (__force cputime_t)(s * 4096000000ULL);
88+
return (__force cputime_t)(s * CPUTIME_PER_SEC);
8789
}
8890

8991
/*
9092
* Convert cputime to timespec and back.
9193
*/
9294
static inline cputime_t timespec_to_cputime(const struct timespec *value)
9395
{
94-
unsigned long long ret = value->tv_sec * 4096000000ULL;
95-
return (__force cputime_t)(ret + value->tv_nsec * 4096 / 1000);
96+
unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
97+
return (__force cputime_t)(ret + (value->tv_nsec * CPUTIME_PER_USEC) / NSEC_PER_USEC);
9698
}
9799

98100
static inline void cputime_to_timespec(const cputime_t cputime,
@@ -103,12 +105,12 @@ static inline void cputime_to_timespec(const cputime_t cputime,
103105
register_pair rp;
104106

105107
rp.pair = __cputime >> 1;
106-
asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
107-
value->tv_nsec = rp.subreg.even * 1000 / 4096;
108+
asm ("dr %0,%1" : "+d" (rp) : "d" (CPUTIME_PER_SEC / 2));
109+
value->tv_nsec = rp.subreg.even * NSEC_PER_USEC / CPUTIME_PER_USEC;
108110
value->tv_sec = rp.subreg.odd;
109111
#else
110-
value->tv_nsec = (__cputime % 4096000000ULL) * 1000 / 4096;
111-
value->tv_sec = __cputime / 4096000000ULL;
112+
value->tv_nsec = (__cputime % CPUTIME_PER_SEC) * NSEC_PER_USEC / CPUTIME_PER_USEC;
113+
value->tv_sec = __cputime / CPUTIME_PER_SEC;
112114
#endif
113115
}
114116

@@ -119,8 +121,8 @@ static inline void cputime_to_timespec(const cputime_t cputime,
119121
*/
120122
static inline cputime_t timeval_to_cputime(const struct timeval *value)
121123
{
122-
unsigned long long ret = value->tv_sec * 4096000000ULL;
123-
return (__force cputime_t)(ret + value->tv_usec * 4096ULL);
124+
unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
125+
return (__force cputime_t)(ret + value->tv_usec * CPUTIME_PER_USEC);
124126
}
125127

126128
static inline void cputime_to_timeval(const cputime_t cputime,
@@ -131,12 +133,12 @@ static inline void cputime_to_timeval(const cputime_t cputime,
131133
register_pair rp;
132134

133135
rp.pair = __cputime >> 1;
134-
asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
135-
value->tv_usec = rp.subreg.even / 4096;
136+
asm ("dr %0,%1" : "+d" (rp) : "d" (CPUTIME_PER_USEC / 2));
137+
value->tv_usec = rp.subreg.even / CPUTIME_PER_USEC;
136138
value->tv_sec = rp.subreg.odd;
137139
#else
138-
value->tv_usec = (__cputime % 4096000000ULL) / 4096;
139-
value->tv_sec = __cputime / 4096000000ULL;
140+
value->tv_usec = (__cputime % CPUTIME_PER_SEC) / CPUTIME_PER_USEC;
141+
value->tv_sec = __cputime / CPUTIME_PER_SEC;
140142
#endif
141143
}
142144

@@ -146,13 +148,13 @@ static inline void cputime_to_timeval(const cputime_t cputime,
146148
static inline clock_t cputime_to_clock_t(cputime_t cputime)
147149
{
148150
unsigned long long clock = (__force unsigned long long) cputime;
149-
do_div(clock, 4096000000ULL / USER_HZ);
151+
do_div(clock, CPUTIME_PER_SEC / USER_HZ);
150152
return clock;
151153
}
152154

153155
static inline cputime_t clock_t_to_cputime(unsigned long x)
154156
{
155-
return (__force cputime_t)(x * (4096000000ULL / USER_HZ));
157+
return (__force cputime_t)(x * (CPUTIME_PER_SEC / USER_HZ));
156158
}
157159

158160
/*
@@ -161,7 +163,7 @@ static inline cputime_t clock_t_to_cputime(unsigned long x)
161163
static inline clock_t cputime64_to_clock_t(cputime64_t cputime)
162164
{
163165
unsigned long long clock = (__force unsigned long long) cputime;
164-
do_div(clock, 4096000000ULL / USER_HZ);
166+
do_div(clock, CPUTIME_PER_SEC / USER_HZ);
165167
return clock;
166168
}
167169

0 commit comments

Comments
 (0)