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