blob: d51243ae0726b321d3696eef4f3ff9bdc09a0403 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9union cpu_time_count {
10 cputime_t cpu;
11 unsigned long long sched;
12};
13
14struct cpu_timer_list {
15 struct list_head entry;
16 union cpu_time_count expires, incr;
17 struct task_struct *task;
18 int firing;
19};
20
Richard Cochran81e294c2011-02-01 13:52:32 +000021/*
22 * Bit fields within a clockid:
23 *
24 * The most significant 29 bits hold either a pid or a file descriptor.
25 *
26 * Bit 2 indicates whether a cpu clock refers to a thread or a process.
27 *
28 * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
29 *
30 * A clockid is invalid if bits 2, 1, and 0 are all set.
31 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
33#define CPUCLOCK_PERTHREAD(clock) \
34 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
Richard Cochran0606f422011-02-01 13:52:35 +000035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#define CPUCLOCK_PERTHREAD_MASK 4
37#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
38#define CPUCLOCK_CLOCK_MASK 3
39#define CPUCLOCK_PROF 0
40#define CPUCLOCK_VIRT 1
41#define CPUCLOCK_SCHED 2
42#define CPUCLOCK_MAX 3
Richard Cochran81e294c2011-02-01 13:52:32 +000043#define CLOCKFD CPUCLOCK_MAX
44#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
47 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
48#define MAKE_THREAD_CPUCLOCK(tid, clock) \
49 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
50
Richard Cochran0606f422011-02-01 13:52:35 +000051#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
52#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/* POSIX.1b interval timer structure. */
55struct k_itimer {
56 struct list_head list; /* free/ allocate list */
57 spinlock_t it_lock;
58 clockid_t it_clock; /* which timer type */
59 timer_t it_id; /* timer id */
60 int it_overrun; /* overrun on pending signal */
61 int it_overrun_last; /* overrun on last delivered signal */
Thomas Gleixner2a698972006-01-09 20:52:28 -080062 int it_requeue_pending; /* waiting to requeue this timer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define REQUEUE_PENDING 1
64 int it_sigev_notify; /* notify word of sigevent struct */
Oleg Nesterov27af4242008-12-01 14:18:13 -080065 struct signal_struct *it_signal;
66 union {
67 struct pid *it_pid; /* pid of process to send signal to */
68 struct task_struct *it_process; /* for clock_nanosleep */
69 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 struct sigqueue *sigq; /* signal queue entry. */
71 union {
72 struct {
Thomas Gleixnerbecf8b52006-01-09 20:52:38 -080073 struct hrtimer timer;
74 ktime_t interval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 } real;
76 struct cpu_timer_list cpu;
77 struct {
78 unsigned int clock;
79 unsigned int node;
80 unsigned long incr;
81 unsigned long expires;
82 } mmtimer;
83 } it;
84};
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086struct k_clock {
Thomas Gleixnera924b042006-01-09 20:52:27 -080087 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
Richard Cochran1e6d7672011-02-01 13:50:58 +000088 int (*clock_set) (const clockid_t which_clock,
89 const struct timespec *tp);
Thomas Gleixnera924b042006-01-09 20:52:27 -080090 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
Richard Cochranf1f1d5e2011-02-01 13:52:26 +000091 int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 int (*timer_create) (struct k_itimer *timer);
Thomas Gleixner2a698972006-01-09 20:52:28 -080093 int (*nsleep) (const clockid_t which_clock, int flags,
Thomas Gleixner97735f22006-01-09 20:52:37 -080094 struct timespec *, struct timespec __user *);
Toyo Abe1711ef32006-09-29 02:00:28 -070095 long (*nsleep_restart) (struct restart_block *restart_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 int (*timer_set) (struct k_itimer * timr, int flags,
97 struct itimerspec * new_setting,
98 struct itimerspec * old_setting);
99 int (*timer_del) (struct k_itimer * timr);
100#define TIMER_RETRY 1
101 void (*timer_get) (struct k_itimer * timr,
102 struct itimerspec * cur_setting);
103};
104
Thomas Gleixner19769452011-02-01 13:51:06 +0000105extern struct k_clock clock_posix_cpu;
Richard Cochran0606f422011-02-01 13:52:35 +0000106extern struct k_clock clock_posix_dynamic;
Thomas Gleixner19769452011-02-01 13:51:06 +0000107
Thomas Gleixner52708732011-02-02 12:10:09 +0100108void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/* function to call to trigger timer event */
111int posix_timer_event(struct k_itimer *timr, int si_private);
112
Thomas Gleixner2a698972006-01-09 20:52:28 -0800113void posix_cpu_timer_schedule(struct k_itimer *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Thomas Gleixner2a698972006-01-09 20:52:28 -0800115void run_posix_cpu_timers(struct task_struct *task);
116void posix_cpu_timers_exit(struct task_struct *task);
117void posix_cpu_timers_exit_group(struct task_struct *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Thomas Gleixner2a698972006-01-09 20:52:28 -0800119void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
120 cputime_t *newval, cputime_t *oldval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Toyo Abe1711ef32006-09-29 02:00:28 -0700122long clock_nanosleep_restart(struct restart_block *restart_block);
123
Jiri Slaby5ab46b32009-08-28 14:05:12 +0200124void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
Frank Mayharf06febc2008-09-12 09:54:39 -0700125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#endif