From patchwork Thu Apr 11 19:22:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13626526 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE9F617BA5; Thu, 11 Apr 2024 19:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863400; cv=none; b=qb4+Cnfm2v3vknQ9CL2LgIMTSvklbsnwKsZssBSxreuqO2vT5ouSBe8MpdedKj7HeWZGOQ+tqM7Sfibn45+7GXwAi3YWf9TMOqJLWrgBw/QGprjyiyC4P3Q1MdEi4PP7BEdJCt4qWLhcSkyiplGXonN3mDhfgd3trivJ+Gca5Q0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863400; c=relaxed/simple; bh=Ymi8vcGeV5U25n5hHY6p/NSyc58XMyU2LXdmqZKED6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eGS3MUspYOcdfRFGyBAV8G0fngv1TeecPgpdxNvgmZ68L4+zgEqKXEgCd5XFCENNb309AjHoKnJfllY1bkBLNN2OfpyB4saqZf4o9k0733to6qDZk3y1vIqviINUl3boe9D4bOMl+QTaX1ent3Up7FrFGY31IoFxwq924rP/UFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-516d536f6f2so193202e87.2; Thu, 11 Apr 2024 12:23:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712863397; x=1713468197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G8m6X0YutT7uWn1TO1PGQ+ufRs6DUh470J81GT16/S0=; b=HKL1P5zEn7W7xwIyAj7kDpV6dS84g8ifaeyj3/1J7KFlH1u83Q/JixQbXslOppjk/z BnGYwiMq6iIdSIrgL3Es8swzipGjJ2Zxt/Omgm8K1fDUgx86kdguQgn089ODfQOV8wV9 Ccimp3Id1boD3v5L3nr30u4u2Bk7TQyD46GDCl7HyEycxNN8SXJz+2ryKTnmN0LA65Ws GMxlveDNKB5cL4JeQe6X7sYyCMGmWF4GPOsusxZ/HqDueSsROGgXdqH3YsALWpy9JQla F2G0/h7EbdfHPHFwwOQWnC5dcFEAv5eVrCwCVoGsFhYOSo49cFHJ8kTIPq86SAXYu0af BQnQ== X-Forwarded-Encrypted: i=1; AJvYcCUlLiCBfMIUPyTjyUHF/zUj5GpcDUG2QXe0bxRsdfgYK9XHuS+oReAMMwmy4K5+WlgbwypdAVgG2L8PymCTH9DtqGT+uJNj X-Gm-Message-State: AOJu0Yz4BLi3Xf4yikxFlu7DIp+70LaRrX97LalKwVXvdVNCCCSMM12R gvX2L6rIQUGNal2dxSP7iaXWvtqqKCKbDZ2rZzZUCOlCB4jfawF9 X-Google-Smtp-Source: AGHT+IFEK2Wfqx5XDgZrycIj/QUR1Ldag37mqz5FG4t4KvnVqFSYp/J133+dSXm9gJDoRtxEh/bxJQ== X-Received: by 2002:a05:6512:3d02:b0:516:d444:b26b with SMTP id d2-20020a0565123d0200b00516d444b26bmr632560lfv.46.1712863396852; Thu, 11 Apr 2024 12:23:16 -0700 (PDT) Received: from localhost (fwdproxy-lla-005.fbsv.net. [2a03:2880:30ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id my48-20020a1709065a7000b00a518debfd49sm1021740ejc.116.2024.04.11.12.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 12:23:16 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v3 1/4] net: dql: Avoid calling BUG() when WARN() is enough Date: Thu, 11 Apr 2024 12:22:29 -0700 Message-ID: <20240411192241.2498631-2-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411192241.2498631-1-leitao@debian.org> References: <20240411192241.2498631-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org If the dql_queued() function receives an invalid argument, WARN about it and continue, instead of crashing the kernel. This was raised by checkpatch, when I am refactoring this code (see following patch/commit) WARNING: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants Signed-off-by: Breno Leitao --- include/linux/dynamic_queue_limits.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/dynamic_queue_limits.h b/include/linux/dynamic_queue_limits.h index 5693a4be0d9a..ff9c65841ae8 100644 --- a/include/linux/dynamic_queue_limits.h +++ b/include/linux/dynamic_queue_limits.h @@ -91,7 +91,8 @@ static inline void dql_queued(struct dql *dql, unsigned int count) { unsigned long map, now, now_hi, i; - BUG_ON(count > DQL_MAX_OBJECT); + if (WARN_ON_ONCE(count > DQL_MAX_OBJECT)) + return; dql->last_obj_cnt = count; From patchwork Thu Apr 11 19:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13626527 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4921C182DF; Thu, 11 Apr 2024 19:23:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863403; cv=none; b=ngxa7tGfYr09zKAzLEibCpoWpmhzqztuk/Ojqv9Aja4o1agjzfMrwtFHhle7H+fBf0N/ZaBeaIcKEnvp+uL++/DnQWsDwFuiRzWMcMypqnRJIf2PML5GwlYTaZZK/j1aAW5/LeEknUaEELdRFZDioNjlNb0pnOW9JCioaADP//U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863403; c=relaxed/simple; bh=QPTI0Nkyu1TM5zoNdUKd64u7ifIX9UASRm9jdOshan0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JKiq/DtR0msyrX7XR83sIzOI8PzYWpLZ+Twgj3MVeMOB2vmrDeLsPBEZZ/bqy69h4T9WSKB483Fgdhrp0ZDC6zlj4kCmJynqgrEb9zn5ATEHVvLlTXESx0eRiJGrFmkCxRHhUPqS5uqevS+HQBSkN4BHVw7QG1PgImE2QeiU+2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a51d3193e54so16730966b.2; Thu, 11 Apr 2024 12:23:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712863400; x=1713468200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lEv54p1vC2qDsADoejwxZbGsBSC01L0fD1We714EtHU=; b=mvwjQDiV2ilTtthar2q9rShEn5RXw6SHo8nzIV/cvzmkZs+zBQyRh2Lf8I3Jhzd8wP 2kLAkTspGrOgxyr892XI9gVQlnloGBaINQy12axGvD+UXKMl+L4ZwZIFjSa4UvYBIKiU wRp0jNLgg4mDGLq/F9/O4WuPApAYvgk9p6rof4ulDNcJz5uOtDwo5xvlq3ktorfEtYns x+jg6LMY5LW4YcKZb3QdXjCz6HBBvuJ+SSWhowpdsiZJIcMhUJuCcbqri4qpXtMxbuq7 BfJ/MtIoD3n2C5BIf80clneW9jeFzxJccZvofQfkw70KTCd2OSSi4fku8pfn4LrPEvma xPZg== X-Forwarded-Encrypted: i=1; AJvYcCUUORls+rur0uODHrJD51HQ087U0U5cFFJ2Dv8yiHcChHjAdXbhJus2mdE6XI6jrftAlbwijdfySSS/CvAW0gi6gDLAAG86 X-Gm-Message-State: AOJu0Yxp6wenxq4XBGQBQHQSVpf+ZlgN5FlRRytjDzP2LbI5MxgwD/9M VP8lWfyDbQwsYFarHwsPplki8Alr3D64S1BenhwATaDTpFbZbJ/N X-Google-Smtp-Source: AGHT+IGdgNwyIFMyr6Rhok3HHtgo78XoHXVjVQjg56eVusm0XtiU7uKa947mvkVX/faDh3ZwiiKdKw== X-Received: by 2002:a17:906:6a01:b0:a4e:a7a:84e0 with SMTP id qw1-20020a1709066a0100b00a4e0a7a84e0mr480350ejc.34.1712863400319; Thu, 11 Apr 2024 12:23:20 -0700 (PDT) Received: from localhost (fwdproxy-lla-118.fbsv.net. [2a03:2880:30ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id e11-20020a17090681cb00b00a46af0fbf5dsm1007595ejx.103.2024.04.11.12.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 12:23:20 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v3 2/4] net: dql: Separate queue function responsibilities Date: Thu, 11 Apr 2024 12:22:30 -0700 Message-ID: <20240411192241.2498631-3-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411192241.2498631-1-leitao@debian.org> References: <20240411192241.2498631-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The dql_queued() function currently handles both queuing object counts and populating bitmaps for reporting stalls. This commit splits the bitmap population into a separate function, allowing for conditional invocation in scenarios where the feature is disabled. This refactor maintains functionality while improving code organization. Signed-off-by: Breno Leitao --- include/linux/dynamic_queue_limits.h | 44 ++++++++++++++++------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/include/linux/dynamic_queue_limits.h b/include/linux/dynamic_queue_limits.h index ff9c65841ae8..9980df0b7247 100644 --- a/include/linux/dynamic_queue_limits.h +++ b/include/linux/dynamic_queue_limits.h @@ -83,28 +83,11 @@ struct dql { #define DQL_MAX_OBJECT (UINT_MAX / 16) #define DQL_MAX_LIMIT ((UINT_MAX / 2) - DQL_MAX_OBJECT) -/* - * Record number of objects queued. Assumes that caller has already checked - * availability in the queue with dql_avail. - */ -static inline void dql_queued(struct dql *dql, unsigned int count) +/* Populate the bitmap to be processed later in dql_check_stall() */ +static inline void dql_queue_stall(struct dql *dql) { unsigned long map, now, now_hi, i; - if (WARN_ON_ONCE(count > DQL_MAX_OBJECT)) - return; - - dql->last_obj_cnt = count; - - /* We want to force a write first, so that cpu do not attempt - * to get cache line containing last_obj_cnt, num_queued, adj_limit - * in Shared state, but directly does a Request For Ownership - * It is only a hint, we use barrier() only. - */ - barrier(); - - dql->num_queued += count; - now = jiffies; now_hi = now / BITS_PER_LONG; @@ -134,6 +117,29 @@ static inline void dql_queued(struct dql *dql, unsigned int count) WRITE_ONCE(DQL_HIST_ENT(dql, now_hi), map | BIT_MASK(now)); } +/* + * Record number of objects queued. Assumes that caller has already checked + * availability in the queue with dql_avail. + */ +static inline void dql_queued(struct dql *dql, unsigned int count) +{ + if (WARN_ON_ONCE(count > DQL_MAX_OBJECT)) + return; + + dql->last_obj_cnt = count; + + /* We want to force a write first, so that cpu do not attempt + * to get cache line containing last_obj_cnt, num_queued, adj_limit + * in Shared state, but directly does a Request For Ownership + * It is only a hint, we use barrier() only. + */ + barrier(); + + dql->num_queued += count; + + dql_queue_stall(dql); +} + /* Returns how many objects can be queued, < 0 indicates over limit. */ static inline int dql_avail(const struct dql *dql) { From patchwork Thu Apr 11 19:22:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13626528 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C285134B0; Thu, 11 Apr 2024 19:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863408; cv=none; b=iN5uGrcuXIyVqX33gU3txCH68hcTg8B/RQYJBDNp8HAaM2Jw+x7fZtKTHQiVR7/+WIFbBQKbnll44E9CdQ3MK7IcO+Pi1L5eMdYI/CL0IojWrJYeI5MRIwkkTSMRMEkyM/zjmgzhDpyIeN+AAP/NZX9Mig1gy/3JLEJNvyJeDz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863408; c=relaxed/simple; bh=36sh5N/jvpjq6jwl9uDLoGCYQeODe9Y4/Xxq15VmGxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WreY4DlL/JJObYcBt/xqLUKC6nvvM6Cb76lDO4ZnzIp/VTy/2yIXJLptE0irR4bnjIwbS6+mPk7NvvXwHVaurKH1ViFD1T7eQDOA+w+W/epn9rEZL+PVI3SZEglVJprVL44mCssdlApqQRxQ8yR5NjXte7rooYm1Fip1Q+mkI9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-56fead80bacso198820a12.0; Thu, 11 Apr 2024 12:23:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712863404; x=1713468204; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xFdhNk5nsJDp0fP+o1jjxdXhOlujveYc4TGfWkAd6Tw=; b=hAjIAuJxRcDBNV/E8KW9Gy5TEcDDKFP8k1vaGWkC3FSImDNZQLL9vrv51Hd3ubZovX SJf0yDfPLsG0RWqnZaGtF1bra+UBB4opMjXARsE7IdP+FlRvmKQ0EqijdvxlB197r6jR IurG690u3XyS71/mAhHIVesK5X/9zf80JiVmtV2ygIHGwAj7dfqMAHFfJvHaOmyTbkPg ys9DR1VenvLj9ghRmPvwDUa7GnJuqW4CbVFsh5QniEv/1I1fsmO0vJ3tgZXQZdTjWwia 6eAFzLKjHYvpu9bs5ufpqrNoiL5OrL4zJ/Z6upRa2KCPjbp8GIhQXyn3FNkbU5XyW9zW WjLA== X-Forwarded-Encrypted: i=1; AJvYcCUObvQ140bN6YRmPJgC3y1m/qGfgK74bJeP5b9sp6T2Z3sT7NU+XGVVheDQCvQFxCLUm27JNQwRFjPThuSabR4VeBPn4NLZ X-Gm-Message-State: AOJu0YwaA0p7jJLR+HbLXVh241x5fJehi8szfVvliCYGzN3RMJMqkRwQ WY/rx2aHsERnEd8PwYKD/RAi3RNZXHS+ae1FwE2tPedNvU8iW4CZO3tYaQ== X-Google-Smtp-Source: AGHT+IFTxVaPDiV/0E34xLIuAe7BAWfYY2dx9Viq/9AT+41JHibEdwYee3rPh8Kzbt0Dkaydg5a/DA== X-Received: by 2002:a17:906:3292:b0:a51:c720:5107 with SMTP id 18-20020a170906329200b00a51c7205107mr491692ejw.22.1712863403759; Thu, 11 Apr 2024 12:23:23 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id rs6-20020a170907036600b00a4e6626ae21sm1027945ejb.0.2024.04.11.12.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 12:23:23 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v3 3/4] net: dql: Optimize stall information population Date: Thu, 11 Apr 2024 12:22:31 -0700 Message-ID: <20240411192241.2498631-4-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411192241.2498631-1-leitao@debian.org> References: <20240411192241.2498631-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When Dynamic Queue Limit (DQL) is set, it always populate stall information through dql_queue_stall(). However, this information is only necessary if a stall threshold is set, stored in struct dql->stall_thrs. dql_queue_stall() is cheap, but not free, since it does have memory barriers and so forth. Do not call dql_queue_stall() if there is no stall threshold set, and save some CPU cycles. Signed-off-by: Breno Leitao --- include/linux/dynamic_queue_limits.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/dynamic_queue_limits.h b/include/linux/dynamic_queue_limits.h index 9980df0b7247..869afb800ea1 100644 --- a/include/linux/dynamic_queue_limits.h +++ b/include/linux/dynamic_queue_limits.h @@ -137,7 +137,9 @@ static inline void dql_queued(struct dql *dql, unsigned int count) dql->num_queued += count; - dql_queue_stall(dql); + /* Only populate stall information if the threshold is set */ + if (READ_ONCE(dql->stall_thrs)) + dql_queue_stall(dql); } /* Returns how many objects can be queued, < 0 indicates over limit. */ From patchwork Thu Apr 11 19:22:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13626529 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 104B724A0D; Thu, 11 Apr 2024 19:23:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863410; cv=none; b=jvzQ9ZZ9B0XtjyxWM4IAGFVOdSpL8v2NVpfaHJx+XbTHxgrjJWVohokhOEPvPDU8xvyteYoF1IGFd9FeSWdPCXripIwYR6TJquDlnBH+ejgthPE26I9MzSX1x4Y0vDB8qTBf1eZgKkGheX9f7USTeS5jystTHVT/nU2w6n6J4uQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863410; c=relaxed/simple; bh=R0Unvm4NPmW3WkpDmOtgB6W1uSHwGQG46cIqieQoOnc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BW11vScbUdHF9VtkodiMSlV3LtnKnHEk5X3gqs6JQ2TDmWWTKy5dixW8LmyPStmJ6sOWE/d658eNbPRGsSzcRSrPnD5WDnER4orqrlhhv+/3KUiJXruWvmMV4L1yy4fhYK6cKm22ZfjZNx9yxq08DPjk9SOn1/3c0kpdWSQHM7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a44ad785a44so15245766b.3; Thu, 11 Apr 2024 12:23:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712863407; x=1713468207; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jE/a2AjBDEZ+YFbJt7MyFbW2ZbrRq3LCz8VwZ+JVQuI=; b=wFhT+wputGSxMgB0XveUlnPj4COIbrE8v0Lsu+6/H1oR+vC2cZPL6tHt50y5BOD/dU 9DyLjzJaLws3LDqP4mCaG2fkeVBYoyWZcp+A69G8D94YzMnJkEC3HXpVIVdMdsG40atE 2eqtLk82tssPd9vhXoE2cVrCguURnctr5aUECZgzfC8Cz+Ia+mKc06x2LaixcJ3ap2u2 x9OV95ogrZb9XkljclfWyOpB6oKyr4ZYGGRxGWYCG2US9hJyC/nN3C0Dor0VuARdJxVw Am1LaK/sMJvlYd+8odCYhRnizHJBwFSfD/rTozj1/WJ/HTDwIg0lKwuo9gkXaiMVmXsL iT5Q== X-Forwarded-Encrypted: i=1; AJvYcCUFN7Z+MJGMUg8vrOoL95crew4RI2DMBqyxlkig88hvYkUbsz/CHEiKiKU0wCvWJhFvkLNw2TA2YefHcSSY32gtJ3q7VAMQ X-Gm-Message-State: AOJu0Ywb38YXUnM9wFTj8slLOFIYjF2+Aii/V7rgYoisXsU+yHY13wnE QLHpHFwLp2opn25rCbLDHj4wMNb1LjRIWvIcsyLo02gYut5UA0J+ X-Google-Smtp-Source: AGHT+IFgf7RWrgPJwWaUWZVy2wh7tEVoEbXLg0EZq7L4ZAEv3VrmCaSKE/4E7N5zG4BW50T6UGrH0g== X-Received: by 2002:a17:906:d20d:b0:a51:ad60:ea32 with SMTP id w13-20020a170906d20d00b00a51ad60ea32mr391686ejz.27.1712863407391; Thu, 11 Apr 2024 12:23:27 -0700 (PDT) Received: from localhost (fwdproxy-lla-117.fbsv.net. [2a03:2880:30ff:75::face:b00c]) by smtp.gmail.com with ESMTPSA id gb25-20020a170907961900b00a522d34fee8sm339842ejc.114.2024.04.11.12.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 12:23:27 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, Andrew Morton Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v3 4/4] net: dqs: make struct dql more cache efficient Date: Thu, 11 Apr 2024 12:22:32 -0700 Message-ID: <20240411192241.2498631-5-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411192241.2498631-1-leitao@debian.org> References: <20240411192241.2498631-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org With the previous change, struct dqs->stall_thrs will be in the hot path (at queue side), even if DQS is disabled. The other fields accessed in this function (last_obj_cnt and num_queued) are in the first cache line, let's move this field (stall_thrs) to the very first cache line, since there is a hole there. This does not change the structure size, since it moves an short (2 bytes) to 4-bytes whole in the first cache line. This is the new structure format now: struct dql { unsigned int num_queued; unsigned int last_obj_cnt; ... short unsigned int stall_thrs; /* XXX 2 bytes hole, try to pack */ ... /* --- cacheline 1 boundary (64 bytes) --- */ ... /* Longest stall detected, reported to user */ short unsigned int stall_max; /* XXX 2 bytes hole, try to pack */ }; Also, read the stall_thrs (now in the very first cache line) earlier, together with dql->num_queued (also in the first cache line). Suggested-by: Jakub Kicinski Suggested-by: Eric Dumazet Signed-off-by: Breno Leitao --- include/linux/dynamic_queue_limits.h | 5 +++-- lib/dynamic_queue_limits.c | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/linux/dynamic_queue_limits.h b/include/linux/dynamic_queue_limits.h index 869afb800ea1..281298e77a15 100644 --- a/include/linux/dynamic_queue_limits.h +++ b/include/linux/dynamic_queue_limits.h @@ -50,6 +50,9 @@ struct dql { unsigned int adj_limit; /* limit + num_completed */ unsigned int last_obj_cnt; /* Count at last queuing */ + /* Stall threshold (in jiffies), defined by user */ + unsigned short stall_thrs; + unsigned long history_head; /* top 58 bits of jiffies */ /* stall entries, a bit per entry */ unsigned long history[DQL_HIST_LEN]; @@ -71,8 +74,6 @@ struct dql { unsigned int min_limit; /* Minimum limit */ unsigned int slack_hold_time; /* Time to measure slack */ - /* Stall threshold (in jiffies), defined by user */ - unsigned short stall_thrs; /* Longest stall detected, reported to user */ unsigned short stall_max; unsigned long last_reap; /* Last reap (in jiffies) */ diff --git a/lib/dynamic_queue_limits.c b/lib/dynamic_queue_limits.c index a1389db1c30a..e49deddd3de9 100644 --- a/lib/dynamic_queue_limits.c +++ b/lib/dynamic_queue_limits.c @@ -15,12 +15,10 @@ #define POSDIFF(A, B) ((int)((A) - (B)) > 0 ? (A) - (B) : 0) #define AFTER_EQ(A, B) ((int)((A) - (B)) >= 0) -static void dql_check_stall(struct dql *dql) +static void dql_check_stall(struct dql *dql, unsigned short stall_thrs) { - unsigned short stall_thrs; unsigned long now; - stall_thrs = READ_ONCE(dql->stall_thrs); if (!stall_thrs) return; @@ -86,9 +84,16 @@ void dql_completed(struct dql *dql, unsigned int count) { unsigned int inprogress, prev_inprogress, limit; unsigned int ovlimit, completed, num_queued; + unsigned short stall_thrs; bool all_prev_completed; num_queued = READ_ONCE(dql->num_queued); + /* Read stall_thrs in advance since it belongs to the same (first) + * cache line as ->num_queued. This way, dql_check_stall() does not + * need to touch the first cache line again later, reducing the window + * of possible false sharing. + */ + stall_thrs = READ_ONCE(dql->stall_thrs); /* Can't complete more than what's in queue */ BUG_ON(count > num_queued - dql->num_completed); @@ -178,7 +183,7 @@ void dql_completed(struct dql *dql, unsigned int count) dql->num_completed = completed; dql->prev_num_queued = num_queued; - dql_check_stall(dql); + dql_check_stall(dql, stall_thrs); } EXPORT_SYMBOL(dql_completed);