Skip to content

Commit

Permalink
kernel/idle: Update and use idle-hint in VPA region
Browse files Browse the repository at this point in the history
In guest, Set idle_hint to 1 when the prev_cpu of a vCPU goes into idle state,
similarly set idle_hint to 0 when exiting an idle state.

Since the idle_hint is in VPA region, the available_idle_cpu() in guest can
read this region every time to find if a vCPU can be scheduled instantly by
the hypervsior or not.

Signed-off-by: Parth Shah <parth@linux.ibm.com>
  • Loading branch information
Parth Shah authored and intel-lab-lkp committed Jul 13, 2021
1 parent 09b5719 commit c14c774
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arch/powerpc/include/asm/paravirt.h
Expand Up @@ -21,6 +21,12 @@ static inline bool is_shared_processor(void)
return static_branch_unlikely(&shared_processor);
}

static inline int idle_hint_of(int cpu)
{
__be32 idle_hint = READ_ONCE(lppaca_of(cpu).idle_hint);
return be32_to_cpu(idle_hint);
}

/* If bit 0 is set, the cpu has been preempted */
static inline u32 yield_count_of(int cpu)
{
Expand Down Expand Up @@ -109,8 +115,10 @@ static inline bool vcpu_is_preempted(int cpu)
}
#endif

if (yield_count_of(cpu) & 1)
return true;
if (yield_count_of(cpu) & 1) {
if (idle_hint_of(cpu) == 0)
return true;
}
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions kernel/sched/idle.c
Expand Up @@ -7,6 +7,7 @@
* tasks which are handled in sched/fair.c )
*/
#include "sched.h"
#include <asm/idle_hint.h>

#include <trace/events/power.h>

Expand Down Expand Up @@ -290,6 +291,7 @@ static void do_idle(void)
arch_cpu_idle_dead();
}

set_idle_hint(cpu, 1);
arch_cpu_idle_enter();
rcu_nocb_flush_deferred_wakeup();

Expand All @@ -306,6 +308,7 @@ static void do_idle(void)
cpuidle_idle_call();
}
arch_cpu_idle_exit();
set_idle_hint(cpu, 0);
}

/*
Expand Down

0 comments on commit c14c774

Please sign in to comment.