diff options
author | Jakub Kicinski <kuba@kernel.org> | 2024-04-15 11:19:58 -0700 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2024-04-15 11:19:58 -0700 |
commit | 77c842caa772044db9f8517a03d33df779f9517c (patch) | |
tree | c35d85cdf08a651df1049f026d4e6c4eb2dcd178 /lib | |
parent | 444cde13826bb4d3f9fdf829bf5e2f7bb03d9c32 (diff) | |
parent | 4ba67ef3a1fbb7d8dc5f00de9b93a583d05b38cc (diff) |
Merge branch 'net-dqs-optimize-if-stall-threshold-is-not-set'
Breno Leitao says:
====================
net: dqs: optimize if stall threshold is not set
Here are four patches aimed at enhancing the Dynamic Queue Limit (DQL)
subsystem within the networking stack.
The first two commits involve code refactoring, while the third patch
introduces the actual change. The fourth patch just improves the cache
locality.
Typically, when DQL is enabled, stall information is always populated
through dql_queue_stall(). However, this information is only necessary
if a stall threshold is set, which is stored in struct dql->stall_thrs.
Although dql_queue_stall() is relatively inexpensive, it is not entirely
free due to memory barriers and similar overheads.
To optimize performance, refrain from calling dql_queue_stall() when no
stall threshold is set, thus avoiding the processing of unnecessary
information.
v1: https://lore.kernel.org/all/20240404145939.3601097-1-leitao@debian.org/
====================
Link: https://lore.kernel.org/r/20240411192241.2498631-1-leitao@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dynamic_queue_limits.c | 13 |
1 files changed, 9 insertions, 4 deletions
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); |