mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 12:21:22 -05:00
KVM: selftests: Add option to rseq test to override /dev/cpu_dma_latency
Add a "-l <latency>" param to the rseq test so that the user can override /dev/cpu_dma_latency, as described by the test's suggested workaround for not being able to complete enough migrations. cpu_dma_latency is not a normal file, even as far as procfs files go. Writes to cpu_dma_latency only persist so long as the file is open, e.g. so that the kernel automatically reverts back to a power-optimized state once the sensitive workload completes. Provide the necessary functionality instead of effectively forcing the user to write a non-obvious wrapper. Cc: Dongsheng Zhang <dongsheng.x.zhang@intel.com> Cc: Zide Chen <zide.chen@intel.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-ID: <20250401142238.819487-1-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
committed by
Paolo Bonzini
parent
ef01cac401
commit
0297cdc12a
@@ -196,25 +196,27 @@ static void calc_min_max_cpu(void)
|
||||
static void help(const char *name)
|
||||
{
|
||||
puts("");
|
||||
printf("usage: %s [-h] [-u]\n", name);
|
||||
printf("usage: %s [-h] [-u] [-l latency]\n", name);
|
||||
printf(" -u: Don't sanity check the number of successful KVM_RUNs\n");
|
||||
printf(" -l: Set /dev/cpu_dma_latency to suppress deep sleep states\n");
|
||||
puts("");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int r, i, snapshot, opt, fd = -1, latency = -1;
|
||||
bool skip_sanity_check = false;
|
||||
int r, i, snapshot;
|
||||
struct kvm_vm *vm;
|
||||
struct kvm_vcpu *vcpu;
|
||||
u32 cpu, rseq_cpu;
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "hu")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "hl:u")) != -1) {
|
||||
switch (opt) {
|
||||
case 'u':
|
||||
skip_sanity_check = true;
|
||||
case 'l':
|
||||
latency = atoi_paranoid(optarg);
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
@@ -243,6 +245,20 @@ int main(int argc, char *argv[])
|
||||
pthread_create(&migration_thread, NULL, migration_worker,
|
||||
(void *)(unsigned long)syscall(SYS_gettid));
|
||||
|
||||
if (latency >= 0) {
|
||||
/*
|
||||
* Writes to cpu_dma_latency persist only while the file is
|
||||
* open, i.e. it allows userspace to provide guaranteed latency
|
||||
* while running a workload. Keep the file open until the test
|
||||
* completes, otherwise writing cpu_dma_latency is meaningless.
|
||||
*/
|
||||
fd = open("/dev/cpu_dma_latency", O_RDWR);
|
||||
TEST_ASSERT(fd >= 0, __KVM_SYSCALL_ERROR("open() /dev/cpu_dma_latency", fd));
|
||||
|
||||
r = write(fd, &latency, 4);
|
||||
TEST_ASSERT(r >= 1, "Error setting /dev/cpu_dma_latency");
|
||||
}
|
||||
|
||||
for (i = 0; !done; i++) {
|
||||
vcpu_run(vcpu);
|
||||
TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC,
|
||||
@@ -278,6 +294,9 @@ int main(int argc, char *argv[])
|
||||
"rseq CPU = %d, sched CPU = %d", rseq_cpu, cpu);
|
||||
}
|
||||
|
||||
if (fd > 0)
|
||||
close(fd);
|
||||
|
||||
/*
|
||||
* Sanity check that the test was able to enter the guest a reasonable
|
||||
* number of times, e.g. didn't get stalled too often/long waiting for
|
||||
@@ -293,8 +312,8 @@ int main(int argc, char *argv[])
|
||||
TEST_ASSERT(skip_sanity_check || i > (NR_TASK_MIGRATIONS / 2),
|
||||
"Only performed %d KVM_RUNs, task stalled too much?\n\n"
|
||||
" Try disabling deep sleep states to reduce CPU wakeup latency,\n"
|
||||
" e.g. via cpuidle.off=1 or setting /dev/cpu_dma_latency to '0',\n"
|
||||
" or run with -u to disable this sanity check.", i);
|
||||
" e.g. via cpuidle.off=1 or via -l <latency>, or run with -u to\n"
|
||||
" disable this sanity check.", i);
|
||||
|
||||
pthread_join(migration_thread, NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user