blob: a7c7213555492520e649a4920d9fc671e88460cd [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>
7
8union cpu_time_count {
9 cputime_t cpu;
10 unsigned long long sched;
11};
12
13struct cpu_timer_list {
14 struct list_head entry;
15 union cpu_time_count expires, incr;
16 struct task_struct *task;
17 int firing;
18};
19
20#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
21#define CPUCLOCK_PERTHREAD(clock) \
22 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
23#define CPUCLOCK_PID_MASK 7
24#define CPUCLOCK_PERTHREAD_MASK 4
25#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
26#define CPUCLOCK_CLOCK_MASK 3
27#define CPUCLOCK_PROF 0
28#define CPUCLOCK_VIRT 1
29#define CPUCLOCK_SCHED 2
30#define CPUCLOCK_MAX 3
31
32#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
33 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
34#define MAKE_THREAD_CPUCLOCK(tid, clock) \
35 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
36
37/* POSIX.1b interval timer structure. */
38struct k_itimer {
39 struct list_head list; /* free/ allocate list */
40 spinlock_t it_lock;
41 clockid_t it_clock; /* which timer type */
42 timer_t it_id; /* timer id */
43 int it_overrun; /* overrun on pending signal */
44 int it_overrun_last; /* overrun on last delivered signal */
Thomas Gleixner2a698972006-01-09 20:52:28 -080045 int it_requeue_pending; /* waiting to requeue this timer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define REQUEUE_PENDING 1
47 int it_sigev_notify; /* notify word of sigevent struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 struct task_struct *it_process; /* process to send signal to */
49 struct sigqueue *sigq; /* signal queue entry. */
50 union {
51 struct {
Thomas Gleixnerbecf8b52006-01-09 20:52:38 -080052 struct hrtimer timer;
53 ktime_t interval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 } real;
55 struct cpu_timer_list cpu;
56 struct {
57 unsigned int clock;
58 unsigned int node;
59 unsigned long incr;
60 unsigned long expires;
61 } mmtimer;
62 } it;
63};
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065struct k_clock {
Thomas Gleixner2a698972006-01-09 20:52:28 -080066 int res; /* in nanoseconds */
Thomas Gleixnera924b042006-01-09 20:52:27 -080067 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
Thomas Gleixnera924b042006-01-09 20:52:27 -080068 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
69 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 int (*timer_create) (struct k_itimer *timer);
Thomas Gleixner2a698972006-01-09 20:52:28 -080071 int (*nsleep) (const clockid_t which_clock, int flags,
Thomas Gleixner97735f22006-01-09 20:52:37 -080072 struct timespec *, struct timespec __user *);
Toyo Abe1711ef32006-09-29 02:00:28 -070073 long (*nsleep_restart) (struct restart_block *restart_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 int (*timer_set) (struct k_itimer * timr, int flags,
75 struct itimerspec * new_setting,
76 struct itimerspec * old_setting);
77 int (*timer_del) (struct k_itimer * timr);
78#define TIMER_RETRY 1
79 void (*timer_get) (struct k_itimer * timr,
80 struct itimerspec * cur_setting);
81};
82
Thomas Gleixnera924b042006-01-09 20:52:27 -080083void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Thomas Gleixner2a698972006-01-09 20:52:28 -080085/* error handlers for timer_create, nanosleep and settime */
Thomas Gleixner97735f22006-01-09 20:52:37 -080086int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
87 struct timespec __user *);
Thomas Gleixnera924b042006-01-09 20:52:27 -080088int do_posix_clock_nosettime(const clockid_t, struct timespec *tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/* function to call to trigger timer event */
91int posix_timer_event(struct k_itimer *timr, int si_private);
92
Thomas Gleixner2a698972006-01-09 20:52:28 -080093int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts);
94int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts);
95int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts);
96int posix_cpu_timer_create(struct k_itimer *timer);
97int posix_cpu_nsleep(const clockid_t which_clock, int flags,
Thomas Gleixner97735f22006-01-09 20:52:37 -080098 struct timespec *rqtp, struct timespec __user *rmtp);
Toyo Abe1711ef32006-09-29 02:00:28 -070099long posix_cpu_nsleep_restart(struct restart_block *restart_block);
Thomas Gleixner2a698972006-01-09 20:52:28 -0800100int posix_cpu_timer_set(struct k_itimer *timer, int flags,
101 struct itimerspec *new, struct itimerspec *old);
102int posix_cpu_timer_del(struct k_itimer *timer);
103void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Thomas Gleixner2a698972006-01-09 20:52:28 -0800105void posix_cpu_timer_schedule(struct k_itimer *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Thomas Gleixner2a698972006-01-09 20:52:28 -0800107void run_posix_cpu_timers(struct task_struct *task);
108void posix_cpu_timers_exit(struct task_struct *task);
109void posix_cpu_timers_exit_group(struct task_struct *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Thomas Gleixner2a698972006-01-09 20:52:28 -0800111void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
112 cputime_t *newval, cputime_t *oldval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Toyo Abe1711ef32006-09-29 02:00:28 -0700114long clock_nanosleep_restart(struct restart_block *restart_block);
115
Frank Mayharf06febc2008-09-12 09:54:39 -0700116void update_rlimit_cpu(unsigned long rlim_new);
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#endif