Re: posix-cpu-timers revamp

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Frank Mayhar
Date: Monday, March 31, 2008 - 1:24 pm

Roland, I'm very much having to read between the lines of what you've
written.  And, obviously, getting it wrong at least half the time. :-)

So you've cleared part of my understanding with your latest email.
Here's what I've gotten from it:

        struct task_cputime {
        	cputime_t utime;		/* User time. */
        	cputime_t stime;		/* System time. */
        	unsigned long long sched_runtime; /* Scheduler time. */
        };
        
This is for both SMP and UP, defined before signal_struct in sched.h
(since that structure refers to this one).  Following that:

        struct thread_group_cputime;

Which is a forward reference to the real definition later in the file.
The inline functions depend on signal_struct and task_struct, so they
have to come after:

        #ifdef SMP

        struct thread_group_cputime {
        	struct task_cputime *totals;
        };

        < ... inline functions ... >

        #else /* SMP */

        struct thread_group_cputime {
        	struct task_cputime totals;
        };

        < ... inline functions ... >

        #endif

The SMP version is percpu, the UP version is just a substructure.  In
signal_struct itself, delete utime & stime, add
        struct thread_group_cputime cputime;

The inline functions include the ones you defined for UP plus equivalent
ones for SMP.  The SMP inlines check the percpu pointer
(sig->cputime.totals) and don't update if it's NULL.  One small
correction to one of your inlines, in thread_group_cputime:
                *cputime = sig->cputime;
should be
                *cputime = sig->cputime.totals;

A representative inline for SMP is:

        static inline void account_group_system_time(struct task_struct *task,
        					      cputime_t cputime)
        {
        	struct task_cputime *times;
        
        	if (!sig->cputime.totals)
        		return;
        	times = per_cpu_ptr(sig->cputime.totals, get_cpu());
        	times->stime = cputime_add(times->stime, cputime);
        	put_cpu_no_resched();
        }
        
To deal with the need for bookkeeping with multiple threads in the SMP
case (where there isn't a per-cpu structure until it's needed), I'll
allocate the per-cpu structure in __exit_signal() where the relevant
fields are updated.  I'll also allocate it where I do now, in
do_setitimer(), when needed.  The allocation will be a "return 0" for UP
and a call to "thread_group_times_alloc_smp()" (which lives in sched.c)
for SMP.

I'll also optimize run_posix_cpu_timers() as you suggest, and eliminate
rlim_expires.

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