Re: [PATCH v2 2/3] x86/smp: Allow forcing the mwait hint for play dead loop
From: Patryk Wlazlyn
Date: Wed Oct 30 2024 - 09:34:18 EST
>> +void smp_set_mwait_play_dead_hint(unsigned int hint)
>> +{
>> + WRITE_ONCE(play_dead_mwait_hint, hint);
>> +}
>
> This all feels a bit hacky and unstructured to me.
>
> Could we at least set up a few rules here? Like, say what the hints
> are, what values can they have? Where do they come from? Can this get
> called more than once? Does it _need_ to be set? What's the behavior
> when it is not set? Who is responsible for calling this?
The other idea is to first check if currently loaded idle driver provides
enter_dead() callback first and leave the current, deepest mwait hint
computation code as a fallback.
Does that sound less hacky?
Unfortunately, it comes with a little problem. In case of kexec, we need to
have a way to exit from the mwait loop and enter hlt to prevent offlined CPU
from crashing when the old memory is being overwritten.
I think, we can solve it by bringing the CPU back online before we proceed
with kexec, but I would appreciate some feedback from someone who is more
familiar with kexec, before merging that.
We may also signal that by touching the resched flag on which enter_dead()
code will monitor in case of mwait and enter hlt right after, but that's a
bit hackier IMO.
> What good does the smp_ prefix do? I don't think _callers_ care whether
> this is getting optimized out or not.
The prefix makes it a little bit cleaner by not exporting new global symbol
with "set_mwait_play_dead_hint" name.