On Thu, 23 Mar 2023, Alexey Dobriyan wrote: > On Wed, Mar 22, 2023 at 05:07:09PM +0100, Miroslav Benes wrote: > > On Wed, 22 Mar 2023, Alexey Dobriyan wrote: > > > > > Hi, Josh. > > > > > > I've been profiling how much time livepatching takes and I have a question > > > regarding these lines: > > > > > > void klp_try_complete_transition(void) > > > { > > > ... > > > if (!complete) { > > > schedule_delayed_work(&klp_transition_work, round_jiffies_relative(HZ)); > > > return; > > > } > > > > > > } > > > > > > The problem here is that if the system is idle, then the previous loop > > > checking idle tasks will reliably sets "complete = false" and then > > > patching wastes time waiting for next second so that klp_transition_work > > > will repeat the same code without reentering itself. > > > > Only if klp_try_switch_task() cannot switch the idle task right away. We > > then prod it using wake_up_if_idle() and handle it in the next iteration. > > > > So the question might be why klp_try_switch_task() did not succeed in the > > first place. > > Yes, sort of. Transitioning never happens on the first try becase of idle > tasks (see debugging patch below). But it should happen immediately > because machine is idle! Yes. My guess is that swapper task is running and cannot be switched through klp_try_switch_task() so we prod it and it migrates itself through our hook in do_idle(). You can enable a dynamic debug and see if it helps to confirm it # echo "file kernel/livepatch/* +p" > /sys/kernel/debug/dynamic_debug/control Miroslav