Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231114071219.198222-1-aneesh.kumar@linux.ibm.com

authored by

Aneesh Kumar K.V and committed by
Michael Ellerman
6f4b7052 a143892c

+25 -8
+25 -8
arch/powerpc/include/asm/paravirt.h
··· 76 76 { 77 77 return lppaca_of(vcpu).idle; 78 78 } 79 + 80 + static inline bool vcpu_is_dispatched(int vcpu) 81 + { 82 + /* 83 + * This is the yield_count. An "odd" value (low bit on) means that 84 + * the processor is yielded (either because of an OS yield or a 85 + * hypervisor preempt). An even value implies that the processor is 86 + * currently executing. 87 + */ 88 + return (!(yield_count_of(vcpu) & 1)); 89 + } 79 90 #else 80 91 static inline bool is_shared_processor(void) 81 92 { ··· 120 109 { 121 110 return false; 122 111 } 112 + static inline bool vcpu_is_dispatched(int vcpu) 113 + { 114 + return true; 115 + } 123 116 #endif 124 117 125 118 #define vcpu_is_preempted vcpu_is_preempted ··· 149 134 * If the hypervisor has dispatched the target CPU on a physical 150 135 * processor, then the target CPU is definitely not preempted. 151 136 */ 152 - if (!(yield_count_of(cpu) & 1)) 137 + if (vcpu_is_dispatched(cpu)) 153 138 return false; 154 139 155 140 /* 156 - * If the target CPU has yielded to Hypervisor but OS has not 157 - * requested idle then the target CPU is definitely preempted. 141 + * if the target CPU is not dispatched and the guest OS 142 + * has not marked the CPU idle, then it is hypervisor preempted. 158 143 */ 159 144 if (!is_vcpu_idle(cpu)) 160 145 return true; ··· 181 166 182 167 /* 183 168 * The PowerVM hypervisor dispatches VMs on a whole core 184 - * basis. So we know that a thread sibling of the local CPU 169 + * basis. So we know that a thread sibling of the executing CPU 185 170 * cannot have been preempted by the hypervisor, even if it 186 171 * has called H_CONFER, which will set the yield bit. 187 172 */ ··· 189 174 return false; 190 175 191 176 /* 192 - * If any of the threads of the target CPU's core are not 193 - * preempted or ceded, then consider target CPU to be 194 - * non-preempted. 177 + * The specific target CPU was marked by guest OS as idle, but 178 + * then also check all other cpus in the core for PowerVM 179 + * because it does core scheduling and one of the vcpu 180 + * of the core getting preempted by hypervisor implies 181 + * other vcpus can also be considered preempted. 195 182 */ 196 183 first_cpu = cpu_first_thread_sibling(cpu); 197 184 for (i = first_cpu; i < first_cpu + threads_per_core; i++) { 198 185 if (i == cpu) 199 186 continue; 200 - if (!(yield_count_of(i) & 1)) 187 + if (vcpu_is_dispatched(i)) 201 188 return false; 202 189 if (!is_vcpu_idle(i)) 203 190 return true;