Re: [PATCH] printf: mark errptr() noinline

From: Petr Mladek

Date: Tue Apr 07 2026 - 07:27:38 EST


On Mon 2026-04-06 12:32:32, Steven Rostedt wrote:
> On Mon, 6 Apr 2026 11:21:39 -0400
> Tamir Duberstein <tamird@xxxxxxxxxx> wrote:
>
> > Thanks Steve. IMO that is a very big hammer and not warranted in this
> > case. There's been talk of encouraging distros to enable CONFIG_KUNIT
> > by default [0], which would probably interact poorly with the change
> > you propose.
> >
>
> Branch profiling is really just a niche that is enabled specifically for
> seeing all branches taken in the kernel. It hooks to all "if" statements!
> As you can imagine, it causes a rather large overhead in performance.
>
> This option is only used by developers doing special analysis of their code
> (namely me ;-).
>
> The only real concern I would have is if the kunit test developers would
> want to use the branch profiling on their code, in which case my suggestion
> would prevent that.

I wonder if it might be possible to disable the branch profiling just
for the printf_kunit.c as a compromise.

Would "#undef if" in printf_kunit.c help?

Or I see that DISABLE_BRANCH_PROFILING is an official
way to disable the feature.

I wonder if the following change would solve the problem.
I am sorry, I could not test it easily.

diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index 05f74edbc62b..45d69769ccdf 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_MIN_HEAP_KUNIT_TEST) += min_heap_kunit.o
CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare)
obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
obj-$(CONFIG_PRINTF_KUNIT_TEST) += printf_kunit.o
+CFLAGS_printf_kunit.o += -DDISABLE_BRANCH_PROFILING
obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o
obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
obj-$(CONFIG_SEQ_BUF_KUNIT_TEST) += seq_buf_kunit.o


Best Regards,
Petr