License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-2.6-block.git] / include / linux / posix-timers.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef _linux_POSIX_TIMERS_H
3#define _linux_POSIX_TIMERS_H
4
5#include <linux/spinlock.h>
6#include <linux/list.h>
7#include <linux/sched.h>
f1f1d5eb 8#include <linux/timex.h>
9a7adcf5 9#include <linux/alarmtimer.h>
1da177e4 10
31ea70e0 11struct siginfo;
55ccb616 12
1da177e4
LT
13struct cpu_timer_list {
14 struct list_head entry;
ebd7e7fc 15 u64 expires, incr;
1da177e4
LT
16 struct task_struct *task;
17 int firing;
18};
19
81e294cb
RC
20/*
21 * Bit fields within a clockid:
22 *
23 * The most significant 29 bits hold either a pid or a file descriptor.
24 *
25 * Bit 2 indicates whether a cpu clock refers to a thread or a process.
26 *
27 * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
28 *
29 * A clockid is invalid if bits 2, 1, and 0 are all set.
30 */
1da177e4
LT
31#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
32#define CPUCLOCK_PERTHREAD(clock) \
33 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
0606f422 34
1da177e4
LT
35#define CPUCLOCK_PERTHREAD_MASK 4
36#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
37#define CPUCLOCK_CLOCK_MASK 3
38#define CPUCLOCK_PROF 0
39#define CPUCLOCK_VIRT 1
40#define CPUCLOCK_SCHED 2
41#define CPUCLOCK_MAX 3
81e294cb
RC
42#define CLOCKFD CPUCLOCK_MAX
43#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
1da177e4
LT
44
45#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
46 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
47#define MAKE_THREAD_CPUCLOCK(tid, clock) \
48 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
49
0606f422
RC
50#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
51#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
52
1da177e4 53#define REQUEUE_PENDING 1
03676b41
TG
54
55/**
56 * struct k_itimer - POSIX.1b interval timer structure.
57 * @list: List head for binding the timer to signals->posix_timers
58 * @t_hash: Entry in the posix timer hash table
59 * @it_lock: Lock protecting the timer
d97bb75d 60 * @kclock: Pointer to the k_clock struct handling this timer
03676b41
TG
61 * @it_clock: The posix timer clock id
62 * @it_id: The posix timer id for identifying the timer
21e55c1f 63 * @it_active: Marker that timer is active
03676b41
TG
64 * @it_overrun: The overrun counter for pending signals
65 * @it_overrun_last: The overrun at the time of the last delivered signal
66 * @it_requeue_pending: Indicator that timer waits for being requeued on
67 * signal delivery
68 * @it_sigev_notify: The notify word of sigevent struct for signal delivery
80105cd0 69 * @it_interval: The interval for periodic timers
03676b41
TG
70 * @it_signal: Pointer to the creators signal struct
71 * @it_pid: The pid of the process/task targeted by the signal
72 * @it_process: The task to wakeup on clock_nanosleep (CPU timers)
73 * @sigq: Pointer to preallocated sigqueue
74 * @it: Union representing the various posix timer type
75 * internals. Also used for rcu freeing the timer.
76 */
77struct k_itimer {
78 struct list_head list;
79 struct hlist_node t_hash;
80 spinlock_t it_lock;
d97bb75d 81 const struct k_clock *kclock;
03676b41
TG
82 clockid_t it_clock;
83 timer_t it_id;
21e55c1f 84 int it_active;
03676b41
TG
85 int it_overrun;
86 int it_overrun_last;
87 int it_requeue_pending;
88 int it_sigev_notify;
80105cd0 89 ktime_t it_interval;
03676b41 90 struct signal_struct *it_signal;
27af4245 91 union {
03676b41
TG
92 struct pid *it_pid;
93 struct task_struct *it_process;
27af4245 94 };
03676b41 95 struct sigqueue *sigq;
1da177e4
LT
96 union {
97 struct {
03676b41 98 struct hrtimer timer;
1da177e4 99 } real;
03676b41 100 struct cpu_timer_list cpu;
9e264762 101 struct {
03676b41 102 struct alarm alarmtimer;
9e264762 103 } alarm;
03676b41 104 struct rcu_head rcu;
1da177e4
LT
105 } it;
106};
107
2a698971
TG
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);
2a698971 111void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
858cf3a8 112 u64 *newval, u64 *oldval);
1da177e4 113
5ab46b34 114void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
f06febc9 115
96fe3b07 116void posixtimer_rearm(struct siginfo *info);
1da177e4 117#endif