posix-timers.h 4.0 KB

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