Writing Device Drivers

Kernel Statistics

A kstat or kernel statistic is a data structure that records the time, counters, various measurements, and other data regarding the use of a device. kstats are stored as NULL-terminated linked lists.

Table 4–2 kstat Member Descriptions

kstat Member 

Description 

ks_crtime 

Time at which the kstat was created, commonly used in calculating rates of various counters. 

ks_next 

Points to next kstat in chain. 

ks_kid 

Unique ID for kstat, for example,??? 

ks_module[KSTAT_STRLEN] 

Identifies kernel module that created kstat. ks_module is combined with ks_instance and ks_name to give the kstat a unique, meaningful name. KSTAT_STRLEN sets the maximum length of ks_module. 

ks_resv 

A reserved field. 

ks_instance 

The instance of the kernel module that created this kstat. ks_instance is combined with ks_module and ks_name to give the kstat a unique, meaningful name.  

ks_name[KSTAT_STRLEN] 

A name assigned to the kstat in combination with ks_module and ks_instance. KSTAT_STRLEN sets the maximum length of ks_module. 

ks_type 

The data type,which can be KSTAT_TYPE_RAW (binary data), KSTAT_TYPE_NAMED (name/value pairs), KSTAT_TYPE_INTR (interrupt statistics), KSTAT_TYPE_IO (I/O statistics), and KSTAT_TYPE_TIMER (event timers). 

ks_class[KSTAT_STRLEN] 

This categorizes the kstat into one of the following classes: bus, controller, device_error, disk, hat, kmem_cache, kstat, misc, net, nfs, pages, partition, rps, ufs, vm, and vmem. 

ks_data 

Points to the data saction for the kstat. 

ks_ndata 

Indicates the number of data records, for those kstat types that support multiple records (KSTAT_TYPE_RAW, KSTAT_TYPE_NAMED, and KSTAT_TYPE_TIMER). 

ks_data_size 

Total size of the data section in bytes. 

ks_snaptime 

The timestamp for the last data sanpshot, useful in calculating rates.