login
Header Space

 
 

Re: posix-cpu-timers revamp

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Roland McGrath <roland@...>
Cc: <linux-kernel@...>
Date: Thursday, March 13, 2008 - 8:37 pm

After the recent conversation with Roland and after more testing, I have
another patch for review (although _not_ for submission, as again it's
against 2.6.18.5).  This patch breaks the shared utime/stime/sched_time
fields out into their own structure which is allocated as needed via
alloc_percpu().  This avoids cache thrashing when running lots of
threads on lots of CPUs.

Please take a look and let me know what you think.  In the meantime I'll
be working on a similar patch to 2.6-head that has optimizations for
uniprocessor and two-CPU operation, to avoid the overhead of the percpu
functions when they are unneeded.

This patch:

	Replaces the utime, stime and sched_time fields in signal_struct with
	the shared_times structure, which is cacheline aligned and allocated
	when needed using the alloc_percpu() mechanism.  There is one copy of
	this structure per running CPU when it is being used.

	Each place that loops through all threads in a thread group to sum
	task->utime and/or task->stime now use the shared_*_sum() inline
	functions defined in sched.h to sum the per-CPU structures.  This
	includes compat_sys_times(), do_task_stat(), do_getitimer(),
	sys_times() and k_getrusage().

	Certain routines that used task->signal->[us]time now use the
	shared_*_sum() functions instead, which may (but hopefully will not)
	change their semantics slightly.  These include fill_prstatus() (in
	fs/binfmt_elf.c), do_task_stat() (in fs/proc/array.c),
	wait_task_zombie() and do_notify_parent().

	At each tick, update_cpu_clock(), account_user_time() and
	account_system_time() update the relevant field of the shared_times
	structure using a pointer obtained using per_cpu_ptr, with the effect
	that these functions do not compete with one another for the cacheline.
	Each of these functions updates the task-private field followed by the
	shared_times version if one is present.

	Finally, kernel/posix-cpu-timers.c has changed quite dramatically.
	First, run_posix_cpu_timers() decides whether a timer has expired by
	consulting the it_*_expires fields in the task struct of the running
	thread and the shared_*_sum() functions that cover the entire process.
	The check_process_timers() routine bases its computations on the
	shared structure, removing two loops through the threads. "Rebalancing"
	is no longer required, the process_timer_rebalance() routine as
	disappeared entirely and the arm_timer() routine merely fills
	p->signal->it_*_expires from timer->it.cpu.expires.*.  The
	cpu_clock_sample_group_locked() loses its summing loops, using the
	the shared structure instead.  Finally, set_process_cpu_timer() sets
	tsk->signal->it_*_expires directly rather than calling the deleted
	rebalance routine.

	The only remaining open question is whether these changes break the
	semantics of the status-returning routines fill_prstatus(),
	do_task_stat(), wait_task_zombie() and do_notify_parent().
-- 
Frank Mayhar <fmayhar@google.com>
Google, Inc.
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [Bugme-new] [Bug 9906] New: Weird hang with NPTL and SIG..., Alejandro Riveira , (Thu Feb 7, 11:22 am)
Re: [Bugme-new] [Bug 9906] New: Weird hang with NPTL and SIG..., Alejandro Riveira , (Thu Feb 7, 11:54 am)
posix-cpu-timers revamp, Roland McGrath, (Tue Mar 11, 3:50 am)
Re: posix-cpu-timers revamp, Frank Mayhar, (Tue Mar 11, 5:05 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Tue Mar 11, 5:35 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Thu Mar 13, 8:37 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Fri Mar 21, 3:18 am)
Re: posix-cpu-timers revamp, Frank Mayhar, (Fri Mar 21, 4:40 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Fri Mar 21, 1:57 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Sat Mar 22, 5:58 pm)
[PATCH 2.6.25-rc6] Fix itimer/many thread hang., Frank Mayhar, (Thu Mar 27, 8:52 pm)
Re: [PATCH 2.6.25-rc6] Fix itimer/many thread hang., Ingo Molnar, (Fri Mar 28, 6:28 am)
Re: posix-cpu-timers revamp, Frank Mayhar, (Mon Mar 24, 1:34 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Mon Mar 31, 1:44 am)
Re: posix-cpu-timers revamp, Frank Mayhar, (Mon Mar 31, 4:24 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Tue Apr 1, 10:07 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Wed Apr 2, 2:42 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Wed Apr 2, 1:42 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Wed Apr 2, 3:48 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Wed Apr 2, 4:34 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Fri Apr 4, 7:17 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Sun Apr 6, 1:26 am)
Re: posix-cpu-timers revamp, Roland McGrath, (Mon Apr 7, 4:08 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Tue Apr 8, 5:27 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Tue Apr 8, 6:49 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Wed Apr 9, 12:29 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Tue Apr 8, 5:52 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Mon Apr 7, 5:31 pm)
Re: posix-cpu-timers revamp, Roland McGrath, (Mon Apr 7, 6:02 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Wed Apr 2, 5:42 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Thu Apr 3, 8:53 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Wed Apr 2, 12:34 pm)
Re: posix-cpu-timers revamp, Frank Mayhar, (Mon Mar 24, 6:43 pm)
speck-geostationary