syskstat.h

来自「嵌入式RMON,RMON为Remote monitor的缩写,基于SNMP为网络」· C头文件 代码 · 共 816 行 · 第 1/2 页

H
816
字号
typedef struct kstat_io {	/*	 * Basic counters.	 *	 * The counters should be updated at the end of service	 * (e.g., just prior to calling biodone()).	 */	u_longlong_t	nread;		/* number of bytes read */	u_longlong_t	nwritten;	/* number of bytes written */	ulong_t		reads;		/* number of read operations */	ulong_t		writes;		/* number of write operations */	/*	 * Accumulated time and queue length statistics.	 *	 * Accumulated time statistics are kept as a running sum	 * of "active" time.  Queue length statistics are kept as a	 * running sum of the product of queue length and elasped time	 * at that length -- i.e., a Riemann sum for queue length	 * integrated against time.  (You can also think of active time	 * as a Riemann sum, for the boolean function (queue_length > 0)	 * integrated against time, or you can think of it as the	 * Lebesgue measure of the set on which queue_length > 0.)	 *	 *		^	 *		|			_________	 *		8			| i4	|	 *		|			|	|	 *	Queue	6			|	|	 *	Length	|	_________	|	|	 *		4	| i2	|_______|	|	 *		|	|	    i3		|	 *		2_______|			|	 *		|    i1				|	 *		|_______________________________|	 *		Time->	t1	t2	t3	t4	 *	 * At each change of state (entry or exit from the queue),	 * we add the elapsed time (since the previous state change)	 * to the active time if the queue length was non-zero during	 * that interval; and we add the product of the elapsed time	 * times the queue length to the running length*time sum.	 *	 * This method is generalizable to measuring residency	 * in any defined system: instead of queue lengths, think	 * of "outstanding RPC calls to server X".	 *	 * A large number of I/O subsystems have at least two basic	 * "lists" of transactions they manage: one for transactions	 * that have been accepted for processing but for which processing	 * has yet to begin, and one for transactions which are actively	 * being processed (but not done). For this reason, two cumulative	 * time statistics are defined here: pre-service (wait) time,	 * and service (run) time.	 *	 * All times are 64-bit nanoseconds (kstime_t), as returned by	 * kstat_time().	 *	 * The units of cumulative busy time are accumulated nanoseconds.	 * The units of cumulative length*time products are elapsed time	 * times queue length.	 *	 * Updates to the fields below are performed implicitly by calls to	 * these five functions:	 *	 *	kstat_waitq_enter()	 *	kstat_waitq_exit()	 *	kstat_runq_enter()	 *	kstat_runq_exit()	 *	 *	kstat_waitq_to_runq()		(see below)	 *	kstat_runq_back_to_waitq()	(see below)	 *	 * Since kstat_waitq_exit() is typically followed immediately	 * by kstat_runq_enter(), there is a single kstat_waitq_to_runq()	 * function which performs both operations.  This is a performance	 * win since only one timestamp is required.	 *	 * In some instances, it may be necessary to move a request from	 * the run queue back to the wait queue, e.g. for write throttling.	 * For these situations, call kstat_runq_back_to_waitq().	 *	 * These fields should never be updated by any other means.	 */	kstime_t wtime;		/* cumulative wait (pre-service) time */	kstime_t wlentime;	/* cumulative wait length*time product */	kstime_t wlastupdate;	/* last time wait queue changed */	kstime_t rtime;		/* cumulative run (service) time */	kstime_t rlentime;	/* cumulative run length*time product */	kstime_t rlastupdate;	/* last time run queue changed */	ulong_t	wcnt;		/* count of elements in wait state */	ulong_t	rcnt;		/* count of elements in run state */} kstat_io_t;#define	KSTAT_IO_PTR(kptr)	((kstat_io_t *) (kptr)->ks_data)/* * Event timer statistics - cumulative elapsed time and number of events. * * Updates to these fields are performed implicitly by calls to * kstat_timer_start() and kstat_timer_stop(). */typedef struct kstat_timer {	char		name[KSTAT_STRLEN];	/* event name */	uchar_t		resv;			/* reserved */	u_longlong_t	num_events;		/* number of events */	kstime_t	elapsed_time;		/* cumulative elapsed time */	kstime_t	min_time;		/* shortest event duration */	kstime_t	max_time;		/* longest event duration */	kstime_t	start_time;		/* previous event start time */	kstime_t	stop_time;		/* previous event stop time */} kstat_timer_t;#define	KSTAT_TIMER_PTR(kptr)	((kstat_timer_t *) (kptr)->ks_data)#if	defined(_KERNEL)extern kstat_t	*kstat_chain;		/* kstat chain head */extern kmutex_t	kstat_chain_lock;	/* protects the kstat chain */extern kid_t	kstat_chain_id;		/* bumped at each state change */extern int	kstat_clients;		/* non-zero if active kstat clients *//* * Adding and deleting kstats. * * The typical sequence to add a kstat is: * *	ksp = kstat_create(module, instance, name, class, type, ndata, flags); *	if (ksp) { *		... client initialization, if necessary *		kstat_install(ksp); *	} * * In general, adding a kstat to the system is a three-step process: * system initialization, client initialization, and installation. * * Step 1: System Initialization * * kstat_create() performs system initialization.  kstat_create() * allocates memory for the entire kstat (header plus data), initializes * all header fields, initializes the data section to all zeroes, and puts * the kstat onto the system's kstat chain with a KID of -1.  The kstat * will not be visible to /dev/kstat until the KID is set to a non-negative * value by kstat_install(). * * Step 2: Client Initialization * * The client performs any necessary initialization of the data section, * e.g. setting the name fields in a KSTAT_TYPE_NAMED.  The client also * has the option of assigning new values to any of the following header * fields: ks_lock, ks_update, ks_private, ks_copy.  Virual kstats also * set the ks_data field at this time.  If the client has a dynamic update * routine, it sets the ks_update field to the address of the update * function; similarly, the client may install an alternate ks_copy routine. * Optionally, the client can also set the ks_private field however * it sees fit. * * Step 3: Installation * * Once the kstat is completely initialized, kstat_install() assigns it * a unique non-negative KID, making it visible to the outside world. * * Removing a kstat from the system * * kstat_delete(ksp) removes ksp from the kstat chain and frees all * associated system resources. *//* * kstat_t * * kstat_create(char *ks_module, int ks_instance, char *ks_name, *	char *ks_class, uchar_t ks_type, ulong_t ks_ndata, uchar_t ks_flags) * *	Purpose: * *		Create and initialize a new kstat * *	Arguments: * *		ks_module: the name of the caller's module, e.g. sd, esp, etc. *		The "core" kernel (/kernel/unix) uses the name "unix". * *		ks_instance: the caller's instance, as from ddi_get_instance(). *		Modules which don't have a meaningful instance should use 0. * *		ks_name: pointer to a string that will uniquely identify this *		structure. Only KSTAT_STRLEN - 1 characters are significant. * *		ks_class: the general class that this kstat belongs to * *		ks_type: the type of kstat to allocate (raw, named, *		interrupt, i/o, timer) * *		ks_ndata: the number of type-specific data records to allocate * *		ks_flags: various flags for this kstat * *	Failure Return Value: * *		A null pointer due to the inability to create a new *		kstat structure or a (ks_module, ks_instance, ks_name) *		namespace collision. * *	Success Return Value: * *		A pointer to an initialized kstat structure, whose *		data field points to zero-initialized type-specific data. */extern kstat_t *kstat_create(char *, int, char *, char *, uchar_t,	ulong_t, uchar_t);/* * void * kstat_install(kstat_t *ksp) * *	Puspose: * *		Add an initialized kstat to the system's kstat chain * *	Arguments: * *		ksp: pointer to an initialized kstat structure */extern void kstat_install(kstat_t *);/* * void * kstat_delete(kstat_t *ksp) * *	Puspose: * *		Delete a kstat from the system's kstat chain, and *		free all associated system resources * *	Arguments: * *		ksp: pointer to a currently installed kstat */extern void kstat_delete(kstat_t *);/* * kstat_t * * kstat_lookup_byname(char *ks_module, int ks_instance, char *ks_name) * *	Puspose: * *		Find the kstat with the specified (module, instance, name) */extern kstat_t *kstat_lookup_byname(char *, int, char *);/* * kstat_t * * kstat_lookup_bykid(kid_t ks_kid) * *	Puspose: * *		Find the kstat with the specified KID */extern kstat_t *kstat_lookup_bykid(kid_t);/* * kstime_t * kstat_time(void) * *	Puspose: * *		Returns the current kstat time.  This is a 64-bit *		nanosecond value. */extern kstime_t kstat_time();/* * void * kstat_set_string(char *dst, char *src) * *	Purpose: * *		Sets any string field of a kstat.  This is a convenience *		routine: it bzero()s the name field (dst), then copies in *		up to KSTAT_STRLEN - 1 characters of src.  This ensures *		that kstat strings are always null-terminated. */extern void kstat_set_string(char *, char *);/* * void * kstat_named_init(kstat_named_t *knp, char *name, uchar_t data_type) * * void * kstat_timer_init(kstat_timer_t *ktp, char *name) * *	Purpose: * *		Initialize type-specific data fields. */extern void kstat_named_init(kstat_named_t *, char *, uchar_t);extern void kstat_timer_init(kstat_timer_t *, char *);/* * int * kstat_copyin(char *src, char *dst, size_t size) * * int * kstat_copyout(char *src, char *dst, size_t size) * *	Puspose: * *		Copy in/out a chunk of kstat data from/to userland. *		Currently, these are just wrappers around copyin() and *		copyout(), but this may change in the future. */extern int kstat_copyin(char *, char *, size_t);extern int kstat_copyout(char *, char *, size_t);/* * int * default_kstat_copy(kstat_t *ksp, kstat_t *user_ksp, int rw) * *	Puspose: * *		The default routine to copy a kstat's data to/from userland. *		Performs certain massaging first, e.g. it corrects i/o *		statistics to compensate for incomplete transactions. */extern int default_kstat_copy(kstat_t *, kstat_t *, int);/* * Call kstat_waitq_enter() when a request arrives * and is placed into a pre-service state * (e.g., just prior to calling disksort). */extern void kstat_waitq_enter(kstat_io_t *);/* * Call kstat_waitq_exit() when a request is * removed from its pre-service state. * (e.g., just prior to calling XXstart). */extern void kstat_waitq_exit(kstat_io_t *);/* * Call kstat_runq_enter() when a request * is placed in its service state * (e.g., just prior to calling XXstart, * but after kstat_waitq_exit()). */extern void kstat_runq_enter(kstat_io_t *);/* * Call kstat_runq_exit() when a request is * removed from its service state * (e.g., just prior to calling biodone). */extern void kstat_runq_exit(kstat_io_t *);/* * kstat_waitq_to_runq() is equivalent to * kstat_waitq_exit() immediately followed by * kstat_runq_enter().  This is cheaper since * only one timestamp is required. */extern void kstat_waitq_to_runq(kstat_io_t *);/* * Call kstat_runq_back_to_waitq() if a request * has to be moved from the run queue back to the * wait queue, e.g. due to write throttling. */extern void kstat_runq_back_to_waitq(kstat_io_t *);/* * Call kstat_timer_start() to begin timing an event. * Call kstat_timer_stop() when that event completes. */extern void kstat_timer_start(kstat_timer_t *);extern void kstat_timer_stop(kstat_timer_t *);#endif	/* defined(_KERNEL) */#ifdef	__cplusplus}#endif#endif	/* _SYS_KSTAT_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?