netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Patrick McHardy <kaber@trash.net>
Cc: netfilter-devel@vger.kernel.org, fw@strlen.de, eric.dumazet@gmail.com
Subject: Re: [PATCH nf-next,v2] netfilter: nft_counter: convert it to use per-cpu counters
Date: Fri, 19 Jun 2015 11:49:36 +0200	[thread overview]
Message-ID: <20150619094936.GA5011@salvia> (raw)
In-Reply-To: <20150619093937.GD22946@acer.localdomain>

On Fri, Jun 19, 2015 at 11:39:37AM +0200, Patrick McHardy wrote:
> On 19.06, Pablo Neira Ayuso wrote:
> >  static void nft_counter_eval(const struct nft_expr *expr,
> >  			     struct nft_regs *regs,
> >  			     const struct nft_pktinfo *pkt)
> >  {
> > -	struct nft_counter *priv = nft_expr_priv(expr);
> > +	struct nft_counter_percpu_priv *priv = nft_expr_priv(expr);
> > +	struct nft_counter_percpu *this_cpu;
> >  
> > -	write_seqlock_bh(&priv->lock);
> > -	priv->bytes += pkt->skb->len;
> > -	priv->packets++;
> > -	write_sequnlock_bh(&priv->lock);
> > +	this_cpu = this_cpu_ptr(priv->counter);
> > +	this_cpu->counter.bytes += pkt->skb->len;
> > +	this_cpu->counter.packets++;
> 
> u64_state_update_begin()/end()?

Right, will fix that, thanks!

> > @@ -67,23 +83,46 @@ static int nft_counter_init(const struct nft_ctx *ctx,
> >  			    const struct nft_expr *expr,
> >  			    const struct nlattr * const tb[])
> >  {
> > -	struct nft_counter *priv = nft_expr_priv(expr);
> > -
> > -	if (tb[NFTA_COUNTER_PACKETS])
> > -	        priv->packets = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_PACKETS]));
> > -	if (tb[NFTA_COUNTER_BYTES])
> > -		priv->bytes = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_BYTES]));
> > +	struct nft_counter_percpu_priv *priv = nft_expr_priv(expr);
> > +	struct nft_counter_percpu __percpu *cpu_stats;
> > +	struct nft_counter_percpu *this_cpu;
> > +
> > +	cpu_stats = netdev_alloc_pcpu_stats(struct nft_counter_percpu);
> > +	if (cpu_stats == NULL)
> > +		return ENOMEM;
> > +
> > +	preempt_disable();
> 
> Seems unnecessary, the stats are not active durign ->init().

I know, I need to find a better way to silent a lockdep preempt splat
that I'm getting here because of illegal use of this_cpu_ptr() with
preemption enabled.

> > +	this_cpu = this_cpu_ptr(cpu_stats);
> > +	if (tb[NFTA_COUNTER_PACKETS]) {
> > +	        this_cpu->counter.packets =
> > +			be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_PACKETS]));
> > +	}
> > +	if (tb[NFTA_COUNTER_BYTES]) {
> > +		this_cpu->counter.bytes =
> > +			be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_BYTES]));
> > +	}
> > +	preempt_enable();
> > +
> > +	priv->counter = cpu_stats;
> >  
> > -	seqlock_init(&priv->lock);
> >  	return 0;
> >  }

  reply	other threads:[~2015-06-19  9:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-19  9:36 [PATCH nf-next,v2] netfilter: nft_counter: convert it to use per-cpu counters Pablo Neira Ayuso
2015-06-19  9:39 ` Patrick McHardy
2015-06-19  9:49   ` Pablo Neira Ayuso [this message]
2015-06-19  9:50     ` Patrick McHardy
2015-06-19  9:59       ` Pablo Neira Ayuso
2015-06-19 10:00         ` Patrick McHardy
2015-06-19 13:43     ` Marcelo Ricardo Leitner

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=20150619094936.GA5011@salvia \
    --to=pablo@netfilter.org \
    --cc=eric.dumazet@gmail.com \
    --cc=fw@strlen.de \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    /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).