Skip to content

Commit

Permalink
net_sched: act_gact: make tcfg_pval non zero
Browse files Browse the repository at this point in the history
First step for gact RCU operation :

Instead of testing if tcfg_pval is zero or not, just make it 1.

No change in behavior, but slightly faster code.

The smp_rmb()/smp_wmb() barriers, while not strictly needed at this
stage are added for upcoming spinlock removal.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Jul 8, 2015
1 parent 519c818 commit cef5ecf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
#ifdef CONFIG_GACT_PROB
static int gact_net_rand(struct tcf_gact *gact)
{
if (!gact->tcfg_pval || prandom_u32() % gact->tcfg_pval)
smp_rmb(); /* coupled with smp_wmb() in tcf_gact_init() */
if (prandom_u32() % gact->tcfg_pval)
return gact->tcf_action;
return gact->tcfg_paction;
}

static int gact_determ(struct tcf_gact *gact)
{
if (!gact->tcfg_pval || gact->tcf_bstats.packets % gact->tcfg_pval)
smp_rmb(); /* coupled with smp_wmb() in tcf_gact_init() */
if (gact->tcf_bstats.packets % gact->tcfg_pval)
return gact->tcf_action;
return gact->tcfg_paction;
}
Expand Down Expand Up @@ -105,7 +107,11 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
#ifdef CONFIG_GACT_PROB
if (p_parm) {
gact->tcfg_paction = p_parm->paction;
gact->tcfg_pval = p_parm->pval;
gact->tcfg_pval = max_t(u16, 1, p_parm->pval);
/* Make sure tcfg_pval is written before tcfg_ptype
* coupled with smp_rmb() in gact_net_rand() & gact_determ()
*/
smp_wmb();
gact->tcfg_ptype = p_parm->ptype;
}
#endif
Expand Down

0 comments on commit cef5ecf

Please sign in to comment.