From: Rik van Riel <riel@surriel.com>
To: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: linux-kernel@vger.kernel.org,
Andy Lutomirsky <amluto@amacapital.com>,
Frederic Weisbecker <fweisbec@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Luiz Capitulino <lcapitulino@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Clark Williams <williams@redhat.com>
Subject: Re: [PATCH] context_tracking: remove local_irq_save from __acct_update_integrals
Date: Fri, 24 Apr 2015 11:10:31 -0400 [thread overview]
Message-ID: <553A5CE7.4080200@surriel.com> (raw)
In-Reply-To: <20150424091156.GB4089@osiris>
On 04/24/2015 05:11 AM, Heiko Carstens wrote:
> On Thu, Apr 23, 2015 at 09:57:13PM -0400, Rik van Riel wrote:
>> diff --git a/kernel/tsacct.c b/kernel/tsacct.c
>> index 975cb49e32bf..0b967f116a6b 100644
>> --- a/kernel/tsacct.c
>> +++ b/kernel/tsacct.c
>> @@ -126,23 +126,29 @@ static void __acct_update_integrals(struct task_struct *tsk,
>> if (likely(tsk->mm)) {
>> cputime_t time, dtime;
>> struct timeval value;
>> - unsigned long flags;
>> u64 delta;
>>
>> - local_irq_save(flags);
>> time = stime + utime;
>> dtime = time - tsk->acct_timexpd;
>> + /*
>> + * This code is called both from irq context and from
>> + * task context. There is a race where irq context advances
>> + * tsk->acct_timexpd to a value larger than time, creating
>> + * a negative value. In that case, the irq has already
>> + * updated the statistics.
>> + */
>> + if (unlikely((signed long)dtime <= 0))
>> + return;
>
> FWIW, I think you either need a barrier() before the if-statement or use
> READ_ONCE() when reading tsk->acct_timexpd above.
>
> Otherwise the compiler could (in theory at least) generate code which
> would translate to
> if (unlikely(time <= tsk->acct_timexpd))
> in order to achieve the same result, no?
>
> Besides that cputime_t might be 64 bit in size, therefore you don't have
> much of a guarentee that reading tsk->acct_timexpd happens atomically on
> 32 bit architectures, so you _may_ end up with garbage, no?
You are right on both counts. Thank you for pointing out what
should have been obvious...
Let me post a new patch :)
--
All rights reversed.
prev parent reply other threads:[~2015-04-24 15:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-24 1:57 [PATCH] context_tracking: remove local_irq_save from __acct_update_integrals Rik van Riel
2015-04-24 9:11 ` Heiko Carstens
2015-04-24 15:10 ` Rik van Riel [this message]
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=553A5CE7.4080200@surriel.com \
--to=riel@surriel.com \
--cc=amluto@amacapital.com \
--cc=fweisbec@redhat.com \
--cc=heiko.carstens@de.ibm.com \
--cc=lcapitulino@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=peterz@infradead.org \
--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 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.