blob: ac2762aaf110438a085de19e32a9af1c4e5fdbd2 [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001#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#include <linux/timex.h>
8#include <linux/alarmtimer.h>
9
10union cpu_time_count {
11 cputime_t cpu;
12 unsigned long long sched;
13};
14
15struct cpu_timer_list {
16 struct list_head entry;
17 union cpu_time_count expires, incr;
18 struct task_struct *task;
19 int firing;
20};
21
22#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
23#define CPUCLOCK_PERTHREAD(clock) \
24 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
25
26#define CPUCLOCK_PERTHREAD_MASK 4
27#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
28#define CPUCLOCK_CLOCK_MASK 3
29#define CPUCLOCK_PROF 0
30#define CPUCLOCK_VIRT 1
31#define CPUCLOCK_SCHED 2
32#define CPUCLOCK_MAX 3
33#define CLOCKFD CPUCLOCK_MAX
34#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
35
36#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
37 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
38#define MAKE_THREAD_CPUCLOCK(tid, clock) \
39 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
40
41#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
42#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
43
44struct k_itimer {
45 struct list_head list;
46 spinlock_t it_lock;
47 clockid_t it_clock;
48 timer_t it_id;
49 int it_overrun;
50 int it_overrun_last;
51 int it_requeue_pending;
52#define REQUEUE_PENDING 1
53 int it_sigev_notify;
54 struct signal_struct *it_signal;
55 union {
56 struct pid *it_pid;
57 struct task_struct *it_process;
58 };
59 struct sigqueue *sigq;
60 union {
61 struct {
62 struct hrtimer timer;
63 ktime_t interval;
64 } real;
65 struct cpu_timer_list cpu;
66 struct {
67 unsigned int clock;
68 unsigned int node;
69 unsigned long incr;
70 unsigned long expires;
71 } mmtimer;
72 struct {
73 struct alarm alarmtimer;
74 ktime_t interval;
75 } alarm;
76 struct rcu_head rcu;
77 } it;
78};
79
80struct k_clock {
81 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
82 int (*clock_set) (const clockid_t which_clock,
83 const struct timespec *tp);
84 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
85 int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
86 int (*timer_create) (struct k_itimer *timer);
87 int (*nsleep) (const clockid_t which_clock, int flags,
88 struct timespec *, struct timespec __user *);
89 long (*nsleep_restart) (struct restart_block *restart_block);
90 int (*timer_set) (struct k_itimer * timr, int flags,
91 struct itimerspec * new_setting,
92 struct itimerspec * old_setting);
93 int (*timer_del) (struct k_itimer * timr);
94#define TIMER_RETRY 1
95 void (*timer_get) (struct k_itimer * timr,
96 struct itimerspec * cur_setting);
97};
98
99extern struct k_clock clock_posix_cpu;
100extern struct k_clock clock_posix_dynamic;
101
102void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
103
104int posix_timer_event(struct k_itimer *timr, int si_private);
105
106void posix_cpu_timer_schedule(struct k_itimer *timer);
107
108void 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);
111
112void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
113 cputime_t *newval, cputime_t *oldval);
114
115long clock_nanosleep_restart(struct restart_block *restart_block);
116
117void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
118
119#endif