blob: 64aa189efe21d6792b07f2b9005fcf5345b2e98c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Cochranf1f1d5e2011-02-01 13:52:26 +00007#include <linux/timex.h>
John Stultz9a7adcf2011-01-11 09:54:33 -08008#include <linux/alarmtimer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Frederic Weisbecker55ccb612013-06-28 00:06:42 +000010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011struct cpu_timer_list {
12 struct list_head entry;
Frederic Weisbeckerebd7e7f2017-01-31 04:09:34 +010013 u64 expires, incr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 struct task_struct *task;
15 int firing;
16};
17
Richard Cochran81e294c2011-02-01 13:52:32 +000018/*
19 * Bit fields within a clockid:
20 *
21 * The most significant 29 bits hold either a pid or a file descriptor.
22 *
23 * Bit 2 indicates whether a cpu clock refers to a thread or a process.
24 *
25 * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
26 *
27 * A clockid is invalid if bits 2, 1, and 0 are all set.
28 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
30#define CPUCLOCK_PERTHREAD(clock) \
31 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
Richard Cochran0606f422011-02-01 13:52:35 +000032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define CPUCLOCK_PERTHREAD_MASK 4
34#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
35#define CPUCLOCK_CLOCK_MASK 3
36#define CPUCLOCK_PROF 0
37#define CPUCLOCK_VIRT 1
38#define CPUCLOCK_SCHED 2
39#define CPUCLOCK_MAX 3
Richard Cochran81e294c2011-02-01 13:52:32 +000040#define CLOCKFD CPUCLOCK_MAX
41#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
44 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
45#define MAKE_THREAD_CPUCLOCK(tid, clock) \
46 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
47
Richard Cochran0606f422011-02-01 13:52:35 +000048#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
49#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/* POSIX.1b interval timer structure. */
52struct k_itimer {
53 struct list_head list; /* free/ allocate list */
Pavel Emelyanov5ed67f02013-03-11 13:12:21 +040054 struct hlist_node t_hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 spinlock_t it_lock;
56 clockid_t it_clock; /* which timer type */
57 timer_t it_id; /* timer id */
58 int it_overrun; /* overrun on pending signal */
59 int it_overrun_last; /* overrun on last delivered signal */
Thomas Gleixner2a698972006-01-09 20:52:28 -080060 int it_requeue_pending; /* waiting to requeue this timer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#define REQUEUE_PENDING 1
62 int it_sigev_notify; /* notify word of sigevent struct */
Oleg Nesterov27af4242008-12-01 14:18:13 -080063 struct signal_struct *it_signal;
64 union {
65 struct pid *it_pid; /* pid of process to send signal to */
66 struct task_struct *it_process; /* for clock_nanosleep */
67 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 struct sigqueue *sigq; /* signal queue entry. */
69 union {
70 struct {
Thomas Gleixnerbecf8b52006-01-09 20:52:38 -080071 struct hrtimer timer;
72 ktime_t interval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 } real;
74 struct cpu_timer_list cpu;
75 struct {
76 unsigned int clock;
77 unsigned int node;
78 unsigned long incr;
79 unsigned long expires;
80 } mmtimer;
John Stultz9e264762011-08-10 12:09:24 -070081 struct {
82 struct alarm alarmtimer;
83 ktime_t interval;
84 } alarm;
Eric Dumazet8af08872011-05-24 11:12:58 +020085 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 } it;
87};
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089struct k_clock {
Thomas Gleixnera924b042006-01-09 20:52:27 -080090 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
Richard Cochran1e6d7672011-02-01 13:50:58 +000091 int (*clock_set) (const clockid_t which_clock,
92 const struct timespec *tp);
Thomas Gleixnera924b042006-01-09 20:52:27 -080093 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
Richard Cochranf1f1d5e2011-02-01 13:52:26 +000094 int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 int (*timer_create) (struct k_itimer *timer);
Thomas Gleixner2a698972006-01-09 20:52:28 -080096 int (*nsleep) (const clockid_t which_clock, int flags,
Thomas Gleixner97735f22006-01-09 20:52:37 -080097 struct timespec *, struct timespec __user *);
Toyo Abe1711ef32006-09-29 02:00:28 -070098 long (*nsleep_restart) (struct restart_block *restart_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 int (*timer_set) (struct k_itimer * timr, int flags,
100 struct itimerspec * new_setting,
101 struct itimerspec * old_setting);
102 int (*timer_del) (struct k_itimer * timr);
103#define TIMER_RETRY 1
104 void (*timer_get) (struct k_itimer * timr,
105 struct itimerspec * cur_setting);
106};
107
Thomas Gleixner19769452011-02-01 13:51:06 +0000108extern struct k_clock clock_posix_cpu;
Richard Cochran0606f422011-02-01 13:52:35 +0000109extern struct k_clock clock_posix_dynamic;
Thomas Gleixner19769452011-02-01 13:51:06 +0000110
Thomas Gleixner52708732011-02-02 12:10:09 +0100111void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* function to call to trigger timer event */
114int posix_timer_event(struct k_itimer *timr, int si_private);
115
Thomas Gleixner2a698972006-01-09 20:52:28 -0800116void posix_cpu_timer_schedule(struct k_itimer *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Thomas Gleixner2a698972006-01-09 20:52:28 -0800118void run_posix_cpu_timers(struct task_struct *task);
119void posix_cpu_timers_exit(struct task_struct *task);
120void posix_cpu_timers_exit_group(struct task_struct *task);
Thomas Gleixner2a698972006-01-09 20:52:28 -0800121void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
Frederic Weisbecker858cf3a2017-01-31 04:09:35 +0100122 u64 *newval, u64 *oldval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Toyo Abe1711ef32006-09-29 02:00:28 -0700124long clock_nanosleep_restart(struct restart_block *restart_block);
125
Jiri Slaby5ab46b32009-08-28 14:05:12 +0200126void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
Frank Mayharf06febc2008-09-12 09:54:39 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#endif