Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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.

Link: https://lore.kernel.org/linux-trace-kernel/20230130130246.247537-1-arnd@kernel.org

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Fixes: b56c68f705ca ("ftrace: Add sample with custom ops")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Arnd Bergmann and committed by
Steven Rostedt (Google)
f94fe704 01678fbc

+1 -1
+1 -1
samples/ftrace/ftrace-ops.c
··· 223 223 224 224 pr_info("Attempted %u calls to %ps in %lluns (%lluns / call)\n", 225 225 nr_function_calls, tracee_relevant, 226 - period, period / nr_function_calls); 226 + period, div_u64(period, nr_function_calls)); 227 227 228 228 if (persist) 229 229 return 0;