diff mbox

[net-next-2.6] rps: avoid one atomic in enqueue_to_backlog

Message ID 1273225881.2261.39.camel@edumazet-laptop
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Eric Dumazet May 7, 2010, 9:51 a.m. UTC
Le vendredi 07 mai 2010 à 07:16 +0200, Eric Dumazet a écrit :
> Le jeudi 06 mai 2010 à 22:07 -0700, David Miller a écrit :
> 
> > Looks great, applied, thanks Eric.
> 
> Thanks, I have a followup to avoid one atomic in enqueue phase too ;)
> 

[PATCH net-next-2.6] rps: avoid one atomic in enqueue_to_backlog

If CONFIG_SMP=y, then we own a queue spinlock, we can avoid the atomic
test_and_set_bit() from napi_schedule_prep().

We now have same number of atomic ops per netif_rx() calls than with
pre-RPS kernel.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Changli Gao May 7, 2010, 10:01 a.m. UTC | #1
On Fri, May 7, 2010 at 5:51 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le vendredi 07 mai 2010 à 07:16 +0200, Eric Dumazet a écrit :
>> Le jeudi 06 mai 2010 à 22:07 -0700, David Miller a écrit :
>>
>> > Looks great, applied, thanks Eric.
>>
>> Thanks, I have a followup to avoid one atomic in enqueue phase too ;)
>>
>
> [PATCH net-next-2.6] rps: avoid one atomic in enqueue_to_backlog
>
> If CONFIG_SMP=y, then we own a queue spinlock, we can avoid the atomic
> test_and_set_bit() from napi_schedule_prep().
>
> We now have same number of atomic ops per netif_rx() calls than with
> pre-RPS kernel.
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> ---
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 32611c8..49fa5a6 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -2426,8 +2426,10 @@ enqueue:
>                        return NET_RX_SUCCESS;
>                }
>
> -               /* Schedule NAPI for backlog device */
> -               if (napi_schedule_prep(&sd->backlog)) {
> +               /* Schedule NAPI for backlog device
> +                * We can use non atomic operation since we own the queue lock
> +                */
> +               if (!__test_and_set_bit(NAPI_STATE_SCHED, &sd->backlog.state)) {
>                        if (!rps_ipi_queued(sd))
>                                ____napi_schedule(sd, &sd->backlog);
>                }
>

Why not use a wrapper function?

sth. like:

static inline int __napi_schedule_prep(struct napi_struct *n)
{
   return (!__test_and_set_bit(NAPI_STATE_SCHED, &n->state)
}
Eric Dumazet May 7, 2010, 10:05 a.m. UTC | #2
Le vendredi 07 mai 2010 à 18:01 +0800, Changli Gao a écrit :
> On Fri, May 7, 2010 at 5:51 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > Le vendredi 07 mai 2010 à 07:16 +0200, Eric Dumazet a écrit :
> >> Le jeudi 06 mai 2010 à 22:07 -0700, David Miller a écrit :
> >>
> >> > Looks great, applied, thanks Eric.
> >>
> >> Thanks, I have a followup to avoid one atomic in enqueue phase too ;)
> >>
> >
> > [PATCH net-next-2.6] rps: avoid one atomic in enqueue_to_backlog
> >
> > If CONFIG_SMP=y, then we own a queue spinlock, we can avoid the atomic
> > test_and_set_bit() from napi_schedule_prep().
> >
> > We now have same number of atomic ops per netif_rx() calls than with
> > pre-RPS kernel.
> >
> > Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> > ---
> > diff --git a/net/core/dev.c b/net/core/dev.c
> > index 32611c8..49fa5a6 100644
> > --- a/net/core/dev.c
> > +++ b/net/core/dev.c
> > @@ -2426,8 +2426,10 @@ enqueue:
> >                        return NET_RX_SUCCESS;
> >                }
> >
> > -               /* Schedule NAPI for backlog device */
> > -               if (napi_schedule_prep(&sd->backlog)) {
> > +               /* Schedule NAPI for backlog device
> > +                * We can use non atomic operation since we own the queue lock
> > +                */
> > +               if (!__test_and_set_bit(NAPI_STATE_SCHED, &sd->backlog.state)) {
> >                        if (!rps_ipi_queued(sd))
> >                                ____napi_schedule(sd, &sd->backlog);
> >                }
> >
> 
> Why not use a wrapper function?
> 
> sth. like:
> 
> static inline int __napi_schedule_prep(struct napi_struct *n)
> {
>    return (!__test_and_set_bit(NAPI_STATE_SCHED, &n->state)
> }
> 


For one user ? 
Not sure it helps code readability.

Right now we all have our minds knowing every bit of this code, but next
year ?



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller May 18, 2010, 12:22 a.m. UTC | #3
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 07 May 2010 11:51:21 +0200

> Le vendredi 07 mai 2010 à 07:16 +0200, Eric Dumazet a écrit :
>> Le jeudi 06 mai 2010 à 22:07 -0700, David Miller a écrit :
>> 
>> > Looks great, applied, thanks Eric.
>> 
>> Thanks, I have a followup to avoid one atomic in enqueue phase too ;)
>> 
> 
> [PATCH net-next-2.6] rps: avoid one atomic in enqueue_to_backlog
> 
> If CONFIG_SMP=y, then we own a queue spinlock, we can avoid the atomic
> test_and_set_bit() from napi_schedule_prep().
> 
> We now have same number of atomic ops per netif_rx() calls than with
> pre-RPS kernel.
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Also applied, thanks Eric.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index 32611c8..49fa5a6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2426,8 +2426,10 @@  enqueue:
 			return NET_RX_SUCCESS;
 		}
 
-		/* Schedule NAPI for backlog device */
-		if (napi_schedule_prep(&sd->backlog)) {
+		/* Schedule NAPI for backlog device
+		 * We can use non atomic operation since we own the queue lock
+		 */
+		if (!__test_and_set_bit(NAPI_STATE_SCHED, &sd->backlog.state)) {
 			if (!rps_ipi_queued(sd))
 				____napi_schedule(sd, &sd->backlog);
 		}