blob: 672c4f32311e2f569e99fac56448009d5efbe3ac [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _linux_POSIX_TIMERS_H
3#define _linux_POSIX_TIMERS_H
4
5#include <linux/spinlock.h>
6#include <linux/list.h>
7#include <linux/sched.h>
Richard Cochranf1f1d5e2011-02-01 13:52:26 +00008#include <linux/timex.h>
John Stultz9a7adcf2011-01-11 09:54:33 -08009#include <linux/alarmtimer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Christoph Hellwig31ea70e2017-06-03 21:01:00 +020011struct siginfo;
Frederic Weisbecker55ccb612013-06-28 00:06:42 +000012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013struct cpu_timer_list {
14 struct list_head entry;
Frederic Weisbeckerebd7e7f2017-01-31 04:09:34 +010015 u64 expires, incr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 struct task_struct *task;
17 int firing;
18};
19
Richard Cochran81e294c2011-02-01 13:52:32 +000020/*
21 * Bit fields within a clockid:
22 *
23 * The most significant 29 bits hold either a pid or a file descriptor.
24 *
25 * Bit 2 indicates whether a cpu clock refers to a thread or a process.
26 *
27 * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
28 *
29 * A clockid is invalid if bits 2, 1, and 0 are all set.
30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
32#define CPUCLOCK_PERTHREAD(clock) \
33 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
Richard Cochran0606f422011-02-01 13:52:35 +000034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define CPUCLOCK_PERTHREAD_MASK 4
36#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
37#define CPUCLOCK_CLOCK_MASK 3
38#define CPUCLOCK_PROF 0
39#define CPUCLOCK_VIRT 1
40#define CPUCLOCK_SCHED 2
41#define CPUCLOCK_MAX 3
Richard Cochran81e294c2011-02-01 13:52:32 +000042#define CLOCKFD CPUCLOCK_MAX
43#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
46 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
47#define MAKE_THREAD_CPUCLOCK(tid, clock) \
48 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
49
Richard Cochran0606f422011-02-01 13:52:35 +000050#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
51#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define REQUEUE_PENDING 1
Thomas Gleixner03676b42017-05-30 23:15:40 +020054
55/**
56 * struct k_itimer - POSIX.1b interval timer structure.
57 * @list: List head for binding the timer to signals->posix_timers
58 * @t_hash: Entry in the posix timer hash table
59 * @it_lock: Lock protecting the timer
Thomas Gleixnerd97bb752017-05-30 23:15:44 +020060 * @kclock: Pointer to the k_clock struct handling this timer
Thomas Gleixner03676b42017-05-30 23:15:40 +020061 * @it_clock: The posix timer clock id
62 * @it_id: The posix timer id for identifying the timer
Thomas Gleixner21e55c12017-05-30 23:15:48 +020063 * @it_active: Marker that timer is active
Thomas Gleixner03676b42017-05-30 23:15:40 +020064 * @it_overrun: The overrun counter for pending signals
65 * @it_overrun_last: The overrun at the time of the last delivered signal
66 * @it_requeue_pending: Indicator that timer waits for being requeued on
67 * signal delivery
68 * @it_sigev_notify: The notify word of sigevent struct for signal delivery
Thomas Gleixner80105cd2017-05-30 23:15:43 +020069 * @it_interval: The interval for periodic timers
Thomas Gleixner03676b42017-05-30 23:15:40 +020070 * @it_signal: Pointer to the creators signal struct
71 * @it_pid: The pid of the process/task targeted by the signal
72 * @it_process: The task to wakeup on clock_nanosleep (CPU timers)
73 * @sigq: Pointer to preallocated sigqueue
74 * @it: Union representing the various posix timer type
75 * internals. Also used for rcu freeing the timer.
76 */
77struct k_itimer {
78 struct list_head list;
79 struct hlist_node t_hash;
80 spinlock_t it_lock;
Thomas Gleixnerd97bb752017-05-30 23:15:44 +020081 const struct k_clock *kclock;
Thomas Gleixner03676b42017-05-30 23:15:40 +020082 clockid_t it_clock;
83 timer_t it_id;
Thomas Gleixner21e55c12017-05-30 23:15:48 +020084 int it_active;
Thomas Gleixner03676b42017-05-30 23:15:40 +020085 int it_overrun;
86 int it_overrun_last;
87 int it_requeue_pending;
88 int it_sigev_notify;
Thomas Gleixner80105cd2017-05-30 23:15:43 +020089 ktime_t it_interval;
Thomas Gleixner03676b42017-05-30 23:15:40 +020090 struct signal_struct *it_signal;
Oleg Nesterov27af4242008-12-01 14:18:13 -080091 union {
Thomas Gleixner03676b42017-05-30 23:15:40 +020092 struct pid *it_pid;
93 struct task_struct *it_process;
Oleg Nesterov27af4242008-12-01 14:18:13 -080094 };
Thomas Gleixner03676b42017-05-30 23:15:40 +020095 struct sigqueue *sigq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 union {
97 struct {
Thomas Gleixner03676b42017-05-30 23:15:40 +020098 struct hrtimer timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 } real;
Thomas Gleixner03676b42017-05-30 23:15:40 +0200100 struct cpu_timer_list cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 struct {
Thomas Gleixner03676b42017-05-30 23:15:40 +0200102 struct alarm alarmtimer;
John Stultz9e264762011-08-10 12:09:24 -0700103 } alarm;
Thomas Gleixner03676b42017-05-30 23:15:40 +0200104 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 } it;
106};
107
Thomas Gleixner2a698972006-01-09 20:52:28 -0800108void run_posix_cpu_timers(struct task_struct *task);
109void posix_cpu_timers_exit(struct task_struct *task);
110void posix_cpu_timers_exit_group(struct task_struct *task);
Thomas Gleixner2a698972006-01-09 20:52:28 -0800111void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
Frederic Weisbecker858cf3a2017-01-31 04:09:35 +0100112 u64 *newval, u64 *oldval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Jiri Slaby5ab46b32009-08-28 14:05:12 +0200114void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
Frank Mayharf06febc2008-09-12 09:54:39 -0700115
Thomas Gleixner96fe3b02017-05-30 23:15:46 +0200116void posixtimer_rearm(struct siginfo *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif