From: "John Kacur" <jkacur@gmail.com>
To: "Peter Zijlstra" <peterz@infradead.org>
Cc: "Sebastien Dugue" <sebastien.dugue@bull.net>,
"Chirag Jog" <chirag@linux.vnet.ibm.com>,
"J?rgen Mell" <j.mell@t-online.de>,
"Thomas Gleixner" <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>,
rt-users <linux-rt-users@vger.kernel.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Clark Williams" <williams@redhat.com>,
"Josh Triplett" <josht@linux.vnet.ibm.com>,
"Timothy R. Chavez" <tim.chavez@linux.vnet.ibm.com>
Subject: Re: [PATCH] Fix Bug messages
Date: Thu, 31 Jul 2008 16:10:21 +0200 [thread overview]
Message-ID: <520f0cf10807310710i85e5a2u8e5f227bc2b82051@mail.gmail.com> (raw)
In-Reply-To: <1217512907.8157.91.camel@twins>
On Thu, Jul 31, 2008 at 4:01 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Thu, 2008-07-31 at 15:49 +0200, John Kacur wrote:
>> Signed-off-by: John Kacur <jkacur@gmail.com>
>> Index: linux-2.6.26-rt1/net/core/sock.c
>> ===================================================================
>> --- linux-2.6.26-rt1.orig/net/core/sock.c
>> +++ linux-2.6.26-rt1/net/core/sock.c
>> @@ -1986,11 +1986,12 @@ static __init int net_inuse_init(void)
>>
>> core_initcall(net_inuse_init);
>> #else
>> -static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);
>> +static DEFINE_PER_CPU_LOCKED(struct prot_inuse, prot_inuse);
>>
>> void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
>> {
>> - __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val;
>> + int cpu = 0;
>> + __get_cpu_var_locked(prot_inuse, cpu).val[prot->inuse_idx] += val;
>> }
>> EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
>>
>> @@ -2000,7 +2001,7 @@ int sock_prot_inuse_get(struct net *net,
>> int res = 0;
>>
>> for_each_possible_cpu(cpu)
>> - res += per_cpu(prot_inuse, cpu).val[idx];
>> + res += per_cpu_var_locked(prot_inuse, cpu).val[idx];
>>
>> return res >= 0 ? res : 0;
>> }
>
> This doesn't look good. You declare it as a PER_CPU_LOCKED, but then
> never use the extra lock to synchronize data.
>
> Given that sock_proc_inuse_get() is a racy read anyway, the 'right' fix
> would be to do something like:
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 91f8bbc..5a8ace4 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1941,8 +1941,9 @@ static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
> #ifdef CONFIG_NET_NS
> void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
> {
> - int cpu = smp_processor_id();
> + int cpu = get_cpu();
> per_cpu_ptr(net->core.inuse, cpu)->val[prot->inuse_idx] += val;
> + put_cpu();
> }
> EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
>
> @@ -1988,7 +1989,9 @@ static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);
>
> void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
> {
> - __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val;
> + int cpu = get_cpu();
> + per_cpu(prot_inuse, cpu).val[prot->inuse_idx] += val;
> + put_cpu();
> }
> EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
>
> This disables preemption, but only for a very short time - so it doesn't
> hurt the preempt-latency.
>
> The alternative is to take a lock, do the inc, and drop the lock again,
> which is much more expensive.
>
>
Cool, thanks for the quick feedback. What kind of criteria are used to
decide between disabling preemption for a short time, or using the
more expensive lock?
next prev parent reply other threads:[~2008-07-31 14:10 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-25 20:09 2.6.24.7-rt15 Thomas Gleixner
2008-07-26 11:03 ` 2.6.24.7-rt15 Carsten Emde
[not found] ` <1985e0f60807252248n581bdfa0s363f6ce0d283ec2c@mail.gmail.com>
2008-07-26 11:13 ` 2.6.24.7-rt15 Jaswinder Singh
2008-07-26 12:28 ` 2.6.24.7-rt15 Steven Rostedt
2008-07-26 13:22 ` 2.6.24.7-rt15 Daniel Walker
2008-07-26 18:28 ` 2.6.24.7-rt15 Jaswinder Singh
2008-07-27 16:16 ` 2.6.24.7-rt16 Thomas Gleixner
2008-07-27 20:28 ` 2.6.24.7-rt16 Avuton Olrich
2008-07-27 20:37 ` 2.6.24.7-rt16 Thomas Gleixner
2008-07-28 8:12 ` 2.6.24.7-rt16 Wolfgang Grandegger
2008-07-28 9:48 ` 2.6.24.7-rt16 Peter Zijlstra
2008-07-28 10:12 ` 2.6.24.7-rt16 Wolfgang Grandegger
2008-07-29 12:57 ` 2.6.24.7-rt16 Thomas Gleixner
2008-07-29 22:21 ` 2.6.26-rt1 Thomas Gleixner
2008-07-30 9:01 ` 2.6.26-rt1 Jürgen Mell
2008-07-30 17:18 ` [PATCH] Fix Bug messages Chirag Jog
2008-07-30 20:16 ` Jürgen Mell
2008-07-31 6:06 ` Peter Zijlstra
2008-07-31 8:00 ` Sebastien Dugue
2008-07-31 10:13 ` John Kacur
2008-07-31 11:23 ` Sebastien Dugue
2008-07-31 13:49 ` John Kacur
2008-07-31 14:01 ` Peter Zijlstra
2008-07-31 14:10 ` John Kacur [this message]
2008-07-31 14:18 ` Peter Zijlstra
2008-07-31 14:35 ` Sebastien Dugue
2008-07-31 15:01 ` Clark Williams
2008-07-31 15:14 ` Sebastien Dugue
2008-08-01 21:11 ` 2.6.26-rt1 Paul E. McKenney
2008-08-13 13:30 ` 2.6.26-rt1 Juergen Beisert
2008-08-13 16:37 ` 2.6.26-rt1 Paul E. McKenney
2008-07-30 14:31 ` 2.6.26-rt1 John Kacur
2008-07-30 14:41 ` 2.6.26-rt1 Ryan Hope
2008-08-01 21:11 ` 2.6.26-rt1 Paul E. McKenney
2008-08-11 8:36 ` 2.6.26-rt1 Juergen Beisert
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=520f0cf10807310710i85e5a2u8e5f227bc2b82051@mail.gmail.com \
--to=jkacur@gmail.com \
--cc=chirag@linux.vnet.ibm.com \
--cc=j.mell@t-online.de \
--cc=josht@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sebastien.dugue@bull.net \
--cc=tglx@linutronix.de \
--cc=tim.chavez@linux.vnet.ibm.com \
--cc=williams@redhat.com \
/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).