Skip to content

Commit b787830

Browse files
committed
posix-cpu-timers: Migrate to use new tick dependency mask model
Instead of providing asynchronous checks for the nohz subsystem to verify posix cpu timers tick dependency, migrate the latter to the new mask. In order to keep track of the running timers and expose the tick dependency accordingly, we must probe the timers queuing and dequeuing on threads and process lists. Unfortunately it implies both task and signal level dependencies. We should be able to further optimize this and merge all that on the task level dependency, at the cost of a bit of complexity and may be overhead. Reviewed-by: Chris Metcalf <cmetcalf@ezchip.com> Cc: Christoph Lameter <cl@linux.com> Cc: Chris Metcalf <cmetcalf@ezchip.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Luiz Capitulino <lcapitulino@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
1 parent 76d92ac commit b787830

4 files changed

Lines changed: 12 additions & 52 deletions

File tree

‎include/linux/posix-timers.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ void posix_cpu_timer_schedule(struct k_itimer *timer);
128128
void run_posix_cpu_timers(struct task_struct *task);
129129
void posix_cpu_timers_exit(struct task_struct *task);
130130
void posix_cpu_timers_exit_group(struct task_struct *task);
131-
132-
bool posix_cpu_timers_can_stop_tick(struct task_struct *tsk);
133-
134131
void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
135132
cputime_t *newval, cputime_t *oldval);
136133

‎include/linux/tick.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ static inline void tick_dep_clear_signal(struct signal_struct *signal,
234234
}
235235

236236
extern void tick_nohz_full_kick_cpu(int cpu);
237-
extern void tick_nohz_full_kick_all(void);
238237
extern void __tick_nohz_task_switch(void);
239238
#else
240239
static inline int housekeeping_any_cpu(void)
@@ -259,7 +258,6 @@ static inline void tick_dep_clear_signal(struct signal_struct *signal,
259258
enum tick_dep_bits bit) { }
260259

261260
static inline void tick_nohz_full_kick_cpu(int cpu) { }
262-
static inline void tick_nohz_full_kick_all(void) { }
263261
static inline void __tick_nohz_task_switch(void) { }
264262
#endif
265263

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

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
333333
return err;
334334
}
335335

336-
337336
/*
338337
* Validate the clockid_t for a new CPU-clock timer, and initialize the timer.
339338
* This is called from sys_timer_create() and do_cpu_nanosleep() with the
@@ -517,6 +516,10 @@ static void arm_timer(struct k_itimer *timer)
517516
cputime_expires->sched_exp = exp;
518517
break;
519518
}
519+
if (CPUCLOCK_PERTHREAD(timer->it_clock))
520+
tick_dep_set_task(p, TICK_DEP_BIT_POSIX_TIMER);
521+
else
522+
tick_dep_set_signal(p->signal, TICK_DEP_BIT_POSIX_TIMER);
520523
}
521524
}
522525

@@ -582,39 +585,6 @@ static int cpu_timer_sample_group(const clockid_t which_clock,
582585
return 0;
583586
}
584587

585-
#ifdef CONFIG_NO_HZ_FULL
586-
static void nohz_kick_work_fn(struct work_struct *work)
587-
{
588-
tick_nohz_full_kick_all();
589-
}
590-
591-
static DECLARE_WORK(nohz_kick_work, nohz_kick_work_fn);
592-
593-
/*
594-
* We need the IPIs to be sent from sane process context.
595-
* The posix cpu timers are always set with irqs disabled.
596-
*/
597-
static void posix_cpu_timer_kick_nohz(void)
598-
{
599-
if (context_tracking_is_enabled())
600-
schedule_work(&nohz_kick_work);
601-
}
602-
603-
bool posix_cpu_timers_can_stop_tick(struct task_struct *tsk)
604-
{
605-
if (!task_cputime_zero(&tsk->cputime_expires))
606-
return false;
607-
608-
/* Check if cputimer is running. This is accessed without locking. */
609-
if (READ_ONCE(tsk->signal->cputimer.running))
610-
return false;
611-
612-
return true;
613-
}
614-
#else
615-
static inline void posix_cpu_timer_kick_nohz(void) { }
616-
#endif
617-
618588
/*
619589
* Guts of sys_timer_settime for CPU timers.
620590
* This is called with the timer locked and interrupts disabled.
@@ -761,8 +731,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
761731
sample_to_timespec(timer->it_clock,
762732
old_incr, &old->it_interval);
763733
}
764-
if (!ret)
765-
posix_cpu_timer_kick_nohz();
734+
766735
return ret;
767736
}
768737

@@ -911,6 +880,8 @@ static void check_thread_timers(struct task_struct *tsk,
911880
__group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk);
912881
}
913882
}
883+
if (task_cputime_zero(tsk_expires))
884+
tick_dep_clear_task(tsk, TICK_DEP_BIT_POSIX_TIMER);
914885
}
915886

916887
static inline void stop_process_timers(struct signal_struct *sig)
@@ -919,6 +890,7 @@ static inline void stop_process_timers(struct signal_struct *sig)
919890

920891
/* Turn off cputimer->running. This is done without locking. */
921892
WRITE_ONCE(cputimer->running, false);
893+
tick_dep_clear_signal(sig, TICK_DEP_BIT_POSIX_TIMER);
922894
}
923895

924896
static u32 onecputick;
@@ -1095,8 +1067,6 @@ void posix_cpu_timer_schedule(struct k_itimer *timer)
10951067
arm_timer(timer);
10961068
unlock_task_sighand(p, &flags);
10971069

1098-
/* Kick full dynticks CPUs in case they need to tick on the new timer */
1099-
posix_cpu_timer_kick_nohz();
11001070
out:
11011071
timer->it_overrun_last = timer->it_overrun;
11021072
timer->it_overrun = -1;
@@ -1270,7 +1240,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
12701240
}
12711241

12721242
if (!*newval)
1273-
goto out;
1243+
return;
12741244
*newval += now;
12751245
}
12761246

@@ -1288,8 +1258,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
12881258
tsk->signal->cputime_expires.virt_exp = *newval;
12891259
break;
12901260
}
1291-
out:
1292-
posix_cpu_timer_kick_nohz();
1261+
1262+
tick_dep_set_signal(tsk->signal, TICK_DEP_BIT_POSIX_TIMER);
12931263
}
12941264

12951265
static int do_cpu_nanosleep(const clockid_t which_clock, int flags,

‎kernel/time/tick-sched.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ static bool can_stop_full_tick(struct tick_sched *ts)
204204
return false;
205205
}
206206

207-
if (!posix_cpu_timers_can_stop_tick(current)) {
208-
trace_tick_stop(0, TICK_DEP_MASK_POSIX_TIMER);
209-
return false;
210-
}
211-
212207
#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
213208
/*
214209
* sched_clock_tick() needs us?
@@ -270,7 +265,7 @@ void tick_nohz_full_kick_cpu(int cpu)
270265
* Kick all full dynticks CPUs in order to force these to re-evaluate
271266
* their dependency on the tick and restart it if necessary.
272267
*/
273-
void tick_nohz_full_kick_all(void)
268+
static void tick_nohz_full_kick_all(void)
274269
{
275270
int cpu;
276271

0 commit comments

Comments
 (0)