From patchwork Mon Oct 24 11:34:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Wei W" X-Patchwork-Id: 8381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp394306wru; Mon, 24 Oct 2022 04:39:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fFO25CNUvLM9+lZOmvhUZ0hiDUX5kxHGpVjU9UDDK5UetEyhplaSN16eX+DjzydbLbyBf X-Received: by 2002:a05:6402:1d4a:b0:461:d375:7927 with SMTP id dz10-20020a0564021d4a00b00461d3757927mr3126875edb.18.1666611591985; Mon, 24 Oct 2022 04:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666611591; cv=none; d=google.com; s=arc-20160816; b=r5n+rCosy1Reb38TPGqO7GDOx6JiaGocZ6+VFmMxy/7CGcjYZjo551sLy4xOuyAJeS j8aBJfXWDSqRK9vth7zjjhNztElUw5avM/hd1w5mspPWul0KTjNRj+WjZ5S76aBbXxt8 /829e/r7a44NEQ0kUWkgS0P/RwGyPLjAWX7u/6cTWIEaaXYzj1eGvWtMEc685I/HTrYe 3zOOIjLBiKRIvGmDPfGewGt8OFx9ymo89ZjWBArlS8P0G845Pt5YuQnixTXTi7BYvGmN Dwwb4CUsrGBN6D/VwJjC8VsBFE9DBTtzm213btlQJh+RMHlRA2v5m2lyJwoT40TD8EtQ Y5Kw== 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=ko7f6d0FTuAy/3ubruVUtPM91P7qP1E08B/BoDaj22Y=; b=lrvL+3FULR5dAFrRLm2bd6gH5xguO94+dERCANMQJ8sYuZNXKggTvs0WVra2SNPfd6 /GpeERarfUjSPuVIiT8t6lBNXPgHsTK4xeIUDf2Fat2DE8ktPG/Oc4usyMB0rHmjPXjx iCvQWZGq3qDwjGqh7g8rbQrS8pKYVeUQYodQFujbhvpgZcbFNmStvQeiW8rXuCBONLPr 4ycAleReQf/ldDLLXpfro4WlPSHsd+oenmiuS6vNmyUhyeK6u2OvjWcR78UvfcNi1ZSg 1NhV7LlN26K6Fb4D9laO5YIC+nV8hwjv1eYsCxHwcKh9TOmxXKFRU4yjHl0DIFTeOR6V OxJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MZl9zgor; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb13-20020a170907160d00b0078b0865d468si27586359ejc.549.2022.10.24.04.39.28; Mon, 24 Oct 2022 04:39:51 -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=@intel.com header.s=Intel header.b=MZl9zgor; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231205AbiJXLig (ORCPT + 99 others); Mon, 24 Oct 2022 07:38:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230490AbiJXLhq (ORCPT ); Mon, 24 Oct 2022 07:37:46 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B93020355; Mon, 24 Oct 2022 04:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666611455; x=1698147455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KJBfPBUBTZiaXIiWbe2G6kNdjfIEI/B2n2ehEAeUbhI=; b=MZl9zgorN8+46itPUOm8HIkfAbSErY3MWfjzKCOLdET+bm6L4W6jXIIf O+mj7pa008+zXjct8s0jKFk5Gm3lvHD0nyGWwRwj8/OFgMX5diZs1zGHl mdZzxCusT5bxWSO1xjAztYAx95dkwM83Ti5R//XkyjyatiUHyeayWvPz5 tdOQc0OJ9gK3vXnsIE7dpSYbpVzzu0/IhFZbyWNI+xq65eUSSPqa1iesy N0CczhYKL7HbzdTUI4K05dbQZwKuY1Xn3X4D5YkPkrZkEhpMwNof3s2vh aOeRcH1vVPry/v3l3kqSSKNtgmqqfTLpYSfVXEe5nRyPG50XYjP8wU5Do w==; X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="369462443" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="369462443" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 04:35:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="773784960" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="773784960" Received: from tdx-lm.sh.intel.com ([10.239.53.27]) by fmsmga001.fm.intel.com with ESMTP; 24 Oct 2022 04:35:12 -0700 From: Wei Wang To: seanjc@google.com, pbonzini@redhat.com Cc: dmatlack@google.com, vipinsh@google.com, ajones@ventanamicro.com, eric.auger@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Wang Subject: [PATCH v1 10/18] KVM: selftests/tsc_scaling_sync: vcpu related code consolidation Date: Mon, 24 Oct 2022 19:34:37 +0800 Message-Id: <20221024113445.1022147-11-wei.w.wang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221024113445.1022147-1-wei.w.wang@intel.com> References: <20221024113445.1022147-1-wei.w.wang@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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?1747568916607682004?= X-GMAIL-MSGID: =?utf-8?q?1747568916607682004?= Remove the unnecessary definition of the vcpu_threads[] array, as it has beend included in the kvm_vcpu struct. Use the helper functions to create and join the vcpu threads. Signed-off-by: Wei Wang --- .../selftests/kvm/x86_64/tsc_scaling_sync.c | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/tsc_scaling_sync.c b/tools/testing/selftests/kvm/x86_64/tsc_scaling_sync.c index 47139aab7408..34a8beef42b6 100644 --- a/tools/testing/selftests/kvm/x86_64/tsc_scaling_sync.c +++ b/tools/testing/selftests/kvm/x86_64/tsc_scaling_sync.c @@ -15,7 +15,6 @@ #include #include #include -#include #define NR_TEST_VCPUS 20 @@ -44,18 +43,15 @@ static void guest_code(void) } -static void *run_vcpu(void *_cpu_nr) +static void *run_vcpu(void *data) { - unsigned long vcpu_id = (unsigned long)_cpu_nr; + struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; unsigned long failures = 0; static bool first_cpu_done; - struct kvm_vcpu *vcpu; /* The kernel is fine, but vm_vcpu_add() needs locking */ pthread_spin_lock(&create_lock); - vcpu = vm_vcpu_add(vm, vcpu_id, guest_code); - if (!first_cpu_done) { first_cpu_done = true; vcpu_set_msr(vcpu, MSR_IA32_TSC, TEST_TSC_OFFSET); @@ -95,23 +91,12 @@ int main(int argc, char *argv[]) { TEST_REQUIRE(kvm_has_cap(KVM_CAP_VM_TSC_CONTROL)); - vm = vm_create(NR_TEST_VCPUS); + vm = vm_create_with_vcpus(NR_TEST_VCPUS, guest_code, NULL); vm_ioctl(vm, KVM_SET_TSC_KHZ, (void *) TEST_TSC_KHZ); pthread_spin_init(&create_lock, PTHREAD_PROCESS_PRIVATE); - pthread_t cpu_threads[NR_TEST_VCPUS]; - unsigned long cpu; - for (cpu = 0; cpu < NR_TEST_VCPUS; cpu++) - pthread_create(&cpu_threads[cpu], NULL, run_vcpu, (void *)cpu); - - unsigned long failures = 0; - for (cpu = 0; cpu < NR_TEST_VCPUS; cpu++) { - void *this_cpu_failures; - pthread_join(cpu_threads[cpu], &this_cpu_failures); - failures += (unsigned long)this_cpu_failures; - } - - TEST_ASSERT(!failures, "TSC sync failed"); + vm_vcpu_threads_create(vm, run_vcpu, 0); + vm_vcpu_threads_join(vm); pthread_spin_destroy(&create_lock); kvm_vm_free(vm); return 0;