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 | 9a7adcf5 | 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 |
Thomas Gleixner | d97bb75 | 2017-05-30 23:15:44 +0200 | [diff] [blame] | 59 | * @kclock: Pointer to the k_clock struct handling this timer |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 60 | * @it_clock: The posix timer clock id |
| 61 | * @it_id: The posix timer id for identifying the timer |
Thomas Gleixner | 21e55c1 | 2017-05-30 23:15:48 +0200 | [diff] [blame] | 62 | * @it_active: Marker that timer is active |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 63 | * @it_overrun: The overrun counter for pending signals |
| 64 | * @it_overrun_last: The overrun at the time of the last delivered signal |
| 65 | * @it_requeue_pending: Indicator that timer waits for being requeued on |
| 66 | * signal delivery |
| 67 | * @it_sigev_notify: The notify word of sigevent struct for signal delivery |
Thomas Gleixner | 80105cd | 2017-05-30 23:15:43 +0200 | [diff] [blame] | 68 | * @it_interval: The interval for periodic timers |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 69 | * @it_signal: Pointer to the creators signal struct |
| 70 | * @it_pid: The pid of the process/task targeted by the signal |
| 71 | * @it_process: The task to wakeup on clock_nanosleep (CPU timers) |
| 72 | * @sigq: Pointer to preallocated sigqueue |
| 73 | * @it: Union representing the various posix timer type |
| 74 | * internals. Also used for rcu freeing the timer. |
| 75 | */ |
| 76 | struct k_itimer { |
| 77 | struct list_head list; |
| 78 | struct hlist_node t_hash; |
| 79 | spinlock_t it_lock; |
Thomas Gleixner | d97bb75 | 2017-05-30 23:15:44 +0200 | [diff] [blame] | 80 | const struct k_clock *kclock; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 81 | clockid_t it_clock; |
| 82 | timer_t it_id; |
Thomas Gleixner | 21e55c1 | 2017-05-30 23:15:48 +0200 | [diff] [blame] | 83 | int it_active; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 84 | int it_overrun; |
| 85 | int it_overrun_last; |
| 86 | int it_requeue_pending; |
| 87 | int it_sigev_notify; |
Thomas Gleixner | 80105cd | 2017-05-30 23:15:43 +0200 | [diff] [blame] | 88 | ktime_t it_interval; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 89 | struct signal_struct *it_signal; |
Oleg Nesterov | 27af424 | 2008-12-01 14:18:13 -0800 | [diff] [blame] | 90 | union { |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 91 | struct pid *it_pid; |
| 92 | struct task_struct *it_process; |
Oleg Nesterov | 27af424 | 2008-12-01 14:18:13 -0800 | [diff] [blame] | 93 | }; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 94 | struct sigqueue *sigq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | union { |
| 96 | struct { |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 97 | struct hrtimer timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } real; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 99 | struct cpu_timer_list cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | struct { |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 101 | struct alarm alarmtimer; |
John Stultz | 9e26476 | 2011-08-10 12:09:24 -0700 | [diff] [blame] | 102 | } alarm; |
Thomas Gleixner | 03676b4 | 2017-05-30 23:15:40 +0200 | [diff] [blame] | 103 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } it; |
| 105 | }; |
| 106 | |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 107 | void run_posix_cpu_timers(struct task_struct *task); |
| 108 | void posix_cpu_timers_exit(struct task_struct *task); |
| 109 | void posix_cpu_timers_exit_group(struct task_struct *task); |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 110 | 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] | 111 | u64 *newval, u64 *oldval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Jiri Slaby | 5ab46b3 | 2009-08-28 14:05:12 +0200 | [diff] [blame] | 113 | void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 114 | |
Thomas Gleixner | 96fe3b0 | 2017-05-30 23:15:46 +0200 | [diff] [blame] | 115 | void posixtimer_rearm(struct siginfo *info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #endif |