Skip to contentSkip to conversation

ftrace: sample: avoid open-coded 64-bit division

PATCH In review Arnd Bergmann 2 participants 2 messages Jan 30, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ftrace: sample: avoid open-coded 64-bit division

From: Arnd Bergmann <[email protected]>

Calculating the average period requires a 64-bit division that leads to a link failure on 32-bit architectures:

x86_64-linux-ld: samples/ftrace/ftrace-ops.o: in function `ftrace_ops_sample_init':
ftrace-ops.c:(.init.text+0x23b): undefined reference to `__udivdi3'

Use the div_u64() helper to do this instead. Since this is an init function that is not called frequently, the runtime overhead is going to be acceptable.

Fixes b56c68f705ca ("ftrace: Add sample with custom ops")
---
 samples/ftrace/ftrace-ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/ftrace/ftrace-ops.c +1 -1
index 24deb51c7261..0c8da87ff5c3 100644
@@ -223,7 +223,7 @@ static int __init ftrace_ops_sample_init(void)
 
 	pr_info("Attempted %u calls to %ps in %lluns (%lluns / call)\n",
 		nr_function_calls, tracee_relevant,
-		period, period / nr_function_calls);
+		period, div_u64(period, nr_function_calls));
 
 	if (persist)
 		return 0;
Signature · 1 line
2.39.0
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Calculating the average period requires a 64-bit division that leads to a link failure on 32-bit architectures:

x86_64-linux-ld: samples/ftrace/ftrace-ops.o: in function `ftrace_ops_sample_init':
ftrace-ops.c:(.init.text+0x23b): undefined reference to `__udivdi3'

Whoops; sorry about that.

Quoted 5 lines

Use the div_u64() helper to do this instead. Since this is an init function that is not called frequently, the runtime overhead is going to be acceptable.

Fixes b56c68f705ca ("ftrace: Add sample with custom ops")

Mark.

Quoted 20 lines
---
 samples/ftrace/ftrace-ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/ftrace/ftrace-ops.c +1 -1
index 24deb51c7261..0c8da87ff5c3 100644
@@ -223,7 +223,7 @@ static int __init ftrace_ops_sample_init(void)
 
 	pr_info("Attempted %u calls to %ps in %lluns (%lluns / call)\n",
 		nr_function_calls, tracee_relevant,
-		period, period / nr_function_calls);
+		period, div_u64(period, nr_function_calls));
 
 	if (persist)
 		return 0;
Signature · 1 line
2.39.0