Skip to content

Commit 53d31ba

Browse files
author
Kent Overstreet
committed
posix-cpu-timers: Split out posix-timers_types.h
Trimming down sched.h dependencies: we don't want to include more than the base types. Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent d84f317 commit 53d31ba

File tree

3 files changed

+84
-67
lines changed

3 files changed

+84
-67
lines changed

include/linux/posix-timers.h

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,16 @@
22
#ifndef _linux_POSIX_TIMERS_H
33
#define _linux_POSIX_TIMERS_H
44

5-
#include <linux/spinlock.h>
5+
#include <linux/alarmtimer.h>
66
#include <linux/list.h>
77
#include <linux/mutex.h>
8-
#include <linux/alarmtimer.h>
8+
#include <linux/posix-timers_types.h>
9+
#include <linux/spinlock.h>
910
#include <linux/timerqueue.h>
1011

1112
struct kernel_siginfo;
1213
struct task_struct;
1314

14-
/*
15-
* Bit fields within a clockid:
16-
*
17-
* The most significant 29 bits hold either a pid or a file descriptor.
18-
*
19-
* Bit 2 indicates whether a cpu clock refers to a thread or a process.
20-
*
21-
* Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
22-
*
23-
* A clockid is invalid if bits 2, 1, and 0 are all set.
24-
*/
25-
#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
26-
#define CPUCLOCK_PERTHREAD(clock) \
27-
(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
28-
29-
#define CPUCLOCK_PERTHREAD_MASK 4
30-
#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
31-
#define CPUCLOCK_CLOCK_MASK 3
32-
#define CPUCLOCK_PROF 0
33-
#define CPUCLOCK_VIRT 1
34-
#define CPUCLOCK_SCHED 2
35-
#define CPUCLOCK_MAX 3
36-
#define CLOCKFD CPUCLOCK_MAX
37-
#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
38-
3915
static inline clockid_t make_process_cpuclock(const unsigned int pid,
4016
const clockid_t clock)
4117
{
@@ -109,44 +85,6 @@ static inline void cpu_timer_setexpires(struct cpu_timer *ctmr, u64 exp)
10985
ctmr->node.expires = exp;
11086
}
11187

112-
/**
113-
* posix_cputimer_base - Container per posix CPU clock
114-
* @nextevt: Earliest-expiration cache
115-
* @tqhead: timerqueue head for cpu_timers
116-
*/
117-
struct posix_cputimer_base {
118-
u64 nextevt;
119-
struct timerqueue_head tqhead;
120-
};
121-
122-
/**
123-
* posix_cputimers - Container for posix CPU timer related data
124-
* @bases: Base container for posix CPU clocks
125-
* @timers_active: Timers are queued.
126-
* @expiry_active: Timer expiry is active. Used for
127-
* process wide timers to avoid multiple
128-
* task trying to handle expiry concurrently
129-
*
130-
* Used in task_struct and signal_struct
131-
*/
132-
struct posix_cputimers {
133-
struct posix_cputimer_base bases[CPUCLOCK_MAX];
134-
unsigned int timers_active;
135-
unsigned int expiry_active;
136-
};
137-
138-
/**
139-
* posix_cputimers_work - Container for task work based posix CPU timer expiry
140-
* @work: The task work to be scheduled
141-
* @mutex: Mutex held around expiry in context of this task work
142-
* @scheduled: @work has been scheduled already, no further processing
143-
*/
144-
struct posix_cputimers_work {
145-
struct callback_head work;
146-
struct mutex mutex;
147-
unsigned int scheduled;
148-
};
149-
15088
static inline void posix_cputimers_init(struct posix_cputimers *pct)
15189
{
15290
memset(pct, 0, sizeof(*pct));
@@ -179,7 +117,6 @@ static inline void posix_cputimers_rt_watchdog(struct posix_cputimers *pct,
179117
.bases = INIT_CPU_TIMERBASES(s.posix_cputimers.bases), \
180118
},
181119
#else
182-
struct posix_cputimers { };
183120
struct cpu_timer { };
184121
#define INIT_CPU_TIMERS(s)
185122
static inline void posix_cputimers_init(struct posix_cputimers *pct) { }

include/linux/posix-timers_types.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _linux_POSIX_TIMERS_TYPES_H
3+
#define _linux_POSIX_TIMERS_TYPES_H
4+
5+
#include <linux/mutex_types.h>
6+
#include <linux/timerqueue.h>
7+
#include <linux/types.h>
8+
9+
/*
10+
* Bit fields within a clockid:
11+
*
12+
* The most significant 29 bits hold either a pid or a file descriptor.
13+
*
14+
* Bit 2 indicates whether a cpu clock refers to a thread or a process.
15+
*
16+
* Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
17+
*
18+
* A clockid is invalid if bits 2, 1, and 0 are all set.
19+
*/
20+
#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
21+
#define CPUCLOCK_PERTHREAD(clock) \
22+
(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
23+
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+
#define CLOCKFD CPUCLOCK_MAX
32+
#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
33+
34+
#ifdef CONFIG_POSIX_TIMERS
35+
36+
/**
37+
* posix_cputimer_base - Container per posix CPU clock
38+
* @nextevt: Earliest-expiration cache
39+
* @tqhead: timerqueue head for cpu_timers
40+
*/
41+
struct posix_cputimer_base {
42+
u64 nextevt;
43+
struct timerqueue_head tqhead;
44+
};
45+
46+
/**
47+
* posix_cputimers - Container for posix CPU timer related data
48+
* @bases: Base container for posix CPU clocks
49+
* @timers_active: Timers are queued.
50+
* @expiry_active: Timer expiry is active. Used for
51+
* process wide timers to avoid multiple
52+
* task trying to handle expiry concurrently
53+
*
54+
* Used in task_struct and signal_struct
55+
*/
56+
struct posix_cputimers {
57+
struct posix_cputimer_base bases[CPUCLOCK_MAX];
58+
unsigned int timers_active;
59+
unsigned int expiry_active;
60+
};
61+
62+
/**
63+
* posix_cputimers_work - Container for task work based posix CPU timer expiry
64+
* @work: The task work to be scheduled
65+
* @mutex: Mutex held around expiry in context of this task work
66+
* @scheduled: @work has been scheduled already, no further processing
67+
*/
68+
struct posix_cputimers_work {
69+
struct callback_head work;
70+
struct mutex mutex;
71+
unsigned int scheduled;
72+
};
73+
74+
#else /* CONFIG_POSIX_TIMERS */
75+
76+
struct posix_cputimers { };
77+
78+
#endif /* CONFIG_POSIX_TIMERS */
79+
80+
#endif /* _linux_POSIX_TIMERS_TYPES_H */

include/linux/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <linux/syscall_user_dispatch.h>
3232
#include <linux/mm_types_task.h>
3333
#include <linux/task_io_accounting.h>
34-
#include <linux/posix-timers.h>
34+
#include <linux/posix-timers_types.h>
3535
#include <linux/rseq.h>
3636
#include <linux/seqlock.h>
3737
#include <linux/kcsan.h>

0 commit comments

Comments
 (0)