]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
sched: Introduce task_is_running()
authorPeter Zijlstra <peterz@infradead.org>
Fri, 11 Jun 2021 08:28:12 +0000 (10:28 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 18 Jun 2021 09:43:07 +0000 (11:43 +0200)
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
33 files changed:
arch/alpha/kernel/process.c
arch/arc/kernel/stacktrace.c
arch/arm/kernel/process.c
arch/arm64/kernel/process.c
arch/csky/kernel/stacktrace.c
arch/h8300/kernel/process.c
arch/hexagon/kernel/process.c
arch/ia64/kernel/process.c
arch/m68k/kernel/process.c
arch/mips/kernel/process.c
arch/nds32/kernel/process.c
arch/nios2/kernel/process.c
arch/parisc/kernel/process.c
arch/powerpc/kernel/process.c
arch/riscv/kernel/stacktrace.c
arch/s390/kernel/process.c
arch/s390/mm/fault.c
arch/sh/kernel/process_32.c
arch/sparc/kernel/process_32.c
arch/sparc/kernel/process_64.c
arch/um/kernel/process.c
arch/x86/kernel/process.c
arch/xtensa/kernel/process.c
block/blk-mq.c
include/linux/sched.h
kernel/kcsan/report.c
kernel/locking/lockdep.c
kernel/rcu/tree_plugin.h
kernel/sched/core.c
kernel/sched/stats.h
kernel/signal.c
kernel/softirq.c
mm/compaction.c

index 5112ab996394773724ddf0103a9601ad0242cb07..ef0c08ed04811c7e70ba7aeedd78d6c0768fa12d 100644 (file)
@@ -380,7 +380,7 @@ get_wchan(struct task_struct *p)
 {
        unsigned long schedule_frame;
        unsigned long pc;
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
        /*
         * This one depends on the frame size of schedule().  Do a
index f73da203b17026f80fa63b68c4be3acf7f243594..1b9576d21e244feda21d000e793fa8e9a800af11 100644 (file)
@@ -83,7 +83,7 @@ seed_unwind_frame_info(struct task_struct *tsk, struct pt_regs *regs,
                 *    is safe-kept and BLINK at a well known location in there
                 */
 
-               if (tsk->state == TASK_RUNNING)
+               if (task_is_running(tsk))
                        return -1;
 
                frame_info->task = tsk;
index 6324f4db9b029ba961b092b47c1bd804bf62647e..fc9e8b37eaa8405144da5c7c553d4613215ab801 100644 (file)
@@ -288,7 +288,7 @@ unsigned long get_wchan(struct task_struct *p)
        struct stackframe frame;
        unsigned long stack_page;
        int count = 0;
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        frame.fp = thread_saved_fp(p);
index b4bb67f17a2cab967bd4187d46fd9b982496feca..14f3c19c6ad22cf162ab713134a2be3a9223fea2 100644 (file)
@@ -598,7 +598,7 @@ unsigned long get_wchan(struct task_struct *p)
        struct stackframe frame;
        unsigned long stack_page, ret = 0;
        int count = 0;
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        stack_page = (unsigned long)try_get_task_stack(p);
index 16ae20a0af3421e5cf7ccb1f3ca30730672668c0..1b280ef0800452bc8cf4e2e7ddeab29847cd3ae8 100644 (file)
@@ -115,7 +115,7 @@ unsigned long get_wchan(struct task_struct *task)
 {
        unsigned long pc = 0;
 
-       if (likely(task && task != current && task->state != TASK_RUNNING))
+       if (likely(task && task != current && !task_is_running(task)))
                walk_stackframe(task, NULL, save_wchan, &pc);
        return pc;
 }
index 46b1342ce515b3a33b63a9559786fbe55f2770ce..2ac27e4248a4623468d1171b930f5764b1cea80e 100644 (file)
@@ -134,7 +134,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long stack_page;
        int count = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        stack_page = (unsigned long)p;
index c61165c99ae0ba9d45c79e6f3ab9323ef72cebc4..6a6835fb42425a6e69b86e9951751fb28d4d658c 100644 (file)
@@ -135,7 +135,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long fp, pc;
        unsigned long stack_page;
        int count = 0;
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        stack_page = (unsigned long)task_stack_page(p);
index 7e1a1525e2026f243fd386f875d44bf4ef509de6..e56d63f4abf9decb151c1b6333062bf4c9657680 100644 (file)
@@ -529,7 +529,7 @@ get_wchan (struct task_struct *p)
        unsigned long ip;
        int count = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        /*
@@ -542,7 +542,7 @@ get_wchan (struct task_struct *p)
         */
        unw_init_from_blocked_task(&info, p);
        do {
-               if (p->state == TASK_RUNNING)
+               if (task_is_running(p))
                        return 0;
                if (unw_unwind(&info) < 0)
                        return 0;
index da83cc83e79123b92654fb99f1dbbeb972593d09..db49f90917112b8d76769050b5ed774e32b9550d 100644 (file)
@@ -268,7 +268,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long fp, pc;
        unsigned long stack_page;
        int count = 0;
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        stack_page = (unsigned long)task_stack_page(p);
index bff080db0294e3fa2117e97c2b4a58389d0ad390..73c8e7990a97316a5a3de70a96d0788646335086 100644 (file)
@@ -662,7 +662,7 @@ unsigned long get_wchan(struct task_struct *task)
        unsigned long ra = 0;
 #endif
 
-       if (!task || task == current || task->state == TASK_RUNNING)
+       if (!task || task == current || task_is_running(task))
                goto out;
        if (!task_stack_page(task))
                goto out;
index c1327e552ec6c68a66ea708c127e7fc7e00d1df3..391895b54d13cb5ace1a174104385ff4278e8c04 100644 (file)
@@ -239,7 +239,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long stack_start, stack_end;
        int count = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        if (IS_ENABLED(CONFIG_FRAME_POINTER)) {
index c5f916ca6845f02876a9826a0b0fa9dcfa265715..9ff37ba2bb6032184fcf3d284b00f42f5b3b8ff5 100644 (file)
@@ -223,7 +223,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long stack_page;
        int count = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        stack_page = (unsigned long)p;
index b144fbe29bc16517a81fa200de7be2304ed29796..184ec3c1eae440af9f102333c579db34d59c5319 100644 (file)
@@ -249,7 +249,7 @@ get_wchan(struct task_struct *p)
        unsigned long ip;
        int count = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        /*
@@ -260,7 +260,7 @@ get_wchan(struct task_struct *p)
        do {
                if (unwind_once(&info) < 0)
                        return 0;
-               if (p->state == TASK_RUNNING)
+               if (task_is_running(p))
                         return 0;
                ip = info.ip;
                if (!in_sched_functions(ip))
index 89e34aa273e21afbc4a1bbad2362176ddd640101..8935c5696bcefcfd59355de87d454250016d0a74 100644 (file)
@@ -2084,7 +2084,7 @@ static unsigned long __get_wchan(struct task_struct *p)
        unsigned long ip, sp;
        int count = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        sp = p->thread.ksp;
@@ -2094,7 +2094,7 @@ static unsigned long __get_wchan(struct task_struct *p)
        do {
                sp = *(unsigned long *)sp;
                if (!validate_sp(sp, p, STACK_FRAME_OVERHEAD) ||
-                   p->state == TASK_RUNNING)
+                   task_is_running(p))
                        return 0;
                if (count > 0) {
                        ip = ((unsigned long *)sp)[STACK_FRAME_LR_SAVE];
index bde85fc53357f8a0369fe20dc4f55b9926ac1175..ff467b98c3e3364bcbfefeff1f681a3c4c2d8c0e 100644 (file)
@@ -132,7 +132,7 @@ unsigned long get_wchan(struct task_struct *task)
 {
        unsigned long pc = 0;
 
-       if (likely(task && task != current && task->state != TASK_RUNNING))
+       if (likely(task && task != current && !task_is_running(task)))
                walk_stackframe(task, NULL, save_wchan, &pc);
        return pc;
 }
index e20bed1ed34a2d8691cd8bd000832875fcf85ebd..7ae5dde9c54daf01c9b0c5d5fd6033a99ea5851b 100644 (file)
@@ -180,7 +180,7 @@ unsigned long get_wchan(struct task_struct *p)
        struct unwind_state state;
        unsigned long ip = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING || !task_stack_page(p))
+       if (!p || p == current || task_is_running(p) || !task_stack_page(p))
                return 0;
 
        if (!try_get_task_stack(p))
index 826d017773616d76a42c0c6534ae230c544dac2b..8ae3dc5783fde34dd72f1832ac48846917be18a9 100644 (file)
@@ -702,7 +702,7 @@ static void pfault_interrupt(struct ext_code ext_code,
                         * interrupt since it must be a leftover of a PFAULT
                         * CANCEL operation which didn't remove all pending
                         * completion interrupts. */
-                       if (tsk->state == TASK_RUNNING)
+                       if (task_is_running(tsk))
                                tsk->thread.pfault_wait = -1;
                }
        } else {
index 1aa508eb0823ae3d0ffd70437d22227a585b21b9..717de05c81f49f175f528433445f531107cc84d2 100644 (file)
@@ -186,7 +186,7 @@ unsigned long get_wchan(struct task_struct *p)
 {
        unsigned long pc;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        /*
index 3b9794978e5bc97c3cc4c536dc43e2dacb6d5a58..93983d6d431def5441b5827425744e017cfe5c76 100644 (file)
@@ -376,8 +376,7 @@ unsigned long get_wchan(struct task_struct *task)
        struct reg_window32 *rw;
        int count = 0;
 
-       if (!task || task == current ||
-            task->state == TASK_RUNNING)
+       if (!task || task == current || task_is_running(task))
                goto out;
 
        fp = task_thread_info(task)->ksp + bias;
index 7afd0a859a78c8aa0389de0e6409df7defa7adc7..d33c58a58d4ffb7045eb578bc99297a213ce35ec 100644 (file)
@@ -674,8 +674,7 @@ unsigned long get_wchan(struct task_struct *task)
         unsigned long ret = 0;
        int count = 0; 
 
-       if (!task || task == current ||
-            task->state == TASK_RUNNING)
+       if (!task || task == current || task_is_running(task))
                goto out;
 
        tp = task_thread_info(task);
index c5011064b5dd4207c564cd7e8a10e45e0be63249..457a38db368b7d77ed4b13ccace09d0939a905f4 100644 (file)
@@ -369,7 +369,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long stack_page, sp, ip;
        bool seen_sched = 0;
 
-       if ((p == NULL) || (p == current) || (p->state == TASK_RUNNING))
+       if ((p == NULL) || (p == current) || task_is_running(p))
                return 0;
 
        stack_page = (unsigned long) task_stack_page(p);
index 5e1f38179f4957080a3d282287fc5592496e552c..e52b208b4641b50537c52d05da353ad9cf8cd64b 100644 (file)
@@ -931,7 +931,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long start, bottom, top, sp, fp, ip, ret = 0;
        int count = 0;
 
-       if (p == current || p->state == TASK_RUNNING)
+       if (p == current || task_is_running(p))
                return 0;
 
        if (!try_get_task_stack(p))
@@ -975,7 +975,7 @@ unsigned long get_wchan(struct task_struct *p)
                        goto out;
                }
                fp = READ_ONCE_NOCHECK(*(unsigned long *)fp);
-       } while (count++ < 16 && p->state != TASK_RUNNING);
+       } while (count++ < 16 && !task_is_running(p));
 
 out:
        put_task_stack(p);
index 9534ef515d7487d9a82cdbb1aa626f2f4b9b99f7..0601653406123f5e1006f582bdcb75040a740a50 100644 (file)
@@ -304,7 +304,7 @@ unsigned long get_wchan(struct task_struct *p)
        unsigned long stack_page = (unsigned long) task_stack_page(p);
        int count = 0;
 
-       if (!p || p == current || p->state == TASK_RUNNING)
+       if (!p || p == current || task_is_running(p))
                return 0;
 
        sp = p->thread.sp;
index c86c01bfecdbe51e67128bc952c2780c4a9eecab..655db5fb46d01e9c6f790151e2a67d212db86f89 100644 (file)
@@ -3926,7 +3926,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin)
                if (signal_pending_state(state, current))
                        __set_current_state(TASK_RUNNING);
 
-               if (current->state == TASK_RUNNING)
+               if (task_is_running(current))
                        return 1;
                if (ret < 0 || !spin)
                        break;
index ac5a7d29fd4f97ef84409050df73d6432a6b5917..2cd56352dae14a1768dff4be265e04b589c2fd38 100644 (file)
@@ -113,6 +113,8 @@ struct task_group;
                                         __TASK_TRACED | EXIT_DEAD | EXIT_ZOMBIE | \
                                         TASK_PARKED)
 
+#define task_is_running(task)          (READ_ONCE((task)->state) == TASK_RUNNING)
+
 #define task_is_traced(task)           ((task->state & __TASK_TRACED) != 0)
 
 #define task_is_stopped(task)          ((task->state & __TASK_STOPPED) != 0)
index 13dce3c664d6342a6313b841ea688044077705d8..56016e8e74611b54a38e21bc0fa429608faecd47 100644 (file)
@@ -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
index 7641bd4072390de193fdb28489a3dad76c132586..4931a93c51621f2f8bc254695be4e59a7b37b4fb 100644 (file)
@@ -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);
index ad0156b8693716b8d5bc862f34a25ed418b466f3..4d6962048c30404a7aedbda0b53a4fef333c6a25 100644 (file)
@@ -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)
index 75655cdee3bb98048925ce8cba4838ae3a21ebdb..618c2b5a5758f38585942b24e5f456f07aef7889 100644 (file)
@@ -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);
index 111072ee96638c1e7fbe7870ef66cf2892a13446..d8f8eb0c655ba9a962201ebad7d99f71fcb3ceab 100644 (file)
@@ -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);
 }
 
index f7c6ffcbd04407adf91a0594a949a7bd4ca1463f..5fc8fcf70c240d3b61ca0ca27624a0db8b866f85 100644 (file)
@@ -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"
index 5ddc3b15a4db8b41911ea19dd0d2f16eea65c288..f3a012179f472ce7d98dd76daa1723483abb5e90 100644 (file)
@@ -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
index 84fde270ae74f2117caf70f3b9cc5516acdd8644..725f564a56640c1c6b2d19fb70473475b9bbed1c 100644 (file)
@@ -1955,7 +1955,7 @@ static inline bool is_via_compact_memory(int order)
 
 static bool kswapd_is_running(pg_data_t *pgdat)
 {
-       return pgdat->kswapd && (pgdat->kswapd->state == TASK_RUNNING);
+       return pgdat->kswapd && task_is_running(pgdat->kswapd);
 }
 
 /*