Skip to content

Commit 1d9adaf

Browse files
committed
KVM: selftests: Allow skipping the KVM_RUN sanity check in rseq_test
JIRA: https://issues.redhat.com/browse/RHEL-28186 commit 20ecf59 Author: Zide Chen <[email protected]> Date: Thu May 2 14:39:36 2024 -0700 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 <[email protected]> Signed-off-by: Dongsheng Zhang <[email protected]> Signed-off-by: Zide Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: massage changelog] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Vitaly Kuznetsov <[email protected]>
1 parent c1d10d8 commit 1d9adaf

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
@@ -198,12 +198,35 @@ static void calc_min_max_cpu(void)
198198
"Only one usable CPU, task migration not possible");
199199
}
200200

201+
static void help(const char *name)
202+
{
203+
puts("");
204+
printf("usage: %s [-h] [-u]\n", name);
205+
printf(" -u: Don't sanity check the number of successful KVM_RUNs\n");
206+
puts("");
207+
exit(0);
208+
}
209+
201210
int main(int argc, char *argv[])
202211
{
212+
bool skip_sanity_check = false;
203213
int r, i, snapshot;
204214
struct kvm_vm *vm;
205215
struct kvm_vcpu *vcpu;
206216
u32 cpu, rseq_cpu;
217+
int opt;
218+
219+
while ((opt = getopt(argc, argv, "hu")) != -1) {
220+
switch (opt) {
221+
case 'u':
222+
skip_sanity_check = true;
223+
break;
224+
case 'h':
225+
default:
226+
help(argv[0]);
227+
break;
228+
}
229+
}
207230

208231
r = sched_getaffinity(0, sizeof(possible_mask), &possible_mask);
209232
TEST_ASSERT(!r, "sched_getaffinity failed, errno = %d (%s)", errno,
@@ -264,9 +287,17 @@ int main(int argc, char *argv[])
264287
* getcpu() to stabilize. A 2:1 migration:KVM_RUN ratio is a fairly
265288
* conservative ratio on x86-64, which can do _more_ KVM_RUNs than
266289
* migrations given the 1us+ delay in the migration task.
290+
*
291+
* Another reason why it may have small migration:KVM_RUN ratio is that,
292+
* on systems with large low power mode wakeup latency, it may happen
293+
* quite often that the scheduler is not able to wake up the target CPU
294+
* before the vCPU thread is scheduled to another CPU.
267295
*/
268-
TEST_ASSERT(i > (NR_TASK_MIGRATIONS / 2),
269-
"Only performed %d KVM_RUNs, task stalled too much?", i);
296+
TEST_ASSERT(skip_sanity_check || i > (NR_TASK_MIGRATIONS / 2),
297+
"Only performed %d KVM_RUNs, task stalled too much?\n\n"
298+
" Try disabling deep sleep states to reduce CPU wakeup latency,\n"
299+
" e.g. via cpuidle.off=1 or setting /dev/cpu_dma_latency to '0',\n"
300+
" or run with -u to disable this sanity check.", i);
270301

271302
pthread_join(migration_thread, NULL);
272303

0 commit comments

Comments
 (0)