diff mbox series

[net-next] udp: introduce and use indirect call wrapper for data ready()

Message ID 8834aadd89c1ebcbad32f591ea4d29c9f2684497.1689587539.git.pabeni@redhat.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] udp: introduce and use indirect call wrapper for data ready() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3847 this patch: 3847
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1899 this patch: 1899
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4021 this patch: 4021
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Paolo Abeni July 17, 2023, 9:52 a.m. UTC
In most cases UDP sockets use the default data ready callback.
This patch Introduces and uses a specific indirect call wrapper for
such callback to avoid an indirect call in fastpath.

The above gives small but measurable performance gain under UDP flood.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
Note that this helper could be used for TCP, too. I did not send such
patch right away because in my tests the perf delta there is below the
noise level even in RR scenarios and the patch would be a little more
invasive - there are more sk_data_ready() invocation places.
---
 include/net/sock.h | 4 ++++
 net/ipv4/udp.c     | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Willem de Bruijn July 17, 2023, 1:44 p.m. UTC | #1
Paolo Abeni wrote:
> In most cases UDP sockets use the default data ready callback.
> This patch Introduces and uses a specific indirect call wrapper for
> such callback to avoid an indirect call in fastpath.
> 
> The above gives small but measurable performance gain under UDP flood.

Interesting. I recently wrote a patch to add indirect call wrappers
around getfrag (ip_generic_getfrag), expecting that to improve  UDP
senders. Since it's an indirect call on each send call. Not sent,
because I did not see measurable gains, at least with a udp_rr bench.

> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
> Note that this helper could be used for TCP, too. I did not send such
> patch right away because in my tests the perf delta there is below the
> noise level even in RR scenarios and the patch would be a little more
> invasive - there are more sk_data_ready() invocation places.
> ---
>  include/net/sock.h | 4 ++++
>  net/ipv4/udp.c     | 2 +-
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 2eb916d1ff64..1b26dbecdcca 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -2947,6 +2947,10 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
>  }
>  
>  void sock_def_readable(struct sock *sk);
> +static inline void sk_data_ready(struct sock *sk)
> +{
> +	INDIRECT_CALL_1(sk->sk_data_ready, sock_def_readable, sk);
> +}
>

Why introduce a static inline in the header for this?

To reuse it in other protocols later?

>  int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk);
>  void sock_set_timestamp(struct sock *sk, int optname, bool valbool);
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 42a96b3547c9..5aec1854b711 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -1553,7 +1553,7 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
>  	spin_unlock(&list->lock);
>  
>  	if (!sock_flag(sk, SOCK_DEAD))
> -		sk->sk_data_ready(sk);
> +		sk_data_ready(sk);
>  
>  	busylock_release(busy);
>  	return 0;
> -- 
> 2.41.0
>
Paolo Abeni July 17, 2023, 2:13 p.m. UTC | #2
On Mon, 2023-07-17 at 09:44 -0400, Willem de Bruijn wrote:
> Paolo Abeni wrote:
> > In most cases UDP sockets use the default data ready callback.
> > This patch Introduces and uses a specific indirect call wrapper for
> > such callback to avoid an indirect call in fastpath.
> > 
> > The above gives small but measurable performance gain under UDP flood.
> 
> Interesting. I recently wrote a patch to add indirect call wrappers
> around getfrag (ip_generic_getfrag), expecting that to improve  UDP
> senders. Since it's an indirect call on each send call. Not sent,
> because I did not see measurable gains, at least with a udp_rr bench.
> 
> > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > ---
> > Note that this helper could be used for TCP, too. I did not send such
> > patch right away because in my tests the perf delta there is below the
> > noise level even in RR scenarios and the patch would be a little more
> > invasive - there are more sk_data_ready() invocation places.
> > ---
> >  include/net/sock.h | 4 ++++
> >  net/ipv4/udp.c     | 2 +-
> >  2 files changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/net/sock.h b/include/net/sock.h
> > index 2eb916d1ff64..1b26dbecdcca 100644
> > --- a/include/net/sock.h
> > +++ b/include/net/sock.h
> > @@ -2947,6 +2947,10 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
> >  }
> >  
> >  void sock_def_readable(struct sock *sk);
> > +static inline void sk_data_ready(struct sock *sk)
> > +{
> > +	INDIRECT_CALL_1(sk->sk_data_ready, sock_def_readable, sk);
> > +}
> > 
> 
> Why introduce a static inline in the header for this?
> 
> To reuse it in other protocols later?

I originally thought about re-using it even for TCP, but showed no gain
there. I think/hope there could be other users, and I found the code
nicer this way ;)

Cheers,

Paolo
Willem de Bruijn July 17, 2023, 2:47 p.m. UTC | #3
Paolo Abeni wrote:
> On Mon, 2023-07-17 at 09:44 -0400, Willem de Bruijn wrote:
> > Paolo Abeni wrote:
> > > In most cases UDP sockets use the default data ready callback.
> > > This patch Introduces and uses a specific indirect call wrapper for
> > > such callback to avoid an indirect call in fastpath.
> > > 
> > > The above gives small but measurable performance gain under UDP flood.
> > 
> > Interesting. I recently wrote a patch to add indirect call wrappers
> > around getfrag (ip_generic_getfrag), expecting that to improve  UDP
> > senders. Since it's an indirect call on each send call. Not sent,
> > because I did not see measurable gains, at least with a udp_rr bench.
> > 
> > > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > > ---
> > > Note that this helper could be used for TCP, too. I did not send such
> > > patch right away because in my tests the perf delta there is below the
> > > noise level even in RR scenarios and the patch would be a little more
> > > invasive - there are more sk_data_ready() invocation places.
> > > ---
> > >  include/net/sock.h | 4 ++++
> > >  net/ipv4/udp.c     | 2 +-
> > >  2 files changed, 5 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/include/net/sock.h b/include/net/sock.h
> > > index 2eb916d1ff64..1b26dbecdcca 100644
> > > --- a/include/net/sock.h
> > > +++ b/include/net/sock.h
> > > @@ -2947,6 +2947,10 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
> > >  }
> > >  
> > >  void sock_def_readable(struct sock *sk);
> > > +static inline void sk_data_ready(struct sock *sk)
> > > +{
> > > +	INDIRECT_CALL_1(sk->sk_data_ready, sock_def_readable, sk);
> > > +}
> > > 
> > 
> > Why introduce a static inline in the header for this?
> > 
> > To reuse it in other protocols later?
> 
> I originally thought about re-using it even for TCP, but showed no gain
> there. I think/hope there could be other users, and I found the code
> nicer this way ;)

Until there are other users I disagree. And maybe even then, as this
is a single line function. It's more readable to see the actual code.

That said, no other concerns from me, if no one else objects.
diff mbox series

Patch

diff --git a/include/net/sock.h b/include/net/sock.h
index 2eb916d1ff64..1b26dbecdcca 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2947,6 +2947,10 @@  static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
 }
 
 void sock_def_readable(struct sock *sk);
+static inline void sk_data_ready(struct sock *sk)
+{
+	INDIRECT_CALL_1(sk->sk_data_ready, sock_def_readable, sk);
+}
 
 int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk);
 void sock_set_timestamp(struct sock *sk, int optname, bool valbool);
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 42a96b3547c9..5aec1854b711 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1553,7 +1553,7 @@  int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
 	spin_unlock(&list->lock);
 
 	if (!sock_flag(sk, SOCK_DEAD))
-		sk->sk_data_ready(sk);
+		sk_data_ready(sk);
 
 	busylock_release(busy);
 	return 0;