timex.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * include/asm-s390/timex.h
  3. *
  4. * S390 version
  5. * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. *
  7. * Derived from "include/asm-i386/timex.h"
  8. * Copyright (C) 1992, Linus Torvalds
  9. */
  10. #ifndef _ASM_S390_TIMEX_H
  11. #define _ASM_S390_TIMEX_H
  12. /* The value of the TOD clock for 1.1.1970. */
  13. #define TOD_UNIX_EPOCH 0x7d91048bca000000ULL
  14. /* Inline functions for clock register access. */
  15. static inline int set_clock(__u64 time)
  16. {
  17. int cc;
  18. asm volatile(
  19. " sck %1\n"
  20. " ipm %0\n"
  21. " srl %0,28\n"
  22. : "=d" (cc) : "Q" (time) : "cc");
  23. return cc;
  24. }
  25. static inline int store_clock(__u64 *time)
  26. {
  27. int cc;
  28. asm volatile(
  29. " stck %1\n"
  30. " ipm %0\n"
  31. " srl %0,28\n"
  32. : "=d" (cc), "=Q" (*time) : : "cc");
  33. return cc;
  34. }
  35. static inline void set_clock_comparator(__u64 time)
  36. {
  37. asm volatile("sckc %0" : : "Q" (time));
  38. }
  39. static inline void store_clock_comparator(__u64 *time)
  40. {
  41. asm volatile("stckc %0" : "=Q" (*time));
  42. }
  43. #define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
  44. typedef unsigned long long cycles_t;
  45. static inline unsigned long long get_clock (void)
  46. {
  47. unsigned long long clk;
  48. asm volatile("stck %0" : "=Q" (clk) : : "cc");
  49. return clk;
  50. }
  51. static inline unsigned long long get_clock_xt(void)
  52. {
  53. unsigned char clk[16];
  54. asm volatile("stcke %0" : "=Q" (clk) : : "cc");
  55. return *((unsigned long long *)&clk[1]);
  56. }
  57. static inline cycles_t get_cycles(void)
  58. {
  59. return (cycles_t) get_clock() >> 2;
  60. }
  61. int get_sync_clock(unsigned long long *clock);
  62. void init_cpu_timer(void);
  63. unsigned long long monotonic_clock(void);
  64. void tod_to_timeval(__u64, struct timespec *);
  65. static inline
  66. void stck_to_timespec(unsigned long long stck, struct timespec *ts)
  67. {
  68. tod_to_timeval(stck - TOD_UNIX_EPOCH, ts);
  69. }
  70. extern u64 sched_clock_base_cc;
  71. /**
  72. * get_clock_monotonic - returns current time in clock rate units
  73. *
  74. * The caller must ensure that preemption is disabled.
  75. * The clock and sched_clock_base get changed via stop_machine.
  76. * Therefore preemption must be disabled when calling this
  77. * function, otherwise the returned value is not guaranteed to
  78. * be monotonic.
  79. */
  80. static inline unsigned long long get_clock_monotonic(void)
  81. {
  82. return get_clock_xt() - sched_clock_base_cc;
  83. }
  84. #endif