From: Frank Mayhar <fmayhar@google.com>
To: Roland McGrath <roland@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: posix-cpu-timers revamp
Date: Thu, 03 Apr 2008 17:53:07 -0700 [thread overview]
Message-ID: <1207270387.2232.56.camel@bobble.smo.corp.google.com> (raw)
In-Reply-To: <1207172527.11976.58.camel@bobble.smo.corp.google.com>
On Wed, 2008-04-02 at 14:42 -0700, Frank Mayhar wrote:
> On Wed, 2008-04-02 at 13:34 -0700, Frank Mayhar wrote:
> > One little gotcha we just ran into, though: When checking
> > tsk->signal->(anything) in run_posix_cpu_timers(), we have to hold
> > tasklist_lock to avoid a race with release_task(). This is going to
> > make even the null case always cost more than before.
>
> This race, by the way, is because we're dereferencing task->signal at
> interrupt once per tick. We ran into a case where a process was going
> through release_task() and being torn down on one CPU while running a
> timer tick on another. Under load. It's not a very likely race but
> with sufficient time or load it's pretty much inevitable.
>
> My thought is to move thread_group_cputime from the signal structure to
> hanging directly off the task structure. It would be shared in the same
> way as the signal structure is now but would be deallocated with the
> task structure rather than the signal structure. This should mean that
> I could avoid getting tasklist_lock under most conditions.
Okay, having run face-first into this race and having every combination
of spinlock serialization fail for me, I've done a variation of the
above scheme.
For the local environment, I solved the problem by moving the percpu
structure out of the signal structure entirely and by making it
refcounted. It is allocated as before, but now in two parts, a normal
structure with an atomic refcount that has a pointer to the percpu
structure. The signal structure doesn't point to it any longer, but
each task_struct in the thread group does, and each of these references
is counted. New threads will also get a reference (at the top of
copy_signal()) and be counted. All access goes through the task
structure. References are removed in __put_task_struct() when the task
itself is destroyed; when the last reference goes away, the structures
are freed.
This eliminates the races with signal_struct being freed and has the
nice effect that there is a bit less overhead in places like
account_group_user_time() and friends. In run_posix_cpu_timers(),
though, I have to pick up the tasklist_lock early (and therefore in
every case) because it's still dereferencing tsk->signal in the early
comparison.
I'm thinking about moving all of the itimer stuff (i.e. the
cputime_expires structures) into the refcounted structure as well, thus
avoiding the signal_struct entirely so we don't need the tasklist_lock
in the fast path. I don't know how any of this will affect the UP case,
though. I'll have to continue to think about it and I'm sure you have
something to say as well. (And if anyone else wants to chime in,
they're welcome.)
--
Frank Mayhar <fmayhar@google.com>
Google, Inc.
next prev parent reply other threads:[~2008-04-04 0:53 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-9906-10286@http.bugzilla.kernel.org/>
2008-02-07 0:50 ` [Bugme-new] [Bug 9906] New: Weird hang with NPTL and SIGPROF Andrew Morton
2008-02-07 0:58 ` Frank Mayhar
2008-02-07 2:57 ` Parag Warudkar
2008-02-07 15:22 ` Alejandro Riveira Fernández
2008-02-07 15:53 ` Parag Warudkar
2008-02-07 15:56 ` Parag Warudkar
2008-02-07 15:54 ` Alejandro Riveira Fernández
2008-02-07 16:01 ` Parag Warudkar
2008-02-07 16:53 ` Parag Warudkar
2008-02-29 19:55 ` Frank Mayhar
2008-03-04 7:00 ` Roland McGrath
2008-03-04 19:52 ` Frank Mayhar
2008-03-05 4:08 ` Roland McGrath
2008-03-06 19:04 ` Frank Mayhar
2008-03-11 7:50 ` posix-cpu-timers revamp Roland McGrath
2008-03-11 21:05 ` Frank Mayhar
2008-03-11 21:35 ` Roland McGrath
2008-03-14 0:37 ` Frank Mayhar
2008-03-21 7:18 ` Roland McGrath
2008-03-21 17:57 ` Frank Mayhar
2008-03-22 21:58 ` Roland McGrath
2008-03-24 17:34 ` Frank Mayhar
2008-03-24 22:43 ` Frank Mayhar
2008-03-31 5:44 ` Roland McGrath
2008-03-31 20:24 ` Frank Mayhar
2008-04-02 2:07 ` Roland McGrath
2008-04-02 16:34 ` Frank Mayhar
2008-04-02 17:42 ` Frank Mayhar
2008-04-02 19:48 ` Roland McGrath
2008-04-02 20:34 ` Frank Mayhar
2008-04-02 21:42 ` Frank Mayhar
2008-04-04 0:53 ` Frank Mayhar [this message]
2008-04-04 23:17 ` Roland McGrath
2008-04-06 5:26 ` Frank Mayhar
2008-04-07 20:08 ` Roland McGrath
2008-04-07 21:31 ` Frank Mayhar
2008-04-07 22:02 ` Roland McGrath
2008-04-08 21:27 ` Frank Mayhar
2008-04-08 21:52 ` Frank Mayhar
2008-04-08 22:49 ` Roland McGrath
2008-04-09 16:29 ` Frank Mayhar
2008-04-02 18:42 ` Frank Mayhar
2008-03-28 0:52 ` [PATCH 2.6.25-rc6] Fix itimer/many thread hang Frank Mayhar
2008-03-28 10:28 ` Ingo Molnar
2008-03-28 22:46 ` [PATCH 2.6.25-rc7 resubmit] " Frank Mayhar
2008-04-01 18:45 ` Andrew Morton
2008-04-01 21:46 ` Frank Mayhar
2008-03-21 20:40 ` posix-cpu-timers revamp Frank Mayhar
2008-03-07 23:26 ` [Bugme-new] [Bug 9906] New: Weird hang with NPTL and SIGPROF Frank Mayhar
2008-03-08 0:01 ` Frank Mayhar
2008-02-07 17:36 ` Frank Mayhar
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=1207270387.2232.56.camel@bobble.smo.corp.google.com \
--to=fmayhar@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=roland@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