Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6739722rwi; Mon, 24 Oct 2022 05:38:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6A//HiI7p3sLlX1q49OAC/AIYq3+xlcNkMOpL+IZToVMwbbga7wkxe3SXNulbdSBlTJ6tb X-Received: by 2002:a05:6402:3641:b0:45c:4231:ddcc with SMTP id em1-20020a056402364100b0045c4231ddccmr30146945edb.224.1666615094511; Mon, 24 Oct 2022 05:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615094; cv=none; d=google.com; s=arc-20160816; b=Bzb0Dzh8bFgh1oNHnlO1dVjFi9znWXzQ1IpRyf9jL4cwAxjljgmEhsSOafrpyvrry+ WGtEVD6m+zVTupYyXMvEAtMiuQXqrx0Vr4erTCC7q3+qv4i/bsYecDIVxrx6yk1gPZGB 7D/WdfefJ8c5vw+KeqvuDZGRL5Nle/UnWiMQD+s95FiS8ByRy4nusYu6HbrG0cVu+Gl1 bbg++FBoTzwUczJxuFt0pJkU2/30iqtTAS65/L7ZQHJGaCrcRP2qq2ohJADKly41yHfz iONWyZaLtAZKNVAsCchQ0ldNhvsogxelBPZgil2a0BX6zzR4uhFvt6qWMtScwz/255ME MpHQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc23-20020a1709071c1700b00783a0e64f86si31614831ejc.7.2022.10.24.05.37.50; Mon, 24 Oct 2022 05:38:14 -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 Content-Transfer-Encoding: 8bit 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 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; -- 2.27.0