posix-timers.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef _linux_POSIX_TIMERS_H
  2. #define _linux_POSIX_TIMERS_H
  3. #include <linux/spinlock.h>
  4. #include <linux/list.h>
  5. #include <linux/sched.h>
  6. #include <linux/timex.h>
  7. #include <linux/alarmtimer.h>
  8. static inline unsigned long long cputime_to_expires(cputime_t expires)
  9. {
  10. return (__force unsigned long long)expires;
  11. }
  12. static inline cputime_t expires_to_cputime(unsigned long long expires)
  13. {
  14. return (__force cputime_t)expires;
  15. }
  16. struct cpu_timer_list {
  17. struct list_head entry;
  18. unsigned long long expires, incr;
  19. struct task_struct *task;
  20. int firing;
  21. };
  22. /*
  23. * Bit fields within a clockid:
  24. *
  25. * The most significant 29 bits hold either a pid or a file descriptor.
  26. *
  27. * Bit 2 indicates whether a cpu clock refers to a thread or a process.
  28. *
  29. * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
  30. *
  31. * A clockid is invalid if bits 2, 1, and 0 are all set.
  32. */
  33. #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
  34. #define CPUCLOCK_PERTHREAD(clock) \
  35. (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
  36. #define CPUCLOCK_PERTHREAD_MASK 4
  37. #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
  38. #define CPUCLOCK_CLOCK_MASK 3
  39. #define CPUCLOCK_PROF 0
  40. #define CPUCLOCK_VIRT 1
  41. #define CPUCLOCK_SCHED 2
  42. #define CPUCLOCK_MAX 3
  43. #define CLOCKFD CPUCLOCK_MAX
  44. #define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
  45. #define MAKE_PROCESS_CPUCLOCK(pid, clock) \
  46. ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
  47. #define MAKE_THREAD_CPUCLOCK(tid, clock) \
  48. MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
  49. #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
  50. #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
  51. /* POSIX.1b interval timer structure. */
  52. struct k_itimer {
  53. struct list_head list; /* free/ allocate list */
  54. struct hlist_node t_hash;
  55. spinlock_t it_lock;
  56. clockid_t it_clock; /* which timer type */
  57. timer_t it_id; /* timer id */
  58. s64 it_overrun; /* overrun on pending signal */
  59. s64 it_overrun_last; /* overrun on last delivered signal */
  60. int it_requeue_pending; /* waiting to requeue this timer */
  61. #define REQUEUE_PENDING 1
  62. int it_sigev_notify; /* notify word of sigevent struct */
  63. struct signal_struct *it_signal;
  64. union {
  65. struct pid *it_pid; /* pid of process to send signal to */
  66. struct task_struct *it_process; /* for clock_nanosleep */
  67. };
  68. struct sigqueue *sigq; /* signal queue entry. */
  69. union {
  70. struct {
  71. struct hrtimer timer;
  72. ktime_t interval;
  73. } real;
  74. struct cpu_timer_list cpu;
  75. struct {
  76. unsigned int clock;
  77. unsigned int node;
  78. unsigned long incr;
  79. unsigned long expires;
  80. } mmtimer;
  81. struct {
  82. struct alarm alarmtimer;
  83. ktime_t interval;
  84. } alarm;
  85. struct rcu_head rcu;
  86. } it;
  87. };
  88. struct k_clock {
  89. int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
  90. int (*clock_set) (const clockid_t which_clock,
  91. const struct timespec *tp);
  92. int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
  93. int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
  94. int (*timer_create) (struct k_itimer *timer);
  95. int (*nsleep) (const clockid_t which_clock, int flags,
  96. struct timespec *, struct timespec __user *);
  97. long (*nsleep_restart) (struct restart_block *restart_block);
  98. int (*timer_set) (struct k_itimer * timr, int flags,
  99. struct itimerspec * new_setting,
  100. struct itimerspec * old_setting);
  101. int (*timer_del) (struct k_itimer * timr);
  102. #define TIMER_RETRY 1
  103. void (*timer_get) (struct k_itimer * timr,
  104. struct itimerspec * cur_setting);
  105. };
  106. extern struct k_clock clock_posix_cpu;
  107. extern struct k_clock clock_posix_dynamic;
  108. void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
  109. /* function to call to trigger timer event */
  110. int posix_timer_event(struct k_itimer *timr, int si_private);
  111. void posix_cpu_timer_schedule(struct k_itimer *timer);
  112. void run_posix_cpu_timers(struct task_struct *task);
  113. void posix_cpu_timers_exit(struct task_struct *task);
  114. void posix_cpu_timers_exit_group(struct task_struct *task);
  115. bool posix_cpu_timers_can_stop_tick(struct task_struct *tsk);
  116. void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
  117. cputime_t *newval, cputime_t *oldval);
  118. long clock_nanosleep_restart(struct restart_block *restart_block);
  119. void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
  120. #endif