Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _linux_POSIX_TIMERS_H |
| 2 | #define _linux_POSIX_TIMERS_H |
| 3 | |
| 4 | #include <linux/spinlock.h> |
| 5 | #include <linux/list.h> |
| 6 | #include <linux/sched.h> |
Richard Cochran | f1f1d5e | 2011-02-01 13:52:26 +0000 | [diff] [blame] | 7 | #include <linux/timex.h> |
John Stultz | 9a7adcf | 2011-01-11 09:54:33 -0800 | [diff] [blame] | 8 | #include <linux/alarmtimer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Christoph Hellwig | 31ea70e | 2017-06-03 21:01:00 +0200 | [diff] [blame] | 10 | struct siginfo; |
Frederic Weisbecker | 55ccb61 | 2013-06-28 00:06:42 +0000 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | struct cpu_timer_list { |
| 13 | struct list_head entry; |
Frederic Weisbecker | ebd7e7f | 2017-01-31 04:09:34 +0100 | [diff] [blame] | 14 | u64 expires, incr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | struct task_struct *task; |
| 16 | int firing; |
| 17 | }; |
| 18 | |
Richard Cochran | 81e294c | 2011-02-01 13:52:32 +0000 | [diff] [blame] | 19 | /* |
| 20 | * Bit fields within a clockid: |
| 21 | * |
| 22 | * The most significant 29 bits hold either a pid or a file descriptor. |
| 23 | * |
| 24 | * Bit 2 indicates whether a cpu clock refers to a thread or a process. |
| 25 | * |
| 26 | * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3. |
| 27 | * |
| 28 | * A clockid is invalid if bits 2, 1, and 0 are all set. |
| 29 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3)) |
| 31 | #define CPUCLOCK_PERTHREAD(clock) \ |
| 32 | (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) |
Richard Cochran | 0606f42 | 2011-02-01 13:52:35 +0000 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define CPUCLOCK_PERTHREAD_MASK 4 |
| 35 | #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK) |
| 36 | #define CPUCLOCK_CLOCK_MASK 3 |
| 37 | #define CPUCLOCK_PROF 0 |
| 38 | #define CPUCLOCK_VIRT 1 |
| 39 | #define CPUCLOCK_SCHED 2 |
| 40 | #define CPUCLOCK_MAX 3 |
Richard Cochran | 81e294c | 2011-02-01 13:52:32 +0000 | [diff] [blame] | 41 | #define CLOCKFD CPUCLOCK_MAX |
| 42 | #define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #define MAKE_PROCESS_CPUCLOCK(pid, clock) \ |
| 45 | ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) |
| 46 | #define MAKE_THREAD_CPUCLOCK(tid, clock) \ |
| 47 | MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) |
| 48 | |
Richard Cochran | 0606f42 | 2011-02-01 13:52:35 +0000 | [diff] [blame] | 49 | #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) |
| 50 | #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3)) |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define REQUEUE_PENDING 1 |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame^] | 53 | |
| 54 | /** |
| 55 | * struct k_itimer - POSIX.1b interval timer structure. |
| 56 | * @list: List head for binding the timer to signals->posix_timers |
| 57 | * @t_hash: Entry in the posix timer hash table |
| 58 | * @it_lock: Lock protecting the timer |
| 59 | * @it_clock: The posix timer clock id |
| 60 | * @it_id: The posix timer id for identifying the timer |
| 61 | * @it_overrun: The overrun counter for pending signals |
| 62 | * @it_overrun_last: The overrun at the time of the last delivered signal |
| 63 | * @it_requeue_pending: Indicator that timer waits for being requeued on |
| 64 | * signal delivery |
| 65 | * @it_sigev_notify: The notify word of sigevent struct for signal delivery |
| 66 | * @it_signal: Pointer to the creators signal struct |
| 67 | * @it_pid: The pid of the process/task targeted by the signal |
| 68 | * @it_process: The task to wakeup on clock_nanosleep (CPU timers) |
| 69 | * @sigq: Pointer to preallocated sigqueue |
| 70 | * @it: Union representing the various posix timer type |
| 71 | * internals. Also used for rcu freeing the timer. |
| 72 | */ |
| 73 | struct k_itimer { |
| 74 | struct list_head list; |
| 75 | struct hlist_node t_hash; |
| 76 | spinlock_t it_lock; |
| 77 | clockid_t it_clock; |
| 78 | timer_t it_id; |
| 79 | int it_overrun; |
| 80 | int it_overrun_last; |
| 81 | int it_requeue_pending; |
| 82 | int it_sigev_notify; |
| 83 | struct signal_struct *it_signal; |
Oleg Nesterov | 27af424 | 2008-12-01 14:18:13 -0800 | [diff] [blame] | 84 | union { |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame^] | 85 | struct pid *it_pid; |
| 86 | struct task_struct *it_process; |
Oleg Nesterov | 27af424 | 2008-12-01 14:18:13 -0800 | [diff] [blame] | 87 | }; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame^] | 88 | struct sigqueue *sigq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | union { |
| 90 | struct { |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame^] | 91 | struct hrtimer timer; |
| 92 | ktime_t interval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } real; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame^] | 94 | struct cpu_timer_list cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | struct { |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame^] | 96 | struct alarm alarmtimer; |
| 97 | ktime_t interval; |
John Stultz | 9e26476 | 2011-08-10 12:09:24 -0700 | [diff] [blame] | 98 | } alarm; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame^] | 99 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } it; |
| 101 | }; |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | struct k_clock { |
Deepa Dinamani | d2e3e0c | 2017-03-26 12:04:15 -0700 | [diff] [blame] | 104 | int (*clock_getres) (const clockid_t which_clock, struct timespec64 *tp); |
Richard Cochran | 1e6d767 | 2011-02-01 13:50:58 +0000 | [diff] [blame] | 105 | int (*clock_set) (const clockid_t which_clock, |
Deepa Dinamani | 0fe6afe | 2017-03-26 12:04:16 -0700 | [diff] [blame] | 106 | const struct timespec64 *tp); |
Deepa Dinamani | 3c9c12f | 2017-03-26 12:04:14 -0700 | [diff] [blame] | 107 | int (*clock_get) (const clockid_t which_clock, struct timespec64 *tp); |
Richard Cochran | f1f1d5e | 2011-02-01 13:52:26 +0000 | [diff] [blame] | 108 | int (*clock_adj) (const clockid_t which_clock, struct timex *tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | int (*timer_create) (struct k_itimer *timer); |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 110 | int (*nsleep) (const clockid_t which_clock, int flags, |
Deepa Dinamani | ad19638 | 2017-03-26 12:04:18 -0700 | [diff] [blame] | 111 | struct timespec64 *, struct timespec __user *); |
Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 112 | long (*nsleep_restart) (struct restart_block *restart_block); |
Deepa Dinamani | 5f252b3 | 2017-03-26 12:04:17 -0700 | [diff] [blame] | 113 | int (*timer_set) (struct k_itimer *timr, int flags, |
| 114 | struct itimerspec64 *new_setting, |
| 115 | struct itimerspec64 *old_setting); |
| 116 | int (*timer_del) (struct k_itimer *timr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #define TIMER_RETRY 1 |
Deepa Dinamani | 5f252b3 | 2017-03-26 12:04:17 -0700 | [diff] [blame] | 118 | void (*timer_get) (struct k_itimer *timr, |
| 119 | struct itimerspec64 *cur_setting); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
Christoph Hellwig | d3ba5a9 | 2017-05-26 12:03:11 +0300 | [diff] [blame] | 122 | extern const struct k_clock clock_posix_cpu; |
| 123 | extern const struct k_clock clock_posix_dynamic; |
| 124 | extern const struct k_clock clock_process; |
| 125 | extern const struct k_clock clock_thread; |
| 126 | extern const struct k_clock alarm_clock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* function to call to trigger timer event */ |
| 129 | int posix_timer_event(struct k_itimer *timr, int si_private); |
| 130 | |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 131 | void posix_cpu_timer_schedule(struct k_itimer *timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 133 | void run_posix_cpu_timers(struct task_struct *task); |
| 134 | void posix_cpu_timers_exit(struct task_struct *task); |
| 135 | void posix_cpu_timers_exit_group(struct task_struct *task); |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 136 | void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, |
Frederic Weisbecker | 858cf3a | 2017-01-31 04:09:35 +0100 | [diff] [blame] | 137 | u64 *newval, u64 *oldval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 139 | long clock_nanosleep_restart(struct restart_block *restart_block); |
| 140 | |
Jiri Slaby | 5ab46b3 | 2009-08-28 14:05:12 +0200 | [diff] [blame] | 141 | void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 142 | |
Christoph Hellwig | 31ea70e | 2017-06-03 21:01:00 +0200 | [diff] [blame] | 143 | void do_schedule_next_timer(struct siginfo *info); |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | #endif |