| KSTAT(4) | Device Drivers Manual | KSTAT(4) |
kstat — kernel
statistics
pseudo-device kstat
The /dev/kstat device exposes kernel statistics (kstats) to userland.
The kstat ioctl(2) calls are provided in
<sys/kstat.h>.
With the exception of KSTATIOC_VERSION,
the kstat ioctl(2) calls use the
kstat_req structure to request or enumerate kernel
statistic data from the kernel:
struct kstat_req {
unsigned int ks_rflags;
#define KSTATIOC_F_IGNVER (1 << 0)
/* the current version of the kstat subsystem */
unsigned int ks_version;
uint64_t ks_id;
char ks_provider[KSTAT_STRLEN];
unsigned int ks_instance;
char ks_name[KSTAT_STRLEN];
unsigned int ks_unit;
struct timespec ks_created;
struct timespec ks_updated;
struct timespec ks_interval;
unsigned int ks_type;
unsigned int ks_state;
void *ks_data;
size_t ks_datalen;
unsigned int ks_dataver;
};
The kstat subsystem increments a version number when a kstat is
added to or removed from the subsystem so changes to the set of kstats can
be detected. The current version can be requested with a
KSTATIOC_VERSION ioctl(2) call.
Programs requesting a kstat with the other ioctl(2) calls
pass the current version in ks_version, and if the
version differs an error will be returned with errno(2)
set to EINVAL to indicate that the program should
resynchronise with the kernel subsystem. This check can be disabled by
setting the KSTATIOC_F_IGNVER flag in
ks_rflags.
A kstat is identified by a 64bit number, or the combination of a provider name, instance number, name, and unit number.
Unless ks_data is
NULL, the kstat subsystem will request an update of
the statistics data and copy up to ks_datalen bytes of
it to the specified memory.
The kstat ioctl(2) calls are as follows:
KSTATIOC_VERSION
unsigned intKSTATIOC_FIND_ID
struct kstat_reqKSTATIOC_NFIND_ID
struct kstat_reqKSTATIOC_FIND_PROVIDER
struct kstat_reqKSTATIOC_NFIND_PROVIDER
struct kstat_reqKSTATIOC_FIND_NAME
struct kstat_reqKSTATIOC_NFIND_NAME
struct kstat_reqUpon the successful request of a kstat, the
kstat driver will update the
kstat_req structure with current information about
that kstat. Updated fields include:
KSTATIOC_FIND_ID ioctl(2)
call.KSTATIOC_FIND_NAME and
KSTATIOC_FIND_PROVIDER ioctl(2)
calls. Groups of kstats with the same identifier or name can be enumerated
or requested with the KSTATIOC_NFIND_NAME and
KSTATIOC_NFIND_PROVIDER ioctl(2)
calls without having to fetch the entire set of kstats and filtering
them.The kstat device appeared in
OpenBSD 6.8.
| January 14, 2022 | Debian |