posix-timers.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. union cpu_time_count {
  7. cputime_t cpu;
  8. unsigned long long sched;
  9. };
  10. struct cpu_timer_list {
  11. struct list_head entry;
  12. union cpu_time_count expires, incr;
  13. struct task_struct *task;
  14. int firing;
  15. };
  16. #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
  17. #define CPUCLOCK_PERTHREAD(clock) \
  18. (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
  19. #define CPUCLOCK_PID_MASK 7
  20. #define CPUCLOCK_PERTHREAD_MASK 4
  21. #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
  22. #define CPUCLOCK_CLOCK_MASK 3
  23. #define CPUCLOCK_PROF 0
  24. #define CPUCLOCK_VIRT 1
  25. #define CPUCLOCK_SCHED 2
  26. #define CPUCLOCK_MAX 3
  27. #define MAKE_PROCESS_CPUCLOCK(pid, clock) \
  28. ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
  29. #define MAKE_THREAD_CPUCLOCK(tid, clock) \
  30. MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
  31. /* POSIX.1b interval timer structure. */
  32. struct k_itimer {
  33. struct list_head list; /* free/ allocate list */
  34. spinlock_t it_lock;
  35. clockid_t it_clock; /* which timer type */
  36. timer_t it_id; /* timer id */
  37. int it_overrun; /* overrun on pending signal */
  38. int it_overrun_last; /* overrun on last delivered signal */
  39. int it_requeue_pending; /* waiting to requeue this timer */
  40. #define REQUEUE_PENDING 1
  41. int it_sigev_notify; /* notify word of sigevent struct */
  42. int it_sigev_signo; /* signo word of sigevent struct */
  43. sigval_t it_sigev_value; /* value word of sigevent struct */
  44. struct task_struct *it_process; /* process to send signal to */
  45. struct sigqueue *sigq; /* signal queue entry. */
  46. union {
  47. struct {
  48. struct hrtimer timer;
  49. ktime_t interval;
  50. } real;
  51. struct cpu_timer_list cpu;
  52. struct {
  53. unsigned int clock;
  54. unsigned int node;
  55. unsigned long incr;
  56. unsigned long expires;
  57. } mmtimer;
  58. } it;
  59. };
  60. struct k_clock {
  61. int res; /* in nanoseconds */
  62. int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
  63. int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
  64. int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
  65. int (*timer_create) (struct k_itimer *timer);
  66. int (*nsleep) (const clockid_t which_clock, int flags,
  67. struct timespec *, struct timespec __user *);
  68. long (*nsleep_restart) (struct restart_block *restart_block);
  69. int (*timer_set) (struct k_itimer * timr, int flags,
  70. struct itimerspec * new_setting,
  71. struct itimerspec * old_setting);
  72. int (*timer_del) (struct k_itimer * timr);
  73. #define TIMER_RETRY 1
  74. void (*timer_get) (struct k_itimer * timr,
  75. struct itimerspec * cur_setting);
  76. };
  77. void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
  78. /* error handlers for timer_create, nanosleep and settime */
  79. int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
  80. struct timespec __user *);
  81. int do_posix_clock_nosettime(const clockid_t, struct timespec *tp);
  82. /* function to call to trigger timer event */
  83. int posix_timer_event(struct k_itimer *timr, int si_private);
  84. int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts);
  85. int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts);
  86. int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts);
  87. int posix_cpu_timer_create(struct k_itimer *timer);
  88. int posix_cpu_nsleep(const clockid_t which_clock, int flags,
  89. struct timespec *rqtp, struct timespec __user *rmtp);
  90. long posix_cpu_nsleep_restart(struct restart_block *restart_block);
  91. int posix_cpu_timer_set(struct k_itimer *timer, int flags,
  92. struct itimerspec *new, struct itimerspec *old);
  93. int posix_cpu_timer_del(struct k_itimer *timer);
  94. void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp);
  95. void posix_cpu_timer_schedule(struct k_itimer *timer);
  96. void run_posix_cpu_timers(struct task_struct *task);
  97. void posix_cpu_timers_exit(struct task_struct *task);
  98. void posix_cpu_timers_exit_group(struct task_struct *task);
  99. void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
  100. cputime_t *newval, cputime_t *oldval);
  101. long clock_nanosleep_restart(struct restart_block *restart_block);
  102. void update_rlimit_cpu(unsigned long rlim_new);
  103. #endif