linux/arch/s390/include/asm/cputime.h
<<
>>
Prefs
   1/*
   2 *  Copyright IBM Corp. 2004
   3 *
   4 *  Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
   5 */
   6
   7#ifndef _S390_CPUTIME_H
   8#define _S390_CPUTIME_H
   9
  10#include <linux/types.h>
  11#include <asm/div64.h>
  12
  13#define CPUTIME_PER_USEC 4096ULL
  14#define CPUTIME_PER_SEC (CPUTIME_PER_USEC * USEC_PER_SEC)
  15
  16/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
  17
  18typedef unsigned long long __nocast cputime_t;
  19typedef unsigned long long __nocast cputime64_t;
  20
  21#define cmpxchg_cputime(ptr, old, new) cmpxchg64(ptr, old, new)
  22
  23static inline unsigned long __div(unsigned long long n, unsigned long base)
  24{
  25#ifndef CONFIG_64BIT
  26        register_pair rp;
  27
  28        rp.pair = n >> 1;
  29        asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1));
  30        return rp.subreg.odd;
  31#else /* CONFIG_64BIT */
  32        return n / base;
  33#endif /* CONFIG_64BIT */
  34}
  35
  36#define cputime_one_jiffy               jiffies_to_cputime(1)
  37
  38/*
  39 * Convert cputime to jiffies and back.
  40 */
  41static inline unsigned long cputime_to_jiffies(const cputime_t cputime)
  42{
  43        return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / HZ);
  44}
  45
  46static inline cputime_t jiffies_to_cputime(const unsigned int jif)
  47{
  48        return (__force cputime_t)(jif * (CPUTIME_PER_SEC / HZ));
  49}
  50
  51static inline u64 cputime64_to_jiffies64(cputime64_t cputime)
  52{
  53        unsigned long long jif = (__force unsigned long long) cputime;
  54        do_div(jif, CPUTIME_PER_SEC / HZ);
  55        return jif;
  56}
  57
  58static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
  59{
  60        return (__force cputime64_t)(jif * (CPUTIME_PER_SEC / HZ));
  61}
  62
  63/*
  64 * Convert cputime to microseconds and back.
  65 */
  66static inline unsigned int cputime_to_usecs(const cputime_t cputime)
  67{
  68        return (__force unsigned long long) cputime >> 12;
  69}
  70
  71static inline cputime_t usecs_to_cputime(const unsigned int m)
  72{
  73        return (__force cputime_t)(m * CPUTIME_PER_USEC);
  74}
  75
  76#define usecs_to_cputime64(m)           usecs_to_cputime(m)
  77
  78/*
  79 * Convert cputime to milliseconds and back.
  80 */
  81static inline unsigned int cputime_to_secs(const cputime_t cputime)
  82{
  83        return __div((__force unsigned long long) cputime, CPUTIME_PER_SEC / 2) >> 1;
  84}
  85
  86static inline cputime_t secs_to_cputime(const unsigned int s)
  87{
  88        return (__force cputime_t)(s * CPUTIME_PER_SEC);
  89}
  90
  91/*
  92 * Convert cputime to timespec and back.
  93 */
  94static inline cputime_t timespec_to_cputime(const struct timespec *value)
  95{
  96        unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
  97        return (__force cputime_t)(ret + __div(value->tv_nsec * CPUTIME_PER_USEC, NSEC_PER_USEC));
  98}
  99
 100static inline void cputime_to_timespec(const cputime_t cputime,
 101                                       struct timespec *value)
 102{
 103        unsigned long long __cputime = (__force unsigned long long) cputime;
 104#ifndef CONFIG_64BIT
 105        register_pair rp;
 106
 107        rp.pair = __cputime >> 1;
 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;
 110        value->tv_sec = rp.subreg.odd;
 111#else
 112        value->tv_nsec = (__cputime % CPUTIME_PER_SEC) * NSEC_PER_USEC / CPUTIME_PER_USEC;
 113        value->tv_sec = __cputime / CPUTIME_PER_SEC;
 114#endif
 115}
 116
 117/*
 118 * Convert cputime to timeval and back.
 119 * Since cputime and timeval have the same resolution (microseconds)
 120 * this is easy.
 121 */
 122static inline cputime_t timeval_to_cputime(const struct timeval *value)
 123{
 124        unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
 125        return (__force cputime_t)(ret + value->tv_usec * CPUTIME_PER_USEC);
 126}
 127
 128static inline void cputime_to_timeval(const cputime_t cputime,
 129                                      struct timeval *value)
 130{
 131        unsigned long long __cputime = (__force unsigned long long) cputime;
 132#ifndef CONFIG_64BIT
 133        register_pair rp;
 134
 135        rp.pair = __cputime >> 1;
 136        asm ("dr %0,%1" : "+d" (rp) : "d" (CPUTIME_PER_USEC / 2));
 137        value->tv_usec = rp.subreg.even / CPUTIME_PER_USEC;
 138        value->tv_sec = rp.subreg.odd;
 139#else
 140        value->tv_usec = (__cputime % CPUTIME_PER_SEC) / CPUTIME_PER_USEC;
 141        value->tv_sec = __cputime / CPUTIME_PER_SEC;
 142#endif
 143}
 144
 145/*
 146 * Convert cputime to clock and back.
 147 */
 148static inline clock_t cputime_to_clock_t(cputime_t cputime)
 149{
 150        unsigned long long clock = (__force unsigned long long) cputime;
 151        do_div(clock, CPUTIME_PER_SEC / USER_HZ);
 152        return clock;
 153}
 154
 155static inline cputime_t clock_t_to_cputime(unsigned long x)
 156{
 157        return (__force cputime_t)(x * (CPUTIME_PER_SEC / USER_HZ));
 158}
 159
 160/*
 161 * Convert cputime64 to clock.
 162 */
 163static inline clock_t cputime64_to_clock_t(cputime64_t cputime)
 164{
 165        unsigned long long clock = (__force unsigned long long) cputime;
 166        do_div(clock, CPUTIME_PER_SEC / USER_HZ);
 167        return clock;
 168}
 169
 170cputime64_t arch_cpu_idle_time(int cpu);
 171
 172#define arch_idle_time(cpu) arch_cpu_idle_time(cpu)
 173
 174#endif /* _S390_CPUTIME_H */
 175