posix-timers.h 3.8 KB

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