Skip to contentSkip to conversation

fixed dump_backtrace() when task running on another cpu

PATCH Superseded Wang Qing 3 participants 7 messages Apr 13, 2020 – Apr 15, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wang Qing

author
#0 lore raw

cover fixed dump_backtrace() when task running on another cpu

We cannot get FP and PC when the task is running on another CPU, task->thread.cpu_context is the last time the task was switched out, it's better to give a reminder than to provide wrong information.

We have no interface whether the task is running, so we need to add an interface and distinguish CONFIG_SMP.

Wang Qing (2):
[V2 1/2]sched:add task_running_oncpu
[V2 2/2]ARM64:fixed dump_backtrace() when task running on another cpu

 arch/arm64/kernel/traps.c |  7 +++++++
 include/linux/sched.h     | 10 ++++++++++
 2 files changed, 17 insertions(+)
Signature · 7 lines
2.7.4


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#1 lore raw

PATCH v2 1/2 sched:add task_running_oncpu

We have no interface whether the task is running, so we need to add an interface and distinguish CONFIG_SMP.

---
 include/linux/sched.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/sched.h +10 -0
index 4418f5c..13cc8f5 100644
@@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
 
 extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
 
+static inline int task_running_oncpu(const struct task_struct *p)
+{
+	return p->on_cpu;
+}
+
 #else
 
 static inline unsigned int task_cpu(const struct task_struct *p)
@@ -1854,6 +1859,11 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
 {
 }
 
+static inline int task_running_oncpu(const struct task_struct *p)
+{
+	return p == current;
+}
+
 #endif /* CONFIG_SMP */
 
 /*
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

Quoted 14 lines · Wang Qing

We have no interface whether the task is running, so we need to add an interface and distinguish CONFIG_SMP.

---
 include/linux/sched.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/sched.h +0 -0
index 4418f5c..13cc8f5 100644

include/linux/sched.h static inline unsigned int task_cpu(const struct task_struct *p) · line 1846

Quoted 4 lines
include/linux/sched.h +1 -0
@@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
 
 extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
 
+static inline int task_running_oncpu(const struct task_struct *p)

This function name is too close from task_running_on_cpu() and can be misleading as the difference is only "_"
Also, how task_running_oncpu() is different from task_running() ?

Quoted 22 lines
include/linux/sched.h +9 -1
+{
+       return p->on_cpu;
+}
+
 #else
 
 static inline unsigned int task_cpu(const struct task_struct *p)
@@ -1854,6 +1859,11 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
 {
 }
 
+static inline int task_running_oncpu(const struct task_struct *p)
+{
+       return p == current;
+}
+
 #endif /* CONFIG_SMP */
 
 /*
--

2.7.4

maintainer
#3 lore raw

Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

Quoted 16 lines · Vincent Guittot
Quoted 15 lines · Wang Qing

We have no interface whether the task is running, so we need to add an interface and distinguish CONFIG_SMP.

---
 include/linux/sched.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/sched.h +0 -0
index 4418f5c..13cc8f5 100644
@@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
 
Quoted 7 lines

include/linux/sched.h static inline unsigned int task_cpu(const struct task_struct *p) · line 1846

Quoted 3 lines
include/linux/sched.h +1 -0
 extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
 
+static inline int task_running_oncpu(const struct task_struct *p)

This function name is too close from task_running_on_cpu() and can be misleading as the difference is only "_"
Also, how task_running_oncpu() is different from task_running() ?

It doesn't have the (arguably superfluous) rq argument. But yes, agreed, if anything lift that thing (without the argument).

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#4 lore raw

Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

In reply to Wang Qing
Quoted 16 lines · Wang Qing
Quoted 15 lines

We have no interface whether the task is running, so we need to add an interface and distinguish CONFIG_SMP.

---
 include/linux/sched.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/sched.h +0 -0
index 4418f5c..13cc8f5 100644
@@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
 
Quoted 7 lines

include/linux/sched.h static inline unsigned int task_cpu(const struct task_struct *p) · line 1846

Quoted 3 lines
include/linux/sched.h +1 -0
 extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
 
+static inline int task_running_oncpu(const struct task_struct *p)

This function name is too close from task_running_on_cpu() and can be misleading as the difference is only "_"
Also, how task_running_oncpu() is different from task_running() ?

I think task_running() should be renamed to task_running_on_rq(), this is what it originally mean. And the task_running_oncpu I added should be called task_running(). This solves the confusing naming problem that already exists.

Thanks,
Wang Qing.

Quoted 23 lines
Quoted 23 lines
include/linux/sched.h +9 -1
+{
+       return p->on_cpu;
+}
+
 #else
 
 static inline unsigned int task_cpu(const struct task_struct *p)
@@ -1854,6 +1859,11 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
 {
 }
 
+static inline int task_running_oncpu(const struct task_struct *p)
+{
+       return p == current;
+}
+
 #endif /* CONFIG_SMP */
 
 /*
--

2.7.4

author
#5 lore raw

Re: [PATCH 1/2] [V2 1/2]sched:add task_running_oncpu

In reply to Wang Qing
Quoted 19 lines · Vincent Guittot
Quoted 18 lines · Wang Qing
Quoted 17 lines

We have no interface whether the task is running, so we need to add an interface and distinguish CONFIG_SMP.

---
 include/linux/sched.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/sched.h +0 -0
index 4418f5c..13cc8f5 100644
@@ -1843,6 +1843,11 @@ static inline unsigned int task_cpu(const struct task_struct *p)
 
 extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
 
Quoted 8 lines
Quoted 5 lines

include/linux/sched.h static inline unsigned int task_cpu(const struct task_struct *p) · line 1846

Quoted 1 line
include/linux/sched.h +1 -0
+static inline int task_running_oncpu(const struct task_struct *p)

This function name is too close from task_running_on_cpu() and can be misleading as the difference is only "_"
Also, how task_running_oncpu() is different from task_running() ?

It doesn't have the (arguably superfluous) rq argument. But yes, agreed, if anything lift that thing (without the argument).

I think task_running() should be renamed to task_running_on_rq() like the naming of task_running_on_cpu(), this is what it originally mean, and add task_running() (with the task argument only).

I updated the patch for that.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#6 lore raw

PATCH v2 2/2 ARM64:fixed dump_backtrace() when task running on another cpu

In reply to Wang Qing

We cannot get FP and PC when the task is running on another CPU, task->thread.cpu_context is the last time the task was switched out, it's better to give a reminder than to provide wrong information.

---
 arch/arm64/kernel/traps.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm64/kernel/traps.c +7 -0
index cf402be..831b8fd 100644
@@ -106,6 +106,13 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 		start_backtrace(&frame,
 				(unsigned long)__builtin_frame_address(0),
 				(unsigned long)dump_backtrace);
+	} else if (task_running_oncpu(tsk)) {
+		/*
+		 * The task is running in another cpu, we cannot get it.
+		 */
+		pr_warn("tsk: %s is running in CPU%d, Don't call trace!\n",
+			tsk->comm, task_cpu(tsk));
+		return;
 	} else {
 		/*
 		 * task blocked in __switch_to
Signature · 1 line
2.7.4