From patchwork Mon Oct 24 11:34:33 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: 13017418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB4C8FA3740 for ; Mon, 24 Oct 2022 11:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231135AbiJXLiB (ORCPT ); Mon, 24 Oct 2022 07:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbiJXLhf (ORCPT ); Mon, 24 Oct 2022 07:37:35 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 174B065240; Mon, 24 Oct 2022 04:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666611443; x=1698147443; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mKq2NUT7YOX2uBR+Ke1CoZuizyxYRwCCOE+dvTpxS40=; b=kDl178Yi+/m+aNCVfLI5i/erG9pOJsBXIeHSvN0CgLZ5jb1dN7SO+Edw cL/VxnlXR3g/0s6WVDzgN7EJfPENcT8MmGKYtX6amXc+mGw0YHQJ8F24K knSqUKICLr+yue2LbtDStAojmbMkAFzbBpLRdoO34zZZcPU65MlSD8zKP czFI6M0t+IMtMyxkby+9z66mBTgtK9rYI5n0ZAEibRAUZWuSHVBqxiy2K c0WtCL9sFvLATiYBUuKEqSM5DLhF2Spt0ZJkRRRqHsgKIqRih3OIKNSBK i0eXcN6HbJJ9toPHdwhAp74S4SGFvs2r5bw0jRQUdNsW5YiAGhSBx71Gd w==; X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="369462415" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="369462415" 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:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="773784761" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="773784761" Received: from tdx-lm.sh.intel.com ([10.239.53.27]) by fmsmga001.fm.intel.com with ESMTP; 24 Oct 2022 04:35:03 -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 06/18] KVM: selftests/dirty_log_test: vcpu related code consolidation Date: Mon, 24 Oct 2022 19:34:33 +0800 Message-Id: <20221024113445.1022147-7-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 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Remove the globally defined vcpu thread, and reuse the one from kvm_vcpu. Also, use the helper functions to create and join the vcpu thread, which has implemented error check (i.e. TEST_ASSERT) inside. Signed-off-by: Wei Wang --- tools/testing/selftests/kvm/dirty_log_test.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index b5234d6efbe1..9177b8ca004d 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -188,12 +187,11 @@ enum log_mode_t { static enum log_mode_t host_log_mode_option = LOG_MODE_ALL; /* Logging mode for current run */ static enum log_mode_t host_log_mode; -static pthread_t vcpu_thread; static uint32_t test_dirty_ring_count = TEST_DIRTY_RING_COUNT; -static void vcpu_kick(void) +static void vcpu_kick(struct kvm_vcpu *vcpu) { - pthread_kill(vcpu_thread, SIG_IPI); + pthread_kill(vcpu->thread, SIG_IPI); } /* @@ -315,10 +313,10 @@ static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn *dirty_gfns, return count; } -static void dirty_ring_wait_vcpu(void) +static void dirty_ring_wait_vcpu(struct kvm_vcpu *vcpu) { /* This makes sure that hardware PML cache flushed */ - vcpu_kick(); + vcpu_kick(vcpu); sem_wait_until(&sem_vcpu_stop); } @@ -336,7 +334,7 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot, uint32_t count = 0, cleared; bool continued_vcpu = false; - dirty_ring_wait_vcpu(); + dirty_ring_wait_vcpu(vcpu); if (!dirty_ring_vcpu_ring_full) { /* @@ -772,7 +770,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) host_clear_count = 0; host_track_next_count = 0; - pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu); + vcpu_thread_create(vcpu, vcpu_worker, 0); while (iteration < p->iterations) { /* Give the vcpu thread some time to dirty some pages */ @@ -805,7 +803,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) /* Tell the vcpu thread to quit */ host_quit = true; log_mode_before_vcpu_join(); - pthread_join(vcpu_thread, NULL); + vm_vcpu_threads_join(vm); pr_info("Total bits checked: dirty (%"PRIu64"), clear (%"PRIu64"), " "track_next (%"PRIu64")\n", host_dirty_count, host_clear_count,