From patchwork Thu Oct 20 07:12:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 5990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp108734wrs; Thu, 20 Oct 2022 00:14:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Is3LTa9bM0+RWVzJOAZ8b0qoJ85Nmrc7oASKQkpzfYTZI1oXtC4+bj/tY2Yq8HFWdKI+l X-Received: by 2002:a05:6a00:3249:b0:565:fc2c:ad79 with SMTP id bn9-20020a056a00324900b00565fc2cad79mr12490652pfb.72.1666250068798; Thu, 20 Oct 2022 00:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666250068; cv=none; d=google.com; s=arc-20160816; b=KWkrqxxJPpbquPisxFRaXX3PbyBfc3nysEq4h6sqMUGt3emJunFK0O/vsDq3y8sw2L /quKk6NS5ltBh0bHQxY3KwEUETbcLdFlc4/r9cGoV3/r2SLyUKsSblTRWZhi0Wj88urL YcJRQhWS63e1wQ2NqxwmsYq6DOPT3VZ4ruK2hLec2h+N+MH7jrmVGV7dn+iH5PO3etGW tj0xiufKk7dJND/NDplByqIXsvhwWWqpQOFT10iAa6qSb5TKSHNRB6ThuB9xL1vVRA6N wWaL9rbOOZlXJGj9TKtSQMnrg1A6CMWCHrNohrBsEECLEnhDuesycbcEjQF9WsJOqzSN +qOA== 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=PqVmt5YoyTpdybpQLaBWLMwp2J8t1L+xxmd4ToLLOLQ=; b=qRUs/93avZBioohG7U8MZ2Ff6kJS/sPng3jveCAjgOr42bUchVIYgNDUcHmJUaLcHB YsJpF03ljl1fZT4gMLdIpecpl5A9wuGYTTQreoGvT2mjZIgFuHfELQI2EC+bClEE/z2V 9hQeCnLViAHytE4m8RtgjRBBi8Nmes624/htaOxfRdBBB7g7qU8KEmQ7JGpkC6H2SX4/ qKsTWkTNqK1AqPXP23IUDbX1ejWLsVRDoee7wzJTfYszjYb7AHfLn9O+cE5SGniSWfi3 p2IP6UAWaa+50ILwrMCxXmS8qVkOiIft8QGnP90wtA5Q79z765N8b98pZBOV/VK+yI0F A2zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fqx79MR5; 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 n5-20020a632705000000b00460ea4393c9si19277520pgn.448.2022.10.20.00.14.15; Thu, 20 Oct 2022 00:14:28 -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=fqx79MR5; 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 S230203AbiJTHNk (ORCPT + 99 others); Thu, 20 Oct 2022 03:13:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbiJTHNT (ORCPT ); Thu, 20 Oct 2022 03:13:19 -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 B59D715ECCF for ; Thu, 20 Oct 2022 00:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666249985; 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=PqVmt5YoyTpdybpQLaBWLMwp2J8t1L+xxmd4ToLLOLQ=; b=fqx79MR5Va1gql312ChQT53fYkDgGAijM9ngUHtqkp75b+DY3ItB/FjMT3vTT8Dg0zrfD7 F/M8/90aMLt6zZwmiwJmbewmICcz3N4DFCqNuMxhsEku1j1EKZZ+k7EVQOzHMsDnMSqmt5 bIeMKhQV8z6kYt1PmxKpHvBUPhvllz4= 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-330-gKNIcA3RMcqrmkokm2R28A-1; Thu, 20 Oct 2022 03:13:01 -0400 X-MC-Unique: gKNIcA3RMcqrmkokm2R28A-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 C39AB86F123; Thu, 20 Oct 2022 07:13:00 +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 7057E40C6EC2; Thu, 20 Oct 2022 07:12:55 +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 3/6] KVM: selftests: memslot_perf_test: Probe memory slots for once Date: Thu, 20 Oct 2022 15:12:06 +0800 Message-Id: <20221020071209.559062-4-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=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?1747189832253472404?= X-GMAIL-MSGID: =?utf-8?q?1747189832253472404?= 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 | 32 +++++++++++-------- 1 file changed, 19 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..f0ea3f75b6e1 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; @@ -869,6 +859,7 @@ static void help(char *name, struct test_args *targs) static bool parse_args(int argc, char *argv[], struct test_args *targs) { + uint32_t max_mem_slots; int opt; while ((opt = getopt(argc, argv, "hvds:f:e:l:r:")) != -1) { @@ -885,8 +876,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 +923,21 @@ static bool parse_args(int argc, char *argv[], return false; } + max_mem_slots = kvm_check_cap(KVM_CAP_NR_MEMSLOTS); + if (max_mem_slots <= 1) { + pr_info("KVM_CAP_NR_MEMSLOTS should be greater than 1\n"); + return false; + } + + /* Memory slot 0 is reserved */ + if (targs->nslots == -1) + targs->nslots = max_mem_slots - 1; + else + targs->nslots = min_t(int, targs->nslots, max_mem_slots) - 1; + + pr_info_v("Allowed Number of memory slots: %"PRIu32"\n", + targs->nslots + 1); + return true; }