xref: /titanic_51/usr/src/lib/libzonestat/common/zonestat_impl.h (revision f5c2e7ea56aaa46a9976476fb0cb1f02b9426f07)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef _ZONESTAT_IMPL_H
27 #define	_ZONESTAT_IMPL_H
28 
29 #include <zonestat.h>
30 #include <sys/list.h>
31 #include <sys/priv_const.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 
36 #endif
37 
38 #define	ZS_VERSION	1
39 
40 #define	ZS_PSET_DEFAULT		PS_NONE
41 #define	ZS_PSET_MULTI		PS_MYID
42 #define	ZS_PSET_ERROR		PS_QUERY
43 
44 #define	ZS_DOOR_PATH		"/etc/svc/volatile/zonestat_door"
45 
46 #define	ZSD_CMD_READ		1
47 #define	ZSD_CMD_CONNECT		2
48 #define	ZSD_CMD_NEW_ZONE	3
49 
50 /* The following read commands are unimplemented */
51 #define	ZSD_CMD_READ_TIME	3
52 #define	ZSD_CMD_READ_SET	4
53 #define	ZSD_CMD_READ_SET_TIME	5
54 
55 #define	ZSD_STATUS_OK			0
56 #define	ZSD_STATUS_VERSION_MISMATCH	1
57 #define	ZSD_STATUS_PERMISSION		2
58 #define	ZSD_STATUS_INTERNAL_ERROR	3
59 
60 #define	TIMESTRUC_ADD_NANOSEC(ts, nsec)				\
61 	{							\
62 		(ts).tv_sec += (time_t)((nsec) / NANOSEC);	\
63 		(ts).tv_nsec += (long)((nsec) % NANOSEC);	\
64 		if ((ts).tv_nsec > NANOSEC) {			\
65 			(ts).tv_sec += (ts).tv_nsec / NANOSEC;	\
66 			(ts).tv_nsec = (ts).tv_nsec % NANOSEC;	\
67 		}						\
68 	}
69 
70 #define	TIMESTRUC_ADD_TIMESTRUC(ts, add)			\
71 	{							\
72 		(ts).tv_sec += (add).tv_sec;			\
73 		(ts).tv_nsec += (add).tv_nsec;			\
74 		if ((ts).tv_nsec > NANOSEC) {			\
75 			(ts).tv_sec += (ts).tv_nsec / NANOSEC;	\
76 			(ts).tv_nsec = (ts).tv_nsec % NANOSEC;	\
77 		}						\
78 	}
79 
80 #define	TIMESTRUC_DELTA(delta, new, old)			\
81 	{							\
82 		(delta).tv_sec = (new).tv_sec - (old).tv_sec;	\
83 		(delta).tv_nsec = (new).tv_nsec - (old).tv_nsec;\
84 		if ((delta).tv_nsec < 0) {			\
85 			delta.tv_nsec += NANOSEC;		\
86 			delta.tv_sec -= 1;			\
87 		}						\
88 		if ((delta).tv_sec < 0) {			\
89 			delta.tv_sec = 0;			\
90 			delta.tv_nsec = 0;			\
91 		}						\
92 	}
93 
94 typedef struct zs_system {
95 
96 	uint64_t zss_ram_total;
97 	uint64_t zss_ram_kern;
98 	uint64_t zss_ram_zones;
99 
100 	uint64_t zss_locked_kern;
101 	uint64_t zss_locked_zones;
102 
103 	uint64_t zss_vm_total;
104 	uint64_t zss_vm_kern;
105 	uint64_t zss_vm_zones;
106 
107 	uint64_t zss_swap_total;
108 	uint64_t zss_swap_used;
109 
110 	timestruc_t zss_cpu_total_time;
111 	timestruc_t zss_cpu_usage_kern;
112 	timestruc_t zss_cpu_usage_zones;
113 
114 	uint64_t zss_processes_max;
115 	uint64_t zss_lwps_max;
116 	uint64_t zss_shm_max;
117 	uint64_t zss_shmids_max;
118 	uint64_t zss_semids_max;
119 	uint64_t zss_msgids_max;
120 	uint64_t zss_lofi_max;
121 
122 	uint64_t zss_processes;
123 	uint64_t zss_lwps;
124 	uint64_t zss_shm;
125 	uint64_t zss_shmids;
126 	uint64_t zss_semids;
127 	uint64_t zss_msgids;
128 	uint64_t zss_lofi;
129 
130 	uint64_t zss_ncpus;
131 	uint64_t zss_ncpus_online;
132 
133 } zs_system_t;
134 
135 struct zs_pset_zone {
136 
137 	list_node_t	zspz_next;
138 	struct zs_pset	*zspz_pset;
139 	struct zs_zone	*zspz_zone;
140 	zoneid_t	zspz_zoneid;
141 	time_t		zspz_start;
142 	hrtime_t	zspz_hrstart;
143 	uint_t		zspz_intervals;
144 
145 	uint64_t	zspz_cpu_shares;
146 	uint_t		zspz_scheds;
147 
148 	timestruc_t	zspz_cpu_usage;
149 
150 };
151 
152 struct zs_ctl {
153 	int	 zsctl_door;
154 	uint64_t zsctl_gen;
155 	zs_usage_t *zsctl_start;
156 };
157 
158 struct zs_zone {
159 	list_node_t	zsz_next;
160 	struct zs_system *zsz_system;
161 	char		zsz_name[ZS_ZONENAME_MAX];
162 	char		zsz_pool[ZS_POOLNAME_MAX];
163 	char		zsz_pset[ZS_PSETNAME_MAX];
164 	zoneid_t	zsz_id;
165 	uint_t		zsz_cputype;
166 	uint_t		zsz_iptype;
167 	time_t		zsz_start;
168 	hrtime_t	zsz_hrstart;
169 	uint_t		zsz_intervals;
170 
171 	uint_t		zsz_scheds;
172 	uint64_t	zsz_cpu_shares;
173 	uint64_t	zsz_cpu_cap;
174 	uint64_t	zsz_ram_cap;
175 	uint64_t	zsz_vm_cap;
176 	uint64_t	zsz_locked_cap;
177 
178 	uint64_t	zsz_cpus_online;
179 	timestruc_t	zsz_cpu_usage;
180 	timestruc_t	zsz_pset_time;
181 	timestruc_t	zsz_cap_time;
182 	timestruc_t	zsz_share_time;
183 
184 	uint64_t	zsz_usage_ram;
185 	uint64_t	zsz_usage_locked;
186 	uint64_t	zsz_usage_vm;
187 
188 	uint64_t	zsz_processes_cap;
189 	uint64_t	zsz_lwps_cap;
190 	uint64_t	zsz_shm_cap;
191 	uint64_t	zsz_shmids_cap;
192 	uint64_t	zsz_semids_cap;
193 	uint64_t	zsz_msgids_cap;
194 	uint64_t	zsz_lofi_cap;
195 
196 	uint64_t	zsz_processes;
197 	uint64_t	zsz_lwps;
198 	uint64_t	zsz_shm;
199 	uint64_t	zsz_shmids;
200 	uint64_t	zsz_semids;
201 	uint64_t	zsz_msgids;
202 	uint64_t	zsz_lofi;
203 
204 };
205 
206 struct zs_pset {
207 	list_node_t	zsp_next;
208 	char		zsp_name[ZS_PSETNAME_MAX];
209 	psetid_t	zsp_id;
210 	uint_t		zsp_cputype;
211 	time_t		zsp_start;
212 	hrtime_t	zsp_hrstart;
213 	uint_t		zsp_intervals;
214 
215 	uint64_t	zsp_online;
216 	uint64_t	zsp_size;
217 	uint64_t	zsp_min;
218 	uint64_t	zsp_max;
219 	int64_t		zsp_importance;
220 
221 	uint_t		zsp_scheds;
222 	uint64_t	zsp_cpu_shares;
223 	timestruc_t	zsp_total_time;
224 	timestruc_t	zsp_usage_kern;
225 	timestruc_t	zsp_usage_zones;
226 
227 	uint_t		zsp_nusage;
228 	list_t		zsp_usage_list;
229 };
230 
231 struct zs_usage {
232 	time_t		zsu_start;
233 	hrtime_t	zsu_hrstart;
234 	time_t		zsu_time;
235 	hrtime_t	zsu_hrtime;
236 	uint64_t	zsu_size;
237 	uint_t		zsu_intervals;
238 	uint64_t	zsu_gen;
239 	boolean_t	zsu_mmap;
240 	uint_t		zsu_nzones;
241 	uint_t		zsu_npsets;
242 	zs_system_t	*zsu_system;
243 	list_t		zsu_zone_list;
244 	list_t		zsu_pset_list;
245 };
246 
247 struct zs_usage_set {
248 	struct zs_usage *zsus_total;
249 	struct zs_usage *zsus_avg;
250 	struct zs_usage *zsus_high;
251 	uint_t		zsus_count;
252 };
253 
254 struct zs_property {
255 	int zsp_type;
256 	int zsp_id;
257 	union zsp_value_union {
258 		char zsv_string[ZS_PSETNAME_MAX];
259 		timestruc_t zsv_ts;
260 		double zsv_double;
261 		uint64_t zsv_uint64;
262 		int64_t zsv_int64;
263 		uint_t zsv_uint;
264 		int zsv_int;
265 	} zsp_v;
266 };
267 
268 typedef struct zs_usage_cache {
269 	int zsuc_ref;
270 	uint_t zsuc_size;
271 	uint64_t zsuc_gen;
272 	zs_usage_t *zsuc_usage;
273 } zs_usage_cache_t;
274 
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif	/* _ZONESTAT_IMPL_H */
281