From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CFE61A034C; Fri, 21 Jan 2022 04:36:07 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4CA1442724; Fri, 21 Jan 2022 04:36:07 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 7BD914271F; Fri, 21 Jan 2022 04:36:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642736166; x=1674272166; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kI8solEmnxu6xyJ+dY1I6nbtrKGHsUh1fSFd987y+10=; b=eYOBpNGDtSvkwc8lBrYijrnpqNr0+5vUJNrNwl7hTdrWBFu7aj7GsTho Z4ViQ3D8ZBy7NptLceZQ4yi3rXgyj6PqwKY+dGGfE1Lc6TqTw62w4J3BP FrnkWFy+g2u8JivqDsbwZveWiqBlT5Ia6/pUkVumuuVdr18ZjmRY/sTiR y4WvwyY/SHdT76DhKxW6n/rMW0KGlOfiSaHooipZhgoI8mx67m1SmFvoX Lb4RF01gP9ApaGThB7z8pA/GRMtvzc/oguCGgEzIRrKjyRalYlXOhdCgJ x1f1WI+9GFt5uzrsKfNHgbpF9zRzI1ZBiVVLKfoXccGTKb2h8CZ3Caqdp w==; X-IronPort-AV: E=McAfee;i="6200,9189,10233"; a="232916756" X-IronPort-AV: E=Sophos;i="5.88,304,1635231600"; d="scan'208";a="232916756" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2022 19:36:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,304,1635231600"; d="scan'208";a="616361711" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.238.175.107]) by FMSMGA003.fm.intel.com with ESMTP; 20 Jan 2022 19:36:01 -0800 From: Wei Huang To: dev@dpdk.org, rosen.xu@intel.com, qi.z.zhang@intel.com Cc: stable@dpdk.org, tianfei.zhang@intel.com, ferruh.yigit@intel.com, stephen@networkplumber.org, david.marchand@redhat.com Subject: [PATCH v5] raw/ifpga: fix pthread cannot join Date: Thu, 20 Jan 2022 22:32:46 -0500 Message-Id: <20220121033246.10339-1-wei.huang@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220121012932.9827-1-wei.huang> References: <20220121012932.9827-1-wei.huang> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Tianfei Zhang When we want to close a thread, we should set a flag to notify thread handler function. Fixes: 9c006c45 ("raw/ifpga: scan PCIe BDF device tree") Cc: stable@dpdk.org Signed-off-by: Tianfei Zhang --- v2: update commit log --- v3: set thread id to 0 after pthread_join --- v4: do not evaluate and set pthread_t variable --- v5: use builtin atomic function to access ifpga_monitor_start flag --- drivers/raw/ifpga/ifpga_rawdev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index 8d9db58..b72c13a 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -68,7 +68,7 @@ static struct ifpga_rawdev ifpga_rawdevices[IFPGA_RAWDEV_NUM]; -static int ifpga_monitor_start; +static rte_atomic32_t ifpga_monitor_start; static pthread_t ifpga_monitor_start_thread; #define IFPGA_MAX_IRQ 12 @@ -497,7 +497,7 @@ static int set_surprise_link_check_aer( int gsd_enable, ret; #define MS 1000 - while (1) { + while (rte_atomic32_read(&ifpga_monitor_start)) { gsd_enable = 0; for (i = 0; i < IFPGA_RAWDEV_NUM; i++) { ifpga_rdev = &ifpga_rawdevices[i]; @@ -525,7 +525,7 @@ static int set_surprise_link_check_aer( { int ret; - if (ifpga_monitor_start == 0) { + if (!rte_atomic32_read(&ifpga_monitor_start)) { ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread, "ifpga-monitor", NULL, ifpga_rawdev_gsd_handle, NULL); @@ -534,7 +534,7 @@ static int set_surprise_link_check_aer( "Fail to create ifpga nonitor thread"); return -1; } - ifpga_monitor_start = 1; + rte_atomic32_set(&ifpga_monitor_start, 1); } return 0; @@ -544,7 +544,9 @@ static int set_surprise_link_check_aer( { int ret; - if (ifpga_monitor_start == 1) { + if (rte_atomic32_read(&ifpga_monitor_start)) { + rte_atomic32_set(&ifpga_monitor_start, 0); + ret = pthread_cancel(ifpga_monitor_start_thread); if (ret) IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread"); @@ -553,8 +555,6 @@ static int set_surprise_link_check_aer( if (ret) IFPGA_RAWDEV_PMD_ERR("Can't join the thread"); - ifpga_monitor_start = 0; - return ret; } -- 1.8.3.1