* [PATCH v2 0/2] Add basic tracing support for m68k
@ 2024-12-03 17:21 Jean-Michel Hautbois
2024-12-03 17:21 ` [PATCH v2 1/2] m68k: Add tracirqs Jean-Michel Hautbois
2024-12-03 17:21 ` [PATCH v2 2/2] arch: m68k: Add STACKTRACE support Jean-Michel Hautbois
0 siblings, 2 replies; 5+ messages in thread
From: Jean-Michel Hautbois @ 2024-12-03 17:21 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: linux-m68k, linux-kernel, linux-trace-kernel, rostedt,
Jean-Michel Hautbois
In order to debug latency issues, I wanted to use ftrace on my M54418
coldfire. Sadly, it is not supported yet.
Thanks to Steven [1] it does not sound too difficult.
This small series adds basic functions to make it work, and for the few
tests I could do, it seems to be working well.
Here is a simple output I get:
```
bash-232 [000] d..3. 947.629000: thread_noise: bash:232 start 947.629000000 duration 0 ns
timerlat/0-274 [000] ..... 947.629000: #51598 context thread timer_latency 409280 ns
bash-232 [000] d.h.. 947.630000: #51599 context irq timer_latency 110720 ns
bash-232 [000] dnh1. 947.630000: irq_noise: timer:206 start 947.629000000 duration 1000000 ns
bash-232 [000] d..3. 947.630000: thread_noise: bash:232 start 947.630000000 duration 0 ns
timerlat/0-274 [000] ..... 947.630000: #51599 context thread timer_latency 407168 ns
bash-232 [000] d.h.. 947.631000: #51600 context irq timer_latency 108608 ns
bash-232 [000] dnh1. 947.631000: irq_noise: timer:206 start 947.630000000 duration 1000000 ns
bash-232 [000] d..3. 947.631000: thread_noise: bash:232 start 947.631000000 duration 0 ns
timerlat/0-274 [000] ..... 947.631000: #51600 context thread timer_latency 401472 ns
```
I used this on my board and afaik, it works quite well.
```
telnetd-229 0Dnh4. 13us+: 229:120:R + [000] 118: 49:R irq/100-enet-fe
telnetd-229 0Dnh4. 53us+: <stack trace>
=> __trace_stack
=> probe_wakeup
=> try_to_wake_up
=> wake_up_process
=> __handle_irq_event_percpu
=> handle_irq_event
=> handle_level_irq
=> generic_handle_irq
=> do_IRQ
=> inthandler
=> ip_finish_output2
=> __ip_finish_output
=> ip_output
=> __ip_queue_xmit
=> ip_queue_xmit
=> __tcp_transmit_skb
=> tcp_write_xmit
=> __tcp_push_pending_frames
=> tcp_push
=> tcp_sendmsg_locked
=> tcp_sendmsg
=> inet_sendmsg
=> sock_write_iter
=> vfs_write
=> ksys_write
=> sys_write
=> system_call
telnetd-229 0Dnh4. 68us!: wake_up_process <-__handle_irq_event_percpu
telnetd-229 0D..3. 348us+: __schedule <-preempt_schedule_irq
telnetd-229 0D..3. 368us+: 229:120:R ==> [000] 118: 49:R irq/100-enet-fe
telnetd-229 0D..3. 395us : <stack trace>
=> __trace_stack
=> probe_wakeup_sched_switch
=> __schedule
=> preempt_schedule_irq
=> Lkernel_return
=> ip_finish_output2
=> __ip_finish_output
=> ip_output
=> __ip_queue_xmit
=> ip_queue_xmit
=> __tcp_transmit_skb
=> tcp_write_xmit
=> __tcp_push_pending_frames
=> tcp_push
=> tcp_sendmsg_locked
=> tcp_sendmsg
=> inet_sendmsg
=> sock_write_iter
=> vfs_write
=> ksys_write
=> sys_write
=> system_call
```
[1]: https://lore.kernel.org/linux-m68k/20241018124511.70d29198@gandalf.local.home
Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
---
Changes in v2:
- Use the frame pointer and declare it
- Comments on trace_irq have been tested, but adding the trace_on/off in
entry.S fails badly
- Link to v1: https://lore.kernel.org/r/20241021-add-m68k-tracing-support-v1-0-0883d704525b@yoseli.org
---
Jean-Michel Hautbois (2):
m68k: Add tracirqs
arch: m68k: Add STACKTRACE support
arch/m68k/Kconfig | 7 +++++
arch/m68k/kernel/Makefile | 1 +
arch/m68k/kernel/irq.c | 2 ++
arch/m68k/kernel/stacktrace.c | 70 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 80 insertions(+)
---
base-commit: e70140ba0d2b1a30467d4af6bcfe761327b9ec95
change-id: 20241021-add-m68k-tracing-support-36c18d2233d8
Best regards,
--
Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] m68k: Add tracirqs
2024-12-03 17:21 [PATCH v2 0/2] Add basic tracing support for m68k Jean-Michel Hautbois
@ 2024-12-03 17:21 ` Jean-Michel Hautbois
2024-12-03 17:21 ` [PATCH v2 2/2] arch: m68k: Add STACKTRACE support Jean-Michel Hautbois
1 sibling, 0 replies; 5+ messages in thread
From: Jean-Michel Hautbois @ 2024-12-03 17:21 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: linux-m68k, linux-kernel, linux-trace-kernel, rostedt,
Jean-Michel Hautbois
The TRACE_IRQFLAGS_SUPPORT requires the architecture to call
trace_hardirqs_off() when interrupts are disabled and
trace_hardirqs_on() when they are enabled.
Add those calls to do_IRQ function.
Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
---
arch/m68k/Kconfig | 1 +
arch/m68k/kernel/irq.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 7c4f7bcc89d76326b9d7280a3bcba79412ead7d2..793ab1e2762609725bbf793f6dffecfa3ecfff0f 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -39,6 +39,7 @@ config M68K
select OLD_SIGSUSPEND3
select UACCESS_MEMCPY if !MMU
select ZONE_DMA
+ select TRACE_IRQFLAGS_SUPPORT
config CPU_BIG_ENDIAN
def_bool y
diff --git a/arch/m68k/kernel/irq.c b/arch/m68k/kernel/irq.c
index 9ab4f550342e5de11c528f55781432675ffd66bf..74cf60ebbc4bca51f3caa4046dbd2bdb02355711 100644
--- a/arch/m68k/kernel/irq.c
+++ b/arch/m68k/kernel/irq.c
@@ -21,9 +21,11 @@ asmlinkage void do_IRQ(int irq, struct pt_regs *regs)
{
struct pt_regs *oldregs = set_irq_regs(regs);
+ trace_hardirqs_off();
irq_enter();
generic_handle_irq(irq);
irq_exit();
+ trace_hardirqs_on();
set_irq_regs(oldregs);
}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] arch: m68k: Add STACKTRACE support
2024-12-03 17:21 [PATCH v2 0/2] Add basic tracing support for m68k Jean-Michel Hautbois
2024-12-03 17:21 ` [PATCH v2 1/2] m68k: Add tracirqs Jean-Michel Hautbois
@ 2024-12-03 17:21 ` Jean-Michel Hautbois
2024-12-03 18:21 ` Michael Schmitz
1 sibling, 1 reply; 5+ messages in thread
From: Jean-Michel Hautbois @ 2024-12-03 17:21 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: linux-m68k, linux-kernel, linux-trace-kernel, rostedt,
Jean-Michel Hautbois
In order to use tracing, implement a basic arch_stack_walk() based on
the one in PowerPC.
Tested on a M54418 coldfire.
Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
---
arch/m68k/Kconfig | 6 ++++
arch/m68k/kernel/Makefile | 1 +
arch/m68k/kernel/stacktrace.c | 70 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+)
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 793ab1e2762609725bbf793f6dffecfa3ecfff0f..6ba3238ba2c68acaf5974396739e629b09eee3ca 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -40,6 +40,8 @@ config M68K
select UACCESS_MEMCPY if !MMU
select ZONE_DMA
select TRACE_IRQFLAGS_SUPPORT
+ select ARCH_STACKWALK
+ select ARCH_WANT_FRAME_POINTERS
config CPU_BIG_ENDIAN
def_bool y
@@ -106,6 +108,10 @@ config BOOTINFO_PROC
Say Y to export the bootinfo used to boot the kernel in a
"bootinfo" file in procfs. This is useful with kexec.
+config STACKTRACE_SUPPORT
+ bool
+ default y
+
menu "Platform setup"
source "arch/m68k/Kconfig.cpu"
diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile
index 6c732ed3998b714a4842ee29c977550a61979779..cb02bcfe04c6b265fa97db9237395a262e649989 100644
--- a/arch/m68k/kernel/Makefile
+++ b/arch/m68k/kernel/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_UBOOT) += uboot.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
+obj-y += stacktrace.o
diff --git a/arch/m68k/kernel/stacktrace.c b/arch/m68k/kernel/stacktrace.c
new file mode 100644
index 0000000000000000000000000000000000000000..4c2fb6b0cf675ee5a3a21393a50603fea98a1b03
--- /dev/null
+++ b/arch/m68k/kernel/stacktrace.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Stack trace utility functions etc.
+ *
+ * Copyright 2024 Jean-Michel Hautbois, Yoseli SAS.
+ */
+
+#include <asm/current.h>
+#include <asm/ptrace.h>
+#include <linux/sched.h>
+#include <linux/sched/task_stack.h>
+#include <linux/stacktrace.h>
+
+static inline unsigned long current_stack_frame(void)
+{
+ unsigned long sp;
+
+ asm volatile("movl %%fp, %0" : "=r"(sp));
+ return sp;
+}
+
+static inline int validate_sp(unsigned long sp, struct task_struct *task)
+{
+ unsigned long stack_start, stack_end;
+
+ if (task == current)
+ stack_start = (unsigned long)task_stack_page(task);
+ else
+ stack_start = (unsigned long)task->thread.esp0;
+
+ stack_end = stack_start + THREAD_SIZE;
+
+ if (sp < stack_start || sp >= stack_end)
+ return 0;
+
+ return 1;
+}
+
+void __no_sanitize_address arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
+ struct task_struct *task, struct pt_regs *regs)
+{
+ unsigned long sp;
+
+ if (regs && !consume_entry(cookie, regs->pc))
+ return;
+
+ if (regs)
+ sp = (unsigned long) regs;
+ else if (task == current)
+ sp = current_stack_frame();
+ else
+ sp = task->thread.ksp;
+
+ for (;;) {
+ unsigned long *stack = (unsigned long *) sp;
+ unsigned long newsp, ip;
+
+ if (!validate_sp(sp, task))
+ return;
+
+ newsp = stack[0];
+ ip = stack[1];
+
+ if (!consume_entry(cookie, ip))
+ return;
+
+ sp = newsp;
+ }
+}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] arch: m68k: Add STACKTRACE support
2024-12-03 17:21 ` [PATCH v2 2/2] arch: m68k: Add STACKTRACE support Jean-Michel Hautbois
@ 2024-12-03 18:21 ` Michael Schmitz
2024-12-03 19:10 ` Jean-Michel Hautbois
0 siblings, 1 reply; 5+ messages in thread
From: Michael Schmitz @ 2024-12-03 18:21 UTC (permalink / raw)
To: Jean-Michel Hautbois, Geert Uytterhoeven
Cc: linux-m68k, linux-kernel, linux-trace-kernel, rostedt
Jean-Michel,
good work on adding
On 4/12/24 06:21, Jean-Michel Hautbois wrote:
> In order to use tracing, implement a basic arch_stack_walk() based on
> the one in PowerPC.
> Tested on a M54418 coldfire.
>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
> ---
> arch/m68k/Kconfig | 6 ++++
> arch/m68k/kernel/Makefile | 1 +
> arch/m68k/kernel/stacktrace.c | 70 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 77 insertions(+)
>
> diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
> index 793ab1e2762609725bbf793f6dffecfa3ecfff0f..6ba3238ba2c68acaf5974396739e629b09eee3ca 100644
> --- a/arch/m68k/Kconfig
> +++ b/arch/m68k/Kconfig
> @@ -40,6 +40,8 @@ config M68K
> select UACCESS_MEMCPY if !MMU
> select ZONE_DMA
> select TRACE_IRQFLAGS_SUPPORT
> + select ARCH_STACKWALK
> + select ARCH_WANT_FRAME_POINTERS
How much does that add to kernel size? It's only needed for debugging so
some folks may prefer to save a little on code size (not to mention the
extra frame pointer save on each call) ...
Cheers,
Michael
>
> config CPU_BIG_ENDIAN
> def_bool y
> @@ -106,6 +108,10 @@ config BOOTINFO_PROC
> Say Y to export the bootinfo used to boot the kernel in a
> "bootinfo" file in procfs. This is useful with kexec.
>
> +config STACKTRACE_SUPPORT
> + bool
> + default y
> +
Any reason why you can't place the two 'select' statements in this
conditional?
> menu "Platform setup"
>
> source "arch/m68k/Kconfig.cpu"
> diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile
> index 6c732ed3998b714a4842ee29c977550a61979779..cb02bcfe04c6b265fa97db9237395a262e649989 100644
> --- a/arch/m68k/kernel/Makefile
> +++ b/arch/m68k/kernel/Makefile
> @@ -23,3 +23,4 @@ obj-$(CONFIG_UBOOT) += uboot.o
>
> obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
>
> +obj-y += stacktrace.o
> diff --git a/arch/m68k/kernel/stacktrace.c b/arch/m68k/kernel/stacktrace.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..4c2fb6b0cf675ee5a3a21393a50603fea98a1b03
> --- /dev/null
> +++ b/arch/m68k/kernel/stacktrace.c
> @@ -0,0 +1,70 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * Stack trace utility functions etc.
> + *
> + * Copyright 2024 Jean-Michel Hautbois, Yoseli SAS.
> + */
> +
> +#include <asm/current.h>
> +#include <asm/ptrace.h>
> +#include <linux/sched.h>
> +#include <linux/sched/task_stack.h>
> +#include <linux/stacktrace.h>
> +
> +static inline unsigned long current_stack_frame(void)
> +{
> + unsigned long sp;
> +
> + asm volatile("movl %%fp, %0" : "=r"(sp));
> + return sp;
> +}
> +
> +static inline int validate_sp(unsigned long sp, struct task_struct *task)
> +{
> + unsigned long stack_start, stack_end;
> +
> + if (task == current)
> + stack_start = (unsigned long)task_stack_page(task);
> + else
> + stack_start = (unsigned long)task->thread.esp0;
> +
> + stack_end = stack_start + THREAD_SIZE;
> +
> + if (sp < stack_start || sp >= stack_end)
> + return 0;
> +
> + return 1;
> +}
> +
> +void __no_sanitize_address arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
> + struct task_struct *task, struct pt_regs *regs)
> +{
> + unsigned long sp;
> +
> + if (regs && !consume_entry(cookie, regs->pc))
> + return;
> +
> + if (regs)
> + sp = (unsigned long) regs;
> + else if (task == current)
> + sp = current_stack_frame();
> + else
> + sp = task->thread.ksp;
> +
> + for (;;) {
> + unsigned long *stack = (unsigned long *) sp;
> + unsigned long newsp, ip;
> +
> + if (!validate_sp(sp, task))
> + return;
> +
> + newsp = stack[0];
> + ip = stack[1];
> +
> + if (!consume_entry(cookie, ip))
> + return;
> +
> + sp = newsp;
> + }
> +}
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] arch: m68k: Add STACKTRACE support
2024-12-03 18:21 ` Michael Schmitz
@ 2024-12-03 19:10 ` Jean-Michel Hautbois
0 siblings, 0 replies; 5+ messages in thread
From: Jean-Michel Hautbois @ 2024-12-03 19:10 UTC (permalink / raw)
To: Michael Schmitz, Geert Uytterhoeven
Cc: linux-m68k, linux-kernel, linux-trace-kernel, rostedt
Hi Michael,
On 03/12/2024 19:21, Michael Schmitz wrote:
> Jean-Michel,
>
> good work on adding
Thanks ^_^
> On 4/12/24 06:21, Jean-Michel Hautbois wrote:
>> In order to use tracing, implement a basic arch_stack_walk() based on
>> the one in PowerPC.
>> Tested on a M54418 coldfire.
>>
>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
>> ---
>> arch/m68k/Kconfig | 6 ++++
>> arch/m68k/kernel/Makefile | 1 +
>> arch/m68k/kernel/stacktrace.c | 70 +++++++++++++++++++++++++++++++++
>> ++++++++++
>> 3 files changed, 77 insertions(+)
>>
>> diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
>> index
>> 793ab1e2762609725bbf793f6dffecfa3ecfff0f..6ba3238ba2c68acaf5974396739e629b09eee3ca 100644
>> --- a/arch/m68k/Kconfig
>> +++ b/arch/m68k/Kconfig
>> @@ -40,6 +40,8 @@ config M68K
>> select UACCESS_MEMCPY if !MMU
>> select ZONE_DMA
>> select TRACE_IRQFLAGS_SUPPORT
>> + select ARCH_STACKWALK
>> + select ARCH_WANT_FRAME_POINTERS
>
> How much does that add to kernel size? It's only needed for debugging so
> some folks may prefer to save a little on code size (not to mention the
> extra frame pointer save on each call) ...
Oh yeah, I have such a fast (ah ah) cpu that I forget others may not.
I have not measure the size it adds.
>
> Cheers,
>
> Michael
>
>
>> config CPU_BIG_ENDIAN
>> def_bool y
>> @@ -106,6 +108,10 @@ config BOOTINFO_PROC
>> Say Y to export the bootinfo used to boot the kernel in a
>> "bootinfo" file in procfs. This is useful with kexec.
>> +config STACKTRACE_SUPPORT
>> + bool
>> + default y
>> +
> Any reason why you can't place the two 'select' statements in this
> conditional?
Absolutely not, I will add those here and condition the stacktrace to
coldfire (or even M5441x ?) ?
>> menu "Platform setup"
>> source "arch/m68k/Kconfig.cpu"
>> diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile
>> index
>> 6c732ed3998b714a4842ee29c977550a61979779..cb02bcfe04c6b265fa97db9237395a262e649989 100644
>> --- a/arch/m68k/kernel/Makefile
>> +++ b/arch/m68k/kernel/Makefile
>> @@ -23,3 +23,4 @@ obj-$(CONFIG_UBOOT) += uboot.o
>> obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
>> +obj-y += stacktrace.o
>> diff --git a/arch/m68k/kernel/stacktrace.c b/arch/m68k/kernel/
>> stacktrace.c
>> new file mode 100644
>> index
>> 0000000000000000000000000000000000000000..4c2fb6b0cf675ee5a3a21393a50603fea98a1b03
>> --- /dev/null
>> +++ b/arch/m68k/kernel/stacktrace.c
>> @@ -0,0 +1,70 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +/*
>> + * Stack trace utility functions etc.
>> + *
>> + * Copyright 2024 Jean-Michel Hautbois, Yoseli SAS.
>> + */
>> +
>> +#include <asm/current.h>
>> +#include <asm/ptrace.h>
>> +#include <linux/sched.h>
>> +#include <linux/sched/task_stack.h>
>> +#include <linux/stacktrace.h>
>> +
>> +static inline unsigned long current_stack_frame(void)
>> +{
>> + unsigned long sp;
>> +
>> + asm volatile("movl %%fp, %0" : "=r"(sp));
>> + return sp;
>> +}
>> +
>> +static inline int validate_sp(unsigned long sp, struct task_struct
>> *task)
>> +{
>> + unsigned long stack_start, stack_end;
>> +
>> + if (task == current)
>> + stack_start = (unsigned long)task_stack_page(task);
>> + else
>> + stack_start = (unsigned long)task->thread.esp0;
>> +
>> + stack_end = stack_start + THREAD_SIZE;
>> +
>> + if (sp < stack_start || sp >= stack_end)
>> + return 0;
>> +
>> + return 1;
>> +}
>> +
>> +void __no_sanitize_address arch_stack_walk(stack_trace_consume_fn
>> consume_entry, void *cookie,
>> + struct task_struct *task, struct pt_regs *regs)
>> +{
>> + unsigned long sp;
>> +
>> + if (regs && !consume_entry(cookie, regs->pc))
>> + return;
>> +
>> + if (regs)
>> + sp = (unsigned long) regs;
>> + else if (task == current)
>> + sp = current_stack_frame();
>> + else
>> + sp = task->thread.ksp;
>> +
>> + for (;;) {
>> + unsigned long *stack = (unsigned long *) sp;
>> + unsigned long newsp, ip;
>> +
>> + if (!validate_sp(sp, task))
>> + return;
>> +
>> + newsp = stack[0];
>> + ip = stack[1];
>> +
>> + if (!consume_entry(cookie, ip))
>> + return;
>> +
>> + sp = newsp;
>> + }
>> +}
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-03 19:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-03 17:21 [PATCH v2 0/2] Add basic tracing support for m68k Jean-Michel Hautbois
2024-12-03 17:21 ` [PATCH v2 1/2] m68k: Add tracirqs Jean-Michel Hautbois
2024-12-03 17:21 ` [PATCH v2 2/2] arch: m68k: Add STACKTRACE support Jean-Michel Hautbois
2024-12-03 18:21 ` Michael Schmitz
2024-12-03 19:10 ` Jean-Michel Hautbois
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox