Print this page
3379 Typo or undefined operation in uts/common/cpr/cpr_stat.c
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/cpr/cpr_stat.c
+++ new/usr/src/uts/common/cpr/cpr_stat.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 + * Copyright (c) 2014 Gary Mills
22 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 24 * Use is subject to license terms.
24 25 */
25 26
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 27 #include <sys/types.h>
29 28 #include <sys/ddi.h>
30 29 #include <sys/pte.h>
31 30 #include <sys/cpr.h>
32 31
33 32 /*
34 33 * Support routines for CPR statistic collection
35 34 */
36 35 struct cpr_event cpr_events_buf[CPR_E_MAX_EVENTNUM];
37 36
38 37 extern struct cpr_terminator cpr_term;
39 38
40 39 struct cpr_event *cpr_find_event(char *name, int new);
41 40
42 41 #define CPR_DEFAULT_PROMTIME 30
43 42 #define CE_START_MASK 0x8000000
44 43
45 44 /*
46 45 * Use ctp to specify another time point instead of the current time;
47 46 * Otherwise, ctp is NULL.
48 47 */
49 48 void
50 49 cpr_stat_event_start(char *name, cpr_time_t *ctp)
51 50 {
52 51 struct cpr_event *cep;
53 52 cpr_time_t tv;
54 53
55 54 if (ctp)
56 55 tv = *ctp;
57 56 else {
58 57 /* need relative time even when hrestime is stoped */
59 58 cpr_tod_get(&tv);
60 59 }
61 60
62 61 if ((cep = cpr_find_event(name, 1)) == NULL) {
63 62 cpr_err(CE_WARN, "cpr_stat: run out of event buffers");
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
64 63 return;
65 64 }
66 65 /*
67 66 * disallow entering start twice without calling end first
68 67 */
69 68 if (cep->ce_ntests & CE_START_MASK)
70 69 return;
71 70
72 71 cep->ce_ntests |= CE_START_MASK;
73 72 cep->ce_sec.stime = cep->ce_sec.etime = tv.tv_sec;
74 - cep->ce_sec.ltime = cep->ce_sec.ltime = 0;
73 + cep->ce_sec.ltime = 0;
75 74 cep->ce_msec.stime = cep->ce_msec.etime = tv.tv_nsec / 100000000;
76 - cep->ce_msec.ltime = cep->ce_msec.ltime = 0;
75 + cep->ce_msec.ltime = 0;
77 76 }
78 77
79 78 void
80 79 cpr_stat_event_end(char *name, cpr_time_t *ctp)
81 80 {
82 81 struct cpr_stat *cp = STAT;
83 82 struct cpr_event *cep;
84 83 cpr_time_t tv;
85 84
86 85 if (ctp)
87 86 tv = *ctp;
88 87 else
89 88 cpr_tod_get(&tv);
90 89
91 90 if ((cep = cpr_find_event(name, 0)) == NULL) {
92 91 #ifdef CPR_STAT
93 92 prom_printf("cpr_stat: event \"%s\" is not monitored\n", name);
94 93 #endif /* CPR_STAT */
95 94 return;
96 95 }
97 96
98 97 /*
99 98 * diallow entering end twice without calling end first
100 99 */
101 100 if (!(cep->ce_ntests & CE_START_MASK))
102 101 return;
103 102
104 103 cep->ce_ntests &= ~CE_START_MASK;
105 104 cep->ce_ntests++;
106 105
107 106 /*
108 107 * calculate seconds
109 108 */
110 109 cep->ce_sec.etime = tv.tv_sec;
111 110 cep->ce_sec.ltime = cep->ce_sec.etime - cep->ce_sec.stime;
112 111 cep->ce_sec.mtime = ((cep->ce_sec.mtime * (cep->ce_ntests - 1)) +
113 112 cep->ce_sec.ltime) / cep->ce_ntests;
114 113
115 114 /*
116 115 * calculate 100*milliseconds
117 116 */
118 117 if (cep->ce_sec.ltime == 0) {
119 118 cep->ce_msec.etime = tv.tv_nsec / 100000000;
120 119 cep->ce_msec.ltime =
121 120 (cep->ce_msec.etime <= cep->ce_msec.stime) ? 0 :
122 121 (cep->ce_msec.etime - cep->ce_msec.stime);
123 122 cep->ce_msec.mtime =
124 123 ((cep->ce_msec.mtime * (cep->ce_ntests - 1)) +
125 124 cep->ce_msec.ltime) / cep->ce_ntests;
126 125 }
127 126 cp->cs_ntests = cep->ce_ntests & ~CE_START_MASK;
128 127 }
129 128
130 129 void
131 130 cpr_stat_cleanup()
132 131 {
133 132 struct cpr_stat *cp = STAT;
134 133 struct cpr_event *cep;
135 134
136 135 for (cep = cp->cs_event_head; cep; cep = cep->ce_next) {
137 136 if ((cep->ce_ntests & CE_START_MASK) &&
138 137 strcmp(cep->ce_name, "POST CPR DELAY") != NULL) {
139 138 cpr_stat_event_end(cep->ce_name, 0);
140 139 cep->ce_ntests &= ~CE_START_MASK;
141 140 }
142 141 }
143 142 }
144 143
145 144 void
146 145 cpr_stat_init()
147 146 {
148 147 STAT->cs_real_statefsz = 0;
149 148 STAT->cs_dumped_statefsz = 0;
150 149 }
151 150
152 151 void
153 152 cpr_stat_record_events()
154 153 {
155 154 if (cpr_term.real_statef_size) {
156 155 int cur_comprate;
157 156
158 157 STAT->cs_real_statefsz = cpr_term.real_statef_size;
159 158 cur_comprate = ((longlong_t)((longlong_t)
160 159 STAT->cs_nocomp_statefsz*100)/
161 160 STAT->cs_real_statefsz);
162 161 if (STAT->cs_min_comprate == 0 ||
163 162 (STAT->cs_min_comprate > cur_comprate))
164 163 STAT->cs_min_comprate = cur_comprate;
165 164 }
166 165 }
167 166
168 167 void
169 168 cpr_stat_event_print()
170 169 {
171 170 struct cpr_stat *cp = STAT;
172 171 struct cpr_event *cep;
173 172 char *fmt, *tabs;
174 173 int len;
175 174
176 175 printf("\n");
177 176 printf("---------------\t\tCPR PERFORMANCE SUMMARY\t\t-------------\n");
178 177 printf("Events\t\t\tRepeat[times]\tMeantime[sec]\tLastEvnt[sec]\n");
179 178
180 179 for (cep = cp->cs_event_head; cep; cep = cep->ce_next) {
181 180 len = strlen(cep->ce_name);
182 181 if (len < 8)
183 182 tabs = "\t\t\t";
184 183 else if (len < 16)
185 184 tabs = "\t\t";
186 185 else
187 186 tabs = "\t";
188 187 if (strcmp(cep->ce_name, "Suspend Total") == NULL ||
189 188 strcmp(cep->ce_name, "Resume Total") == NULL ||
190 189 strcmp(cep->ce_name, "POST CPR DELAY") == NULL ||
191 190 strcmp(cep->ce_name, "WHOLE CYCLE") == NULL)
192 191 fmt = "%s%s%d\t\t%3d.%1d\t\t%3d.%1d\n";
193 192 else
194 193 fmt = "%s%s%d\t\t %3d.%1d\t\t %3d.%1d\n";
195 194 printf(fmt, cep->ce_name, tabs, (int)cep->ce_ntests,
196 195 (int)cep->ce_sec.mtime, (int)(cep->ce_msec.mtime / 10),
197 196 (int)cep->ce_sec.ltime, (int)(cep->ce_msec.ltime / 10));
198 197 }
199 198 delay(drv_usectohz(10000)); /* otherwise the next line goes to prom */
200 199 /*
201 200 * print the rest of the stat data
202 201 */
203 202 printf("\nMISCELLANEOUS STATISTICS INFORMATION (units in KBytes)\n\n");
204 203 printf("\tUser Pages w/o Swapspace:\t%8lu (%lu pages)\n",
205 204 cp->cs_nosw_pages*PAGESIZE/1000, cp->cs_nosw_pages);
206 205 printf("\tTotal Upages Saved to Statefile:%8d (%d pages)\n",
207 206 cp->cs_upage2statef*PAGESIZE/1000, cp->cs_upage2statef);
208 207 if (cp->cs_mclustsz)
209 208 printf("\tAverage Cluster Size:\t\t%8d (%d.%1d%1d pages)\n\n",
210 209 cp->cs_mclustsz/1000, cp->cs_mclustsz/PAGESIZE,
211 210 ((cp->cs_mclustsz%PAGESIZE)*10/PAGESIZE),
212 211 ((cp->cs_mclustsz%PAGESIZE)*100/PAGESIZE)%10);
213 212 printf("\tKernel Memory Size:\t\t%8lu\n", cp->cs_nocomp_statefsz/1000);
214 213 printf("\tEstimated Statefile Size:\t%8lu\n", cp->cs_est_statefsz/1000);
215 214 printf("\tActual Statefile Size:\t\t%8lu\n", cp->cs_real_statefsz/1000);
216 215 if (cp->cs_real_statefsz) {
217 216 int min = cp->cs_min_comprate;
218 217 int new = ((longlong_t)((longlong_t)
219 218 cp->cs_nocomp_statefsz*100)/cp->cs_real_statefsz);
220 219
221 220 printf("\tCompression Ratio:\t\t%5d.%1d%1d (worst %d.%1d%1d)\n",
222 221 new/100, (new%100)/10, new%10,
223 222 min/100, (min%100)/10, min%10);
224 223 }
225 224 }
226 225
227 226 struct cpr_event *
228 227 cpr_find_event(char *name, int new)
229 228 {
230 229 struct cpr_stat *cp = STAT;
231 230 struct cpr_event *cep;
232 231 int i;
233 232
234 233 for (cep = cp->cs_event_head; cep; cep = cep->ce_next) {
235 234 if (strcmp(name, cep->ce_name) == NULL)
236 235 return (cep);
237 236 }
238 237
239 238 /* if not begin not end either */
240 239 if (new == NULL)
241 240 return (NULL);
242 241
243 242 for (i = 0; i < CPR_E_MAX_EVENTNUM; i++) {
244 243 for (cep = cp->cs_event_head; cep; cep = cep->ce_next) {
245 244 if (&cpr_events_buf[i] == cep)
246 245 break;
247 246 }
248 247 if (!cep) {
249 248 struct cpr_event *new_cep;
250 249
251 250 new_cep = &cpr_events_buf[i];
252 251 (void) strcpy(new_cep->ce_name, name);
253 252
254 253 if (!cp->cs_event_head) {
255 254 /* The 1st one */
256 255 cp->cs_event_head = new_cep;
257 256 } else {
258 257 /* insert to tail */
259 258 new_cep->ce_next = cp->cs_event_tail->ce_next;
260 259 cp->cs_event_tail->ce_next = new_cep;
261 260 }
262 261 cp->cs_event_tail = new_cep;
263 262 return (new_cep);
264 263 }
265 264 }
266 265 return (NULL);
267 266 }
268 267
269 268 static time_t min_promtime;
270 269
271 270 void
272 271 cpr_convert_promtime(cpr_time_t *pop)
273 272 {
274 273 time_t pwroff_time, cb_time;
275 274 cpr_time_t *startp, *shdnp, *endp;
276 275
277 276 startp = &cpr_term.tm_cprboot_start;
278 277 shdnp = &cpr_term.tm_shutdown;
279 278 endp = &cpr_term.tm_cprboot_end;
280 279
281 280 cb_time = endp->tv_sec - startp->tv_sec;
282 281
283 282 cpr_tod_get(endp);
284 283 startp->tv_sec = endp->tv_sec - cb_time;
285 284
286 285 if (min_promtime == 0 ||
287 286 min_promtime > (endp->tv_sec - shdnp->tv_sec - cb_time))
288 287 min_promtime = endp->tv_sec - shdnp->tv_sec - cb_time;
289 288
290 289 if (min_promtime > CPR_DEFAULT_PROMTIME)
291 290 min_promtime = CPR_DEFAULT_PROMTIME;
292 291
293 292 pwroff_time = startp->tv_sec - shdnp->tv_sec - min_promtime;
294 293
295 294 wholecycle_tv.tv_sec += pwroff_time; /* offset the poweroff time */
296 295
297 296 pop->tv_sec = startp->tv_sec - min_promtime;
298 297 }
↓ open down ↓ |
212 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX