Skip to content

Commit 1f2ea08

Browse files
paulmckLinus Torvalds
authored andcommitted
[PATCH] posix timers: RCU optimization for clock_gettime()
Use RCU to avoid the need to acquire tasklist_lock in the single-threaded case of clock_gettime(). It still acquires tasklist_lock when for a (potentially multithreaded) process. This change allows realtime applications to frequently monitor CPU consumption of individual tasks, as requested (and now deployed) by some off-list users. This has been in Ingo Molnar's -rt patchset since late 2005 with no problems reported, and tests successfully on 2.6.20-rc6, so I believe that it is long-since ready for mainline adoption. [paulmck@linux.vnet.ibm.com: fix exit()/posix_cpu_clock_get() race spotted by Oleg] Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: john stultz <johnstul@us.ibm.com> Cc: Roman Zippel <zippel@linux-m68k.org> Cc: Oleg Nesterov <oleg@tv-sign.ru> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7460ed2 commit 1f2ea08

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

kernel/posix-cpu-timers.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,25 @@ int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
304304
* should be able to see it.
305305
*/
306306
struct task_struct *p;
307-
read_lock(&tasklist_lock);
307+
rcu_read_lock();
308308
p = find_task_by_pid(pid);
309309
if (p) {
310310
if (CPUCLOCK_PERTHREAD(which_clock)) {
311311
if (p->tgid == current->tgid) {
312312
error = cpu_clock_sample(which_clock,
313313
p, &rtn);
314314
}
315-
} else if (p->tgid == pid && p->signal) {
316-
error = cpu_clock_sample_group(which_clock,
317-
p, &rtn);
315+
} else {
316+
read_lock(&tasklist_lock);
317+
if (p->tgid == pid && p->signal) {
318+
error =
319+
cpu_clock_sample_group(which_clock,
320+
p, &rtn);
321+
}
322+
read_unlock(&tasklist_lock);
318323
}
319324
}
320-
read_unlock(&tasklist_lock);
325+
rcu_read_unlock();
321326
}
322327

323328
if (error)

0 commit comments

Comments
 (0)