netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Ilya Maximets <i.maximets@ovn.org>
Cc: "Adrián Moreno" <amorenoz@redhat.com>,
	dev@openvswitch.org, "Donald Hunter" <donald.hunter@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [ovs-dev] [PATCH net-next v7 05/10] net: openvswitch: add psample action
Date: Tue, 2 Jul 2024 13:33:01 +0100	[thread overview]
Message-ID: <20240702123301.GH598357@kernel.org> (raw)
In-Reply-To: <447c0d2a-f7cf-4c34-b5d5-96ca6fffa6b0@ovn.org>

On Tue, Jul 02, 2024 at 11:53:01AM +0200, Ilya Maximets wrote:
> On 7/2/24 11:37, Simon Horman wrote:
> > On Tue, Jul 02, 2024 at 03:05:02AM -0400, Adrián Moreno wrote:
> >> On Mon, Jul 01, 2024 at 02:23:12PM GMT, Aaron Conole wrote:
> >>> Adrian Moreno <amorenoz@redhat.com> writes:
> > 
> > ...
> > 
> >>>> diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
> > 
> > ...
> > 
> >>>> @@ -1299,6 +1304,39 @@ static int execute_dec_ttl(struct sk_buff *skb, struct sw_flow_key *key)
> >>>>  	return 0;
> >>>>  }
> >>>>
> >>>> +#if IS_ENABLED(CONFIG_PSAMPLE)
> >>>> +static void execute_psample(struct datapath *dp, struct sk_buff *skb,
> >>>> +			    const struct nlattr *attr)
> >>>> +{
> >>>> +	struct psample_group psample_group = {};
> >>>> +	struct psample_metadata md = {};
> >>>> +	const struct nlattr *a;
> >>>> +	int rem;
> >>>> +
> >>>> +	nla_for_each_attr(a, nla_data(attr), nla_len(attr), rem) {
> >>>> +		switch (nla_type(a)) {
> >>>> +		case OVS_PSAMPLE_ATTR_GROUP:
> >>>> +			psample_group.group_num = nla_get_u32(a);
> >>>> +			break;
> >>>> +
> >>>> +		case OVS_PSAMPLE_ATTR_COOKIE:
> >>>> +			md.user_cookie = nla_data(a);
> >>>> +			md.user_cookie_len = nla_len(a);
> >>>> +			break;
> >>>> +		}
> >>>> +	}
> >>>> +
> >>>> +	psample_group.net = ovs_dp_get_net(dp);
> >>>> +	md.in_ifindex = OVS_CB(skb)->input_vport->dev->ifindex;
> >>>> +	md.trunc_size = skb->len - OVS_CB(skb)->cutlen;
> >>>> +
> >>>> +	psample_sample_packet(&psample_group, skb, 0, &md);
> >>>> +}
> >>>> +#else
> >>>> +static inline void execute_psample(struct datapath *dp, struct sk_buff *skb,
> >>>> +				   const struct nlattr *attr) {}
> >>>
> >>> I noticed that this got flagged in patchwork since it is 'static inline'
> >>> while being part of a complete translation unit - but I also see some
> >>> other places where that has been done.  I guess it should be just
> >>> 'static' though.  I don't feel very strongly about it.
> >>>
> >>
> >> We had a bit of discussion about this with Ilya. It seems "static
> >> inline" is a common pattern around the kernel. The coding style
> >> documentation says:
> >> "Generally, inline functions are preferable to macros resembling functions."
> >>
> >> So I think this "inline" is correct but I might be missing something.
> > 
> > Hi Adrián,
> > 
> > TL;DR: Please remove this inline keyword
> > 
> > For Kernel networking code at least it is strongly preferred not
> > to use inline in .c files unless there is a demonstrable - usually
> > performance - reason to do so. Rather, it is preferred to let the
> > compiler decide when to inline such functions. OTOH, the inline
> > keyword in .h files is fine.
> 
> FWIW, the main reason for 'inline' here is not performance, but silencing
> compiler's potential 'maybe unused' warnings:
> 
>  Function-like macros with unused parameters should be replaced by static
>  inline functions to avoid the issue of unused variables
> 
> I think, the rule for static inline functions in .c files is at odds with
> the 'Conditional Compilation' section of coding style.  The section does
> recommend to avoid conditional function declaration in .c files, but I'm not
> sure it is reasonable to export internal static functions for that reason.
> 
> In this particular case we can either define a macro, which is discouraged
> by the coding style:
> 
>  Generally, inline functions are preferable to macros resembling functions.
> 
> Or create a static inline function, that is against rule of no static
> inline functions in .c files.
> 
> Or create a simple static function and mark all the arguments as unused,
> which kind of compliant to the coding style, but the least pretty.

Hi Ilya,

I guess I would lean towards the last option.
But in any case, thanks for pointing out that this is complex:
I had not realised that when I wrote my previous email.

  reply	other threads:[~2024-07-02 12:33 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-30 19:57 [PATCH net-next v7 00/10] net: openvswitch: Add sample multicasting Adrian Moreno
2024-06-30 19:57 ` [PATCH net-next v7 01/10] net: psample: add user cookie Adrian Moreno
2024-07-01 11:20   ` Michal Kubiak
2024-07-01 18:05   ` Aaron Conole
2024-06-30 19:57 ` [PATCH net-next v7 02/10] net: sched: act_sample: add action cookie to sample Adrian Moreno
2024-07-01 18:06   ` Aaron Conole
2024-06-30 19:57 ` [PATCH net-next v7 03/10] net: psample: skip packet copy if no listeners Adrian Moreno
2024-07-01 18:07   ` Aaron Conole
2024-06-30 19:57 ` [PATCH net-next v7 04/10] net: psample: allow using rate as probability Adrian Moreno
2024-07-01 18:10   ` Aaron Conole
2024-06-30 19:57 ` [PATCH net-next v7 05/10] net: openvswitch: add psample action Adrian Moreno
2024-07-01 11:40   ` Michal Kubiak
2024-07-01 12:56     ` Adrián Moreno
2024-07-02 11:10       ` Michal Kubiak
2024-07-01 18:13   ` Ilya Maximets
2024-07-01 18:23   ` Aaron Conole
2024-07-02  7:05     ` Adrián Moreno
2024-07-02  7:29       ` Adrián Moreno
2024-07-02  9:37       ` Simon Horman
2024-07-02  9:52         ` Adrián Moreno
2024-07-02  9:53         ` Ilya Maximets
2024-07-02 12:33           ` Simon Horman [this message]
2024-07-02 18:37             ` [ovs-dev] " Adrián Moreno
2024-07-02 18:06           ` Jakub Kicinski
2024-07-02 18:16             ` Ilya Maximets
2024-07-02 18:24               ` Jakub Kicinski
2024-07-02 18:52                 ` Ilya Maximets
2024-06-30 19:57 ` [PATCH net-next v7 06/10] net: openvswitch: store sampling probability in cb Adrian Moreno
2024-07-01 18:24   ` Aaron Conole
2024-06-30 19:57 ` [PATCH net-next v7 07/10] selftests: openvswitch: add psample action Adrian Moreno
2024-07-01 18:40   ` Aaron Conole
2024-06-30 19:57 ` [PATCH net-next v7 08/10] selftests: openvswitch: add userspace parsing Adrian Moreno
2024-06-30 19:57 ` [PATCH net-next v7 09/10] selftests: openvswitch: parse trunc action Adrian Moreno
2024-06-30 19:57 ` [PATCH net-next v7 10/10] selftests: openvswitch: add psample test Adrian Moreno
2024-07-01 18:34   ` Ilya Maximets
2024-07-01 18:38   ` Aaron Conole
2024-07-02  7:16     ` Adrián Moreno
2024-07-02 11:45       ` Aaron Conole

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=20240702123301.GH598357@kernel.org \
    --to=horms@kernel.org \
    --cc=amorenoz@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=i.maximets@ovn.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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).