Skip to content

Commit 265f22a

Browse files
committed
sched: Keep at least 1 tick per second for active dynticks tasks
The scheduler doesn't yet fully support environments with a single task running without a periodic tick. In order to ensure we still maintain the duties of scheduler_tick(), keep at least 1 tick per second. This makes sure that we keep the progression of various scheduler accounting and background maintainance even with a very low granularity. Examples include cpu load, sched average, CFS entity vruntime, avenrun and events such as load balancing, amongst other details handled in sched_class::task_tick(). This limitation will be removed in the future once we get these individual items to work in full dynticks CPUs. Suggested-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Christoph Lameter <cl@linux.com> Cc: Hakan Akkan <hakanakkan@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Kevin Hilman <khilman@linaro.org> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de>
1 parent 73c3082 commit 265f22a

5 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,7 @@ static inline void wake_up_nohz_cpu(int cpu) { }
18621862

18631863
#ifdef CONFIG_NO_HZ_FULL
18641864
extern bool sched_can_stop_tick(void);
1865+
extern u64 scheduler_tick_max_deferment(void);
18651866
#else
18661867
static inline bool sched_can_stop_tick(void) { return false; }
18671868
#endif

‎kernel/sched/core.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,8 +2736,35 @@ void scheduler_tick(void)
27362736
rq->idle_balance = idle_cpu(cpu);
27372737
trigger_load_balance(rq, cpu);
27382738
#endif
2739+
rq_last_tick_reset(rq);
27392740
}
27402741

2742+
#ifdef CONFIG_NO_HZ_FULL
2743+
/**
2744+
* scheduler_tick_max_deferment
2745+
*
2746+
* Keep at least one tick per second when a single
2747+
* active task is running because the scheduler doesn't
2748+
* yet completely support full dynticks environment.
2749+
*
2750+
* This makes sure that uptime, CFS vruntime, load
2751+
* balancing, etc... continue to move forward, even
2752+
* with a very low granularity.
2753+
*/
2754+
u64 scheduler_tick_max_deferment(void)
2755+
{
2756+
struct rq *rq = this_rq();
2757+
unsigned long next, now = ACCESS_ONCE(jiffies);
2758+
2759+
next = rq->last_sched_tick + HZ;
2760+
2761+
if (time_before_eq(next, now))
2762+
return 0;
2763+
2764+
return jiffies_to_usecs(next - now) * NSEC_PER_USEC;
2765+
}
2766+
#endif
2767+
27412768
notrace unsigned long get_parent_ip(unsigned long addr)
27422769
{
27432770
if (in_lock_functions(addr)) {
@@ -6993,6 +7020,9 @@ void __init sched_init(void)
69937020
#ifdef CONFIG_NO_HZ_COMMON
69947021
rq->nohz_flags = 0;
69957022
#endif
7023+
#ifdef CONFIG_NO_HZ_FULL
7024+
rq->last_sched_tick = 0;
7025+
#endif
69967026
#endif
69977027
init_rq_hrtick(rq);
69987028
atomic_set(&rq->nr_iowait, 0);

‎kernel/sched/idle_task.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ select_task_rq_idle(struct task_struct *p, int sd_flag, int flags)
1717
static void pre_schedule_idle(struct rq *rq, struct task_struct *prev)
1818
{
1919
idle_exit_fair(rq);
20+
rq_last_tick_reset(rq);
2021
}
2122

2223
static void post_schedule_idle(struct rq *rq)

‎kernel/sched/sched.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ struct rq {
409409
#ifdef CONFIG_NO_HZ_COMMON
410410
u64 nohz_stamp;
411411
unsigned long nohz_flags;
412+
#endif
413+
#ifdef CONFIG_NO_HZ_FULL
414+
unsigned long last_sched_tick;
412415
#endif
413416
int skip_clock_update;
414417

@@ -1090,6 +1093,13 @@ static inline void dec_nr_running(struct rq *rq)
10901093
rq->nr_running--;
10911094
}
10921095

1096+
static inline void rq_last_tick_reset(struct rq *rq)
1097+
{
1098+
#ifdef CONFIG_NO_HZ_FULL
1099+
rq->last_sched_tick = jiffies;
1100+
#endif
1101+
}
1102+
10931103
extern void update_rq_clock(struct rq *rq);
10941104

10951105
extern void activate_task(struct rq *rq, struct task_struct *p, int flags);

‎kernel/time/tick-sched.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts,
600600
time_delta = KTIME_MAX;
601601
}
602602

603+
#ifdef CONFIG_NO_HZ_FULL
604+
if (!ts->inidle) {
605+
time_delta = min(time_delta,
606+
scheduler_tick_max_deferment());
607+
}
608+
#endif
609+
603610
/*
604611
* calculate the expiry time for the next timer wheel
605612
* timer. delta_jiffies >= NEXT_TIMER_MAX_DELTA signals

0 commit comments

Comments
 (0)