DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
Cc: Marat Khalili <qm2k21@gmail.com>,
	dev@dpdk.org, Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <fanzhang.oss@gmail.com>,
	Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Subject: Re: Proposal using RCU for callbacks
Date: Wed, 21 Oct 2026 08:09:45 -0700	[thread overview]
Message-ID: <20261021080945.19a6993f@phoenix.local> (raw)
In-Reply-To: <163e4df8-ffd1-4f1d-b4ce-b0886f7ee524@yandex.ru>

On Wed, 21 Oct 2026 12:51:11 +0100
Konstantin Ananyev <konstantin.v.ananyev@yandex.ru> wrote:

> In particular, regarding membarrier() - consider using it for BPF CBs
> instead of smb_mb, but decided not to. The main reasons:
> - with membarrier() - all threads in the process will be affected.
>    Also, AFAIK it is implemented via IPI - which is quite heavy.
> - current smp_mb (at least on modern x86_64) is quite fast
> (it uses lock-ed instruction on thread's stack, and last time I measured it,
> takes ¬30-50 cycles). As we usually doing it for a bulk (32+) of packets,
> the overhead is quite small: 1-1.5 cycle per packet.
> 
> But again, if you have some smart ideas how to improve our RCU lib with 
> membarrier() -
> would be really interested to hear.

There is a version in current wireshark extcap patch series.
The membarrier is expensive but only happens when capture is stopped.
We can afford a system call there.

The read side (in callback) is:

static inline void
capture_rcu_enter(unsigned int slot)
{
	struct capture_rcu_reader *r = &capture_rcu.reader[slot];
	uint64_t t;

	if (r->depth++ != 0)
		return;

	t = rte_atomic_load_explicit(&capture_rcu.token, rte_memory_order_relaxed);
	rte_atomic_store_explicit(&r->ctr, t, rte_memory_order_relaxed);

	/*
	 * The loads that follow must not move above the store of ctr. The
	 * writer forces that on every CPU with membarrier, so no fence is
	 * needed here; capture is refused if membarrier does not work.
	 */
	rte_compiler_barrier();
}

static inline void
capture_rcu_exit(unsigned int slot)
{
	struct capture_rcu_reader *r = &capture_rcu.reader[slot];

	if (--r->depth != 0)
		return;

	/* release: prior loads complete before the slot reads idle */
	rte_atomic_store_explicit(&r->ctr, 0, rte_memory_order_release);
}

  reply	other threads:[~2026-10-21 15:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 18:13 Proposal using RCU for callbacks Stephen Hemminger
2026-10-12 20:27 ` Marat Khalili
2026-10-12 22:04   ` Stephen Hemminger
2026-10-21 11:51     ` Konstantin Ananyev
2026-10-21 15:09       ` Stephen Hemminger [this message]
2026-10-22  7:38         ` Konstantin Ananyev

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=20261021080945.19a6993f@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.com \
    --cc=honnappa.nagarahalli@arm.com \
    --cc=konstantin.v.ananyev@yandex.ru \
    --cc=qm2k21@gmail.com \
    /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