From patchwork Thu Oct 20 07:12:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 5989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp108497wrs; Thu, 20 Oct 2022 00:13:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5uY4Sak9pkw2sr2E9v7wGrDvJgDph+mTve0ce/8iL3AwMxdtXKKefbCWTw/Xb9iebmrNq1 X-Received: by 2002:aa7:8d17:0:b0:560:485a:e242 with SMTP id j23-20020aa78d17000000b00560485ae242mr12670280pfe.31.1666250032280; Thu, 20 Oct 2022 00:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666250032; cv=none; d=google.com; s=arc-20160816; b=j4n+Vdy8kllx1d9rlhcdhEtQkntDPJ3TfqnOkifQf3IbuuTmkizDRJjDUXOp3tCWu9 WESxtv+GcuKjaQh7b3CSz8fPZbIqKYMK4EiJlU/jE9UL7QnI2ag5Qb9lQImB5Beda8sP 4O2W8gN9WXUBanir2E0Iq5d8vBUI2OVsBr0rbvJBBMRoK1YebMslubtox2EFC1+qm35x YMXVkKZV06YDgu+uqSXcyOXWXrrXftIiUIH0xWkAzfL8hQ6ygHZUAC+bBeK0iD1TYFmW q/7nBeLLAGMLWnZqLybxgJXh5KB1aIDUBU7Fb1GsIDTDx5et9S7dQo6GD7Y9G2B9ittL L8tw== 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=FLte0OXxinwLRofzPlNNBXzAcKi/vkF5tvjIXcUsIPffI7mIGVe7lB7JK7SaN8Rn9j 5UadUmtxlGkn7QrnO3m1VV3Sirkii/dpuDwIuxzSOYiha6dQrY6Z36ooTZM7CrDv/FdI xlyhdpBFainkRR7/qaUeDHpFOXaBRSk33atIufuKTrILM+paz6lXxtCJAIn0szmgeN59 +6GfRMGRIpJHfpAPJFZRWBAjylg6ja6ifncBVcKnBdGJYKN8EEjrBQCQX/N48avdJjVS 6uEKKktPpMGd3zzXu7BGvHhliFYVaNl8ZWWG6+0dH5OBgSKy2TRONdwKAjiR7jGWNcVW 1UKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BZzP5Hkw; 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 k4-20020a170902c40400b0016f1781307csi23844193plk.303.2022.10.20.00.13.39; Thu, 20 Oct 2022 00:13:52 -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=BZzP5Hkw; 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 S230158AbiJTHNP (ORCPT + 99 others); Thu, 20 Oct 2022 03:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbiJTHNE (ORCPT ); Thu, 20 Oct 2022 03:13:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C1DF15ECEB for ; Thu, 20 Oct 2022 00:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666249980; 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=BZzP5HkwJ8qN2wmRU0SEf5YAXbEUGNHGyX1wVzR8pock7pNJLR3jPYpNolnlz96N6QuLHJ a4MQSERIu1yCTPfWydSmkxTa+RavovMA+VhSB9vSlouNeBMZrsnzLrVgxndqfYOcqzvGlj qUcbLEdJL0tnVOHKEQSMCV11Qdmqgeg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-86-n3h-O6ciMHaqmna_rDKDRg-1; Thu, 20 Oct 2022 03:12:55 -0400 X-MC-Unique: n3h-O6ciMHaqmna_rDKDRg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E665E800186; Thu, 20 Oct 2022 07:12:54 +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 D17E540C6EC2; Thu, 20 Oct 2022 07:12:49 +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, mail@maciej.szmigiero.name, maz@kernel.org, pbonzini@redhat.com, ajones@ventanamicro.com, shuah@kernel.org, peterx@redhat.com, oliver.upton@linux.dev, seanjc@google.com, ricarkol@google.com, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH v3 2/6] KVM: selftests: memslot_perf_test: Consolidate loop conditions in prepare_vm() Date: Thu, 20 Oct 2022 15:12:05 +0800 Message-Id: <20221020071209.559062-3-gshan@redhat.com> In-Reply-To: <20221020071209.559062-1-gshan@redhat.com> References: <20221020071209.559062-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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?1747189794006003930?= X-GMAIL-MSGID: =?utf-8?q?1747189794006003930?= 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; }