blob: 79a1cea7f6ed6337601e21ffce74c3187a761b37 [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
21#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
22#define CPUCLOCK_PERTHREAD(clock) \
23 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
24#define CPUCLOCK_PID_MASK 7
25#define CPUCLOCK_PERTHREAD_MASK 4
26#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
27#define CPUCLOCK_CLOCK_MASK 3
28#define CPUCLOCK_PROF 0
29#define CPUCLOCK_VIRT 1
30#define CPUCLOCK_SCHED 2
31#define CPUCLOCK_MAX 3
32
33#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
34 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
35#define MAKE_THREAD_CPUCLOCK(tid, clock) \
36 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
37
38/* POSIX.1b interval timer structure. */
39struct k_itimer {
40 struct list_head list; /* free/ allocate list */
41 spinlock_t it_lock;
42 clockid_t it_clock; /* which timer type */
43 timer_t it_id; /* timer id */
44 int it_overrun; /* overrun on pending signal */
45 int it_overrun_last; /* overrun on last delivered signal */
Thomas Gleixner2a698972006-01-09 20:52:28 -080046 int it_requeue_pending; /* waiting to requeue this timer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define REQUEUE_PENDING 1
48 int it_sigev_notify; /* notify word of sigevent struct */
Oleg Nesterov27af4242008-12-01 14:18:13 -080049 struct signal_struct *it_signal;
50 union {
51 struct pid *it_pid; /* pid of process to send signal to */
52 struct task_struct *it_process; /* for clock_nanosleep */
53 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 struct sigqueue *sigq; /* signal queue entry. */
55 union {
56 struct {
Thomas Gleixnerbecf8b52006-01-09 20:52:38 -080057 struct hrtimer timer;
58 ktime_t interval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 } real;
60 struct cpu_timer_list cpu;
61 struct {
62 unsigned int clock;
63 unsigned int node;
64 unsigned long incr;
65 unsigned long expires;
66 } mmtimer;
67 } it;
68};
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070struct k_clock {
Thomas Gleixnera924b042006-01-09 20:52:27 -080071 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
Richard Cochran1e6d7672011-02-01 13:50:58 +000072 int (*clock_set) (const clockid_t which_clock,
73 const struct timespec *tp);
Thomas Gleixnera924b042006-01-09 20:52:27 -080074 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
Richard Cochranf1f1d5e2011-02-01 13:52:26 +000075 int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 int (*timer_create) (struct k_itimer *timer);
Thomas Gleixner2a698972006-01-09 20:52:28 -080077 int (*nsleep) (const clockid_t which_clock, int flags,
Thomas Gleixner97735f22006-01-09 20:52:37 -080078 struct timespec *, struct timespec __user *);
Toyo Abe1711ef32006-09-29 02:00:28 -070079 long (*nsleep_restart) (struct restart_block *restart_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 int (*timer_set) (struct k_itimer * timr, int flags,
81 struct itimerspec * new_setting,
82 struct itimerspec * old_setting);
83 int (*timer_del) (struct k_itimer * timr);
84#define TIMER_RETRY 1
85 void (*timer_get) (struct k_itimer * timr,
86 struct itimerspec * cur_setting);
87};
88
Thomas Gleixner19769452011-02-01 13:51:06 +000089extern struct k_clock clock_posix_cpu;
90
Thomas Gleixnera924b042006-01-09 20:52:27 -080091void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/* function to call to trigger timer event */
94int posix_timer_event(struct k_itimer *timr, int si_private);
95
Thomas Gleixner2a698972006-01-09 20:52:28 -080096void posix_cpu_timer_schedule(struct k_itimer *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Thomas Gleixner2a698972006-01-09 20:52:28 -080098void run_posix_cpu_timers(struct task_struct *task);
99void posix_cpu_timers_exit(struct task_struct *task);
100void posix_cpu_timers_exit_group(struct task_struct *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Thomas Gleixner2a698972006-01-09 20:52:28 -0800102void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
103 cputime_t *newval, cputime_t *oldval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Toyo Abe1711ef32006-09-29 02:00:28 -0700105long clock_nanosleep_restart(struct restart_block *restart_block);
106
Jiri Slaby5ab46b32009-08-28 14:05:12 +0200107void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
Frank Mayharf06febc2008-09-12 09:54:39 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#endif