From patchwork Fri Oct 2 12:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 79536 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 53E78A04B5; Fri, 2 Oct 2020 14:07:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D93DA1C1BF; Fri, 2 Oct 2020 14:07:18 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 6EE711C1B8 for ; Fri, 2 Oct 2020 14:07:16 +0200 (CEST) IronPort-SDR: 28htisfXtF6DjAjSMu1D2dFSP0EZlp83O8kzSGRCEXrGRPXXv2htILlZgBJeMtFgxDoXQ1HOER NNe2s7ASliPA== X-IronPort-AV: E=McAfee;i="6000,8403,9761"; a="163061866" X-IronPort-AV: E=Sophos;i="5.77,327,1596524400"; d="scan'208";a="163061866" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2020 05:07:11 -0700 IronPort-SDR: TxKr/+7UBlBkdn6Sumn7/tgY9/tozIaz0iS0nW73hsQf71TdG+T11R2/P8qZNmxkZRxX4uagVD nbCoLuJObrzA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,327,1596524400"; d="scan'208";a="339977892" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.222.52]) by fmsmga004.fm.intel.com with ESMTP; 02 Oct 2020 05:07:09 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: David Hunt , reshma.pattan@intel.com, anatoly.burakov@intel.com Date: Fri, 2 Oct 2020 13:07:09 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2] l3fwd-power: make interrupt wakeup log thread safe X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Currently, the interrupt status notification prevents log spam by remembering whether previous interrupt wakeup was due to traffic or due to timeout expiring. However, it is a single variable that can potentially be accessed from multiple threads, so it is not thread-safe. Fix it by having per-lcore interrupt status. Fixes: f4d1e19c293d ("examples/l3fwd-power: add Rx interrupt timeout") Cc: anatoly.burakov@intel.com Signed-off-by: Anatoly Burakov Acked-by: David Hunt Tested-by: Zhang, XiX Tested-by: Zhang, XiX Acked-by: David Hunt Tested-by: Xi Zhang --- Notes: v2: - Fix confusing variable naming examples/l3fwd-power/main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index d0e6c9bd77..526af0db29 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -821,20 +821,23 @@ power_freq_scaleup_heuristic(unsigned lcore_id, * 0 on success */ static int -sleep_until_rx_interrupt(int num) +sleep_until_rx_interrupt(int num, int lcore) { /* * we want to track when we are woken up by traffic so that we can go - * back to sleep again without log spamming. + * back to sleep again without log spamming. Avoid cache line sharing + * to prevent threads stepping on each others' toes. */ - static bool timeout; + static struct { + bool wakeup; + } __rte_cache_aligned status[RTE_MAX_LCORE]; struct rte_epoll_event event[num]; int n, i; uint16_t port_id; uint8_t queue_id; void *data; - if (!timeout) { + if (status[lcore].wakeup) { RTE_LOG(INFO, L3FWD_POWER, "lcore %u sleeps until interrupt triggers\n", rte_lcore_id()); @@ -851,7 +854,7 @@ sleep_until_rx_interrupt(int num) " port %d queue %d\n", rte_lcore_id(), port_id, queue_id); } - timeout = n == 0; + status[lcore].wakeup = n != 0; return 0; } @@ -1050,7 +1053,8 @@ static int main_intr_loop(__rte_unused void *dummy) if (intr_en) { turn_on_off_intr(qconf, 1); sleep_until_rx_interrupt( - qconf->n_rx_queue); + qconf->n_rx_queue, + lcore_id); turn_on_off_intr(qconf, 0); /** * start receiving packets immediately @@ -1473,7 +1477,8 @@ main_legacy_loop(__rte_unused void *dummy) if (intr_en) { turn_on_off_intr(qconf, 1); sleep_until_rx_interrupt( - qconf->n_rx_queue); + qconf->n_rx_queue, + lcore_id); turn_on_off_intr(qconf, 0); /** * start receiving packets immediately