xref: /titanic_51/usr/src/uts/common/sys/exacct.h (revision da14cebe459d3275048785f25bd869cb09b5307f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57eceb558Srh87107  * Common Development and Distribution License (the "License").
67eceb558Srh87107  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*da14cebeSEric Cheng  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_EXACCT_H
277c478bd9Sstevel@tonic-gate #define	_SYS_EXACCT_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/task.h>
317c478bd9Sstevel@tonic-gate #include <sys/proc.h>
327c478bd9Sstevel@tonic-gate #include <sys/procset.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef _KERNEL
357c478bd9Sstevel@tonic-gate #include <sys/acctctl.h>
367c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
377c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
387c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	EXACCT_VERSION	1
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * unpack and free allocation options:  the behaviour of the ea_free_object()
497c478bd9Sstevel@tonic-gate  * function is coordinated with whether an unpack used EUP_ALLOC or EUP_NOALLOC,
507c478bd9Sstevel@tonic-gate  * such that unpacked object hierarchies can be later freed successfully.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #define	EUP_ALLOC	0x0	/* allocate new memory for vbl length objects */
537c478bd9Sstevel@tonic-gate #define	EUP_NOALLOC	0x1	/* use existing buffer for vbl length objects */
547c478bd9Sstevel@tonic-gate #define	EUP_ALLOC_MASK	0x1
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * wracct and putacct record type options:  the properties of the partial and
587c478bd9Sstevel@tonic-gate  * interval records differ slightly:  a partial record is a snapshot of the
597c478bd9Sstevel@tonic-gate  * resource usage for the given process or task, while an interval record
607c478bd9Sstevel@tonic-gate  * reports the current usage since the last interval record or creation.
617c478bd9Sstevel@tonic-gate  * Interval records are supported only for tasks.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate #define	EW_PARTIAL		(0x01)	/* partial record */
647c478bd9Sstevel@tonic-gate #define	EW_INTERVAL		(0x02)	/* interval record */
657c478bd9Sstevel@tonic-gate #define	EW_FINAL		(0x04)	/* final record: used only in kernel */
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * putacct contents option:  the contents of the buffer passed to putacct may be
697c478bd9Sstevel@tonic-gate  * identified either as raw data or as a packed exacct record.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate #define	EP_RAW			0
727c478bd9Sstevel@tonic-gate #define	EP_EXACCT_OBJECT	1
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	EXACCT_MAX_BUFSIZE	(64 * 1024)
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #ifndef _KERNEL
777c478bd9Sstevel@tonic-gate extern size_t getacct(idtype_t, id_t, void *, size_t);
787c478bd9Sstevel@tonic-gate extern int putacct(idtype_t, id_t, void *, size_t, int);
797c478bd9Sstevel@tonic-gate extern int wracct(idtype_t, id_t, int);
807c478bd9Sstevel@tonic-gate #endif /* ! _KERNEL */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * Error codes.  libexacct reports these errors through the ea_error() function;
847c478bd9Sstevel@tonic-gate  * in the case of EXR_SYSCALL_FAIL, errno will contain the error code
857c478bd9Sstevel@tonic-gate  * encountered by the underlying system call.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate #define	EXR_OK			0
887c478bd9Sstevel@tonic-gate #define	EXR_SYSCALL_FAIL	1
897c478bd9Sstevel@tonic-gate #define	EXR_CORRUPT_FILE	2
907c478bd9Sstevel@tonic-gate #define	EXR_EOF			3
917c478bd9Sstevel@tonic-gate #define	EXR_NO_CREATOR		4
927c478bd9Sstevel@tonic-gate #define	EXR_INVALID_BUF		5
937c478bd9Sstevel@tonic-gate #define	EXR_NOTSUPP		6
947c478bd9Sstevel@tonic-gate #define	EXR_UNKN_VERSION	7
957c478bd9Sstevel@tonic-gate #define	EXR_INVALID_OBJ		8
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate typedef uint64_t ea_size_t;
987c478bd9Sstevel@tonic-gate typedef uint32_t ea_catalog_t;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate typedef enum {EO_ERROR = -1, EO_NONE = 0, EO_GROUP, EO_ITEM} ea_object_type_t;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate typedef struct ea_item {
1037c478bd9Sstevel@tonic-gate 	/*
1047c478bd9Sstevel@tonic-gate 	 * The ei_u union is discriminated via the type field of the enclosing
1057c478bd9Sstevel@tonic-gate 	 * object's catalog tag.
1067c478bd9Sstevel@tonic-gate 	 */
1077c478bd9Sstevel@tonic-gate 	union {
1087c478bd9Sstevel@tonic-gate 		uint8_t		ei_u_uint8;
1097c478bd9Sstevel@tonic-gate 		uint16_t	ei_u_uint16;
1107c478bd9Sstevel@tonic-gate 		uint32_t	ei_u_uint32;
1117c478bd9Sstevel@tonic-gate 		uint64_t	ei_u_uint64;
1127c478bd9Sstevel@tonic-gate 		double		ei_u_double;
1137c478bd9Sstevel@tonic-gate 		char		*ei_u_string;
1147c478bd9Sstevel@tonic-gate 		void		*ei_u_object;	/* for embedded packed object */
1157c478bd9Sstevel@tonic-gate 		void		*ei_u_raw;
1167c478bd9Sstevel@tonic-gate 	}			ei_u;
1177c478bd9Sstevel@tonic-gate 	ea_size_t		ei_size;
1187c478bd9Sstevel@tonic-gate } ea_item_t;
1197c478bd9Sstevel@tonic-gate #define	ei_uint8	ei_u.ei_u_uint8
1207c478bd9Sstevel@tonic-gate #define	ei_uint16	ei_u.ei_u_uint16
1217c478bd9Sstevel@tonic-gate #define	ei_uint32	ei_u.ei_u_uint32
1227c478bd9Sstevel@tonic-gate #define	ei_uint64	ei_u.ei_u_uint64
1237c478bd9Sstevel@tonic-gate #define	ei_double	ei_u.ei_u_double
1247c478bd9Sstevel@tonic-gate #define	ei_string	ei_u.ei_u_string
1257c478bd9Sstevel@tonic-gate #define	ei_object	ei_u.ei_u_object
1267c478bd9Sstevel@tonic-gate #define	ei_raw		ei_u.ei_u_raw
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate typedef struct ea_group {
1297c478bd9Sstevel@tonic-gate 	uint32_t		eg_nobjs;
1307c478bd9Sstevel@tonic-gate 	struct ea_object	*eg_objs;
1317c478bd9Sstevel@tonic-gate } ea_group_t;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate typedef struct ea_object {
1347c478bd9Sstevel@tonic-gate 	ea_object_type_t	eo_type;
1357c478bd9Sstevel@tonic-gate 	union {
1367c478bd9Sstevel@tonic-gate 		ea_group_t	eo_u_group;
1377c478bd9Sstevel@tonic-gate 		ea_item_t	eo_u_item;
1387c478bd9Sstevel@tonic-gate 	}			eo_u;
1397c478bd9Sstevel@tonic-gate 	struct ea_object	*eo_next;
1407c478bd9Sstevel@tonic-gate 	ea_catalog_t		eo_catalog;
1417c478bd9Sstevel@tonic-gate } ea_object_t;
1427c478bd9Sstevel@tonic-gate #define	eo_group	eo_u.eo_u_group
1437c478bd9Sstevel@tonic-gate #define	eo_item		eo_u.eo_u_item
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate extern int ea_set_item(ea_object_t *, ea_catalog_t, const void *, size_t);
1467c478bd9Sstevel@tonic-gate extern int ea_set_group(ea_object_t *, ea_catalog_t);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * In prior releases, the following three functions had the type void, and so
1507c478bd9Sstevel@tonic-gate  * could not return a status code.  In SunOS 5.9, the return type has been
1517c478bd9Sstevel@tonic-gate  * changed to int, so that if errors are detected the invoking application
1527c478bd9Sstevel@tonic-gate  * can be notified appropriately.
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate extern int ea_attach_to_object(ea_object_t *, ea_object_t *);
1557c478bd9Sstevel@tonic-gate extern int ea_attach_to_group(ea_object_t *, ea_object_t *);
1567c478bd9Sstevel@tonic-gate extern int ea_free_item(ea_object_t *, int);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate extern void ea_free_object(ea_object_t *, int);
1597c478bd9Sstevel@tonic-gate extern size_t ea_pack_object(ea_object_t *, void *, size_t);
1607c478bd9Sstevel@tonic-gate extern void *ea_alloc(size_t);
1617c478bd9Sstevel@tonic-gate extern void ea_free(void *, size_t);
1627c478bd9Sstevel@tonic-gate extern char *ea_strdup(const char *);
1637c478bd9Sstevel@tonic-gate extern void ea_strfree(char *);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1667c478bd9Sstevel@tonic-gate extern ea_object_t *ea_alloc_item(ea_catalog_t, void *, size_t);
1677c478bd9Sstevel@tonic-gate extern ea_object_t *ea_alloc_group(ea_catalog_t);
1687c478bd9Sstevel@tonic-gate extern ea_object_t *ea_attach_item(ea_object_t *, void *, size_t, ea_catalog_t);
1697c478bd9Sstevel@tonic-gate extern void exacct_commit_task(void *);
1707c478bd9Sstevel@tonic-gate extern void exacct_commit_proc(proc_t *, int);
1717eceb558Srh87107 extern void exacct_update_task_mstate(proc_t *);
1727c478bd9Sstevel@tonic-gate extern int exacct_tag_task(ac_info_t *, task_t *, void *, size_t, int);
1737c478bd9Sstevel@tonic-gate extern int exacct_tag_proc(ac_info_t *, pid_t, taskid_t, void *, size_t, int,
1747c478bd9Sstevel@tonic-gate     const char *);
1757c478bd9Sstevel@tonic-gate extern void exacct_commit_flow(void *);
176*da14cebeSEric Cheng extern int exacct_commit_netinfo(void *, int);
1777c478bd9Sstevel@tonic-gate extern void exacct_init(void);
1787c478bd9Sstevel@tonic-gate extern void *exacct_create_header(size_t *);
1797c478bd9Sstevel@tonic-gate extern int exacct_write_header(ac_info_t *, void *, size_t);
1807c478bd9Sstevel@tonic-gate extern void exacct_calculate_proc_usage(proc_t *, proc_usage_t *,
1817c478bd9Sstevel@tonic-gate     ulong_t *, int, int);
1827c478bd9Sstevel@tonic-gate extern int exacct_commit_callback(ac_info_t *, void *, size_t, void *,
1837c478bd9Sstevel@tonic-gate     size_t, size_t *);
1847c478bd9Sstevel@tonic-gate extern int exacct_assemble_proc_usage(ac_info_t *, proc_usage_t *,
1857c478bd9Sstevel@tonic-gate     int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
1867c478bd9Sstevel@tonic-gate     void *, size_t, size_t *, int);
1877c478bd9Sstevel@tonic-gate extern int exacct_assemble_task_usage(ac_info_t *, task_t *,
1887c478bd9Sstevel@tonic-gate     int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
1897c478bd9Sstevel@tonic-gate     void *, size_t, size_t *, int);
1907c478bd9Sstevel@tonic-gate extern int exacct_assemble_flow_usage(ac_info_t *, flow_usage_t *,
1917c478bd9Sstevel@tonic-gate     int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
1927c478bd9Sstevel@tonic-gate     void *, size_t, size_t *);
1937eceb558Srh87107 extern void exacct_move_mstate(proc_t *, task_t *, task_t *);
194*da14cebeSEric Cheng extern int exacct_assemble_net_usage(ac_info_t *, void *,
195*da14cebeSEric Cheng     int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
196*da14cebeSEric Cheng     void *, size_t, size_t *, int);
1977c478bd9Sstevel@tonic-gate extern taskq_t *exacct_queue;
1987c478bd9Sstevel@tonic-gate extern kmem_cache_t *exacct_object_cache;
1997c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate #endif
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #endif	/* _SYS_EXACCT_H */
206