Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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 Cochran | f1f1d5e | 2011-02-01 13:52:26 +0000 | [diff] [blame] | 7 | #include <linux/timex.h> |
John Stultz | 9a7adcf | 2011-01-11 09:54:33 -0800 | [diff] [blame] | 8 | #include <linux/alarmtimer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | union cpu_time_count { |
| 11 | cputime_t cpu; |
| 12 | unsigned long long sched; |
| 13 | }; |
| 14 | |
| 15 | struct 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 | |
Richard Cochran | 81e294c | 2011-02-01 13:52:32 +0000 | [diff] [blame] | 22 | /* |
| 23 | * Bit fields within a clockid: |
| 24 | * |
| 25 | * The most significant 29 bits hold either a pid or a file descriptor. |
| 26 | * |
| 27 | * Bit 2 indicates whether a cpu clock refers to a thread or a process. |
| 28 | * |
| 29 | * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3. |
| 30 | * |
| 31 | * A clockid is invalid if bits 2, 1, and 0 are all set. |
| 32 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3)) |
| 34 | #define CPUCLOCK_PERTHREAD(clock) \ |
| 35 | (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) |
Richard Cochran | 0606f42 | 2011-02-01 13:52:35 +0000 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define CPUCLOCK_PERTHREAD_MASK 4 |
| 38 | #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK) |
| 39 | #define CPUCLOCK_CLOCK_MASK 3 |
| 40 | #define CPUCLOCK_PROF 0 |
| 41 | #define CPUCLOCK_VIRT 1 |
| 42 | #define CPUCLOCK_SCHED 2 |
| 43 | #define CPUCLOCK_MAX 3 |
Richard Cochran | 81e294c | 2011-02-01 13:52:32 +0000 | [diff] [blame] | 44 | #define CLOCKFD CPUCLOCK_MAX |
| 45 | #define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #define MAKE_PROCESS_CPUCLOCK(pid, clock) \ |
| 48 | ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) |
| 49 | #define MAKE_THREAD_CPUCLOCK(tid, clock) \ |
| 50 | MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) |
| 51 | |
Richard Cochran | 0606f42 | 2011-02-01 13:52:35 +0000 | [diff] [blame] | 52 | #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) |
| 53 | #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3)) |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* POSIX.1b interval timer structure. */ |
| 56 | struct k_itimer { |
| 57 | struct list_head list; /* free/ allocate list */ |
| 58 | spinlock_t it_lock; |
| 59 | clockid_t it_clock; /* which timer type */ |
| 60 | timer_t it_id; /* timer id */ |
| 61 | int it_overrun; /* overrun on pending signal */ |
| 62 | int it_overrun_last; /* overrun on last delivered signal */ |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 63 | int it_requeue_pending; /* waiting to requeue this timer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define REQUEUE_PENDING 1 |
| 65 | int it_sigev_notify; /* notify word of sigevent struct */ |
Oleg Nesterov | 27af424 | 2008-12-01 14:18:13 -0800 | [diff] [blame] | 66 | struct signal_struct *it_signal; |
| 67 | union { |
| 68 | struct pid *it_pid; /* pid of process to send signal to */ |
| 69 | struct task_struct *it_process; /* for clock_nanosleep */ |
| 70 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | struct sigqueue *sigq; /* signal queue entry. */ |
| 72 | union { |
| 73 | struct { |
Thomas Gleixner | becf8b5 | 2006-01-09 20:52:38 -0800 | [diff] [blame] | 74 | struct hrtimer timer; |
| 75 | ktime_t interval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } real; |
| 77 | struct cpu_timer_list cpu; |
| 78 | struct { |
| 79 | unsigned int clock; |
| 80 | unsigned int node; |
| 81 | unsigned long incr; |
| 82 | unsigned long expires; |
| 83 | } mmtimer; |
John Stultz | 9a7adcf | 2011-01-11 09:54:33 -0800 | [diff] [blame] | 84 | struct alarm alarmtimer; |
Eric Dumazet | 8af0887 | 2011-05-24 11:12:58 +0200 | [diff] [blame^] | 85 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } it; |
| 87 | }; |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | struct k_clock { |
Thomas Gleixner | a924b04 | 2006-01-09 20:52:27 -0800 | [diff] [blame] | 90 | int (*clock_getres) (const clockid_t which_clock, struct timespec *tp); |
Richard Cochran | 1e6d767 | 2011-02-01 13:50:58 +0000 | [diff] [blame] | 91 | int (*clock_set) (const clockid_t which_clock, |
| 92 | const struct timespec *tp); |
Thomas Gleixner | a924b04 | 2006-01-09 20:52:27 -0800 | [diff] [blame] | 93 | int (*clock_get) (const clockid_t which_clock, struct timespec * tp); |
Richard Cochran | f1f1d5e | 2011-02-01 13:52:26 +0000 | [diff] [blame] | 94 | int (*clock_adj) (const clockid_t which_clock, struct timex *tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | int (*timer_create) (struct k_itimer *timer); |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 96 | int (*nsleep) (const clockid_t which_clock, int flags, |
Thomas Gleixner | 97735f2 | 2006-01-09 20:52:37 -0800 | [diff] [blame] | 97 | struct timespec *, struct timespec __user *); |
Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 98 | long (*nsleep_restart) (struct restart_block *restart_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | 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 Gleixner | 1976945 | 2011-02-01 13:51:06 +0000 | [diff] [blame] | 108 | extern struct k_clock clock_posix_cpu; |
Richard Cochran | 0606f42 | 2011-02-01 13:52:35 +0000 | [diff] [blame] | 109 | extern struct k_clock clock_posix_dynamic; |
Thomas Gleixner | 1976945 | 2011-02-01 13:51:06 +0000 | [diff] [blame] | 110 | |
Thomas Gleixner | 5270873 | 2011-02-02 12:10:09 +0100 | [diff] [blame] | 111 | void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* function to call to trigger timer event */ |
| 114 | int posix_timer_event(struct k_itimer *timr, int si_private); |
| 115 | |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 116 | void posix_cpu_timer_schedule(struct k_itimer *timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 118 | void run_posix_cpu_timers(struct task_struct *task); |
| 119 | void posix_cpu_timers_exit(struct task_struct *task); |
| 120 | void posix_cpu_timers_exit_group(struct task_struct *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 122 | void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, |
| 123 | cputime_t *newval, cputime_t *oldval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 125 | long clock_nanosleep_restart(struct restart_block *restart_block); |
| 126 | |
Jiri Slaby | 5ab46b3 | 2009-08-28 14:05:12 +0200 | [diff] [blame] | 127 | void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | #endif |