From patchwork Tue Oct 18 04:04:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 3929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1771729wrs; Mon, 17 Oct 2022 21:32:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM77FS+mwN+V9rjonNBIbdn7clx/y4aVJeQbT0bIencnuC4VAV2Lp+iJmsWAUYOUasOtyUIY X-Received: by 2002:a05:6402:150a:b0:459:2575:99c6 with SMTP id f10-20020a056402150a00b00459257599c6mr864100edw.231.1666067539600; Mon, 17 Oct 2022 21:32:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666067539; cv=none; d=google.com; s=arc-20160816; b=fnqseWQaXKrtgeqaeHxsGJXdkOaXi2PdXr/U89GwjExfm1bF4G2gEoZluRQewyVMIe oY+RsDpc9fMNskja8PAj5K7vOyoTNAblqKFYWLNFDJnt4yIBDT7LRUug2SIVVBhlSKBI Jq25Gi6OhDa145cJyHx7MI/+LZWY8TZTD2BucaCqQ6Wm2DgF870XM8hSZEmxJrkjf3un h5OpciJeiU4XxczS5IgoODUnlizYCCGyN5H/0fK+7uDmddgKbBRNhikXTVjicXchP/me /6D06cxkSxpPSnp3anzvMRZO64z38/sa+PVG9PhDv60/8k2ZXx5BqyRDpDfm+rKftVXD zJig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9FjkKJ4RB0wBhJUFjtqAZ3VQdnrJF4akYRPmacZ3lG8=; b=aJfftEoV1oFDEKH0YdkRyGy46j2azeL8n3FmsNPBdJsb3lgxdmeoiqzIgG/pholWkT MN8v7TFae1bJR65BI2xwb8FsK+JgxOHNhHqCSQqvUp+SheJQ7JvOadOOoDZe1Q5HtU1T y2RrOv0jtAJl6Mw9vEq+bfxnC0myZusALXzvBDaRfRudm1tFgxk7upRj8/ozxbWrT6Oc HPVQNeEyTleoLeSgIOKwHVISOGEoliuQN+lAd3ry0SYMrX7wRiJLZVC2POXHpQCtwmey Tngx3bZ2xhrQRk4ELPTOrhd636sp2yEqkC5O3z+8FydNF5EJ5iY7ScEilaGsjHrsmjbA ge3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bFxN5F/7"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h4-20020a170906854400b0077b287e3adesi8804250ejy.190.2022.10.17.21.31.47; Mon, 17 Oct 2022 21:32:19 -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=@redhat.com header.s=mimecast20190719 header.b="bFxN5F/7"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbiJREFd (ORCPT + 99 others); Tue, 18 Oct 2022 00:05:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbiJREFa (ORCPT ); Tue, 18 Oct 2022 00:05:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5585E52FF2 for ; Mon, 17 Oct 2022 21:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666065920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9FjkKJ4RB0wBhJUFjtqAZ3VQdnrJF4akYRPmacZ3lG8=; b=bFxN5F/75k0NzoOyPgFqnNI/FVTZslDAVD3xa/y120K6g5JS6cwuc5UUFj0cZzpceV50uO ETY0unH+c2XDsHnxfRm2kdO1Q4F4Bn07Qi2ViAUk16dHrOw676K6JPkKrg1uFLk0lBgcqi sKgOYp6/kBfq3ulI+qtsxJv2qAkn5nE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-265-KFKb15AGP3Oh9hIgeZ4WZw-1; Tue, 18 Oct 2022 00:05:17 -0400 X-MC-Unique: KFKb15AGP3Oh9hIgeZ4WZw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7B4238041CB; Tue, 18 Oct 2022 04:05:16 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-70.bne.redhat.com [10.64.54.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9C7B2166B41; Tue, 18 Oct 2022 04:05:10 +0000 (UTC) From: Gavin Shan To: kvmarm@lists.linux.dev Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, ajones@ventanamicro.com, pbonzini@redhat.com, maz@kernel.org, shuah@kernel.org, oliver.upton@linux.dev, mail@maciej.szmigiero.name, maciej.szmigiero@oracle.com, seanjc@google.com, peterx@redhat.com, ricarkol@google.com, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH v2 2/6] KVM: selftests: memslot_perf_test: Consolidate loop conditions in prepare_vm() Date: Tue, 18 Oct 2022 12:04:50 +0800 Message-Id: <20221018040454.405719-3-gshan@redhat.com> In-Reply-To: <20221018040454.405719-1-gshan@redhat.com> References: <20221018040454.405719-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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?1746998436488906069?= X-GMAIL-MSGID: =?utf-8?q?1746998436488906069?= There are two loops in prepare_vm(), which have different conditions. 'slot' is treated as meory slot index in the first loop, but index of the host virtual address array in the second loop. It makes it a bit hard to understand the code. Change the usage of 'slot' in the second loop, to treat it as the memory slot index either. No functional change intended. Signed-off-by: Gavin Shan --- tools/testing/selftests/kvm/memslot_perf_test.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/selftests/kvm/memslot_perf_test.c index 231cc8449c2e..dcb492b3f27b 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -297,21 +297,20 @@ static bool prepare_vm(struct vm_data *data, int nslots, uint64_t *maxslots, } *slot_runtime = timespec_elapsed(tstart); - for (slot = 0, guest_addr = MEM_GPA; slot < data->nslots; slot++) { + for (slot = 1, guest_addr = MEM_GPA; slot <= data->nslots; slot++) { uint64_t npages; uint64_t gpa; npages = data->pages_per_slot; - if (slot == data->nslots - 1) + if (slot == data->nslots) npages += rempages; - gpa = vm_phy_pages_alloc(data->vm, npages, guest_addr, - slot + 1); + gpa = vm_phy_pages_alloc(data->vm, npages, guest_addr, slot); TEST_ASSERT(gpa == guest_addr, "vm_phy_pages_alloc() failed\n"); - data->hva_slots[slot] = addr_gpa2hva(data->vm, guest_addr); - memset(data->hva_slots[slot], 0, npages * 4096); + data->hva_slots[slot - 1] = addr_gpa2hva(data->vm, guest_addr); + memset(data->hva_slots[slot - 1], 0, npages * 4096); guest_addr += npages * 4096; }