sched: Introduce task_is_running()
Replace a bunch of 'p->state == TASK_RUNNING' with a new helper: task_is_running(p). Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Davidlohr Bueso <dave@stgolabs.net> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20210611082838.222401495@infradead.org
This commit is contained in:
@@ -460,7 +460,7 @@ static void set_other_info_task_blocking(unsigned long *flags,
|
||||
* We may be instrumenting a code-path where current->state is already
|
||||
* something other than TASK_RUNNING.
|
||||
*/
|
||||
const bool is_running = current->state == TASK_RUNNING;
|
||||
const bool is_running = task_is_running(current);
|
||||
/*
|
||||
* To avoid deadlock in case we are in an interrupt here and this is a
|
||||
* race with a task on the same CPU (KCSAN_INTERRUPT_WATCHER), provide a
|
||||
|
||||
@@ -760,7 +760,7 @@ static void lockdep_print_held_locks(struct task_struct *p)
|
||||
* It's not reliable to print a task's held locks if it's not sleeping
|
||||
* and it's not the current task.
|
||||
*/
|
||||
if (p->state == TASK_RUNNING && p != current)
|
||||
if (p != current && task_is_running(p))
|
||||
return;
|
||||
for (i = 0; i < depth; i++) {
|
||||
printk(" #%d: ", i);
|
||||
|
||||
@@ -2768,7 +2768,7 @@ EXPORT_SYMBOL_GPL(rcu_bind_current_to_nocb);
|
||||
#ifdef CONFIG_SMP
|
||||
static char *show_rcu_should_be_on_cpu(struct task_struct *tsp)
|
||||
{
|
||||
return tsp && tsp->state == TASK_RUNNING && !tsp->on_cpu ? "!" : "";
|
||||
return tsp && task_is_running(tsp) && !tsp->on_cpu ? "!" : "";
|
||||
}
|
||||
#else // #ifdef CONFIG_SMP
|
||||
static char *show_rcu_should_be_on_cpu(struct task_struct *tsp)
|
||||
|
||||
+3
-3
@@ -5974,7 +5974,7 @@ static inline void sched_submit_work(struct task_struct *tsk)
|
||||
{
|
||||
unsigned int task_flags;
|
||||
|
||||
if (!tsk->state)
|
||||
if (task_is_running(tsk))
|
||||
return;
|
||||
|
||||
task_flags = tsk->flags;
|
||||
@@ -7949,7 +7949,7 @@ again:
|
||||
if (curr->sched_class != p->sched_class)
|
||||
goto out_unlock;
|
||||
|
||||
if (task_running(p_rq, p) || p->state)
|
||||
if (task_running(p_rq, p) || !task_is_running(p))
|
||||
goto out_unlock;
|
||||
|
||||
yielded = curr->sched_class->yield_to_task(rq, p);
|
||||
@@ -8152,7 +8152,7 @@ void sched_show_task(struct task_struct *p)
|
||||
|
||||
pr_info("task:%-15.15s state:%c", p->comm, task_state_to_char(p));
|
||||
|
||||
if (p->state == TASK_RUNNING)
|
||||
if (task_is_running(p))
|
||||
pr_cont(" running task ");
|
||||
#ifdef CONFIG_DEBUG_STACK_USAGE
|
||||
free = stack_not_used(p);
|
||||
|
||||
@@ -217,7 +217,7 @@ static inline void sched_info_depart(struct rq *rq, struct task_struct *t)
|
||||
|
||||
rq_sched_info_depart(rq, delta);
|
||||
|
||||
if (t->state == TASK_RUNNING)
|
||||
if (task_is_running(t))
|
||||
sched_info_enqueue(rq, t);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4719,7 +4719,7 @@ void kdb_send_sig(struct task_struct *t, int sig)
|
||||
}
|
||||
new_t = kdb_prev_t != t;
|
||||
kdb_prev_t = t;
|
||||
if (t->state != TASK_RUNNING && new_t) {
|
||||
if (!task_is_running(t) && new_t) {
|
||||
spin_unlock(&t->sighand->siglock);
|
||||
kdb_printf("Process is not RUNNING, sending a signal from "
|
||||
"kdb risks deadlock\n"
|
||||
|
||||
+1
-2
@@ -92,8 +92,7 @@ static bool ksoftirqd_running(unsigned long pending)
|
||||
|
||||
if (pending & SOFTIRQ_NOW_MASK)
|
||||
return false;
|
||||
return tsk && (tsk->state == TASK_RUNNING) &&
|
||||
!__kthread_should_park(tsk);
|
||||
return tsk && task_is_running(tsk) && !__kthread_should_park(tsk);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TRACE_IRQFLAGS
|
||||
|
||||
Reference in New Issue
Block a user