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