Skip to content

Commit 20ecf59

Browse files
ZideChen0sean-jc
authored andcommitted
KVM: selftests: Allow skipping the KVM_RUN sanity check in rseq_test
The rseq test's migration worker delays 1-10 us, assuming that one KVM_RUN iteration only takes a few microseconds. But if the CPU low power wakeup latency is large enough, for example, hundreds or even thousands of microseconds for deep C-state exit latencies on x86 server CPUs, it may happen that the target CPU is unable to wakeup and run the vCPU before the migration worker starts to migrate the vCPU thread to the _next_ CPU. If the system workload is light, most CPUs could be at a certain low power state, which may result in less successful migrations and fail the migration/KVM_RUN ratio sanity check. But this is not supposed to be deemed a test failure. Add a command line option to skip the sanity check, along with a comment and a verbose assert message to try to help the user resolve the potential source of failures without having to resort to disabling the check. Co-developed-by: Dongsheng Zhang <dongsheng.x.zhang@intel.com> Signed-off-by: Dongsheng Zhang <dongsheng.x.zhang@intel.com> Signed-off-by: Zide Chen <zide.chen@intel.com> Link: https://lore.kernel.org/r/20240502213936.27619-1-zide.chen@intel.com [sean: massage changelog] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 0540193 commit 20ecf59

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

tools/testing/selftests/kvm/rseq_test.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,35 @@ static void calc_min_max_cpu(void)
186186
"Only one usable CPU, task migration not possible");
187187
}
188188

189+
static void help(const char *name)
190+
{
191+
puts("");
192+
printf("usage: %s [-h] [-u]\n", name);
193+
printf(" -u: Don't sanity check the number of successful KVM_RUNs\n");
194+
puts("");
195+
exit(0);
196+
}
197+
189198
int main(int argc, char *argv[])
190199
{
200+
bool skip_sanity_check = false;
191201
int r, i, snapshot;
192202
struct kvm_vm *vm;
193203
struct kvm_vcpu *vcpu;
194204
u32 cpu, rseq_cpu;
205+
int opt;
206+
207+
while ((opt = getopt(argc, argv, "hu")) != -1) {
208+
switch (opt) {
209+
case 'u':
210+
skip_sanity_check = true;
211+
break;
212+
case 'h':
213+
default:
214+
help(argv[0]);
215+
break;
216+
}
217+
}
195218

196219
r = sched_getaffinity(0, sizeof(possible_mask), &possible_mask);
197220
TEST_ASSERT(!r, "sched_getaffinity failed, errno = %d (%s)", errno,
@@ -254,9 +277,17 @@ int main(int argc, char *argv[])
254277
* getcpu() to stabilize. A 2:1 migration:KVM_RUN ratio is a fairly
255278
* conservative ratio on x86-64, which can do _more_ KVM_RUNs than
256279
* migrations given the 1us+ delay in the migration task.
280+
*
281+
* Another reason why it may have small migration:KVM_RUN ratio is that,
282+
* on systems with large low power mode wakeup latency, it may happen
283+
* quite often that the scheduler is not able to wake up the target CPU
284+
* before the vCPU thread is scheduled to another CPU.
257285
*/
258-
TEST_ASSERT(i > (NR_TASK_MIGRATIONS / 2),
259-
"Only performed %d KVM_RUNs, task stalled too much?", i);
286+
TEST_ASSERT(skip_sanity_check || i > (NR_TASK_MIGRATIONS / 2),
287+
"Only performed %d KVM_RUNs, task stalled too much?\n\n"
288+
" Try disabling deep sleep states to reduce CPU wakeup latency,\n"
289+
" e.g. via cpuidle.off=1 or setting /dev/cpu_dma_latency to '0',\n"
290+
" or run with -u to disable this sanity check.", i);
260291

261292
pthread_join(migration_thread, NULL);
262293

0 commit comments

Comments
 (0)