From patchwork Fri Oct 14 07:19:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 2545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp48440wrs; Fri, 14 Oct 2022 00:35:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71H77+NI/oIcsgX7JZxsbEKeB5iCLoKGLT9Vqa3/kVWIK90wQ3/0zFQJYw9w+wO66MmgpF X-Received: by 2002:a17:90b:4b83:b0:20c:5ac8:1e30 with SMTP id lr3-20020a17090b4b8300b0020c5ac81e30mr16190351pjb.71.1665732937318; Fri, 14 Oct 2022 00:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665732937; cv=none; d=google.com; s=arc-20160816; b=b3UsoRKSTON8OwxoyFU11j0bKdRieRxb3rp3BIEn5kZPeEwjA/8H1rgTGIpAZ7LIFL //66dFKTUbTm/zDjxw9vtTNpUXWb+N0yfxo/NPS3SJfpZjGVzA54AK8GU4TblmFU9P8f bhdWHraRN50gLVX6hkITe2iuPat4N1QrMQJBh9XUscB4wmbbq+ayUsxg04/vleclVGq5 XW6Pqj8o96i9Q+99pP3QCO/3SNp1BGYzLArIXm56a1P3xJt/Hsv1u0imAvD4G1kg2Q1C 7z9uue381jW/xaj4+B9NEr0p6pldD7FvxVJEanynR+bPhFZcSFEyJOrcoK5a2+RaJaSa ISCw== 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=DdHs0tIGZs6Hd5dMAbgHdexs9jDtMkST+MADKDSgxqM=; b=eXexNSOALfCqHgK8MsEpC+RT5/EfOONV1tb60eveNK7PEEWiOCGWla37Vl42RnO8wE bJb8NqwpLi9NpxojXs3Z2bSA4eTWxf4V8r5PWmMdBdZ1DVtK0a/UeINB9wsZTpzuoYN2 TqkY8PQM3R9WASbR5ImPpIiFx1CHezZiZCmG8vhezCu5TpNavNgimBTSFOayD9Xt3deP GvKZWXW2oiylkgn4IiPEzEO062Xb4OyRO3CBgss/MWcXm0yXY9dWD4uNVZon1glodud3 XYKugwILsKBDk/ooWD/++jUEQ+BBFtiETd9T6Ydbu4NwYzdy7zvYiBmMgJ71qRlc3m1z L3UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=as9BqTSW; 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 ay12-20020a1709028b8c00b00178072335cbsi2107517plb.132.2022.10.14.00.35.23; Fri, 14 Oct 2022 00:35:37 -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=as9BqTSW; 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 S229867AbiJNHVP (ORCPT + 99 others); Fri, 14 Oct 2022 03:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiJNHVN (ORCPT ); Fri, 14 Oct 2022 03:21:13 -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 6DA3F7CE2E for ; Fri, 14 Oct 2022 00:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665732071; 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=DdHs0tIGZs6Hd5dMAbgHdexs9jDtMkST+MADKDSgxqM=; b=as9BqTSWqng7mobUeUjwKK2LPHGo15/KchleXMVJYqlFE3blFjUz6K55/8zCZ3k0dENeib HknrQHUQT8EA0I05SYNISAVd6NIA8NzzSJt9oZWBhcavTELpHTeqdBy41qZbTGg70dpTpp EDA9NOEWLMAZLcTNjfFRfD/1Sa7HhE4= 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-297-V9TD_DjrPUuoIF-FNHa4xw-1; Fri, 14 Oct 2022 03:21:08 -0400 X-MC-Unique: V9TD_DjrPUuoIF-FNHa4xw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A88133C0F446; Fri, 14 Oct 2022 07:20:12 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-52.bne.redhat.com [10.64.54.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60002C47DEC; Fri, 14 Oct 2022 07:19:54 +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, seanjc@google.com, peterx@redhat.com, maciej.szmigiero@oracle.com, ricarkol@google.com, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH 3/6] KVM: selftests: memslot_perf_test: Probe memory slots for once Date: Fri, 14 Oct 2022 15:19:11 +0800 Message-Id: <20221014071914.227134-4-gshan@redhat.com> In-Reply-To: <20221014071914.227134-1-gshan@redhat.com> References: <20221014071914.227134-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham 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?1746647580852261037?= X-GMAIL-MSGID: =?utf-8?q?1746647580852261037?= prepare_vm() is called in every iteration and run. The allowed memory slots (KVM_CAP_NR_MEMSLOTS) are probed for multiple times. It's not free and unnecessary. Move the probing logic for the allowed memory slots to parse_args() for once, which is upper layer of prepare_vm(). No functional change intended. Signed-off-by: Gavin Shan --- .../testing/selftests/kvm/memslot_perf_test.c | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/selftests/kvm/memslot_perf_test.c index dcb492b3f27b..d5aa9148f96f 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -245,27 +245,17 @@ static bool prepare_vm(struct vm_data *data, int nslots, uint64_t *maxslots, void *guest_code, uint64_t mempages, struct timespec *slot_runtime) { - uint32_t max_mem_slots; uint64_t rempages; uint64_t guest_addr; uint32_t slot; struct timespec tstart; struct sync_area *sync; - max_mem_slots = kvm_check_cap(KVM_CAP_NR_MEMSLOTS); - TEST_ASSERT(max_mem_slots > 1, - "KVM_CAP_NR_MEMSLOTS should be greater than 1"); - TEST_ASSERT(nslots > 1 || nslots == -1, - "Slot count cap should be greater than 1"); - if (nslots != -1) - max_mem_slots = min(max_mem_slots, (uint32_t)nslots); - pr_info_v("Allowed number of memory slots: %"PRIu32"\n", max_mem_slots); - TEST_ASSERT(mempages > 1, "Can't test without any memory"); data->npages = mempages; - data->nslots = max_mem_slots - 1; + data->nslots = nslots; data->pages_per_slot = mempages / data->nslots; if (!data->pages_per_slot) { *maxslots = mempages + 1; @@ -885,8 +875,8 @@ static bool parse_args(int argc, char *argv[], break; case 's': targs->nslots = atoi(optarg); - if (targs->nslots <= 0 && targs->nslots != -1) { - pr_info("Slot count cap has to be positive or -1 for no cap\n"); + if (targs->nslots <= 1 && targs->nslots != -1) { + pr_info("Slot count cap must be larger than 1 or -1 for no cap\n"); return false; } break; @@ -932,6 +922,19 @@ static bool parse_args(int argc, char *argv[], return false; } + /* Memory slot 0 is reserved */ + if (targs->nslots == -1) { + targs->nslots = kvm_check_cap(KVM_CAP_NR_MEMSLOTS) - 1; + if (targs->nslots < 1) { + pr_info("KVM_CAP_NR_MEMSLOTS should be greater than 1\n"); + return false; + } + } else { + targs->nslots--; + } + + pr_info_v("Number of memory slots: %d\n", targs->nslots); + return true; }