PageRenderTime 14ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/cresqo/cm7-p500-kernel
C Header | 210 lines | 148 code | 34 blank | 28 comment | 3 complexity | d339e5ec5e4eb65fbfcc29b38d55b11d MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /*
  2. * include/asm-s390/cputime.h
  3. *
  4. * (C) Copyright IBM Corp. 2004
  5. *
  6. * Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. */
  8. #ifndef _S390_CPUTIME_H
  9. #define _S390_CPUTIME_H
  10. #include <linux/types.h>
  11. #include <linux/percpu.h>
  12. #include <linux/spinlock.h>
  13. #include <asm/div64.h>
  14. /* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
  15. typedef unsigned long long cputime_t;
  16. typedef unsigned long long cputime64_t;
  17. #ifndef __s390x__
  18. static inline unsigned int
  19. __div(unsigned long long n, unsigned int base)
  20. {
  21. register_pair rp;
  22. rp.pair = n >> 1;
  23. asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1));
  24. return rp.subreg.odd;
  25. }
  26. #else /* __s390x__ */
  27. static inline unsigned int
  28. __div(unsigned long long n, unsigned int base)
  29. {
  30. return n / base;
  31. }
  32. #endif /* __s390x__ */
  33. #define cputime_zero (0ULL)
  34. #define cputime_one_jiffy jiffies_to_cputime(1)
  35. #define cputime_max ((~0UL >> 1) - 1)
  36. #define cputime_add(__a, __b) ((__a) + (__b))
  37. #define cputime_sub(__a, __b) ((__a) - (__b))
  38. #define cputime_div(__a, __n) ({ \
  39. unsigned long long __div = (__a); \
  40. do_div(__div,__n); \
  41. __div; \
  42. })
  43. #define cputime_halve(__a) ((__a) >> 1)
  44. #define cputime_eq(__a, __b) ((__a) == (__b))
  45. #define cputime_gt(__a, __b) ((__a) > (__b))
  46. #define cputime_ge(__a, __b) ((__a) >= (__b))
  47. #define cputime_lt(__a, __b) ((__a) < (__b))
  48. #define cputime_le(__a, __b) ((__a) <= (__b))
  49. #define cputime_to_jiffies(__ct) (__div((__ct), 4096000000ULL / HZ))
  50. #define cputime_to_scaled(__ct) (__ct)
  51. #define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (4096000000ULL / HZ))
  52. #define cputime64_zero (0ULL)
  53. #define cputime64_add(__a, __b) ((__a) + (__b))
  54. #define cputime_to_cputime64(__ct) (__ct)
  55. static inline u64
  56. cputime64_to_jiffies64(cputime64_t cputime)
  57. {
  58. do_div(cputime, 4096000000ULL / HZ);
  59. return cputime;
  60. }
  61. /*
  62. * Convert cputime to milliseconds and back.
  63. */
  64. static inline unsigned int
  65. cputime_to_msecs(const cputime_t cputime)
  66. {
  67. return cputime_div(cputime, 4096000);
  68. }
  69. static inline cputime_t
  70. msecs_to_cputime(const unsigned int m)
  71. {
  72. return (cputime_t) m * 4096000;
  73. }
  74. /*
  75. * Convert cputime to milliseconds and back.
  76. */
  77. static inline unsigned int
  78. cputime_to_secs(const cputime_t cputime)
  79. {
  80. return __div(cputime, 2048000000) >> 1;
  81. }
  82. static inline cputime_t
  83. secs_to_cputime(const unsigned int s)
  84. {
  85. return (cputime_t) s * 4096000000ULL;
  86. }
  87. /*
  88. * Convert cputime to timespec and back.
  89. */
  90. static inline cputime_t
  91. timespec_to_cputime(const struct timespec *value)
  92. {
  93. return value->tv_nsec * 4096 / 1000 + (u64) value->tv_sec * 4096000000ULL;
  94. }
  95. static inline void
  96. cputime_to_timespec(const cputime_t cputime, struct timespec *value)
  97. {
  98. #ifndef __s390x__
  99. register_pair rp;
  100. rp.pair = cputime >> 1;
  101. asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
  102. value->tv_nsec = rp.subreg.even * 1000 / 4096;
  103. value->tv_sec = rp.subreg.odd;
  104. #else
  105. value->tv_nsec = (cputime % 4096000000ULL) * 1000 / 4096;
  106. value->tv_sec = cputime / 4096000000ULL;
  107. #endif
  108. }
  109. /*
  110. * Convert cputime to timeval and back.
  111. * Since cputime and timeval have the same resolution (microseconds)
  112. * this is easy.
  113. */
  114. static inline cputime_t
  115. timeval_to_cputime(const struct timeval *value)
  116. {
  117. return value->tv_usec * 4096 + (u64) value->tv_sec * 4096000000ULL;
  118. }
  119. static inline void
  120. cputime_to_timeval(const cputime_t cputime, struct timeval *value)
  121. {
  122. #ifndef __s390x__
  123. register_pair rp;
  124. rp.pair = cputime >> 1;
  125. asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
  126. value->tv_usec = rp.subreg.even / 4096;
  127. value->tv_sec = rp.subreg.odd;
  128. #else
  129. value->tv_usec = (cputime % 4096000000ULL) / 4096;
  130. value->tv_sec = cputime / 4096000000ULL;
  131. #endif
  132. }
  133. /*
  134. * Convert cputime to clock and back.
  135. */
  136. static inline clock_t
  137. cputime_to_clock_t(cputime_t cputime)
  138. {
  139. return cputime_div(cputime, 4096000000ULL / USER_HZ);
  140. }
  141. static inline cputime_t
  142. clock_t_to_cputime(unsigned long x)
  143. {
  144. return (cputime_t) x * (4096000000ULL / USER_HZ);
  145. }
  146. /*
  147. * Convert cputime64 to clock.
  148. */
  149. static inline clock_t
  150. cputime64_to_clock_t(cputime64_t cputime)
  151. {
  152. return cputime_div(cputime, 4096000000ULL / USER_HZ);
  153. }
  154. struct s390_idle_data {
  155. unsigned int sequence;
  156. unsigned long long idle_count;
  157. unsigned long long idle_enter;
  158. unsigned long long idle_time;
  159. int nohz_delay;
  160. };
  161. DECLARE_PER_CPU(struct s390_idle_data, s390_idle);
  162. void vtime_start_cpu(__u64 int_clock, __u64 enter_timer);
  163. cputime64_t s390_get_idle_time(int cpu);
  164. #define arch_idle_time(cpu) s390_get_idle_time(cpu)
  165. static inline void s390_idle_check(struct pt_regs *regs, __u64 int_clock,
  166. __u64 enter_timer)
  167. {
  168. if (regs->psw.mask & PSW_MASK_WAIT)
  169. vtime_start_cpu(int_clock, enter_timer);
  170. }
  171. static inline int s390_nohz_delay(int cpu)
  172. {
  173. return per_cpu(s390_idle, cpu).nohz_delay != 0;
  174. }
  175. #define arch_needs_cpu(cpu) s390_nohz_delay(cpu)
  176. #endif /* _S390_CPUTIME_H */