From: Stephen Hemminger <stephen@networkplumber.org>
To: Rakesh Kudurumalla <rkudurumalla@marvell.com>
Cc: <ferruh.yigit@amd.com>, <andrew.rybchenko@oktetlabs.ru>,
<orika@nvidia.com>, <thomas@monjalon.net>, <dev@dpdk.org>,
<jerinj@marvell.com>, <ndabilpuram@marvell.com>,
<stable@dpdk.org>
Subject: Re: [PATCH v5 1/1] examples/l2fwd-jobstats: fix lock availability
Date: Tue, 13 Jan 2026 22:24:50 -0800 [thread overview]
Message-ID: <20260113222450.42d0ee18@phoenix.local> (raw)
In-Reply-To: <20240811155957.576645-1-rkudurumalla@marvell.com>
On Sun, 11 Aug 2024 21:29:57 +0530
Rakesh Kudurumalla <rkudurumalla@marvell.com> wrote:
> Race condition between jobstats and time metrics
> for forwarding and flushing is maintained using spinlock.
> Timer metrics are not displayed properly due to the
> frequent unavailability of the lock.This patch fixes
> the issue by introducing a delay before acquiring
> the lock in the loop. This delay allows for betteravailability
> of the lock, ensuring that show_lcore_stats() can
> periodically update the statistics even when forwarding
> jobs are running.
>
> Fixes: 204896f8d66c ("examples/l2fwd-jobstats: add new example")
> Cc: stable@dpdk.org
>
> Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
> ---
I prodded AI to review this patch and it had some good observations.
You could go farther with rte_wait_until_equal which has even better power performance.
Let me see the critical `l2fwd_main_loop` function to understand the full locking context:Now I have a complete picture. Let me provide my review.
---
## Patch Review: examples/l2fwd-jobstats: fix lock availability
### Commit Message Issues
**Errors:**
- Line 84: Missing space before "betteravailability" → should be "better availability"
- Line 82: Missing space after period: "lock.This" → should be "lock. This"
**Style (minor):** The commit message is a bit verbose for what it's doing.
### Technical Analysis
The patch addresses a real problem. Looking at the code flow:
```c
/* Main loop holds lock almost continuously */
for (;;) {
rte_spinlock_lock(&qconf->lock); // Acquire
do {
/* ... lots of work ... */
stats_read_pending = rte_atomic_load_explicit(...);
} while (likely(stats_read_pending == 0));
rte_spinlock_unlock(&qconf->lock); // Release
rte_pause(); // <-- This is too short!
// Immediately re-acquires lock...
}
```
Meanwhile, `show_lcore_stats()` sets the flag and waits on the lock:
```c
rte_atomic_store_explicit(&qconf->stats_read_pending, 1, ...);
rte_spinlock_lock(&qconf->lock); // Starved - main loop re-acquires too fast
```
**The fix works**, but it's suboptimal:
- The 10µs delay is an arbitrary magic number
- It delays **unconditionally**, even when no stats reader is waiting
- Wastes cycles when the system is idle
### Better Option: Wait for stats completion
The `stats_read_pending` flag already exists to coordinate this handshake but isn't used fully. The cleaner fix is to make the main loop wait until the stats reader has finished:
```c
rte_spinlock_unlock(&qconf->lock);
/* Wait for stats reader to complete before reacquiring lock */
while (rte_atomic_load_explicit(&qconf->stats_read_pending,
rte_memory_order_relaxed) != 0)
rte_pause();
```
This approach:
- Uses the existing synchronization mechanism as intended
- Only yields when stats are actually being read
- Has zero overhead when no stats read is pending
- Doesn't introduce arbitrary magic constants
- Guarantees the stats reader gets the lock (not probabilistic)
### Alternative: Conditional delay
If you want to keep the delay approach, at least make it conditional:
```c
rte_spinlock_unlock(&qconf->lock);
if (stats_read_pending)
rte_delay_us(10);
else
rte_pause();
```
This avoids the unconditional 10µs penalty on every iteration.
### Verdict
**NAK as-is.** The fix works but the better solution is to properly use the existing `stats_read_pending` handshake. Would suggest the author revise to use the wait-for-completion pattern instead of an arbitrary delay.
next prev parent reply other threads:[~2026-01-14 6:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-26 5:37 [PATCH 1/1] examples/l2fwd-jobstats: add delay to show stats Rakesh Kudurumalla
2024-07-29 6:10 ` [PATCH v2 " Rakesh Kudurumalla
2024-07-30 10:03 ` [PATCH v3 1/1] examples/l2fwd-jobstats: fix lock availability Rakesh Kudurumalla
2024-07-30 16:12 ` Thomas Monjalon
2024-08-08 11:41 ` [EXTERNAL] " Rakesh Kudurumalla
2024-08-08 12:22 ` Thomas Monjalon
2024-08-11 16:00 ` Rakesh Kudurumalla
2024-08-11 6:58 ` [PATCH v4 " Rakesh Kudurumalla
2024-08-11 15:59 ` [PATCH v5 " Rakesh Kudurumalla
2024-08-11 16:17 ` Stephen Hemminger
2024-08-16 5:25 ` [EXTERNAL] " Rakesh Kudurumalla
2024-10-21 7:13 ` Rakesh Kudurumalla
2024-11-04 10:17 ` Nithin Dabilpuram
2025-05-24 15:39 ` Stephen Hemminger
2026-01-14 6:24 ` Stephen Hemminger [this message]
2026-03-02 6:18 ` [PATCH v6 1/1] examples/l2fwd-jobstats: fix timer stats display with lock contention rkudurumalla
2026-03-02 15:48 ` Stephen Hemminger
2026-03-16 13:36 ` [EXTERNAL] " Rakesh Kudurumalla
2026-03-16 15:20 ` Stephen Hemminger
2026-03-17 16:39 ` Thomas Monjalon
2026-03-17 16:40 ` Thomas Monjalon
2024-07-29 6:20 ` [PATCH v2 1/1] examples/l2fwd-jobstats: add delay to show stats Rakesh Kudurumalla
2026-03-02 16:23 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260113222450.42d0ee18@phoenix.local \
--to=stephen@networkplumber.org \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=jerinj@marvell.com \
--cc=ndabilpuram@marvell.com \
--cc=orika@nvidia.com \
--cc=rkudurumalla@marvell.com \
--cc=stable@dpdk.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox