Commit 6f4b7052 authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Michael Ellerman

powerpc/sched: Cleanup vcpu_is_preempted()

No functional change in this patch. A helper is added to find if
vcpu is dispatched by hypervisor. Use that instead of opencoding.
Also clarify some of the comments.
Signed-off-by: default avatar"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231114071219.198222-1-aneesh.kumar@linux.ibm.com
parent a143892c
...@@ -76,6 +76,17 @@ static inline bool is_vcpu_idle(int vcpu) ...@@ -76,6 +76,17 @@ static inline bool is_vcpu_idle(int vcpu)
{ {
return lppaca_of(vcpu).idle; return lppaca_of(vcpu).idle;
} }
static inline bool vcpu_is_dispatched(int vcpu)
{
/*
* This is the yield_count. An "odd" value (low bit on) means that
* the processor is yielded (either because of an OS yield or a
* hypervisor preempt). An even value implies that the processor is
* currently executing.
*/
return (!(yield_count_of(vcpu) & 1));
}
#else #else
static inline bool is_shared_processor(void) static inline bool is_shared_processor(void)
{ {
...@@ -109,6 +120,10 @@ static inline bool is_vcpu_idle(int vcpu) ...@@ -109,6 +120,10 @@ static inline bool is_vcpu_idle(int vcpu)
{ {
return false; return false;
} }
static inline bool vcpu_is_dispatched(int vcpu)
{
return true;
}
#endif #endif
#define vcpu_is_preempted vcpu_is_preempted #define vcpu_is_preempted vcpu_is_preempted
...@@ -134,12 +149,12 @@ static inline bool vcpu_is_preempted(int cpu) ...@@ -134,12 +149,12 @@ static inline bool vcpu_is_preempted(int cpu)
* If the hypervisor has dispatched the target CPU on a physical * If the hypervisor has dispatched the target CPU on a physical
* processor, then the target CPU is definitely not preempted. * processor, then the target CPU is definitely not preempted.
*/ */
if (!(yield_count_of(cpu) & 1)) if (vcpu_is_dispatched(cpu))
return false; return false;
/* /*
* If the target CPU has yielded to Hypervisor but OS has not * if the target CPU is not dispatched and the guest OS
* requested idle then the target CPU is definitely preempted. * has not marked the CPU idle, then it is hypervisor preempted.
*/ */
if (!is_vcpu_idle(cpu)) if (!is_vcpu_idle(cpu))
return true; return true;
...@@ -166,7 +181,7 @@ static inline bool vcpu_is_preempted(int cpu) ...@@ -166,7 +181,7 @@ static inline bool vcpu_is_preempted(int cpu)
/* /*
* The PowerVM hypervisor dispatches VMs on a whole core * The PowerVM hypervisor dispatches VMs on a whole core
* basis. So we know that a thread sibling of the local CPU * basis. So we know that a thread sibling of the executing CPU
* cannot have been preempted by the hypervisor, even if it * cannot have been preempted by the hypervisor, even if it
* has called H_CONFER, which will set the yield bit. * has called H_CONFER, which will set the yield bit.
*/ */
...@@ -174,15 +189,17 @@ static inline bool vcpu_is_preempted(int cpu) ...@@ -174,15 +189,17 @@ static inline bool vcpu_is_preempted(int cpu)
return false; return false;
/* /*
* If any of the threads of the target CPU's core are not * The specific target CPU was marked by guest OS as idle, but
* preempted or ceded, then consider target CPU to be * then also check all other cpus in the core for PowerVM
* non-preempted. * because it does core scheduling and one of the vcpu
* of the core getting preempted by hypervisor implies
* other vcpus can also be considered preempted.
*/ */
first_cpu = cpu_first_thread_sibling(cpu); first_cpu = cpu_first_thread_sibling(cpu);
for (i = first_cpu; i < first_cpu + threads_per_core; i++) { for (i = first_cpu; i < first_cpu + threads_per_core; i++) {
if (i == cpu) if (i == cpu)
continue; continue;
if (!(yield_count_of(i) & 1)) if (vcpu_is_dispatched(i))
return false; return false;
if (!is_vcpu_idle(i)) if (!is_vcpu_idle(i))
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment