Re: [RFC PATCH] preempt: Add a generic function to return the preemption string.

From: Steven Rostedt
Date: Thu Jan 09 2025 - 10:51:53 EST


On Thu, 9 Jan 2025 15:37:01 +0100
Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:

> > I'm sorry, but I can't even tell what the above is doing without my brain
> > hurting. Why make code that was easy to read into a cryptic obfuscation? I
> > can't see this as an optimization as IS_ENABLED() is determined at compile
> > time.
>
> Upgrade brain. Also the proposed thing was just plain wrong.

Or use seq_buf to make it a little more readable again:

const char *preempt_model_str(void)
{
static char buf[128];
bool brace = IS_ENABLED(CONFIG_PREEMPT_RT) &&
(IS_ENABLED(CONFIG_PREEMPT_DYNAMIC) ||
IS_ENABLED(CONFIG_PREEMPT_LAZY));

if (IS_ENABLED(CONFIG_PREEMPT_BUILD)) {
struct seq_buf s;

seq_buf_init(&s, buf, 128);
seq_buf_puts(&s, "PREEMPT");

if (IS_ENABLED(CONFIG_PREEMPT_RT))
seq_buf_printf(&s, "%sRT%s", brace ? "_{" : "_",
brace ? "," : "");

if (IS_ENABLED(CONFIG_PREEMPT_DYNAMIC)) {
seq_buf_printf(&s, "(%s)%s",
preempt_modes[preempt_dynamic_mode],
brace ? "}" : "");
return seq_buf_str(&s);
}

if (IS_ENABLED(CONFIG_PREEMPT_LAZY)) {
seq_buf_printf(&s, "LAZY%s",
brace ? "}" : "");
return seq_buf_str(&s);
}

return seq_buf_str(&s);
}

if (IS_ENABLED(CONFIG_VOLUNTARY_BUILD))
return "VOLUNTARY";

return "NONE";
}


At least this removes the need for keeping track of off, len and r.

-- Steve