Skip to content

Commit 548796e

Browse files
Cruz ZhaoPeter Zijlstra
authored andcommitted
sched/core: introduce sched_core_idle_cpu()
As core scheduling introduced, a new state of idle is defined as force idle, running idle task but nr_running greater than zero. If a cpu is in force idle state, idle_cpu() will return zero. This result makes sense in some scenarios, e.g., load balance, showacpu when dumping, and judge the RCU boost kthread is starving. But this will cause error in other scenarios, e.g., tick_irq_exit(): When force idle, rq->curr == rq->idle but rq->nr_running > 0, results that idle_cpu() returns 0. In function tick_irq_exit(), if idle_cpu() is 0, tick_nohz_irq_exit() will not be called, and ts->idle_active will not become 1, which became 0 in tick_nohz_irq_enter(). ts->idle_sleeptime won't update in function update_ts_time_stats(), if ts->idle_active is 0, which should be 1. And this bug will result that ts->idle_sleeptime is less than the actual value, and finally will result that the idle time in /proc/stat is less than the actual value. To solve this problem, we introduce sched_core_idle_cpu(), which returns 1 when force idle. We audit all users of idle_cpu(), and change idle_cpu() into sched_core_idle_cpu() in function tick_irq_exit(). v2-->v3: Only replace idle_cpu() with sched_core_idle_cpu() in function tick_irq_exit(). And modify the corresponding commit log. Signed-off-by: Cruz Zhao <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Peter Zijlstra <[email protected]> Reviewed-by: Frederic Weisbecker <[email protected]> Reviewed-by: Joel Fernandes <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 677ea01 commit 548796e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

include/linux/sched.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,9 +2433,11 @@ extern void sched_core_free(struct task_struct *tsk);
24332433
extern void sched_core_fork(struct task_struct *p);
24342434
extern int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
24352435
unsigned long uaddr);
2436+
extern int sched_core_idle_cpu(int cpu);
24362437
#else
24372438
static inline void sched_core_free(struct task_struct *tsk) { }
24382439
static inline void sched_core_fork(struct task_struct *p) { }
2440+
static inline int sched_core_idle_cpu(int cpu) { return idle_cpu(cpu); }
24392441
#endif
24402442

24412443
extern void sched_set_stop_task(int cpu, struct task_struct *stop);

kernel/sched/core.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7383,6 +7383,19 @@ struct task_struct *idle_task(int cpu)
73837383
return cpu_rq(cpu)->idle;
73847384
}
73857385

7386+
#ifdef CONFIG_SCHED_CORE
7387+
int sched_core_idle_cpu(int cpu)
7388+
{
7389+
struct rq *rq = cpu_rq(cpu);
7390+
7391+
if (sched_core_enabled(rq) && rq->curr == rq->idle)
7392+
return 1;
7393+
7394+
return idle_cpu(cpu);
7395+
}
7396+
7397+
#endif
7398+
73867399
#ifdef CONFIG_SMP
73877400
/*
73887401
* This function computes an effective utilization for the given CPU, to be

kernel/softirq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ static inline void tick_irq_exit(void)
612612
int cpu = smp_processor_id();
613613

614614
/* Make sure that timer wheel updates are propagated */
615-
if ((idle_cpu(cpu) && !need_resched()) || tick_nohz_full_cpu(cpu)) {
615+
if ((sched_core_idle_cpu(cpu) && !need_resched()) || tick_nohz_full_cpu(cpu)) {
616616
if (!in_hardirq())
617617
tick_nohz_irq_exit();
618618
}

0 commit comments

Comments
 (0)