From: Jiri Pirko <jiri@resnulli.us>
To: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net,
edumazet@google.com, jacob.e.keller@intel.com, jhs@mojatatu.com,
johannes@sipsolutions.net, andriy.shevchenko@linux.intel.com,
amritha.nambiar@intel.com, sdf@google.com, horms@kernel.org
Subject: Re: [patch net-next v4 3/9] devlink: send notifications only if there are listeners
Date: Tue, 28 Nov 2023 08:39:58 +0100 [thread overview]
Message-ID: <ZWWZTrS3/f2K3fmQ@nanopsycho> (raw)
In-Reply-To: <0455b0ed46dbac54feb13a27b8fede80980b9426.camel@redhat.com>
Mon, Nov 27, 2023 at 04:00:42PM CET, pabeni@redhat.com wrote:
>On Mon, 2023-11-27 at 13:04 +0100, Jiri Pirko wrote:
>> Mon, Nov 27, 2023 at 12:01:10PM CET, pabeni@redhat.com wrote:
>> > On Thu, 2023-11-23 at 19:15 +0100, Jiri Pirko wrote:
>> > > From: Jiri Pirko <jiri@nvidia.com>
>> > >
>> > > Introduce devlink_nl_notify_need() helper and using it to check at the
>> > > beginning of notification functions to avoid overhead of composing
>> > > notification messages in case nobody listens.
>> > >
>> > > Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>> > > ---
>> > > net/devlink/dev.c | 5 ++++-
>> > > net/devlink/devl_internal.h | 6 ++++++
>> > > net/devlink/health.c | 3 +++
>> > > net/devlink/linecard.c | 2 +-
>> > > net/devlink/param.c | 2 +-
>> > > net/devlink/port.c | 2 +-
>> > > net/devlink/rate.c | 2 +-
>> > > net/devlink/region.c | 2 +-
>> > > net/devlink/trap.c | 6 +++---
>> > > 9 files changed, 21 insertions(+), 9 deletions(-)
>> > >
>> > > diff --git a/net/devlink/dev.c b/net/devlink/dev.c
>> > > index 7c7517e26862..46407689ef70 100644
>> > > --- a/net/devlink/dev.c
>> > > +++ b/net/devlink/dev.c
>> > > @@ -204,6 +204,9 @@ static void devlink_notify(struct devlink *devlink, enum devlink_command cmd)
>> > > WARN_ON(cmd != DEVLINK_CMD_NEW && cmd != DEVLINK_CMD_DEL);
>> > > WARN_ON(!devl_is_registered(devlink));
>> >
>> > minor nit: possibly use ASSERT_DEVLINK_REGISTERED(devlink) above?
>>
>> Sure, but unrelated to this patch.
>>
>>
>> >
>> > >
>> > > + if (!devlink_nl_notify_need(devlink))
>> > > + return;
>> > > +
>> > > msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
>> > > if (!msg)
>> > > return;
>> > > @@ -985,7 +988,7 @@ static void __devlink_flash_update_notify(struct devlink *devlink,
>> > > cmd != DEVLINK_CMD_FLASH_UPDATE_END &&
>> > > cmd != DEVLINK_CMD_FLASH_UPDATE_STATUS);
>> > >
>> > > - if (!devl_is_registered(devlink))
>> > > + if (!devl_is_registered(devlink) || !devlink_nl_notify_need(devlink))
>> > > return;
>> > >
>> > > msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
>> > > diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
>> > > index 59ae4761d10a..510990de094e 100644
>> > > --- a/net/devlink/devl_internal.h
>> > > +++ b/net/devlink/devl_internal.h
>> > > @@ -185,6 +185,12 @@ int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
>> > > struct devlink *devlink, int attrtype);
>> > > int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info);
>> > >
>> > > +static inline bool devlink_nl_notify_need(struct devlink *devlink)
>> > > +{
>> > > + return genl_has_listeners(&devlink_nl_family, devlink_net(devlink),
>> > > + DEVLINK_MCGRP_CONFIG);
>> > > +}
>> > > +
>> > > /* Notify */
>> > > void devlink_notify_register(struct devlink *devlink);
>> > > void devlink_notify_unregister(struct devlink *devlink);
>> > > diff --git a/net/devlink/health.c b/net/devlink/health.c
>> > > index 71ae121dc739..0795dcf22ca8 100644
>> > > --- a/net/devlink/health.c
>> > > +++ b/net/devlink/health.c
>> > > @@ -496,6 +496,9 @@ static void devlink_recover_notify(struct devlink_health_reporter *reporter,
>> > > WARN_ON(cmd != DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
>> > > ASSERT_DEVLINK_REGISTERED(devlink);
>> > >
>> > > + if (!devlink_nl_notify_need(devlink))
>> > > + return;
>> > > +
>> > > msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
>> > > if (!msg)
>> > > return;
>> > > diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c
>> > > index 9d080ac1734b..45b36975ee6f 100644
>> > > --- a/net/devlink/linecard.c
>> > > +++ b/net/devlink/linecard.c
>> > > @@ -136,7 +136,7 @@ static void devlink_linecard_notify(struct devlink_linecard *linecard,
>> > > WARN_ON(cmd != DEVLINK_CMD_LINECARD_NEW &&
>> > > cmd != DEVLINK_CMD_LINECARD_DEL);
>> > >
>> > > - if (!__devl_is_registered(devlink))
>> > > + if (!__devl_is_registered(devlink) || !devlink_nl_notify_need(devlink))
>> > > return;
>> > >
>> > > msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
>> > > diff --git a/net/devlink/param.c b/net/devlink/param.c
>> > > index d74df09311a9..6bb6aee5d937 100644
>> > > --- a/net/devlink/param.c
>> > > +++ b/net/devlink/param.c
>> > > @@ -343,7 +343,7 @@ static void devlink_param_notify(struct devlink *devlink,
>> > > * will replay the notifications if the params are added/removed
>> > > * outside of the lifetime of the instance.
>> > > */
>> > > - if (!devl_is_registered(devlink))
>> > > + if (!devlink_nl_notify_need(devlink) || !devl_is_registered(devlink))
>> >
>> > Minor nit: this is the only statement using this order, perhaps swap
>> > the tests for consistency?
>>
>> Right. If respin is needed, I'll swap.
>>
>>
>> >
>> > Also possibly add the devlink_nl_notify_need() check in
>> > devl_is_registered to reduce code duplication? plus a
>>
>> It would be odd to have devlink_nl_notify_need() called from
>> devl_is_registered().
>
>Sorry for the confusion, out-of-order on my side. What I really mean
>is: add __devl_is_registered() in devlink_nl_notify_need().
>
>> Also, it is non only used on notification paths.
>> I thought about putting the checks in one function, but those are 2
>> separate and unrelated checks, so better to keep them separate.
>
>It looks like devlink_nl_notify_need() implies/requires
>__devl_is_registered() ?
>
__devl_is_registered() and devl_is_registered(), depends on the case.
That's why I prefer to have the check outside devlink_nl_notify_need()
>Cheers,
>
>Paolo
>
next prev parent reply other threads:[~2023-11-28 7:40 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-23 18:15 [patch net-next v4 0/9] devlink: introduce notifications filtering Jiri Pirko
2023-11-23 18:15 ` [patch net-next v4 1/9] devlink: use devl_is_registered() helper instead xa_get_mark() Jiri Pirko
2023-11-23 18:15 ` [patch net-next v4 2/9] devlink: introduce __devl_is_registered() helper and use it instead of xa_get_mark() Jiri Pirko
2023-11-23 18:15 ` [patch net-next v4 3/9] devlink: send notifications only if there are listeners Jiri Pirko
2023-11-27 11:01 ` Paolo Abeni
2023-11-27 12:04 ` Jiri Pirko
2023-11-27 15:00 ` Paolo Abeni
2023-11-28 7:39 ` Jiri Pirko [this message]
2023-11-23 18:15 ` [patch net-next v4 4/9] devlink: introduce a helper for netlink multicast send Jiri Pirko
2023-11-23 18:15 ` [patch net-next v4 5/9] genetlink: introduce per-sock family private pointer storage Jiri Pirko
2023-11-27 11:13 ` Paolo Abeni
2023-11-27 12:00 ` Jiri Pirko
2023-11-27 22:46 ` Jakub Kicinski
2023-11-28 8:25 ` Jiri Pirko
2023-11-28 15:11 ` Jakub Kicinski
2023-11-28 16:05 ` Jiri Pirko
2023-11-28 16:36 ` Jakub Kicinski
2023-11-29 13:59 ` Jiri Pirko
2023-11-29 15:01 ` Jakub Kicinski
2023-11-29 15:25 ` Jiri Pirko
2023-11-28 12:30 ` Przemek Kitszel
2023-11-28 15:05 ` Jiri Pirko
2023-11-28 16:18 ` Andy Shevchenko
2023-11-28 19:59 ` Jacob Keller
2023-11-28 20:06 ` Andy Shevchenko
2023-11-29 23:29 ` Jacob Keller
2023-11-23 18:15 ` [patch net-next v4 6/9] netlink: introduce typedef for filter function Jiri Pirko
2023-11-23 18:15 ` [patch net-next v4 7/9] genetlink: introduce helpers to do filtered multicast Jiri Pirko
2023-11-23 18:15 ` [patch net-next v4 8/9] devlink: add a command to set notification filter and use it for multicasts Jiri Pirko
2023-11-27 12:30 ` Przemek Kitszel
2023-11-27 12:51 ` Jiri Pirko
2023-11-27 12:56 ` Jiri Pirko
2023-11-27 15:40 ` Przemek Kitszel
2023-11-28 8:26 ` Jiri Pirko
2023-12-04 16:24 ` Jiri Pirko
2023-12-04 16:47 ` Andy Shevchenko
2023-12-04 19:17 ` Keller, Jacob E
2023-12-05 7:47 ` Jiri Pirko
2023-12-05 15:58 ` andriy.shevchenko
2023-11-23 18:15 ` [patch net-next v4 9/9] devlink: extend multicast filtering by port index Jiri Pirko
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=ZWWZTrS3/f2K3fmQ@nanopsycho \
--to=jiri@resnulli.us \
--cc=amritha.nambiar@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jhs@mojatatu.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.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;
as well as URLs for NNTP newsgroup(s).