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