xref: /onnv-gate/usr/src/uts/common/sys/exacct.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_SYS_EXACCT_H
28*0Sstevel@tonic-gate #define	_SYS_EXACCT_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <sys/task.h>
34*0Sstevel@tonic-gate #include <sys/proc.h>
35*0Sstevel@tonic-gate #include <sys/procset.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #ifdef _KERNEL
38*0Sstevel@tonic-gate #include <sys/acctctl.h>
39*0Sstevel@tonic-gate #include <sys/kmem.h>
40*0Sstevel@tonic-gate #include <sys/taskq.h>
41*0Sstevel@tonic-gate #include <sys/vnode.h>
42*0Sstevel@tonic-gate #endif
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #ifdef	__cplusplus
45*0Sstevel@tonic-gate extern "C" {
46*0Sstevel@tonic-gate #endif
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #define	EXACCT_VERSION	1
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate /*
51*0Sstevel@tonic-gate  * unpack and free allocation options:  the behaviour of the ea_free_object()
52*0Sstevel@tonic-gate  * function is coordinated with whether an unpack used EUP_ALLOC or EUP_NOALLOC,
53*0Sstevel@tonic-gate  * such that unpacked object hierarchies can be later freed successfully.
54*0Sstevel@tonic-gate  */
55*0Sstevel@tonic-gate #define	EUP_ALLOC	0x0	/* allocate new memory for vbl length objects */
56*0Sstevel@tonic-gate #define	EUP_NOALLOC	0x1	/* use existing buffer for vbl length objects */
57*0Sstevel@tonic-gate #define	EUP_ALLOC_MASK	0x1
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate /*
60*0Sstevel@tonic-gate  * wracct and putacct record type options:  the properties of the partial and
61*0Sstevel@tonic-gate  * interval records differ slightly:  a partial record is a snapshot of the
62*0Sstevel@tonic-gate  * resource usage for the given process or task, while an interval record
63*0Sstevel@tonic-gate  * reports the current usage since the last interval record or creation.
64*0Sstevel@tonic-gate  * Interval records are supported only for tasks.
65*0Sstevel@tonic-gate  */
66*0Sstevel@tonic-gate #define	EW_PARTIAL		(0x01)	/* partial record */
67*0Sstevel@tonic-gate #define	EW_INTERVAL		(0x02)	/* interval record */
68*0Sstevel@tonic-gate #define	EW_FINAL		(0x04)	/* final record: used only in kernel */
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate /*
71*0Sstevel@tonic-gate  * putacct contents option:  the contents of the buffer passed to putacct may be
72*0Sstevel@tonic-gate  * identified either as raw data or as a packed exacct record.
73*0Sstevel@tonic-gate  */
74*0Sstevel@tonic-gate #define	EP_RAW			0
75*0Sstevel@tonic-gate #define	EP_EXACCT_OBJECT	1
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate #define	EXACCT_MAX_BUFSIZE	(64 * 1024)
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate #ifndef _KERNEL
80*0Sstevel@tonic-gate extern size_t getacct(idtype_t, id_t, void *, size_t);
81*0Sstevel@tonic-gate extern int putacct(idtype_t, id_t, void *, size_t, int);
82*0Sstevel@tonic-gate extern int wracct(idtype_t, id_t, int);
83*0Sstevel@tonic-gate #endif /* ! _KERNEL */
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate /*
86*0Sstevel@tonic-gate  * Error codes.  libexacct reports these errors through the ea_error() function;
87*0Sstevel@tonic-gate  * in the case of EXR_SYSCALL_FAIL, errno will contain the error code
88*0Sstevel@tonic-gate  * encountered by the underlying system call.
89*0Sstevel@tonic-gate  */
90*0Sstevel@tonic-gate #define	EXR_OK			0
91*0Sstevel@tonic-gate #define	EXR_SYSCALL_FAIL	1
92*0Sstevel@tonic-gate #define	EXR_CORRUPT_FILE	2
93*0Sstevel@tonic-gate #define	EXR_EOF			3
94*0Sstevel@tonic-gate #define	EXR_NO_CREATOR		4
95*0Sstevel@tonic-gate #define	EXR_INVALID_BUF		5
96*0Sstevel@tonic-gate #define	EXR_NOTSUPP		6
97*0Sstevel@tonic-gate #define	EXR_UNKN_VERSION	7
98*0Sstevel@tonic-gate #define	EXR_INVALID_OBJ		8
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate typedef uint64_t ea_size_t;
101*0Sstevel@tonic-gate typedef uint32_t ea_catalog_t;
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate typedef enum {EO_ERROR = -1, EO_NONE = 0, EO_GROUP, EO_ITEM} ea_object_type_t;
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate typedef struct ea_item {
106*0Sstevel@tonic-gate 	/*
107*0Sstevel@tonic-gate 	 * The ei_u union is discriminated via the type field of the enclosing
108*0Sstevel@tonic-gate 	 * object's catalog tag.
109*0Sstevel@tonic-gate 	 */
110*0Sstevel@tonic-gate 	union {
111*0Sstevel@tonic-gate 		uint8_t		ei_u_uint8;
112*0Sstevel@tonic-gate 		uint16_t	ei_u_uint16;
113*0Sstevel@tonic-gate 		uint32_t	ei_u_uint32;
114*0Sstevel@tonic-gate 		uint64_t	ei_u_uint64;
115*0Sstevel@tonic-gate 		double		ei_u_double;
116*0Sstevel@tonic-gate 		char		*ei_u_string;
117*0Sstevel@tonic-gate 		void		*ei_u_object;	/* for embedded packed object */
118*0Sstevel@tonic-gate 		void		*ei_u_raw;
119*0Sstevel@tonic-gate 	}			ei_u;
120*0Sstevel@tonic-gate 	ea_size_t		ei_size;
121*0Sstevel@tonic-gate } ea_item_t;
122*0Sstevel@tonic-gate #define	ei_uint8	ei_u.ei_u_uint8
123*0Sstevel@tonic-gate #define	ei_uint16	ei_u.ei_u_uint16
124*0Sstevel@tonic-gate #define	ei_uint32	ei_u.ei_u_uint32
125*0Sstevel@tonic-gate #define	ei_uint64	ei_u.ei_u_uint64
126*0Sstevel@tonic-gate #define	ei_double	ei_u.ei_u_double
127*0Sstevel@tonic-gate #define	ei_string	ei_u.ei_u_string
128*0Sstevel@tonic-gate #define	ei_object	ei_u.ei_u_object
129*0Sstevel@tonic-gate #define	ei_raw		ei_u.ei_u_raw
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate typedef struct ea_group {
132*0Sstevel@tonic-gate 	uint32_t		eg_nobjs;
133*0Sstevel@tonic-gate 	struct ea_object	*eg_objs;
134*0Sstevel@tonic-gate } ea_group_t;
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate typedef struct ea_object {
137*0Sstevel@tonic-gate 	ea_object_type_t	eo_type;
138*0Sstevel@tonic-gate 	union {
139*0Sstevel@tonic-gate 		ea_group_t	eo_u_group;
140*0Sstevel@tonic-gate 		ea_item_t	eo_u_item;
141*0Sstevel@tonic-gate 	}			eo_u;
142*0Sstevel@tonic-gate 	struct ea_object	*eo_next;
143*0Sstevel@tonic-gate 	ea_catalog_t		eo_catalog;
144*0Sstevel@tonic-gate } ea_object_t;
145*0Sstevel@tonic-gate #define	eo_group	eo_u.eo_u_group
146*0Sstevel@tonic-gate #define	eo_item		eo_u.eo_u_item
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate extern int ea_set_item(ea_object_t *, ea_catalog_t, const void *, size_t);
149*0Sstevel@tonic-gate extern int ea_set_group(ea_object_t *, ea_catalog_t);
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate /*
152*0Sstevel@tonic-gate  * In prior releases, the following three functions had the type void, and so
153*0Sstevel@tonic-gate  * could not return a status code.  In SunOS 5.9, the return type has been
154*0Sstevel@tonic-gate  * changed to int, so that if errors are detected the invoking application
155*0Sstevel@tonic-gate  * can be notified appropriately.
156*0Sstevel@tonic-gate  */
157*0Sstevel@tonic-gate extern int ea_attach_to_object(ea_object_t *, ea_object_t *);
158*0Sstevel@tonic-gate extern int ea_attach_to_group(ea_object_t *, ea_object_t *);
159*0Sstevel@tonic-gate extern int ea_free_item(ea_object_t *, int);
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate extern void ea_free_object(ea_object_t *, int);
162*0Sstevel@tonic-gate extern size_t ea_pack_object(ea_object_t *, void *, size_t);
163*0Sstevel@tonic-gate extern void *ea_alloc(size_t);
164*0Sstevel@tonic-gate extern void ea_free(void *, size_t);
165*0Sstevel@tonic-gate extern char *ea_strdup(const char *);
166*0Sstevel@tonic-gate extern void ea_strfree(char *);
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate #ifdef _KERNEL
169*0Sstevel@tonic-gate extern ea_object_t *ea_alloc_item(ea_catalog_t, void *, size_t);
170*0Sstevel@tonic-gate extern ea_object_t *ea_alloc_group(ea_catalog_t);
171*0Sstevel@tonic-gate extern ea_object_t *ea_attach_item(ea_object_t *, void *, size_t, ea_catalog_t);
172*0Sstevel@tonic-gate extern void exacct_commit_task(void *);
173*0Sstevel@tonic-gate extern void exacct_commit_proc(proc_t *, int);
174*0Sstevel@tonic-gate extern int exacct_tag_task(ac_info_t *, task_t *, void *, size_t, int);
175*0Sstevel@tonic-gate extern int exacct_tag_proc(ac_info_t *, pid_t, taskid_t, void *, size_t, int,
176*0Sstevel@tonic-gate     const char *);
177*0Sstevel@tonic-gate extern void exacct_commit_flow(void *);
178*0Sstevel@tonic-gate extern void exacct_init(void);
179*0Sstevel@tonic-gate extern void *exacct_create_header(size_t *);
180*0Sstevel@tonic-gate extern int exacct_write_header(ac_info_t *, void *, size_t);
181*0Sstevel@tonic-gate extern void exacct_calculate_proc_usage(proc_t *, proc_usage_t *,
182*0Sstevel@tonic-gate     ulong_t *, int, int);
183*0Sstevel@tonic-gate extern int exacct_commit_callback(ac_info_t *, void *, size_t, void *,
184*0Sstevel@tonic-gate     size_t, size_t *);
185*0Sstevel@tonic-gate extern int exacct_assemble_proc_usage(ac_info_t *, proc_usage_t *,
186*0Sstevel@tonic-gate     int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
187*0Sstevel@tonic-gate     void *, size_t, size_t *, int);
188*0Sstevel@tonic-gate extern int exacct_assemble_task_usage(ac_info_t *, task_t *,
189*0Sstevel@tonic-gate     int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
190*0Sstevel@tonic-gate     void *, size_t, size_t *, int);
191*0Sstevel@tonic-gate extern int exacct_assemble_flow_usage(ac_info_t *, flow_usage_t *,
192*0Sstevel@tonic-gate     int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
193*0Sstevel@tonic-gate     void *, size_t, size_t *);
194*0Sstevel@tonic-gate extern taskq_t *exacct_queue;
195*0Sstevel@tonic-gate extern kmem_cache_t *exacct_object_cache;
196*0Sstevel@tonic-gate #endif /* _KERNEL */
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate #ifdef	__cplusplus
199*0Sstevel@tonic-gate }
200*0Sstevel@tonic-gate #endif
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate #endif	/* _SYS_EXACCT_H */
203