[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230330081552.54178-3-zhengqi.arch@bytedance.com>
Date: Thu, 30 Mar 2023 16:15:52 +0800
From: Qi Zheng <zhengqi.arch@...edance.com>
To: peterz@...radead.org, keescook@...omium.org, jpoimboe@...nel.org,
dave.hansen@...ux.intel.com, bp@...en8.de, mingo@...hat.com,
tglx@...utronix.de, rostedt@...dmis.org
Cc: x86@...nel.org, linux-kernel@...r.kernel.org,
Qi Zheng <zhengqi.arch@...edance.com>
Subject: [PATCH 2/2] x86: make __get_wchan() use arch_stack_walk()
Make __get_wchan() use arch_stack_walk() directly to
avoid open-coding of unwind logic.
Signed-off-by: Qi Zheng <zhengqi.arch@...edance.com>
---
arch/x86/kernel/process.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 3ab62ac98c2c..a6ff18fa6d5d 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -1000,6 +1000,17 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
return randomize_page(mm->brk, 0x02000000);
}
+static bool get_wchan_cb(void *arg, unsigned long pc)
+{
+ unsigned long *addr = arg;
+
+ if (in_sched_functions(pc))
+ return true;
+
+ *addr = pc;
+ return false;
+}
+
/*
* Called from fs/proc with a reference on @p to find the function
* which called into schedule(). This needs to be done carefully
@@ -1008,21 +1019,12 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
*/
unsigned long __get_wchan(struct task_struct *p)
{
- struct unwind_state state;
unsigned long addr = 0;
if (!try_get_task_stack(p))
return 0;
- for (unwind_start(&state, p, NULL, NULL); !unwind_done(&state);
- unwind_next_frame(&state)) {
- addr = unwind_get_return_address(&state);
- if (!addr)
- break;
- if (in_sched_functions(addr))
- continue;
- break;
- }
+ arch_stack_walk(get_wchan_cb, &addr, p, NULL);
put_task_stack(p);
--
2.20.1
Powered by blists - more mailing lists