| 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> | 
 | 7 |  | 
 | 8 | union cpu_time_count { | 
 | 9 | 	cputime_t cpu; | 
 | 10 | 	unsigned long long sched; | 
 | 11 | }; | 
 | 12 |  | 
 | 13 | struct 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. */ | 
 | 38 | struct 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 Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 45 | 	int it_requeue_pending;		/* waiting to requeue this timer */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define REQUEUE_PENDING 1 | 
 | 47 | 	int it_sigev_notify;		/* notify word of sigevent struct */ | 
| Oleg Nesterov | 27af424 | 2008-12-01 14:18:13 -0800 | [diff] [blame] | 48 | 	struct signal_struct *it_signal; | 
 | 49 | 	union { | 
 | 50 | 		struct pid *it_pid;	/* pid of process to send signal to */ | 
 | 51 | 		struct task_struct *it_process;	/* for clock_nanosleep */ | 
 | 52 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | 	struct sigqueue *sigq;		/* signal queue entry. */ | 
 | 54 | 	union { | 
 | 55 | 		struct { | 
| Thomas Gleixner | becf8b5 | 2006-01-09 20:52:38 -0800 | [diff] [blame] | 56 | 			struct hrtimer timer; | 
 | 57 | 			ktime_t interval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | 		} real; | 
 | 59 | 		struct cpu_timer_list cpu; | 
 | 60 | 		struct { | 
 | 61 | 			unsigned int clock; | 
 | 62 | 			unsigned int node; | 
 | 63 | 			unsigned long incr; | 
 | 64 | 			unsigned long expires; | 
 | 65 | 		} mmtimer; | 
 | 66 | 	} it; | 
 | 67 | }; | 
 | 68 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | struct k_clock { | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 70 | 	int res;		/* in nanoseconds */ | 
| Thomas Gleixner | a924b04 | 2006-01-09 20:52:27 -0800 | [diff] [blame] | 71 | 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp); | 
| Thomas Gleixner | a924b04 | 2006-01-09 20:52:27 -0800 | [diff] [blame] | 72 | 	int (*clock_set) (const clockid_t which_clock, struct timespec * tp); | 
 | 73 | 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | 	int (*timer_create) (struct k_itimer *timer); | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 75 | 	int (*nsleep) (const clockid_t which_clock, int flags, | 
| Thomas Gleixner | 97735f2 | 2006-01-09 20:52:37 -0800 | [diff] [blame] | 76 | 		       struct timespec *, struct timespec __user *); | 
| Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 77 | 	long (*nsleep_restart) (struct restart_block *restart_block); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | 	int (*timer_set) (struct k_itimer * timr, int flags, | 
 | 79 | 			  struct itimerspec * new_setting, | 
 | 80 | 			  struct itimerspec * old_setting); | 
 | 81 | 	int (*timer_del) (struct k_itimer * timr); | 
 | 82 | #define TIMER_RETRY 1 | 
 | 83 | 	void (*timer_get) (struct k_itimer * timr, | 
 | 84 | 			   struct itimerspec * cur_setting); | 
 | 85 | }; | 
 | 86 |  | 
| Thomas Gleixner | a924b04 | 2006-01-09 20:52:27 -0800 | [diff] [blame] | 87 | void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 |  | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 89 | /* error handlers for timer_create, nanosleep and settime */ | 
| Thomas Gleixner | 97735f2 | 2006-01-09 20:52:37 -0800 | [diff] [blame] | 90 | int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *, | 
 | 91 | 			       struct timespec __user *); | 
| Thomas Gleixner | a924b04 | 2006-01-09 20:52:27 -0800 | [diff] [blame] | 92 | int do_posix_clock_nosettime(const clockid_t, struct timespec *tp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  | 
 | 94 | /* function to call to trigger timer event */ | 
 | 95 | int posix_timer_event(struct k_itimer *timr, int si_private); | 
 | 96 |  | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 97 | int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts); | 
 | 98 | int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts); | 
 | 99 | int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts); | 
 | 100 | int posix_cpu_timer_create(struct k_itimer *timer); | 
 | 101 | int posix_cpu_nsleep(const clockid_t which_clock, int flags, | 
| Thomas Gleixner | 97735f2 | 2006-01-09 20:52:37 -0800 | [diff] [blame] | 102 | 		     struct timespec *rqtp, struct timespec __user *rmtp); | 
| Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 103 | long posix_cpu_nsleep_restart(struct restart_block *restart_block); | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 104 | int posix_cpu_timer_set(struct k_itimer *timer, int flags, | 
 | 105 | 			struct itimerspec *new, struct itimerspec *old); | 
 | 106 | int posix_cpu_timer_del(struct k_itimer *timer); | 
 | 107 | void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 109 | void posix_cpu_timer_schedule(struct k_itimer *timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 |  | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 111 | void run_posix_cpu_timers(struct task_struct *task); | 
 | 112 | void posix_cpu_timers_exit(struct task_struct *task); | 
 | 113 | void posix_cpu_timers_exit_group(struct task_struct *task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 |  | 
| Thomas Gleixner | 2a69897 | 2006-01-09 20:52:28 -0800 | [diff] [blame] | 115 | void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, | 
 | 116 | 			   cputime_t *newval, cputime_t *oldval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 |  | 
| Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 118 | long clock_nanosleep_restart(struct restart_block *restart_block); | 
 | 119 |  | 
| Jiri Slaby | 5ab46b3 | 2009-08-28 14:05:12 +0200 | [diff] [blame] | 120 | void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); | 
| Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 121 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #endif |