Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7814081rwd; Tue, 6 Jun 2023 17:15:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7JnVSqOUpPmg6UUSweObq5Wf7J/Hz/1dk6iab2uKwzUKA5t3XakRz16xKX5JI6pdJ0ia6D X-Received: by 2002:a81:6c91:0:b0:55c:edbb:8e1c with SMTP id h139-20020a816c91000000b0055cedbb8e1cmr4778479ywc.27.1686096942485; Tue, 06 Jun 2023 17:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686096942; cv=none; d=google.com; s=arc-20160816; b=kHST4GT9Hqobm6omY/w98mQ4VoSVUuEyjy8N3fDJ+6tkXDpC4MCRzNAAvGuiyREAbI 1eNmhkZSJwdgNIp+Cyggw3p+n1F9Xjn6DXxjYTzjKpMp9UZAgqXE9CREYeOWYn7/yvBn 8ifWz0uZ+JSmnyD8t1xpIJR9MSkMH4Lnpehdp8RTw7ACCbbuBXkaTnpfTtT6bFR/vqn6 hPBD5XrrCNhRlrAwOYLXTP7vYM+1e5ZkEbzwjhKTsEpfDT28vTlpQ6NMO7HGtTN9rdAN t111eTcN7JhdbpqyXiDPF7nQ+Pr5A2iYTyeOUheBqSbod0Mz2PI5j8s0tFP7x6+0LVUR gzSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :reply-to:dkim-signature; bh=LOKQucxjReBAl4ueIGJC15nKLzQWh4BqOUmVZxC990Y=; b=NSdbC/1yeH2MqSKr6QlKM8unaHi5ZCTRedw6bkMxz7qb5+HaN7psTI8HjDBc+neJme GJV5BuNL5htXCAdKBREVFi9nPy+5tOC4o5bxW0YYLHFItiE7VZtd5MPe+w6IjrZZe2AU bR1G8ImnkQWpSo3OgfvNjH4eP7MiUAiXuhEDnLIUqxjmqibqLJUBtvT764GvR7OueNJn uXnL5fsLLZO9URA7zh++m2IDluGr/8AqS3Z6An+V6pOnYDi4HLaUyj3ToMlzdCf7Lxpk gMvgneykLj5e6D3AuJzhbYXkJ6NekYu7hSgG8oETZJGlyhBZiFH/Zjxvep2AiInGVXEK iuTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=jpOg8A7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk8-20020a17090b4a0800b0024bda568513si184084pjb.123.2023.06.06.17.15.29; Tue, 06 Jun 2023 17:15:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=jpOg8A7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240185AbjFGAMd (ORCPT + 99 others); Tue, 6 Jun 2023 20:12:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240122AbjFGAMc (ORCPT ); Tue, 6 Jun 2023 20:12:32 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA4981988 for ; Tue, 6 Jun 2023 17:12:29 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-5400b72fcb0so1927591a12.1 for ; Tue, 06 Jun 2023 17:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686096749; x=1688688749; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=LOKQucxjReBAl4ueIGJC15nKLzQWh4BqOUmVZxC990Y=; b=jpOg8A7Whukym3P9JMD50SgFY2Q6AnR51vkyYqvhxQYMCaB+QLPDYzMk9YMN0BXJIx Be10BMVUxPzOq5yf0BqSSYDB4yN5YqXMX7q8Iyzl/LuNsCLcWKGMxvot9ofgLGUsElav ZFisDfXzuzu0cpr5cti+WbJCsF+yzrY1GSdF5R7+nTJyEclLxAR4bqW/KkXtJJ7zJ3Fi l645yU4Kk1d1PW0NuxDBqQObLdg8ChcNlVk+MdAYcELVAu2+fke73EI0z+A7aJX6jjdn pkD72BZ8m33UFFfC3kd9fVNSaDPLYUeD6d2FnaZG/oWzr36NmWucpEOIrvtBOkgNgIP6 JoxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686096749; x=1688688749; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LOKQucxjReBAl4ueIGJC15nKLzQWh4BqOUmVZxC990Y=; b=dcsWdB/+7Y609M2/ilBecRHSfZ8/KjmD1WdEaUCBRMecT7PXJSjoJG0FV24vnoEIfW Fz87gokhwHFrFwT/kXHpdxWeiyN7Z6iQ65T6elmmGmhWWh2O+Ob/L0Fnd8uNcS+CY74z UWwp/R9UtFX0ZKAGUSx7563q3Cud4arM8q/5k62Rz3aHUDWQcGjZ6//rFjyoLzPzDDTp ITC/kXV2JFi2kN4kMnvM3sv49LeTyv6Sr7Id9jNgjy/5vgUu+128ppQ0C6mUm1bPScqS 4N5EU8qnZwRmj9lGTF9yzNcbtrOjPaBIN4zoo+Gsq4VFNwfEDfmqyrR3RZtvg5/MjMvn m42A== X-Gm-Message-State: AC+VfDykWFPV/Xsnhh87PWt6SkV2wd2jgseqpgZud7Z5XSInAjBTlnzu FxkLf0tnoROm8gOvHjhnrCrs0veDh2w= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:d611:0:b0:520:7943:3de4 with SMTP id q17-20020a63d611000000b0052079433de4mr785177pgg.4.1686096749257; Tue, 06 Jun 2023 17:12:29 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 6 Jun 2023 17:12:26 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230607001226.1398889-1-seanjc@google.com> Subject: [PATCH v3] KVM: selftests: Allow specify physical cpu list in demand paging test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Sean Christopherson Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Xu Mimic the dirty log test and allow the user to pin demand paging test tasks to physical CPUs. Put the help message into a general helper as suggested by Sean. Signed-off-by: Peter Xu Link: https://lore.kernel.org/r/20230601184256.180413-1-peterx@redhat.com [sean: rebase, tweak arg ordering, add "print" to helper, print program name] Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/demand_paging_test.c | 15 +++++++++++++-- .../testing/selftests/kvm/dirty_log_perf_test.c | 12 +----------- .../selftests/kvm/include/kvm_util_base.h | 1 + tools/testing/selftests/kvm/lib/kvm_util.c | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 9c18686b4f63..09c116a82a84 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -208,10 +208,11 @@ static void help(char *name) { puts(""); printf("usage: %s [-h] [-m vm_mode] [-u uffd_mode] [-d uffd_delay_usec]\n" - " [-b memory] [-s type] [-v vcpus] [-o]\n", name); + " [-b memory] [-s type] [-v vcpus] [-c cpu_list] [-o]\n", name); guest_modes_help(); printf(" -u: use userfaultfd to handle vCPU page faults. Mode is a\n" " UFFD registration mode: 'MISSING' or 'MINOR'.\n"); + kvm_print_vcpu_pinning_help(); printf(" -d: add a delay in usec to the User Fault\n" " FD handler to simulate demand paging\n" " overheads. Ignored without -u.\n"); @@ -229,6 +230,7 @@ static void help(char *name) int main(int argc, char *argv[]) { int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); + const char *cpulist = NULL; struct test_params p = { .src_type = DEFAULT_VM_MEM_SRC, .partition_vcpu_memory_access = true, @@ -237,7 +239,7 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "hm:u:d:b:s:v:o")) != -1) { + while ((opt = getopt(argc, argv, "hm:u:d:b:s:v:c:o")) != -1) { switch (opt) { case 'm': guest_modes_cmdline(optarg); @@ -264,6 +266,9 @@ int main(int argc, char *argv[]) TEST_ASSERT(nr_vcpus <= max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; + case 'c': + cpulist = optarg; + break; case 'o': p.partition_vcpu_memory_access = false; break; @@ -279,6 +284,12 @@ int main(int argc, char *argv[]) TEST_FAIL("userfaultfd MINOR mode requires shared memory; pick a different -s"); } + if (cpulist) { + kvm_parse_vcpu_pinning(cpulist, memstress_args.vcpu_to_pcpu, + nr_vcpus); + memstress_args.pin_vcpus = true; + } + for_each_guest_mode(run_test, &p); return 0; diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 416719e20518..d374dbcf9a53 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -332,17 +332,7 @@ static void help(char *name) " so -w X means each page has an X%% chance of writing\n" " and a (100-X)%% chance of reading.\n" " (default: 100 i.e. all pages are written to.)\n"); - printf(" -c: Pin tasks to physical CPUs. Takes a list of comma separated\n" - " values (target pCPU), one for each vCPU, plus an optional\n" - " entry for the main application task (specified via entry\n" - " ). If used, entries must be provided for all\n" - " vCPUs, i.e. pinning vCPUs is all or nothing.\n\n" - " E.g. to create 3 vCPUs, pin vCPU0=>pCPU22, vCPU1=>pCPU23,\n" - " vCPU2=>pCPU24, and pin the application task to pCPU50:\n\n" - " ./dirty_log_perf_test -v 3 -c 22,23,24,50\n\n" - " To leave the application task unpinned, drop the final entry:\n\n" - " ./dirty_log_perf_test -v 3 -c 22,23,24\n\n" - " (default: no pinning)\n"); + kvm_print_vcpu_pinning_help(); puts(""); exit(0); } diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index a089c356f354..07732a157ccd 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -733,6 +733,7 @@ static inline struct kvm_vm *vm_create_with_one_vcpu(struct kvm_vcpu **vcpu, struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm); void kvm_pin_this_task_to_pcpu(uint32_t pcpu); +void kvm_print_vcpu_pinning_help(void); void kvm_parse_vcpu_pinning(const char *pcpus_string, uint32_t vcpu_to_pcpu[], int nr_vcpus); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 298c4372fb1a..9741a7ff6380 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -494,6 +494,23 @@ static uint32_t parse_pcpu(const char *cpu_str, const cpu_set_t *allowed_mask) return pcpu; } +void kvm_print_vcpu_pinning_help(void) +{ + const char *name = program_invocation_name; + + printf(" -c: Pin tasks to physical CPUs. Takes a list of comma separated\n" + " values (target pCPU), one for each vCPU, plus an optional\n" + " entry for the main application task (specified via entry\n" + " ). If used, entries must be provided for all\n" + " vCPUs, i.e. pinning vCPUs is all or nothing.\n\n" + " E.g. to create 3 vCPUs, pin vCPU0=>pCPU22, vCPU1=>pCPU23,\n" + " vCPU2=>pCPU24, and pin the application task to pCPU50:\n\n" + " %s -v 3 -c 22,23,24,50\n\n" + " To leave the application task unpinned, drop the final entry:\n\n" + " %s -v 3 -c 22,23,24\n\n" + " (default: no pinning)\n", name, name); +} + void kvm_parse_vcpu_pinning(const char *pcpus_string, uint32_t vcpu_to_pcpu[], int nr_vcpus) { base-commit: dfa78a20cc879205b2c6239300dac09907ad3da1 -- 2.41.0.162.gfafddb0af9-goog