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 6F2D2A0A0F; Wed, 7 Apr 2021 22:28:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2710A140F81; Wed, 7 Apr 2021 22:28:56 +0200 (CEST) Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by mails.dpdk.org (Postfix) with ESMTP id 54EA9140F7F; Wed, 7 Apr 2021 22:28:55 +0200 (CEST) Received: by mail-qv1-f47.google.com with SMTP id t13so3717089qvs.7; Wed, 07 Apr 2021 13:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VMz1HXOh0o6zKNzAz8TyY9AAt3vcJaxmFlm9CSQviWI=; b=jWFn1ve1sKtsEsdEUyqNRwHDgZa7wH4oWGPUPcnkS2yMUaaW/5sb/CWkcbhcjcw0rm orGSH+r4BDfFUy9SiGuhgcsJIViF3WI8iF2G7KNLQA1HkVAGqaNSxWRxt4exC6DDJRxH u9cTP3uL91v5IbASihId7UWmJJ55FS5agZYDERGuY3aR3LRJ+9ab7VYS17PYkizY1ZEc BZ9wCVu3LX65o+6N1xGyXALA3TenqFA5mK2cEDblZ3B0A06gc8Ak4MnrqLnjZfU+eU9U MyXTxAnf8Fq3YZVQhDJtOOOqsReTUdrGt9eBTItpg/ieWrd2U5QsPAooJ3jkFnPz3xAn aF/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VMz1HXOh0o6zKNzAz8TyY9AAt3vcJaxmFlm9CSQviWI=; b=q6qdsTQejQxFVzosd6yt6nD598bGMtrMiiqUTNoeqyurN17roikX4skvSygAnooeZx prHPxcokxmdNmNUv6YVet0dqSZjocEDc0gcqm4tsnq5eDB10qtMpVPaYD/z+Lu835Spn zqofhEMBMZHb+ZZud+I8qNlzPSjackEqoG5uBSpJFXoVaJ/UjxY8p+Ne1G6pGtGtLlbi rJabhCOjSMsxckZJZqHDxHuTpk42wb5V4wzc3EhoAKbwrxklzWbnGBesabjAYl/p5WjJ NMvQy9zJNLSSpMHhEM6SC5Re+CU+fAGadQNHsf7NNDnygNad4biu4CCDifN8OqmAQxo8 uQMA== X-Gm-Message-State: AOAM530ROrCxHCHMG+gOi7sCY96NJjemLGX5B7XQpRt+rgc/ar23wj5K 85N4HIuJMiM35EVN5iNLs2A= X-Google-Smtp-Source: ABdhPJway+0jJTXGHvEhXFtGHrSg+GXGtlPTlD6He4td5ajEw4JS3Wp1ZhY1TGDlYjP0DV5gMb1a2Q== X-Received: by 2002:a05:6214:f0d:: with SMTP id gw13mr5402477qvb.33.1617827334877; Wed, 07 Apr 2021 13:28:54 -0700 (PDT) Received: from localhost.localdomain (bras-base-hullpq2034w-grc-18-74-15-213-92.dsl.bell.ca. [74.15.213.92]) by smtp.gmail.com with ESMTPSA id 7sm19532060qkm.64.2021.04.07.13.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 13:28:54 -0700 (PDT) From: Luc Pelletier To: olivier.matz@6wind.com, jianfeng.tan@intel.com, Honnappa.Nagarahalli@arm.com Cc: dev@dpdk.org, Luc Pelletier , stable@dpdk.org Date: Wed, 7 Apr 2021 16:16:06 -0400 Message-Id: <20210407201603.149234-2-lucp.at.work@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/2] eal: fix hang in ctrl thread creation error logic 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 Sender: "dev" The affinity of a control thread is set after it has been launched. If setting the affinity fails, pthread_cancel is called followed by a call to pthread_join, which can hang forever if the thread's start routine doesn't call a pthread cancellation point. This patch modifies the logic so that the control thread exits gracefully if the affinity cannot be set successfully and removes the call to pthread_cancel. Fixes: 6383d26 ("eal: set name when creating a control thread") Cc: olivier.matz@6wind.com Cc: stable@dpdk.org Signed-off-by: Luc Pelletier --- Hi Olivier, Hi Honnappa, As discussed, I've split the changes into 2 patches. This second commit removes the pthread_cancel call which could result in a hang on join, if the ctrl thread routine didn't call a cancellation point. lib/librte_eal/common/eal_common_thread.c | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index 3347e91bf..03dbcd9e8 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -187,14 +187,18 @@ static void *ctrl_thread_init(void *arg) eal_get_internal_configuration(); rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset; struct rte_thread_ctrl_params *params = arg; - void *(*start_routine)(void *) = params->start_routine; + void *(*start_routine)(void *); void *routine_arg = params->arg; __rte_thread_init(rte_lcore_id(), cpuset); pthread_barrier_wait(¶ms->configured); + start_routine = params->start_routine; ctrl_params_free(params); + if (start_routine == NULL) + return NULL; + return start_routine(routine_arg); } @@ -218,14 +222,12 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, params->refcnt = 2; ret = pthread_barrier_init(¶ms->configured, NULL, 2); - if (ret != 0) { - free(params); - return -ret; - } + if (ret != 0) + goto fail_no_barrier; ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params); if (ret != 0) - goto fail; + goto fail_with_barrier; if (name != NULL) { ret = rte_thread_setname(*thread, name); @@ -236,19 +238,22 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, ret = pthread_setaffinity_np(*thread, sizeof(*cpuset), cpuset); if (ret != 0) - goto fail_cancel; + params->start_routine = NULL; pthread_barrier_wait(¶ms->configured); ctrl_params_free(params); - return 0; + if (ret != 0) + /* start_routine has been set to NULL above; */ + /* ctrl thread will exit immediately */ + pthread_join(*thread, NULL); -fail_cancel: - pthread_cancel(*thread); - pthread_join(*thread, NULL); + return -ret; -fail: +fail_with_barrier: pthread_barrier_destroy(¶ms->configured); + +fail_no_barrier: free(params); return -ret; -- 2.25.1