Go to main content

man pages section 9: DDI and DKI Properties and Data Structures

Exit Print View

Updated: Friday, July 24, 2020

kstat2 (9S)


kstat2 - Version 2 kernel statistics structure


#include <sys/types.h>
#include <sys/kstat2.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>

Interface Level

Solaris DDI specific (Solaris DDI)


Each kernel statistic (kstat2) exported by device drivers consists of a header section and a data section. The kstat2 structure is the header portion of the statistic.

A driver receives a pointer to a kstat2 structure (kstat2_t *) from a successful call to kstat2_create(9F). Drivers should never allocate a kstat2 structure in any other manner.

After allocation, the driver should perform any further initialization needed before calling kstat2_install(9F) to actually export the kstat.

Structure Members

kstat_t ks1;                    /* v1 kstat(9S) data */

char ks2_path[KSTAT2_PATHLEN];
                                /* Unique path to this kstat */

uint32_t ks2_metatype;          /* Meta-type of this kstat. Reserved for
                                   use by system kstat templates

uint32_t ks2_err;               /* reserved for use by kstat framework 

kstat2_md_id_t ks2_md;          /* opaque handle to the metadata for the
                                   values in this kstat

int (*ks2_update)(struct kstat2 *, int);
                                  /* Update function which is used to update the
                                      kstat's data and set the size 

Only the ks2_update field may be modified by the provider, and this must only be done during the initialization time before kstat2_install(9F) is called.

Other fields in the kstat must be accessed through the macros:

ks2_kid         /* kstat id */
ks2_private     /* for private use by driver */

ks2_kid, ks2_type, ks2_flags, ks2_data, and ks2_ndata should be regarded as read-only once kstat is created.

ks2_data_size may be updated in a custom ks2_update() function, which will be called under the kstat's lock (ks2_lock).

ks2_private allows the driver developer to store a pointer to private data in the kstat for convenience in processing.

If ks2_lock is to be set, then this must be done prior to calling kstat2_install(9F).

See Also

kstat2_create(9F), kstat2_install(9F), kstat2_md(9S)