Skip to content

Commit 3a245c0

Browse files
committed
posix-cpu-timers: Move expiry cache into struct posix_cputimers
The expiry cache belongs into the posix_cputimers container where the other cpu timers information is. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://lkml.kernel.org/r/20190821192921.014444012@linutronix.de
1 parent 9eacb5c commit 3a245c0

6 files changed

Lines changed: 56 additions & 53 deletions

File tree

‎include/linux/posix-timers.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,43 @@ static inline int clockid_to_fd(const clockid_t clk)
6262
return ~(clk >> 3);
6363
}
6464

65+
/*
66+
* Alternate field names for struct task_cputime when used on cache
67+
* expirations. Will go away soon.
68+
*/
69+
#define virt_exp utime
70+
#define prof_exp stime
71+
#define sched_exp sum_exec_runtime
72+
6573
#ifdef CONFIG_POSIX_TIMERS
6674
/**
6775
* posix_cputimers - Container for posix CPU timer related data
76+
* @cputime_expires: Earliest-expiration cache
6877
* @cpu_timers: List heads to queue posix CPU timers
6978
*
7079
* Used in task_struct and signal_struct
7180
*/
7281
struct posix_cputimers {
82+
struct task_cputime cputime_expires;
7383
struct list_head cpu_timers[CPUCLOCK_MAX];
7484
};
7585

7686
static inline void posix_cputimers_init(struct posix_cputimers *pct)
7787
{
88+
memset(&pct->cputime_expires, 0, sizeof(pct->cputime_expires));
7889
INIT_LIST_HEAD(&pct->cpu_timers[0]);
7990
INIT_LIST_HEAD(&pct->cpu_timers[1]);
8091
INIT_LIST_HEAD(&pct->cpu_timers[2]);
8192
}
8293

94+
void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit);
95+
96+
static inline void posix_cputimers_rt_watchdog(struct posix_cputimers *pct,
97+
u64 runtime)
98+
{
99+
pct->cputime_expires.sched_exp = runtime;
100+
}
101+
83102
/* Init task static initializer */
84103
#define INIT_CPU_TIMERLISTS(c) { \
85104
LIST_HEAD_INIT(c.cpu_timers[0]), \
@@ -94,6 +113,9 @@ static inline void posix_cputimers_init(struct posix_cputimers *pct)
94113
#else
95114
struct posix_cputimers { };
96115
#define INIT_CPU_TIMERS(s)
116+
static inline void posix_cputimers_init(struct posix_cputimers *pct) { }
117+
static inline void posix_cputimers_group_init(struct posix_cputimers *pct,
118+
u64 cpu_limit) { }
97119
#endif
98120

99121
#define REQUEUE_PENDING 1

‎include/linux/sched.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ struct prev_cputime {
246246
#endif
247247
};
248248

249-
/* Alternate field names when used on cache expirations: */
250-
#define virt_exp utime
251-
#define prof_exp stime
252-
#define sched_exp sum_exec_runtime
253-
254249
enum vtime_state {
255250
/* Task is sleeping or running in a CPU with VTIME inactive: */
256251
VTIME_INACTIVE = 0,
@@ -862,9 +857,6 @@ struct task_struct {
862857
unsigned long min_flt;
863858
unsigned long maj_flt;
864859

865-
#ifdef CONFIG_POSIX_TIMERS
866-
struct task_cputime cputime_expires;
867-
#endif
868860
/* Empty if CONFIG_POSIX_CPUTIMERS=n */
869861
struct posix_cputimers posix_cputimers;
870862

‎include/linux/sched/signal.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ struct signal_struct {
149149
*/
150150
struct thread_group_cputimer cputimer;
151151

152-
/* Earliest-expiration cache. */
153-
struct task_cputime cputime_expires;
154-
155152
#endif
156153
/* Empty if CONFIG_POSIX_TIMERS=n */
157154
struct posix_cputimers posix_cputimers;

‎kernel/fork.c‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,12 +1527,9 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig)
15271527
unsigned long cpu_limit;
15281528

15291529
cpu_limit = READ_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur);
1530-
if (cpu_limit != RLIM_INFINITY) {
1531-
sig->cputime_expires.prof_exp = cpu_limit * NSEC_PER_SEC;
1530+
posix_cputimers_group_init(pct, cpu_limit);
1531+
if (cpu_limit != RLIM_INFINITY)
15321532
sig->cputimer.running = true;
1533-
}
1534-
1535-
posix_cputimers_init(pct);
15361533
}
15371534
#else
15381535
static inline void posix_cpu_timers_init_group(struct signal_struct *sig) { }
@@ -1638,22 +1635,6 @@ static void rt_mutex_init_task(struct task_struct *p)
16381635
#endif
16391636
}
16401637

1641-
#ifdef CONFIG_POSIX_TIMERS
1642-
/*
1643-
* Initialize POSIX timer handling for a single task.
1644-
*/
1645-
static void posix_cpu_timers_init(struct task_struct *tsk)
1646-
{
1647-
tsk->cputime_expires.prof_exp = 0;
1648-
tsk->cputime_expires.virt_exp = 0;
1649-
tsk->cputime_expires.sched_exp = 0;
1650-
1651-
posix_cputimers_init(&tsk->posix_cputimers);
1652-
}
1653-
#else
1654-
static inline void posix_cpu_timers_init(struct task_struct *tsk) { }
1655-
#endif
1656-
16571638
static inline void init_task_pid_links(struct task_struct *task)
16581639
{
16591640
enum pid_type type;
@@ -1932,7 +1913,7 @@ static __latent_entropy struct task_struct *copy_process(
19321913
task_io_accounting_init(&p->ioac);
19331914
acct_clear_integrals(p);
19341915

1935-
posix_cpu_timers_init(p);
1916+
posix_cputimers_init(&p->posix_cputimers);
19361917

19371918
p->io_context = NULL;
19381919
audit_set_context(p, NULL);

‎kernel/sched/rt.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,8 +2305,10 @@ static void watchdog(struct rq *rq, struct task_struct *p)
23052305
}
23062306

23072307
next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ);
2308-
if (p->rt.timeout > next)
2309-
p->cputime_expires.sched_exp = p->se.sum_exec_runtime;
2308+
if (p->rt.timeout > next) {
2309+
posix_cputimers_rt_watchdog(&p->posix_cputimers,
2310+
p->se.sum_exec_runtime);
2311+
}
23102312
}
23112313
}
23122314
#else

‎kernel/time/posix-cpu-timers.c‎

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020

2121
static void posix_cpu_timer_rearm(struct k_itimer *timer);
2222

23+
void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit)
24+
{
25+
posix_cputimers_init(pct);
26+
if (cpu_limit != RLIM_INFINITY)
27+
pct->cputime_expires.prof_exp = cpu_limit * NSEC_PER_SEC;
28+
}
29+
2330
/*
2431
* Called after updating RLIMIT_CPU to run cpu timer and update
25-
* tsk->signal->cputime_expires expiration cache if necessary. Needs
26-
* siglock protection since other code may update expiration cache as
27-
* well.
32+
* tsk->signal->posix_cputimers.cputime_expires expiration cache if
33+
* necessary. Needs siglock protection since other code may update
34+
* expiration cache as well.
2835
*/
2936
void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new)
3037
{
@@ -447,10 +454,10 @@ static void arm_timer(struct k_itimer *timer)
447454

448455
if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
449456
head = p->posix_cputimers.cpu_timers;
450-
cputime_expires = &p->cputime_expires;
457+
cputime_expires = &p->posix_cputimers.cputime_expires;
451458
} else {
452459
head = p->signal->posix_cputimers.cpu_timers;
453-
cputime_expires = &p->signal->cputime_expires;
460+
cputime_expires = &p->signal->posix_cputimers.cputime_expires;
454461
}
455462
head += CPUCLOCK_WHICH(timer->it_clock);
456463

@@ -774,7 +781,7 @@ static void check_thread_timers(struct task_struct *tsk,
774781
struct list_head *firing)
775782
{
776783
struct list_head *timers = tsk->posix_cputimers.cpu_timers;
777-
struct task_cputime *tsk_expires = &tsk->cputime_expires;
784+
struct task_cputime *tsk_expires = &tsk->posix_cputimers.cputime_expires;
778785
u64 expires, stime, utime;
779786
unsigned long soft;
780787

@@ -785,7 +792,7 @@ static void check_thread_timers(struct task_struct *tsk,
785792
* If cputime_expires is zero, then there are no active
786793
* per thread CPU timers.
787794
*/
788-
if (task_cputime_zero(&tsk->cputime_expires))
795+
if (task_cputime_zero(tsk_expires))
789796
return;
790797

791798
task_cputime(tsk, &utime, &stime);
@@ -954,10 +961,10 @@ static void check_process_timers(struct task_struct *tsk,
954961
prof_expires = x;
955962
}
956963

957-
sig->cputime_expires.prof_exp = prof_expires;
958-
sig->cputime_expires.virt_exp = virt_expires;
959-
sig->cputime_expires.sched_exp = sched_expires;
960-
if (task_cputime_zero(&sig->cputime_expires))
964+
sig->posix_cputimers.cputime_expires.prof_exp = prof_expires;
965+
sig->posix_cputimers.cputime_expires.virt_exp = virt_expires;
966+
sig->posix_cputimers.cputime_expires.sched_exp = sched_expires;
967+
if (task_cputime_zero(&sig->posix_cputimers.cputime_expires))
961968
stop_process_timers(sig);
962969

963970
sig->cputimer.checking_timer = false;
@@ -1058,12 +1065,13 @@ static inline int fastpath_timer_check(struct task_struct *tsk)
10581065
{
10591066
struct signal_struct *sig;
10601067

1061-
if (!task_cputime_zero(&tsk->cputime_expires)) {
1068+
if (!task_cputime_zero(&tsk->posix_cputimers.cputime_expires)) {
10621069
struct task_cputime task_sample;
10631070

10641071
task_cputime(tsk, &task_sample.utime, &task_sample.stime);
10651072
task_sample.sum_exec_runtime = tsk->se.sum_exec_runtime;
1066-
if (task_cputime_expired(&task_sample, &tsk->cputime_expires))
1073+
if (task_cputime_expired(&task_sample,
1074+
&tsk->posix_cputimers.cputime_expires))
10671075
return 1;
10681076
}
10691077

@@ -1088,7 +1096,8 @@ static inline int fastpath_timer_check(struct task_struct *tsk)
10881096

10891097
sample_cputime_atomic(&group_sample, &sig->cputimer.cputime_atomic);
10901098

1091-
if (task_cputime_expired(&group_sample, &sig->cputime_expires))
1099+
if (task_cputime_expired(&group_sample,
1100+
&sig->posix_cputimers.cputime_expires))
10921101
return 1;
10931102
}
10941103

@@ -1204,12 +1213,12 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
12041213
*/
12051214
switch (clock_idx) {
12061215
case CPUCLOCK_PROF:
1207-
if (expires_gt(tsk->signal->cputime_expires.prof_exp, *newval))
1208-
tsk->signal->cputime_expires.prof_exp = *newval;
1216+
if (expires_gt(tsk->signal->posix_cputimers.cputime_expires.prof_exp, *newval))
1217+
tsk->signal->posix_cputimers.cputime_expires.prof_exp = *newval;
12091218
break;
12101219
case CPUCLOCK_VIRT:
1211-
if (expires_gt(tsk->signal->cputime_expires.virt_exp, *newval))
1212-
tsk->signal->cputime_expires.virt_exp = *newval;
1220+
if (expires_gt(tsk->signal->posix_cputimers.cputime_expires.virt_exp, *newval))
1221+
tsk->signal->posix_cputimers.cputime_expires.virt_exp = *newval;
12131222
break;
12141223
}
12151224

0 commit comments

Comments
 (0)