On 11/2/05, Mike Gerdts <[EMAIL PROTECTED]> wrote:
> The best solution that I have come up with is to write extended
> accounting records (task) every few minutes, then to process the
> exacct file afterwards.  Writing the code to write exacct records
> periodically and make sense of them later is far from trivial.  It is
> also impractical for multiple users (monitoring frameworks,
> administrators, etc.) to make use of this approach on the same machine
> at the same time due to the fact that the exacct records need to be
> written and this is presumably a somewhat expensive operation to do
> too often.

Another approach is to have exacct write final accounting records and
periodically use getacct(2) system call and take live snapshots for
tasks and aggregate them by projects.  I've prototyped a tool called
'taskstat' some
time ago that does exactly that and it works pretty good.  Let me know
if you're interested and I'll send you the source for it.

> It seems as though it should be possible for the kernel to maintain
> per-user, per-project, and per-zone statistics.  Perhaps collecting
> them all the time is not desirable, but it seems as though updating
> the three sets of statistics for each context switch would be lighter
> weight than writing accounting records then post processing them.  The
> side affect of having this data available would be that tools like
> prstat could report accurate data.  Other tools could likely get this
> data through kstat or a similar interface.

That's going to almost certainly degrade the performance of
benchmarks like kenbus which are running with thousands of
threads and doing a lot of context switching. Have you tried
using DTrace instead?  I wrote a script which displays
per-project CPU usage every 10 seconds, and it's very simple
and lightweight.

#!/usr/sbin/dtrace -s

#pragma D option quiet

BEGIN
{
        ncpu = 2; /* XXX Can DTrace give us ncpus? */
}

profile:::profile-10msec
{
        projid = curthread->t_proj->kpj_id;
        idle = curthread->t_cpu->cpu_idle_thread;
        str = (idle == curthread) ? -1 : projid;
        psetid = curthread->t_cpupart->cp_id;

        @intr[str, psetid] = count();
}

profile:::tick-10sec
{
        printf("PROJECT PSET CPU%%\n");
        normalize(@intr, 10 * ncpu);
        printa("%-7d %-3d [EMAIL PROTECTED]", @intr);
        trunc(@intr);
}

> Maybe this already exists but is not exposed.  If it looks like a
> reasonable thing to do, is there a good place to start looking to add
> such functionality.  My guess is that it would be hidden somewhere in
> /usr/src/uts/common/disp, but an admittedly short perusal of that
> directory hasn't turned up anything obvious.

The routine you're looking for is called swtch().  This code is highly
sensitive and adding recent CPU usage to the current thread's project
structure there would probably slow it down enough to be visible
on some benchmarks.   The same thing doesn't actually have to be
done for zones.  Instead, zone kstats could be updated once per
second by a per-zone thread which could walk all of its projects and
calculate total CPU usage.

- Andrei
_______________________________________________
perf-discuss mailing list
perf-discuss@opensolaris.org

Reply via email to