From patchwork Fri Apr 21 16:53:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 86445 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1224083vqo; Fri, 21 Apr 2023 10:17:23 -0700 (PDT) X-Google-Smtp-Source: AKy350YVkeqo23B7acDfLXfoNgF5SdjmHbVbVieoK1ZxZ0OEk00jZI7eFACX6QfYitsJz3op7xDY X-Received: by 2002:a05:6a20:748f:b0:d9:27f7:8c4a with SMTP id p15-20020a056a20748f00b000d927f78c4amr7478478pzd.0.1682097442949; Fri, 21 Apr 2023 10:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682097442; cv=none; d=google.com; s=arc-20160816; b=R54orYpaE+i63MtH1UnrEeIdaS7ahVMNaG+By0s6ofctyPJsENGI7BdxRlB2jdaG2C xdyrz3BX4/E57ZCYSR79gkDNvKVhPk0jeGeDebhG6xwj97iNdx4tiSRjshTj8Q3o6jqR 4sjeodDi3WBgk9PB9KxKyLX70V+EfKui4JR3xKiKrU/RG1ipNTcptTO4RIm76X63ifXV CNbmUZSZvTGISJ7nsMeIp4x6rCBCTpJbDmuYBZj/8mMGtZ5mHEOfuaL0xhIpLI6evwOC xPmoB1VeblkDaU1sCveJ2pv6mYW2YkdqFYfTZ5ZZiYHnnqwA43QqS3Rssq1e6XaWsDU5 ZDQg== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=aIXwJZ86g2cMsPal848/IoLZKDxpkMIUoWM/xoiNZjQ=; b=K4flH6XuI9dv6dwtzR0KQ1PZpqeGOsBZ2CGHMQcZby5bdsCEWZWiEHFfSFi6w0tWzP BUaB0eIxLLzpn08DUhSK4Nf7vHgIob5fQiyLtMyTcL34QuW/eHD7af7p5pBrg0V/AZRB u9JXKYF8y5A8R5F0usZxAl7TeQKW87g5ygbHkEPLHg045CpWq9zdTuqibPoIzcBujZ+b fi8jINKgYfFaLbv063t1gfFNvKYdg0Gvl3Lu/1td0E4F/WVhKL+bVrfgDf8WnBYRnd3Y MWdyQpfEp/xiFJOdT4AFsd5/uAmWtjhXeCjAFwxmorjLPP+HssWb0uSzVUP1E8JmyS84 q20w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=cwKBgaS0; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b201-20020a621bd2000000b0062565210347si4752453pfb.275.2023.04.21.10.17.07; Fri, 21 Apr 2023 10:17:22 -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=cwKBgaS0; 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 S232592AbjDURCf (ORCPT + 99 others); Fri, 21 Apr 2023 13:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbjDURCb (ORCPT ); Fri, 21 Apr 2023 13:02:31 -0400 Received: from mail-vk1-xa4a.google.com (mail-vk1-xa4a.google.com [IPv6:2607:f8b0:4864:20::a4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B948015628 for ; Fri, 21 Apr 2023 10:02:02 -0700 (PDT) Received: by mail-vk1-xa4a.google.com with SMTP id 71dfb90a1353d-4404c17ddc6so549976e0c.2 for ; Fri, 21 Apr 2023 10:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682096508; x=1684688508; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aIXwJZ86g2cMsPal848/IoLZKDxpkMIUoWM/xoiNZjQ=; b=cwKBgaS0WopiwHwuYQpJgWkE9nSxf7p9hQYZ1AUBEY7JH7Up9fxYUEXwnJEII0BBbd SmJV4hpApQTi1NVYumlyuPoXfgmM/B3Cf2dtKbCMXPAe+5MXmna29ZCklFtCoKATSXS5 JiEttU8ikp/7etnI/in+PUnNhWJs0c92v/J+1f6QBLOBcZTijEwdstNfnyz/+OoHilZ9 NtQjDxLpB6ICZTuvFSNjqzHB4h+YIJFrm5adhAsDEQh75uYzWWuJVT/IqK3NxtuWnsbZ EXlf0Yp0zCUyCIGd0MJYepfcd0G1jbpvMTaGnzGsDDjvKjGjTFDTHgCnA2TRkVM1RdY0 uxrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682096508; x=1684688508; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aIXwJZ86g2cMsPal848/IoLZKDxpkMIUoWM/xoiNZjQ=; b=Jdx5+dCP6qCiKszqDiyqKiImLT9FAHW96czEFIIzyztib32rhD+c5kUIN1nFyDnPeC haDqyQ2R22yUPw0ewQw19GZib12WHmV5JnieIaMsHDhwXxiu8bHGdYzQ5i5mW7CNHPPt AIi1r7Wc0Pk4bpR3Y9dvkI7VcRHiOt0RIwBsMsW8UiaEDzEYXecoYmVc/uyGeBbWdDtB BoBnAnnIVZgRLeOtXOG+a7DHnLHo7MkXlDVhwkTzz4Zl04csl275WeTNdxPqRneVnLU4 3xPTi04HNWrdXuydKoke/rMfXUgBZ9HmkLsEz5mlQd/C0e/dxpYwVHlGq3MaZfJRBhwG RnNA== X-Gm-Message-State: AAQBX9dFpOFnVfA3SXbUSi0MzZ+Tag2/88w/TxygrYFtLTc5j0v1X21V KIisamlew501Z0KeEFeKmXIwMG/5MMAd X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a25:d147:0:b0:b8c:ad5:6b4e with SMTP id i68-20020a25d147000000b00b8c0ad56b4emr1983907ybg.12.1682095998019; Fri, 21 Apr 2023 09:53:18 -0700 (PDT) Date: Fri, 21 Apr 2023 09:53:01 -0700 In-Reply-To: <20230421165305.804301-1-vipinsh@google.com> Mime-Version: 1.0 References: <20230421165305.804301-1-vipinsh@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421165305.804301-6-vipinsh@google.com> Subject: [PATCH 5/9] KVM: selftests: Allow independent execution of vCPUs in dirty_log_perf_test From: Vipin Sharma To: maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, tsbogend@alpha.franken.de, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com, ricarkol@google.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763807008699906261?= X-GMAIL-MSGID: =?utf-8?q?1763807008699906261?= Allow vCPUs to execute independent of dirty log iterations after initialization is complete. Hide this feature behind the new option "-j". This change makes dirty_log_perf_test execute like real world workflows where guest vCPUs keep on executing while VMM collects dirty logs. Total pages touched during execution of test will give good estimate of how vCPUs are performing while dirty logging is enabled. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 0a08a3d21123..ffdad535fdaa 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -69,6 +69,7 @@ static int iteration; static int vcpu_last_completed_iteration[KVM_MAX_VCPUS]; static atomic_ullong total_reads; static atomic_ullong total_writes; +static bool lockstep_iterations; static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) { @@ -83,12 +84,16 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) struct timespec total = (struct timespec){0}; struct timespec avg; struct ucall uc = {}; + int current_iteration = -1; int ret; run = vcpu->run; while (!READ_ONCE(host_quit)) { - int current_iteration = READ_ONCE(iteration); + if (lockstep_iterations) + current_iteration = READ_ONCE(iteration); + else + current_iteration++; clock_gettime(CLOCK_MONOTONIC, &start); ret = _vcpu_run(vcpu); @@ -118,13 +123,19 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args) ts_diff.tv_nsec); } - /* - * Keep running the guest while dirty logging is being disabled - * (iteration is negative) so that vCPUs are accessing memory - * for the entire duration of zapping collapsible SPTEs. - */ - while (current_iteration == READ_ONCE(iteration) && - READ_ONCE(iteration) >= 0 && !READ_ONCE(host_quit)) {} + if (lockstep_iterations) { + /* + * Keep running the guest while dirty logging is being disabled + * (iteration is negative) so that vCPUs are accessing memory + * for the entire duration of zapping collapsible SPTEs. + */ + while (current_iteration == READ_ONCE(iteration) && + READ_ONCE(iteration) >= 0 && !READ_ONCE(host_quit)) + ; + } else { + while (!READ_ONCE(iteration)) + ; + } } avg = timespec_div(total, vcpu_last_completed_iteration[vcpu_idx]); @@ -238,17 +249,19 @@ static void run_test(enum vm_guest_mode mode, void *arg) clock_gettime(CLOCK_MONOTONIC, &start); iteration++; - pr_debug("Starting iteration %d\n", iteration); - for (i = 0; i < nr_vcpus; i++) { - while (READ_ONCE(vcpu_last_completed_iteration[i]) - != iteration) - ; - } + if (lockstep_iterations) { + pr_debug("Starting iteration %d\n", iteration); + for (i = 0; i < nr_vcpus; i++) { + while (READ_ONCE(vcpu_last_completed_iteration[i]) + != iteration) + ; + } - ts_diff = timespec_elapsed(start); - vcpu_dirty_total = timespec_add(vcpu_dirty_total, ts_diff); - pr_info("Iteration %d dirty memory time: %ld.%.9lds\n", - iteration, ts_diff.tv_sec, ts_diff.tv_nsec); + ts_diff = timespec_elapsed(start); + vcpu_dirty_total = timespec_add(vcpu_dirty_total, ts_diff); + pr_info("Iteration %d dirty memory time: %ld.%.9lds\n", + iteration, ts_diff.tv_sec, ts_diff.tv_nsec); + } clock_gettime(CLOCK_MONOTONIC, &start); memstress_get_dirty_log(vm, bitmaps, p->slots); @@ -365,6 +378,10 @@ static void help(char *name) " 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"); + printf(" -j: Execute vCPUs independent of dirty log iterations\n" + " Independent vCPUs execution will allow them to continuously\n" + " dirty memory while main thread is collecting and clearing\n" + " dirty logs in the main thread's iterations.\n"); printf(" -k: Specify the chunk size in which dirty memory gets cleared\n" " in memslots in each iteration. If the size is bigger than\n" " the memslot size then whole memslot is cleared in one call.\n" @@ -399,10 +416,10 @@ int main(int argc, char *argv[]) kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | KVM_DIRTY_LOG_INITIALLY_SET); - + lockstep_iterations = true; guest_modes_append_default(); - while ((opt = getopt(argc, argv, "ab:c:eghi:k:l:m:nop:r:s:v:x:w:")) != -1) { + while ((opt = getopt(argc, argv, "ab:c:eghi:jk:l:m:nop:r:s:v:x:w:")) != -1) { switch (opt) { case 'a': p.random_access = true; @@ -426,6 +443,9 @@ int main(int argc, char *argv[]) case 'i': p.iterations = atoi_positive("Number of iterations", optarg); break; + case 'j': + lockstep_iterations = false; + break; case 'k': p.clear_chunk_size = parse_size(optarg); break;