From patchwork Thu Oct 20 07:12:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 5992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp109268wrs; Thu, 20 Oct 2022 00:16:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6dy/hFscJCtvmPLlDBiaUSYNiVoU53TcMSGWJMo+qu32NiQejBf5kkWdr1nN6BL2bCOJdA X-Received: by 2002:a17:90b:4c11:b0:212:ec8:88ff with SMTP id na17-20020a17090b4c1100b002120ec888ffmr1963837pjb.199.1666250160578; Thu, 20 Oct 2022 00:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666250160; cv=none; d=google.com; s=arc-20160816; b=WZVmudMrIlCr6fhOeSbJMm3VH58+KA9q/Gh5H5wGoGTUHQ8yXDUEtyhy+XogDhDcwa OVBpvj4V/cqMC7YH5T6Bybo5lUS5ubfrW1enyig1gZhyKlGwv2EyB7xEiKBkoNff4Dad deTy61DsYpBS322drRRggbNkcuQ1rWulZ4snI2qpxUkMvPvIXPsCKrg4I04tXA2JDv7o shx3DwumVp9QUMGCTqxfwaTopwdOgtPdAWk76lFLA7BsVDU6dyIlplVg7HJ8UHF6Psnv ENDH/QqVguoDWT0kF+VkxalUTYQRXRIN+6MrD4xme3crW0GezOhoml3crYI0/2iaNT6D 1e0w== 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=FzMWVAugfUTLDKVc6MZDfcXiQ1pIkYlmEhf7GtdgsCg=; b=RAiFLMLEwKVmPuHf5OaApR+UaKkv3/PECRAsnIuytRDSMei9AcCx8QkF60hWEjV8Y8 vRG3vXq5XUSNfSn5G5gNB5c9m8JsXXDAWd6fJw6/sNgEhHiX4xr8Zc0zWTT48+mn8wj1 zbi7gKdodrebkGtJsuP1z1DqPvKn3f248ikVi6Ma0WoyOaf5Bgw5kVpnO4Dp8RgKyIcN BEjw1AAOsO0SumEwgmTSlZWoWLE5rKNUd4cC9g8ZOzr6ggjiK2zyyTjxNZx+hgT9nmfM e+O1gAtibqHbnPXQTG+U1H15CgLdX5yx9KnW9IPowcvhei9fgqnT/hpb8gOkAdlqvcue PNvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="cPmG/l9v"; 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 k21-20020a056a00169500b00537ac8547e9si23842976pfc.82.2022.10.20.00.15.46; Thu, 20 Oct 2022 00:16:00 -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="cPmG/l9v"; 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 S230333AbiJTHOM (ORCPT + 99 others); Thu, 20 Oct 2022 03:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230323AbiJTHNw (ORCPT ); Thu, 20 Oct 2022 03:13:52 -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 A891F1645EB for ; Thu, 20 Oct 2022 00:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666250003; 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=FzMWVAugfUTLDKVc6MZDfcXiQ1pIkYlmEhf7GtdgsCg=; b=cPmG/l9vAa8XbXBAUVzLrP9I00nZoQw1ZWdbykUbAae6jmccBQjFNaQYqBDPQgKDCMFetQ XRZT5SD1bKxTBC0sDwBGW0hu0e3uu6JCcFJV+0R9BtFA1lDeSICGmh6Ib2PovOm8fQdFQW VxbG8pnf45X1VNafvBoB7CrmdLYM55E= 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-651-5ez8t1IUM6GylxvlF3TLAA-1; Thu, 20 Oct 2022 03:13:20 -0400 X-MC-Unique: 5ez8t1IUM6GylxvlF3TLAA-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 B5EAC800B30; Thu, 20 Oct 2022 07:13:19 +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 D56C340C6EC2; Thu, 20 Oct 2022 07:13:14 +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 6/6] KVM: selftests: memslot_perf_test: Report optimal memory slots Date: Thu, 20 Oct 2022 15:12:09 +0800 Message-Id: <20221020071209.559062-7-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?1747189928440568472?= X-GMAIL-MSGID: =?utf-8?q?1747189928440568472?= The memory area in each slot should be aligned to host page size. Otherwise, the test will fail. For example, the following command fails with the following messages with 64KB-page-size-host and 4KB-pae-size-guest. It's not user friendly to abort the test. Lets do something to report the optimal memory slots, instead of failing the test. # ./memslot_perf_test -v -s 1000 Number of memory slots: 999 Testing map performance with 1 runs, 5 seconds each Adding slots 1..999, each slot with 8 pages + 216 extra pages last ==== Test Assertion Failure ==== lib/kvm_util.c:824: vm_adjust_num_guest_pages(vm->mode, npages) == npages pid=19872 tid=19872 errno=0 - Success 1 0x00000000004065b3: vm_userspace_mem_region_add at kvm_util.c:822 2 0x0000000000401d6b: prepare_vm at memslot_perf_test.c:273 3 (inlined by) test_execute at memslot_perf_test.c:756 4 (inlined by) test_loop at memslot_perf_test.c:994 5 (inlined by) main at memslot_perf_test.c:1073 6 0x0000ffff7ebb4383: ?? ??:0 7 0x00000000004021ff: _start at :? Number of guest pages is not compatible with the host. Try npages=16 Report the optimal memory slots instead of failing the test when the memory area in each slot isn't aligned to host page size. With this applied, the optimal memory slots is reported. # ./memslot_perf_test -v -s 1000 Number of memory slots: 999 Testing map performance with 1 runs, 5 seconds each Memslot count too high for this test, decrease the cap (max is 514) Signed-off-by: Gavin Shan --- .../testing/selftests/kvm/memslot_perf_test.c | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/selftests/kvm/memslot_perf_test.c index daebc264de5a..2ad40f7c9c08 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -239,16 +239,52 @@ static struct vm_data *alloc_vm(void) return data; } +static bool check_slot_pages(uint32_t host_page_size, uint32_t guest_page_size, + uint64_t pages_per_slot, uint64_t rempages) +{ + if (!pages_per_slot) + return false; + + if ((pages_per_slot * guest_page_size) % host_page_size) + return false; + + if ((rempages * guest_page_size) % host_page_size) + return false; + + return true; +} + + +static uint64_t get_max_slots(struct vm_data *data, uint32_t host_page_size) +{ + uint32_t guest_page_size = data->vm->page_size; + uint64_t mempages, pages_per_slot, rempages; + uint64_t slots; + + mempages = data->npages; + slots = data->nslots; + while (--slots > 1) { + pages_per_slot = mempages / slots; + rempages = mempages % pages_per_slot; + if (check_slot_pages(host_page_size, guest_page_size, + pages_per_slot, rempages)) + return slots + 1; /* slot 0 is reserved */ + } + + return 0; +} + static bool prepare_vm(struct vm_data *data, int nslots, uint64_t *maxslots, void *guest_code, uint64_t mem_size, struct timespec *slot_runtime) { uint64_t mempages, rempages; uint64_t guest_addr; - uint32_t slot, guest_page_size; + uint32_t slot, host_page_size, guest_page_size; struct timespec tstart; struct sync_area *sync; + host_page_size = getpagesize(); guest_page_size = vm_guest_mode_params[VM_MODE_DEFAULT].page_size; mempages = mem_size / guest_page_size; @@ -260,12 +296,13 @@ static bool prepare_vm(struct vm_data *data, int nslots, uint64_t *maxslots, TEST_ASSERT(data->npages > 1, "Can't test without any memory"); data->nslots = nslots; data->pages_per_slot = data->npages / data->nslots; - if (!data->pages_per_slot) { - *maxslots = data->npages + 1; + rempages = data->npages % data->nslots; + if (!check_slot_pages(host_page_size, guest_page_size, + data->pages_per_slot, rempages)) { + *maxslots = get_max_slots(data, host_page_size); return false; } - rempages = data->npages % data->nslots; data->hva_slots = malloc(sizeof(*data->hva_slots) * data->nslots); TEST_ASSERT(data->hva_slots, "malloc() fail");