Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
KVM: selftests: Refactor help message for -s backing_src
Browse files Browse the repository at this point in the history
All selftests that support the backing_src option were printing their
own description of the flag and then calling backing_src_help() to dump
the list of available backing sources. Consolidate the flag printing in
backing_src_help() to align indentation, reduce duplicated strings, and
improve consistency across tests.

Note: Passing "-s" to backing_src_help is unnecessary since every test
uses the same flag. However I decided to keep it for code readability
at the call sites.

While here this opportunistically fixes the incorrectly interleaved
printing -x help message and list of backing source types in
dirty_log_perf_test.

Fixes: 609e620 ("KVM: selftests: Support multiple slots in dirty_log_perf_test")
Reviewed-by: Ben Gardon <[email protected]>
Reviewed-by: Andrew Jones <[email protected]>
Signed-off-by: David Matlack <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
dmatlack authored and bonzini committed Sep 22, 2021
1 parent a1e638d commit 9f2fc55
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
6 changes: 2 additions & 4 deletions tools/testing/selftests/kvm/access_tracking_perf_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,15 @@ static void help(char *name)
printf(" -v: specify the number of vCPUs to run.\n");
printf(" -o: Overlap guest memory accesses instead of partitioning\n"
" them into a separate region of memory for each vCPU.\n");
printf(" -s: specify the type of memory that should be used to\n"
" back the guest data region.\n\n");
backing_src_help();
backing_src_help("-s");
puts("");
exit(0);
}

int main(int argc, char *argv[])
{
struct test_params params = {
.backing_src = VM_MEM_SRC_ANONYMOUS,
.backing_src = DEFAULT_VM_MEM_SRC,
.vcpu_memory_bytes = DEFAULT_PER_VCPU_MEM_SIZE,
.vcpus = 1,
};
Expand Down
5 changes: 2 additions & 3 deletions tools/testing/selftests/kvm/demand_paging_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,7 @@ static void help(char *name)
printf(" -b: specify the size of the memory region which should be\n"
" demand paged by each vCPU. e.g. 10M or 3G.\n"
" Default: 1G\n");
printf(" -s: The type of backing memory to use. Default: anonymous\n");
backing_src_help();
backing_src_help("-s");
printf(" -v: specify the number of vCPUs to run.\n");
printf(" -o: Overlap guest memory accesses instead of partitioning\n"
" them into a separate region of memory for each vCPU.\n");
Expand All @@ -439,7 +438,7 @@ int main(int argc, char *argv[])
{
int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS);
struct test_params p = {
.src_type = VM_MEM_SRC_ANONYMOUS,
.src_type = DEFAULT_VM_MEM_SRC,
.partition_vcpu_memory_access = true,
};
int opt;
Expand Down
8 changes: 3 additions & 5 deletions tools/testing/selftests/kvm/dirty_log_perf_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,9 @@ static void help(char *name)
printf(" -v: specify the number of vCPUs to run.\n");
printf(" -o: Overlap guest memory accesses instead of partitioning\n"
" them into a separate region of memory for each vCPU.\n");
printf(" -s: specify the type of memory that should be used to\n"
" back the guest data region.\n\n");
backing_src_help("-s");
printf(" -x: Split the memory region into this number of memslots.\n"
" (default: 1)");
backing_src_help();
" (default: 1)\n");
puts("");
exit(0);
}
Expand All @@ -324,7 +322,7 @@ int main(int argc, char *argv[])
.iterations = TEST_HOST_LOOP_N,
.wr_fract = 1,
.partition_vcpu_memory_access = true,
.backing_src = VM_MEM_SRC_ANONYMOUS,
.backing_src = DEFAULT_VM_MEM_SRC,
.slots = 1,
};
int opt;
Expand Down
4 changes: 3 additions & 1 deletion tools/testing/selftests/kvm/include/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ enum vm_mem_backing_src_type {
NUM_SRC_TYPES,
};

#define DEFAULT_VM_MEM_SRC VM_MEM_SRC_ANONYMOUS

struct vm_mem_backing_src_alias {
const char *name;
uint32_t flag;
Expand All @@ -100,7 +102,7 @@ size_t get_trans_hugepagesz(void);
size_t get_def_hugetlb_pagesz(void);
const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i);
size_t get_backing_src_pagesz(uint32_t i);
void backing_src_help(void);
void backing_src_help(const char *flag);
enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);

/*
Expand Down
7 changes: 2 additions & 5 deletions tools/testing/selftests/kvm/kvm_page_table_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,7 @@ static void help(char *name)
" (default: 1G)\n");
printf(" -v: specify the number of vCPUs to run\n"
" (default: 1)\n");
printf(" -s: specify the type of memory that should be used to\n"
" back the guest data region.\n"
" (default: anonymous)\n\n");
backing_src_help();
backing_src_help("-s");
puts("");
}

Expand All @@ -468,7 +465,7 @@ int main(int argc, char *argv[])
int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS);
struct test_params p = {
.test_mem_size = DEFAULT_TEST_MEM_SIZE,
.src_type = VM_MEM_SRC_ANONYMOUS,
.src_type = DEFAULT_VM_MEM_SRC,
};
int opt;

Expand Down
17 changes: 13 additions & 4 deletions tools/testing/selftests/kvm/lib/test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,22 @@ size_t get_backing_src_pagesz(uint32_t i)
}
}

void backing_src_help(void)
static void print_available_backing_src_types(const char *prefix)
{
int i;

printf("Available backing src types:\n");
printf("%sAvailable backing src types:\n", prefix);

for (i = 0; i < NUM_SRC_TYPES; i++)
printf("\t%s\n", vm_mem_backing_src_alias(i)->name);
printf("%s %s\n", prefix, vm_mem_backing_src_alias(i)->name);
}

void backing_src_help(const char *flag)
{
printf(" %s: specify the type of memory that should be used to\n"
" back the guest data region. (default: %s)\n",
flag, vm_mem_backing_src_alias(DEFAULT_VM_MEM_SRC)->name);
print_available_backing_src_types(" ");
}

enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name)
Expand All @@ -296,7 +305,7 @@ enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name)
if (!strcmp(type_name, vm_mem_backing_src_alias(i)->name))
return i;

backing_src_help();
print_available_backing_src_types("");
TEST_FAIL("Unknown backing src type: %s", type_name);
return -1;
}

0 comments on commit 9f2fc55

Please sign in to comment.