From: Patrick McHardy <kaber@trash.net>
To: Nuutti Kotivuori <naked@iki.fi>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: [PATCH] Very first try: ipt_connrate patch.
Date: Mon, 16 Feb 2004 12:18:16 +0100 [thread overview]
Message-ID: <4030A6F8.5030606@trash.net> (raw)
In-Reply-To: <87bro9fiqq.fsf@iki.fi>
Nuutti Kotivuori wrote:
> I would be glad to get as many comments about it as early as
> possible, also on the usefulness of what I'm doing here.
> +void
> +ip_conntrack_rate_count(struct ip_conntrack_rate *ctr,
> + unsigned int len)
> +{
> + u_int32_t new_bytes;
> + unsigned long now = jiffies;
> +
> + new_bytes = (ctr->avgrate * IP_CONNTRACK_RATE_INTERVAL +
> + len * IP_CONNTRACK_RATE_SCALE);
> + if(new_bytes > MAX_TOKENS_IN_WINDOW)
> + new_bytes = MAX_TOKENS_IN_WINDOW;
> + ctr->avgrate = new_bytes / (now - xchg(&ctr->prev, now) +
> + IP_CONNTRACK_RATE_INTERVAL);
> +}
You need locking here. Other CPUs can change ctr->avgrate between
reading and updating it. The xchg operation becomes unneccessary
with proper locking.
Regards,
Patrick
next prev parent reply other threads:[~2004-02-16 11:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-08 19:56 [PATCH] Very first try: ipt_connrate patch Nuutti Kotivuori
2004-02-14 20:14 ` Harald Welte
2004-02-16 2:22 ` Nuutti Kotivuori
2004-02-19 18:28 ` Harald Welte
2004-02-19 19:05 ` Nuutti Kotivuori
2004-02-16 11:18 ` Patrick McHardy [this message]
2004-02-16 12:34 ` Nuutti Kotivuori
2004-02-16 13:07 ` Patrick McHardy
2004-02-16 16:19 ` Nuutti Kotivuori
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=4030A6F8.5030606@trash.net \
--to=kaber@trash.net \
--cc=naked@iki.fi \
--cc=netfilter-devel@lists.netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.