How to find out what a "statistic" in a kstat module means?

Just typing "kstat" in the command line displays all the kstat modules and statistics available. For example, on my Solaris 10:

% kstat

.......

module: cpu_statinstance: 0

name:cpu_statclass: misc

anonfree0

anonpgin958

.........

I am trying to write code in my multithreaded application to interface with the kstat facility to determine which thread is using which CPU (I have a dual-core dual-processor Opteron system) and how much it is using the CPU. So, I imagine that my application would print a report like this:

thread 0 used CPU 0 for 10 seconds, CPU1 for 20 seconds

thread 1 used CPU 0 for 30 seconds, CPU1 for 40 seconds

CPU0 runs thread 0 for x seconds, thread 1 for y seconds, 80% utlitized

CPU1 runs thread 0 for xx seconds, thread 1 for yy seconds, 70% utlitized

(Assumed that a thread is not fixed on a particular CPU.)

There are hundreds of statistics (e.g. anonfree, anonpgin shown above) in the cpu_stat module alone, how do I know what each means and which ones are what I need?

[1089 byte] By [minglai] at [2007-11-26 9:10:15]
# 1

> Just typing "kstat" in the command line displays all

> the kstat modules and statistics available. For

> example, on my Solaris 10:

> % kstat

> .......

> module: cpu_statinstance: 0

> name:cpu_statclass: misc

>anonfree0

> anonpgin958

> .........

> I am trying to write code in my multithreaded

> application to interface with the kstat facility to

> determine which thread is using which CPU (I have a

> dual-core dual-processor Opteron system) and how much

> it is using the CPU. So, I imagine that my

> application would print a report like this:

> thread 0 used CPU 0 for 10 seconds, CPU1 for 20

> seconds

> thread 1 used CPU 0 for 30 seconds, CPU1 for 40

> seconds

Before you start, why do you want the breakdown of which thread was on which CPU? I doubt that the cpu statistics keep any such information (at least not per-thread). Likewise the thread statistics won't record individual cpus.

> CPU0 runs thread 0 for x seconds, thread 1 for y

> seconds, 80% utlitized

> CPU1 runs thread 0 for xx seconds, thread 1 for yy

> seconds, 70% utlitized

> (Assumed that a thread is not fixed on a particular

> CPU.)

> There are hundreds of statistics (e.g. anonfree,

> anonpgin shown above) in the cpu_stat module alone,

> how do I know what each means and which ones are what

> I need?

I don't think the level of detail that you seem to want will be present in kstat.

I'll bet you could use 'dtrace' to log when a thread is placed on or removed from a CPU.

--

Darren

Darren_Dunham at 2007-7-6 23:29:01 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 2

> Before you start, why do you want the breakdown of

> which thread was on which CPU?

Each of my machines are dual-proc dual-core. My middleware for distributed programming has one main execution thread and a couple of communication threads responsible for sending and receiving data to/from remote hosts. I am considering adding more execution threads - if the comm threads do not fully utilize the cores they are on. If the cores the comm threads are on are already very busy doing communication, then adding more execution threads does not appear to be able to help overall.

minglai at 2007-7-6 23:29:01 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 3

> I'll bet you could use 'dtrace' to log when a thread

> is placed on or removed from a CPU.

When a thread is placed on a CPU, it does not mean the CPU is busy executing that thread, right? The CPU may still be idle and available to other threads, right?

Just to repeat my original question: where to find out what a "statistic" in a kstat module means?

minglai at 2007-7-6 23:29:01 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 4

> > I'll bet you could use 'dtrace' to log when a

> thread

> > is placed on or removed from a CPU.

> When a thread is placed on a CPU, it does not mean

> the CPU is busy executing that thread, right?

Yes, it does mean that the CPU will be executing that thread.

> The

> CPU may still be idle and available to other threads,

> right?

No. Only one thread can be run by a CPU at one time. Idle CPUs have no threads on them.

> Just to repeat my original question: where to find

> out what a "statistic" in a kstat module means?

Which one? It's not like there's some manual that explains them all. They're kept by the kernel and exposed. If someone doesn't know about a particular one, you'd probably have to go into the kernel source code to figure it out.

A few of them are expanded (not really explained) in /usr/include/sys/sysinfo.h.

The ones you mentioned earlier (anon*) deal with counters for anonymous memory being paged in or out.

--

Darren

Darren_Dunham at 2007-7-6 23:29:01 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 5

> > Before you start, why do you want the breakdown of

> > which thread was on which CPU?

> Each of my machines are dual-proc dual-core. My

> middleware for distributed programming has one main

> execution thread and a couple of communication

> threads responsible for sending and receiving data

> to/from remote hosts. I am considering adding more

> execution threads - if the comm threads do not fully

> utilize the cores they are on. If the cores the comm

> threads are on are already very busy doing

> communication, then adding more execution threads

> does not appear to be able to help overall.

I would think that you could get that information by looking at the core statistics in isolation, without having to understand exactly which threads were on which cores.

--

Darren

Darren_Dunham at 2007-7-6 23:29:01 > top of Java-index,Solaris Operating System,Solaris 10 Features...