On 1/8/07, Nikolay Piskun <[EMAIL PROTECTED]> wrote:

I think I am close to find the answer, but I get stuck in kstat.
I am using calls to kstat but after getting cpu_info kstat I don't know
how to cast it to the right structure, that gives me core_id field. Here is
my code:
.....
kstat_t *kp;
if (strncmp(kp->ks_name, "cpu_info", 8) == 0) {
      kstat_read(kc, kp, NULL);
      printf("%d: %s\n",kp->ks_kid,kp->ks_name);

    cpu_stat_t*  statp = (cpu_stat_t *)(kp->ks_data);
Apparently last line doesn't  work.


It won't. The cpu_info kstats are of type KSTAT_TYPE_NAMED
which means the data is basically a hash with the name as the key,
and you use the kstat routines to access it.

You can pick the entry out with:

kstat_named_t* kn;
kn = kstat_data_lookup(kp, "core_id");

You then need to look at kn->data_type to work out what sort of value
the data is (signed, unsigned, 32bit, 64bit, string, char etc - look at
/usr/include/sys/kstat.h) or just guess that it's a long.

long core_id = kn->value.l;

--
-Peter Tribble
http://www.petertribble.co.uk/ - http://ptribble.blogspot.com/
_______________________________________________
opensolaris-discuss mailing list
[email protected]

Reply via email to