1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte * CDDL HEADER START
3fcf3ce44SJohn Forte *
4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte *
8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte * and limitations under the License.
12fcf3ce44SJohn Forte *
13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte *
19fcf3ce44SJohn Forte * CDDL HEADER END
20fcf3ce44SJohn Forte */
21*570de38fSSurya Prakki
22fcf3ce44SJohn Forte /*
23*570de38fSSurya Prakki * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24fcf3ce44SJohn Forte * Use is subject to license terms.
25fcf3ce44SJohn Forte */
26fcf3ce44SJohn Forte
27fcf3ce44SJohn Forte #include <errno.h>
28fcf3ce44SJohn Forte #include <stdio.h>
29fcf3ce44SJohn Forte #include <unistd.h>
30fcf3ce44SJohn Forte #include <strings.h>
31fcf3ce44SJohn Forte #include <stdlib.h>
32fcf3ce44SJohn Forte
33fcf3ce44SJohn Forte #include <sys/types.h>
34fcf3ce44SJohn Forte #include <sys/time.h>
35fcf3ce44SJohn Forte #include <sys/nsctl/sdbc_ioctl.h>
36fcf3ce44SJohn Forte #include <sys/nsctl/rdc_ioctl.h>
37fcf3ce44SJohn Forte #include <sys/nsctl/sd_bcache.h>
38fcf3ce44SJohn Forte #include <sys/nsctl/sd_conf.h>
39fcf3ce44SJohn Forte #include <sys/nsctl/rdc_io.h>
40fcf3ce44SJohn Forte #include <sys/nsctl/rdc_bitmap.h>
41fcf3ce44SJohn Forte #include <sys/unistat/spcs_s_u.h>
42fcf3ce44SJohn Forte #include <curses.h>
43fcf3ce44SJohn Forte
44fcf3ce44SJohn Forte static rdc_status_t *rdc_status;
45fcf3ce44SJohn Forte static rdc_u_info_t *rdc_info;
46fcf3ce44SJohn Forte static int rdc_maxsets;
47fcf3ce44SJohn Forte static int rdc_enabled_sets;
48fcf3ce44SJohn Forte
49fcf3ce44SJohn Forte static unsigned prev_time, delta_time;
50fcf3ce44SJohn Forte #ifdef m88k
51fcf3ce44SJohn Forte extern unsigned *usec_ptr;
52fcf3ce44SJohn Forte #endif
53fcf3ce44SJohn Forte static int bright = 0;
54fcf3ce44SJohn Forte
55fcf3ce44SJohn Forte extern int sdbc_max_devices;
56fcf3ce44SJohn Forte
57fcf3ce44SJohn Forte extern _sd_stats_t *cs_cur;
58fcf3ce44SJohn Forte extern _sd_stats_t *cs_prev;
59fcf3ce44SJohn Forte extern _sd_stats_t *cs_persec;
60fcf3ce44SJohn Forte
61fcf3ce44SJohn Forte extern int *on_off;
62fcf3ce44SJohn Forte extern int *dual_on_off;
63fcf3ce44SJohn Forte extern int *updates_prev;
64fcf3ce44SJohn Forte extern double *rate_prev;
65fcf3ce44SJohn Forte extern int *samples;
66fcf3ce44SJohn Forte
67fcf3ce44SJohn Forte int range_num = 0;
68fcf3ce44SJohn Forte int screen = 0;
69fcf3ce44SJohn Forte int dual_screen = 0;
70fcf3ce44SJohn Forte static int rnum = 0;
71fcf3ce44SJohn Forte
72fcf3ce44SJohn Forte typedef struct {
73fcf3ce44SJohn Forte int lb, ub;
74fcf3ce44SJohn Forte } range_t;
75fcf3ce44SJohn Forte range_t ranges[100];
76fcf3ce44SJohn Forte
77fcf3ce44SJohn Forte extern int range_first();
78fcf3ce44SJohn Forte extern int range_next(int);
79fcf3ce44SJohn Forte extern int range_last();
80fcf3ce44SJohn Forte
81fcf3ce44SJohn Forte static int dual_initted = 0;
82fcf3ce44SJohn Forte static char status[11][30];
83fcf3ce44SJohn Forte
84fcf3ce44SJohn Forte unsigned dc_delta_time, dc_prev_time;
85fcf3ce44SJohn Forte
86fcf3ce44SJohn Forte #ifdef m88k
87fcf3ce44SJohn Forte #define USEC_INIT() usec_ptr = (unsigned int *)timer_init()
88fcf3ce44SJohn Forte #define USEC_READ() (*usec_ptr)
89fcf3ce44SJohn Forte #else /* !m88k */
90fcf3ce44SJohn Forte #define USEC_INIT() USEC_START()
91fcf3ce44SJohn Forte #include <sys/time.h>
92fcf3ce44SJohn Forte static struct timeval Usec_time;
93fcf3ce44SJohn Forte static int Usec_started = 0;
94fcf3ce44SJohn Forte
95fcf3ce44SJohn Forte void total_display(void);
96fcf3ce44SJohn Forte void disp_stats(void);
97fcf3ce44SJohn Forte void do_calc(void);
98fcf3ce44SJohn Forte void init_dual(void);
99fcf3ce44SJohn Forte void calc_time(void);
100fcf3ce44SJohn Forte void calc_completion(int, int, int);
101fcf3ce44SJohn Forte void disp_total_stats(void);
102fcf3ce44SJohn Forte void display_cache(void);
103fcf3ce44SJohn Forte
104fcf3ce44SJohn Forte #define DISPLEN 16
105fcf3ce44SJohn Forte
106fcf3ce44SJohn Forte static void
USEC_START(void)107fcf3ce44SJohn Forte USEC_START(void)
108fcf3ce44SJohn Forte {
109fcf3ce44SJohn Forte if (!Usec_started) {
110fcf3ce44SJohn Forte (void) gettimeofday(&Usec_time, NULL);
111fcf3ce44SJohn Forte Usec_started = 1;
112fcf3ce44SJohn Forte }
113fcf3ce44SJohn Forte }
114fcf3ce44SJohn Forte
115fcf3ce44SJohn Forte static unsigned int
USEC_READ()116fcf3ce44SJohn Forte USEC_READ()
117fcf3ce44SJohn Forte {
118fcf3ce44SJohn Forte struct timeval tv;
119fcf3ce44SJohn Forte if (!Usec_started)
120fcf3ce44SJohn Forte USEC_START();
121fcf3ce44SJohn Forte
122fcf3ce44SJohn Forte (void) gettimeofday(&tv, NULL);
123fcf3ce44SJohn Forte return (unsigned)((tv.tv_sec - Usec_time.tv_sec) * 1000000 +
124fcf3ce44SJohn Forte (tv.tv_usec - Usec_time.tv_usec));
125fcf3ce44SJohn Forte }
126fcf3ce44SJohn Forte #endif /* m88k */
127fcf3ce44SJohn Forte
128fcf3ce44SJohn Forte #define SAMPLE_RATE 5
129fcf3ce44SJohn Forte
130fcf3ce44SJohn Forte /*
131fcf3ce44SJohn Forte * refresh curses window to file
132fcf3ce44SJohn Forte */
133fcf3ce44SJohn Forte void
wrefresh_file(WINDOW * win,int fd)134fcf3ce44SJohn Forte wrefresh_file(WINDOW *win, int fd)
135fcf3ce44SJohn Forte {
136fcf3ce44SJohn Forte char buf[8192], c, *cp = buf, *line, *blank, *empty;
137fcf3ce44SJohn Forte int x, y;
138fcf3ce44SJohn Forte
139fcf3ce44SJohn Forte empty = NULL; /* cull trailing empty lines */
140fcf3ce44SJohn Forte for (y = 0; y < win->_maxy; y++) {
141fcf3ce44SJohn Forte line = cp;
142fcf3ce44SJohn Forte blank = NULL; /* cull trailing blanks */
143fcf3ce44SJohn Forte for (x = 0; x < win->_maxx; x++) {
144fcf3ce44SJohn Forte c = (win->_y[y][x]) & A_CHARTEXT;
145fcf3ce44SJohn Forte if (c != ' ')
146fcf3ce44SJohn Forte blank = NULL;
147fcf3ce44SJohn Forte else if (blank == NULL)
148fcf3ce44SJohn Forte blank = cp;
149fcf3ce44SJohn Forte *cp++ = c;
150fcf3ce44SJohn Forte }
151fcf3ce44SJohn Forte if (blank)
152fcf3ce44SJohn Forte cp = blank;
153fcf3ce44SJohn Forte if (line != cp)
154fcf3ce44SJohn Forte empty = NULL;
155fcf3ce44SJohn Forte else if (empty == NULL)
156fcf3ce44SJohn Forte empty = cp + 1;
157fcf3ce44SJohn Forte *cp++ = '\n';
158fcf3ce44SJohn Forte }
159fcf3ce44SJohn Forte if (empty)
160fcf3ce44SJohn Forte cp = empty;
161fcf3ce44SJohn Forte *cp++ = '\f'; *cp++ = '\n'; *cp = '\0';
162fcf3ce44SJohn Forte /* cp is eliminated by short _maxy and _maxx, it won't overflow */
163fcf3ce44SJohn Forte /* LINTED, cp - buf won't be > INT32_MAX */
164fcf3ce44SJohn Forte (void) write(fd, buf, cp - buf);
165fcf3ce44SJohn Forte }
166fcf3ce44SJohn Forte
167fcf3ce44SJohn Forte
168fcf3ce44SJohn Forte int
higher(int high)169fcf3ce44SJohn Forte higher(int high)
170fcf3ce44SJohn Forte {
171fcf3ce44SJohn Forte int i;
172fcf3ce44SJohn Forte
173fcf3ce44SJohn Forte for (i = high + 1; i <= sdbc_max_devices; i++) {
174fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_alloc)
175fcf3ce44SJohn Forte return (i);
176fcf3ce44SJohn Forte }
177fcf3ce44SJohn Forte return (0);
178fcf3ce44SJohn Forte }
179fcf3ce44SJohn Forte
180fcf3ce44SJohn Forte int
is_dirty()181fcf3ce44SJohn Forte is_dirty()
182fcf3ce44SJohn Forte {
183fcf3ce44SJohn Forte int i, dirty = 0;
184fcf3ce44SJohn Forte spcs_s_info_t ustats;
185fcf3ce44SJohn Forte
186fcf3ce44SJohn Forte if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0,
187fcf3ce44SJohn Forte &ustats) == SPCS_S_ERROR) {
188fcf3ce44SJohn Forte perror("Could not get stats from kernel");
189fcf3ce44SJohn Forte if (ustats) {
190fcf3ce44SJohn Forte spcs_s_report(ustats, stderr);
191fcf3ce44SJohn Forte spcs_s_ufree(&ustats);
192fcf3ce44SJohn Forte }
193fcf3ce44SJohn Forte return (-errno);
194fcf3ce44SJohn Forte }
195fcf3ce44SJohn Forte if (cs_cur->st_cachesize == 0)
196fcf3ce44SJohn Forte return (0);
197fcf3ce44SJohn Forte
198fcf3ce44SJohn Forte for (i = 0; i < cs_cur->st_count; i++) {
199fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_alloc)
200fcf3ce44SJohn Forte dirty += cs_cur->st_shared[i].sh_numdirty;
201fcf3ce44SJohn Forte }
202fcf3ce44SJohn Forte
203fcf3ce44SJohn Forte return (dirty != 0);
204fcf3ce44SJohn Forte }
205fcf3ce44SJohn Forte
206fcf3ce44SJohn Forte void
display_cache(void)207fcf3ce44SJohn Forte display_cache(void)
208fcf3ce44SJohn Forte {
209fcf3ce44SJohn Forte static int first = 1;
210fcf3ce44SJohn Forte spcs_s_info_t ustats;
211fcf3ce44SJohn Forte
212fcf3ce44SJohn Forte if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats) ==
213fcf3ce44SJohn Forte SPCS_S_ERROR) {
214fcf3ce44SJohn Forte perror("sd_stats");
215fcf3ce44SJohn Forte if (ustats) {
216fcf3ce44SJohn Forte spcs_s_report(ustats, stderr);
217fcf3ce44SJohn Forte spcs_s_ufree(&ustats);
218fcf3ce44SJohn Forte }
219fcf3ce44SJohn Forte }
220fcf3ce44SJohn Forte
221fcf3ce44SJohn Forte do_calc();
222fcf3ce44SJohn Forte if (first) {
223fcf3ce44SJohn Forte prev_time = USEC_READ();
224fcf3ce44SJohn Forte first = 0;
225fcf3ce44SJohn Forte } else
226fcf3ce44SJohn Forte disp_stats();
227fcf3ce44SJohn Forte }
228fcf3ce44SJohn Forte
229fcf3ce44SJohn Forte void
total_display(void)230fcf3ce44SJohn Forte total_display(void)
231fcf3ce44SJohn Forte {
232fcf3ce44SJohn Forte spcs_s_info_t ustats;
233fcf3ce44SJohn Forte
234fcf3ce44SJohn Forte if (SDBC_IOCTL(SDBC_STATS, cs_cur, 0, 0, 0, 0, &ustats) ==
235fcf3ce44SJohn Forte SPCS_S_ERROR) {
236fcf3ce44SJohn Forte if (ustats) {
237fcf3ce44SJohn Forte spcs_s_report(ustats, stderr);
238fcf3ce44SJohn Forte spcs_s_ufree(&ustats);
239fcf3ce44SJohn Forte }
240fcf3ce44SJohn Forte perror("sd_stats");
241fcf3ce44SJohn Forte }
242fcf3ce44SJohn Forte disp_total_stats();
243fcf3ce44SJohn Forte }
244fcf3ce44SJohn Forte
245fcf3ce44SJohn Forte
246fcf3ce44SJohn Forte int
range_first()247fcf3ce44SJohn Forte range_first()
248fcf3ce44SJohn Forte {
249fcf3ce44SJohn Forte rnum = 0;
250fcf3ce44SJohn Forte return (ranges[rnum].lb);
251fcf3ce44SJohn Forte }
252fcf3ce44SJohn Forte
253fcf3ce44SJohn Forte int
range_next(int cd)254fcf3ce44SJohn Forte range_next(int cd)
255fcf3ce44SJohn Forte {
256fcf3ce44SJohn Forte if (ranges[rnum].ub > cd)
257fcf3ce44SJohn Forte return (cd + 1);
258fcf3ce44SJohn Forte if (range_num > rnum)
259fcf3ce44SJohn Forte rnum++;
260fcf3ce44SJohn Forte else
261fcf3ce44SJohn Forte return (cd + 1);
262fcf3ce44SJohn Forte return (ranges[rnum].lb);
263fcf3ce44SJohn Forte }
264fcf3ce44SJohn Forte
265fcf3ce44SJohn Forte int
range_last()266fcf3ce44SJohn Forte range_last() {
267fcf3ce44SJohn Forte return (ranges[range_num].ub);
268fcf3ce44SJohn Forte }
269fcf3ce44SJohn Forte
270fcf3ce44SJohn Forte
271fcf3ce44SJohn Forte void
set_dual_on_off()272fcf3ce44SJohn Forte set_dual_on_off()
273fcf3ce44SJohn Forte {
274fcf3ce44SJohn Forte int i, j, ct = 0, newct = 0;
275fcf3ce44SJohn Forte
276fcf3ce44SJohn Forte for (i = range_first(); i < rdc_enabled_sets && i <= range_last();
277fcf3ce44SJohn Forte i = range_next(i)) {
278fcf3ce44SJohn Forte if (rdc_info[i].flags & RDC_ENABLED) {
279fcf3ce44SJohn Forte ct++;
280fcf3ce44SJohn Forte if (ct > dual_screen * ((LINES - 9) / 2))
281fcf3ce44SJohn Forte break;
282fcf3ce44SJohn Forte }
283fcf3ce44SJohn Forte }
284fcf3ce44SJohn Forte if (((i >= rdc_enabled_sets) ||
285fcf3ce44SJohn Forte (i > range_last())) && (dual_screen > 0)) {
286fcf3ce44SJohn Forte dual_screen--;
287fcf3ce44SJohn Forte set_dual_on_off();
288fcf3ce44SJohn Forte } else {
289fcf3ce44SJohn Forte bzero(dual_on_off, sdbc_max_devices * sizeof (int));
290fcf3ce44SJohn Forte for (j = i; j < rdc_enabled_sets && j <= range_last();
291fcf3ce44SJohn Forte j = range_next(j)) {
292fcf3ce44SJohn Forte if (rdc_info[j].flags & RDC_ENABLED) {
293fcf3ce44SJohn Forte newct++;
294fcf3ce44SJohn Forte if (newct <= (LINES - 9) / 2) {
295fcf3ce44SJohn Forte dual_on_off[j] = 1;
296fcf3ce44SJohn Forte } else
297fcf3ce44SJohn Forte break;
298fcf3ce44SJohn Forte }
299fcf3ce44SJohn Forte }
300fcf3ce44SJohn Forte }
301fcf3ce44SJohn Forte }
302fcf3ce44SJohn Forte
303fcf3ce44SJohn Forte
304fcf3ce44SJohn Forte void
set_on_off()305fcf3ce44SJohn Forte set_on_off()
306fcf3ce44SJohn Forte {
307fcf3ce44SJohn Forte int i, j, ct = 0, newct = 0;
308fcf3ce44SJohn Forte
309fcf3ce44SJohn Forte for (i = range_first(); i <= range_last(); i = range_next(i)) {
310fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_alloc) {
311fcf3ce44SJohn Forte ct++;
312fcf3ce44SJohn Forte if (ct > screen*((LINES - 9) / 2))
313fcf3ce44SJohn Forte break;
314fcf3ce44SJohn Forte }
315fcf3ce44SJohn Forte }
316fcf3ce44SJohn Forte if ((i > range_last()) && (screen > 0)) {
317fcf3ce44SJohn Forte screen--;
318fcf3ce44SJohn Forte set_on_off();
319fcf3ce44SJohn Forte } else {
320fcf3ce44SJohn Forte bzero(on_off, sdbc_max_devices * sizeof (int));
321fcf3ce44SJohn Forte for (j = i; j <= range_last(); j = range_next(j)) {
322fcf3ce44SJohn Forte if (cs_cur->st_shared[j].sh_alloc) {
323fcf3ce44SJohn Forte newct++;
324fcf3ce44SJohn Forte if (newct <= (LINES - 9) / 2)
325fcf3ce44SJohn Forte on_off[j] = 1;
326fcf3ce44SJohn Forte else
327fcf3ce44SJohn Forte break;
328fcf3ce44SJohn Forte }
329fcf3ce44SJohn Forte }
330fcf3ce44SJohn Forte }
331fcf3ce44SJohn Forte }
332fcf3ce44SJohn Forte
333fcf3ce44SJohn Forte void
disp_stats(void)334fcf3ce44SJohn Forte disp_stats(void)
335fcf3ce44SJohn Forte {
336fcf3ce44SJohn Forte double read_s, write_s, access_s, readp, writep;
337fcf3ce44SJohn Forte double rmiss_s, wmiss_s;
338fcf3ce44SJohn Forte double elapsed = delta_time / 1000000.0;
339fcf3ce44SJohn Forte double kbps = elapsed * 1024.0; /* for Kbytes per second */
340fcf3ce44SJohn Forte int rtotal, wtotal, i, j;
341fcf3ce44SJohn Forte double throughput = 0.0, rthroughput = 0.0;
342fcf3ce44SJohn Forte double creads = 0.0, cwrites = 0.0;
343fcf3ce44SJohn Forte char status_bit, down = 0;
344fcf3ce44SJohn Forte int len;
345fcf3ce44SJohn Forte char fn[19];
346fcf3ce44SJohn Forte
347fcf3ce44SJohn Forte if (delta_time != 0) {
348fcf3ce44SJohn Forte read_s = cs_persec->st_rdhits / elapsed;
349fcf3ce44SJohn Forte write_s = cs_persec->st_wrhits / elapsed;
350fcf3ce44SJohn Forte rmiss_s = cs_persec->st_rdmiss / elapsed;
351fcf3ce44SJohn Forte wmiss_s = cs_persec->st_wrmiss / elapsed;
352fcf3ce44SJohn Forte access_s = (cs_persec->st_wrhits + cs_persec->st_rdhits +
353fcf3ce44SJohn Forte cs_persec->st_rdmiss + cs_persec->st_wrmiss) / elapsed;
354fcf3ce44SJohn Forte } else
355fcf3ce44SJohn Forte read_s = write_s = access_s = 0.0;
356fcf3ce44SJohn Forte
357fcf3ce44SJohn Forte rtotal = cs_persec->st_rdhits + cs_persec->st_rdmiss;
358fcf3ce44SJohn Forte wtotal = cs_persec->st_wrhits + cs_persec->st_wrmiss;
359fcf3ce44SJohn Forte if (rtotal != 0)
360fcf3ce44SJohn Forte readp = cs_persec->st_rdhits / (double)rtotal;
361fcf3ce44SJohn Forte else
362fcf3ce44SJohn Forte readp = 0.0;
363fcf3ce44SJohn Forte
364fcf3ce44SJohn Forte if (wtotal != 0) {
365fcf3ce44SJohn Forte writep = cs_persec->st_wrhits / (double)wtotal;
366fcf3ce44SJohn Forte } else
367fcf3ce44SJohn Forte writep = 0.0;
368fcf3ce44SJohn Forte
369fcf3ce44SJohn Forte set_on_off();
370fcf3ce44SJohn Forte if (cs_cur->st_cachesize == 0)
371fcf3ce44SJohn Forte (void) mvprintw(0, 20, "****** Storage Cache Disabled ******");
372fcf3ce44SJohn Forte else
373fcf3ce44SJohn Forte (void) mvprintw(0, 20, "****** Storage Cache ******");
374fcf3ce44SJohn Forte (void) mvprintw(2, 26, "disk_io cache write_blocks");
375fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
376fcf3ce44SJohn Forte (void) mvprintw(3, 1, " cd cached_partition reads writes reads writes"
377fcf3ce44SJohn Forte " dirty todisk failed");
378fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
379fcf3ce44SJohn Forte for (i = 0, j = 0; j < cs_cur->st_count; i++) {
380fcf3ce44SJohn Forte if (i >= sdbc_max_devices)
381fcf3ce44SJohn Forte break;
382fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_alloc) {
383fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_disk_write /= kbps;
384fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_disk_read /= kbps;
385fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_cache_write /= kbps;
386fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_cache_read /= kbps;
387fcf3ce44SJohn Forte rthroughput += cs_persec->st_shared[i].sh_disk_read;
388fcf3ce44SJohn Forte throughput += cs_persec->st_shared[i].sh_disk_write;
389fcf3ce44SJohn Forte creads += cs_persec->st_shared[i].sh_cache_read;
390fcf3ce44SJohn Forte cwrites += cs_persec->st_shared[i].sh_cache_write;
391fcf3ce44SJohn Forte if (!down)
392fcf3ce44SJohn Forte down = cs_cur->st_shared[i].sh_failed;
393fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_failed && bright) {
394fcf3ce44SJohn Forte status_bit = '*';
395fcf3ce44SJohn Forte } else
396fcf3ce44SJohn Forte status_bit = ' ';
397fcf3ce44SJohn Forte if ((len = strlen(cs_cur->st_shared[i].sh_filename))
398fcf3ce44SJohn Forte > 15) {
399*570de38fSSurya Prakki (void) strcpy(fn, "...");
400*570de38fSSurya Prakki (void) strcat(fn,
401*570de38fSSurya Prakki cs_cur->st_shared[i].sh_filename +
402fcf3ce44SJohn Forte len - 12);
403fcf3ce44SJohn Forte } else
404*570de38fSSurya Prakki (void) strcpy(fn,
405*570de38fSSurya Prakki cs_cur->st_shared[i].sh_filename);
406fcf3ce44SJohn Forte if (on_off[i]) {
407fcf3ce44SJohn Forte (void) mvprintw(4 + j, 1,
408fcf3ce44SJohn Forte "%3d %-15s%c %6d %6d %6d %6d %6d %6d %6d",
409fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_cd,
410fcf3ce44SJohn Forte fn,
411fcf3ce44SJohn Forte status_bit,
412fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_disk_read,
413fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_disk_write,
414fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_cache_read,
415fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_cache_write,
416fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_numdirty,
417fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_numio,
418fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_numfail);
419fcf3ce44SJohn Forte j++;
420fcf3ce44SJohn Forte }
421fcf3ce44SJohn Forte }
422fcf3ce44SJohn Forte }
423fcf3ce44SJohn Forte bright = !bright;
424fcf3ce44SJohn Forte
425fcf3ce44SJohn Forte (void) mvprintw(4 + j, 22, "------ ------ ------ ------");
426fcf3ce44SJohn Forte (void) mvprintw(5 + j, 6, " Kbytes/s total:%6d %6d %6d %6d",
427fcf3ce44SJohn Forte (int)rthroughput, (int)throughput,
428fcf3ce44SJohn Forte (int)creads, (int)cwrites);
429fcf3ce44SJohn Forte (void) mvprintw(7 + j, 1, "accesses/s");
430fcf3ce44SJohn Forte (void) mvprintw(7 + j, 15, "read/s write/s %%readh %%writeh");
431fcf3ce44SJohn Forte
432fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
433fcf3ce44SJohn Forte (void) mvprintw(8 + j, 1, " ");
434fcf3ce44SJohn Forte (void) mvprintw(8 + j, 13,
435fcf3ce44SJohn Forte " ");
436fcf3ce44SJohn Forte (void) mvprintw(8 + j, 13, "(misses/s) (misses/s)");
437fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
438fcf3ce44SJohn Forte
439fcf3ce44SJohn Forte (void) mvprintw(9 + j, 0, "%10.2lf %7.2f %7.2f %6.1f %6.1f",
440fcf3ce44SJohn Forte access_s, read_s, write_s, readp * 100.0, writep * 100.0);
441fcf3ce44SJohn Forte (void) mvprintw(10 + j, 0, " (%7.2f ) (%7.2f )\n\n",
442fcf3ce44SJohn Forte rmiss_s, wmiss_s);
443fcf3ce44SJohn Forte
444fcf3ce44SJohn Forte if (down)
445fcf3ce44SJohn Forte (void) mvprintw(20 + j, 1, "* -- disk off-line");
446fcf3ce44SJohn Forte }
447fcf3ce44SJohn Forte
448fcf3ce44SJohn Forte void
do_calc(void)449fcf3ce44SJohn Forte do_calc(void)
450fcf3ce44SJohn Forte {
451fcf3ce44SJohn Forte int i, j;
452fcf3ce44SJohn Forte
453fcf3ce44SJohn Forte delta_time = USEC_READ() - prev_time;
454fcf3ce44SJohn Forte
455fcf3ce44SJohn Forte cs_persec->st_rdhits = cs_cur->st_rdhits - cs_prev->st_rdhits;
456fcf3ce44SJohn Forte cs_persec->st_rdmiss = cs_cur->st_rdmiss - cs_prev->st_rdmiss;
457fcf3ce44SJohn Forte cs_persec->st_wrhits = cs_cur->st_wrhits - cs_prev->st_wrhits;
458fcf3ce44SJohn Forte cs_persec->st_wrmiss = cs_cur->st_wrmiss - cs_prev->st_wrmiss;
459fcf3ce44SJohn Forte
460fcf3ce44SJohn Forte for (i = 0, j = 0; j < cs_cur->st_count; i++) {
461fcf3ce44SJohn Forte if (i >= sdbc_max_devices)
462fcf3ce44SJohn Forte break;
463fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_alloc) {
464fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_disk_write =
465fcf3ce44SJohn Forte FBA_SIZE(cs_cur->st_shared[i].sh_disk_write -
466fcf3ce44SJohn Forte cs_prev->st_shared[i].sh_disk_write);
467fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_disk_read =
468fcf3ce44SJohn Forte FBA_SIZE(cs_cur->st_shared[i].sh_disk_read -
469fcf3ce44SJohn Forte cs_prev->st_shared[i].sh_disk_read);
470fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_cache_read =
471fcf3ce44SJohn Forte FBA_SIZE(cs_cur->st_shared[i].sh_cache_read -
472fcf3ce44SJohn Forte cs_prev->st_shared[i].sh_cache_read);
473fcf3ce44SJohn Forte cs_persec->st_shared[i].sh_cache_write =
474fcf3ce44SJohn Forte FBA_SIZE(cs_cur->st_shared[i].sh_cache_write -
475fcf3ce44SJohn Forte cs_prev->st_shared[i].sh_cache_write);
476fcf3ce44SJohn Forte j++;
477fcf3ce44SJohn Forte }
478fcf3ce44SJohn Forte }
479fcf3ce44SJohn Forte (void) memcpy((char *) cs_prev, (char *) cs_cur, sizeof (_sd_stats_t) +
480fcf3ce44SJohn Forte (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
481fcf3ce44SJohn Forte prev_time = USEC_READ();
482fcf3ce44SJohn Forte }
483fcf3ce44SJohn Forte
484fcf3ce44SJohn Forte
485fcf3ce44SJohn Forte void
init_dual(void)486fcf3ce44SJohn Forte init_dual(void)
487fcf3ce44SJohn Forte {
488fcf3ce44SJohn Forte #define IND_ENABLED 0
489fcf3ce44SJohn Forte #define IND_RESYNC 1
490fcf3ce44SJohn Forte #define IND_RESYNC_REVERSE 2
491fcf3ce44SJohn Forte #define IND_VOLUME_DOWN 3
492fcf3ce44SJohn Forte #define IND_MIRROR_DOWN 4
493fcf3ce44SJohn Forte #define IND_LOGGING 5
494fcf3ce44SJohn Forte #define IND_RESYNC_NEEDED 6
495fcf3ce44SJohn Forte #define IND_REV_RESYNC_NEEDED 7
496fcf3ce44SJohn Forte #define IND_BITMAP_FAILED 8
497fcf3ce44SJohn Forte #define IND_FULL_SYNC_NEEDED 9
498fcf3ce44SJohn Forte #define IND_FCAL_FAILED 10
499*570de38fSSurya Prakki (void) strcpy(status[IND_ENABLED], "replicating");
500*570de38fSSurya Prakki (void) strcpy(status[IND_RESYNC], "sync");
501*570de38fSSurya Prakki (void) strcpy(status[IND_RESYNC_REVERSE], "rev sync");
502*570de38fSSurya Prakki (void) strcpy(status[IND_VOLUME_DOWN], "volume down");
503*570de38fSSurya Prakki (void) strcpy(status[IND_MIRROR_DOWN], "mirror down");
504*570de38fSSurya Prakki (void) strcpy(status[IND_LOGGING], "logging");
505*570de38fSSurya Prakki (void) strcpy(status[IND_RESYNC_NEEDED], "need sync");
506*570de38fSSurya Prakki (void) strcpy(status[IND_REV_RESYNC_NEEDED], "need rev sync");
507*570de38fSSurya Prakki (void) strcpy(status[IND_BITMAP_FAILED], "bitmap failed");
508*570de38fSSurya Prakki (void) strcpy(status[IND_FULL_SYNC_NEEDED], "full sync needed");
509*570de38fSSurya Prakki (void) strcpy(status[IND_FCAL_FAILED], "fcal failed");
510fcf3ce44SJohn Forte dual_initted = 1;
511fcf3ce44SJohn Forte }
512fcf3ce44SJohn Forte
513fcf3ce44SJohn Forte
514fcf3ce44SJohn Forte int
rdc_get_maxsets(void)515fcf3ce44SJohn Forte rdc_get_maxsets(void)
516fcf3ce44SJohn Forte {
517fcf3ce44SJohn Forte rdc_status_t rdc_status;
518fcf3ce44SJohn Forte spcs_s_info_t ustatus;
519fcf3ce44SJohn Forte int rc;
520fcf3ce44SJohn Forte
521fcf3ce44SJohn Forte rdc_status.nset = 0;
522fcf3ce44SJohn Forte ustatus = spcs_s_ucreate();
523fcf3ce44SJohn Forte
524fcf3ce44SJohn Forte rc = RDC_IOCTL(RDC_STATUS, &rdc_status, 0, 0, 0, 0, ustatus);
525fcf3ce44SJohn Forte spcs_s_ufree(&ustatus);
526fcf3ce44SJohn Forte
527fcf3ce44SJohn Forte if (rc == SPCS_S_ERROR)
528fcf3ce44SJohn Forte return (-1);
529fcf3ce44SJohn Forte
530fcf3ce44SJohn Forte return (rdc_status.maxsets);
531fcf3ce44SJohn Forte }
532fcf3ce44SJohn Forte
533fcf3ce44SJohn Forte int
dual_stats()534fcf3ce44SJohn Forte dual_stats()
535fcf3ce44SJohn Forte {
536fcf3ce44SJohn Forte int ind, i, k, len;
537fcf3ce44SJohn Forte int stars, size, segs;
538fcf3ce44SJohn Forte int rdcindex;
539fcf3ce44SJohn Forte float pct;
540fcf3ce44SJohn Forte char fn[19];
541fcf3ce44SJohn Forte char *phost;
542fcf3ce44SJohn Forte char *shost;
543fcf3ce44SJohn Forte char *pfile;
544fcf3ce44SJohn Forte char *sfile;
545fcf3ce44SJohn Forte char lhost[16];
546fcf3ce44SJohn Forte spcs_s_info_t ustats = NULL;
547fcf3ce44SJohn Forte
548fcf3ce44SJohn Forte (void) gethostname(lhost, 16);
549fcf3ce44SJohn Forte
550fcf3ce44SJohn Forte if (rdc_maxsets <= 0)
551fcf3ce44SJohn Forte rdc_maxsets = rdc_get_maxsets();
552fcf3ce44SJohn Forte
553fcf3ce44SJohn Forte if (rdc_maxsets < 0)
554fcf3ce44SJohn Forte goto no_stats;
555fcf3ce44SJohn Forte
556fcf3ce44SJohn Forte if (!rdc_status) {
557fcf3ce44SJohn Forte rdc_status = malloc(sizeof (rdc_status_t) +
558fcf3ce44SJohn Forte (sizeof (rdc_set_t) * (rdc_maxsets - 1)));
559fcf3ce44SJohn Forte if (!rdc_status) {
560fcf3ce44SJohn Forte no_stats:
561fcf3ce44SJohn Forte (void) mvprintw(0, 20,
562fcf3ce44SJohn Forte "****** Dual Copy Not Available ******");
563fcf3ce44SJohn Forte return (-1);
564fcf3ce44SJohn Forte }
565fcf3ce44SJohn Forte
566fcf3ce44SJohn Forte rdc_info = rdc_status->rdc_set;
567fcf3ce44SJohn Forte }
568fcf3ce44SJohn Forte
569fcf3ce44SJohn Forte rdc_status->nset = rdc_maxsets;
570fcf3ce44SJohn Forte ustats = spcs_s_ucreate();
571fcf3ce44SJohn Forte
572fcf3ce44SJohn Forte size = RDC_IOCTL(RDC_STATUS, rdc_status, 0, 0, 0, 0, ustats);
573fcf3ce44SJohn Forte if (size == SPCS_S_ERROR) {
574fcf3ce44SJohn Forte if (ustats) {
575fcf3ce44SJohn Forte spcs_s_report(ustats, stderr);
576fcf3ce44SJohn Forte spcs_s_ufree(&ustats);
577fcf3ce44SJohn Forte }
578fcf3ce44SJohn Forte (void) mvprintw(0, 20, "****** Dual Copy Not Available ******");
579fcf3ce44SJohn Forte return (-1);
580fcf3ce44SJohn Forte }
581fcf3ce44SJohn Forte spcs_s_ufree(&ustats);
582fcf3ce44SJohn Forte rdc_enabled_sets = rdc_status->nset;
583fcf3ce44SJohn Forte
584fcf3ce44SJohn Forte if (!dual_initted)
585fcf3ce44SJohn Forte init_dual();
586fcf3ce44SJohn Forte
587fcf3ce44SJohn Forte set_dual_on_off();
588fcf3ce44SJohn Forte
589fcf3ce44SJohn Forte calc_time();
590fcf3ce44SJohn Forte
591fcf3ce44SJohn Forte (void) mvprintw(0, 20, "****** Dual Copy Statistics ******");
592fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
593fcf3ce44SJohn Forte (void) mvprintw(2, 0, "primary");
594fcf3ce44SJohn Forte (void) mvprintw(2, 22, "link status");
595fcf3ce44SJohn Forte (void) mvprintw(2, 36, "secondary");
596fcf3ce44SJohn Forte (void) mvprintw(2, 54, "dual copy status");
597fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
598fcf3ce44SJohn Forte
599fcf3ce44SJohn Forte for (rdcindex = 0, k = 0; rdcindex < rdc_enabled_sets; rdcindex++) {
600fcf3ce44SJohn Forte if (!(rdc_info[rdcindex].flags & RDC_ENABLED) ||
601fcf3ce44SJohn Forte !dual_on_off[rdcindex])
602fcf3ce44SJohn Forte continue;
603fcf3ce44SJohn Forte
604fcf3ce44SJohn Forte if (rdc_info[rdcindex].sync_flags & RDC_VOL_FAILED)
605fcf3ce44SJohn Forte ind = IND_VOLUME_DOWN;
606fcf3ce44SJohn Forte else if (rdc_info[rdcindex].flags & RDC_FCAL_FAILED)
607fcf3ce44SJohn Forte ind = IND_FCAL_FAILED;
608fcf3ce44SJohn Forte else if (rdc_info[rdcindex].bmap_flags & RDC_BMP_FAILED)
609fcf3ce44SJohn Forte ind = IND_BITMAP_FAILED;
610fcf3ce44SJohn Forte else if (rdc_info[rdcindex].flags & RDC_LOGGING) {
611fcf3ce44SJohn Forte if (rdc_info[rdcindex].sync_flags &
612fcf3ce44SJohn Forte RDC_SYNC_NEEDED)
613fcf3ce44SJohn Forte ind = IND_RESYNC_NEEDED;
614fcf3ce44SJohn Forte else if (rdc_info[rdcindex].sync_flags &
615fcf3ce44SJohn Forte RDC_RSYNC_NEEDED)
616fcf3ce44SJohn Forte ind = IND_REV_RESYNC_NEEDED;
617fcf3ce44SJohn Forte else
618fcf3ce44SJohn Forte ind = IND_LOGGING;
619fcf3ce44SJohn Forte } else if ((rdc_info[rdcindex].flags & RDC_SLAVE) &&
620fcf3ce44SJohn Forte (rdc_info[rdcindex].flags & RDC_SYNCING)) {
621fcf3ce44SJohn Forte if (rdc_info[rdcindex].flags & RDC_PRIMARY)
622fcf3ce44SJohn Forte ind = IND_RESYNC_REVERSE;
623fcf3ce44SJohn Forte else
624fcf3ce44SJohn Forte ind = IND_RESYNC;
625fcf3ce44SJohn Forte } else if (rdc_info[rdcindex].flags & RDC_SYNCING) {
626fcf3ce44SJohn Forte if (rdc_info[rdcindex].flags & RDC_PRIMARY)
627fcf3ce44SJohn Forte ind = IND_RESYNC;
628fcf3ce44SJohn Forte else
629fcf3ce44SJohn Forte ind = IND_RESYNC_REVERSE;
630fcf3ce44SJohn Forte } else
631fcf3ce44SJohn Forte ind = IND_ENABLED;
632fcf3ce44SJohn Forte
633fcf3ce44SJohn Forte phost = rdc_info[rdcindex].primary.intf;
634fcf3ce44SJohn Forte pfile = rdc_info[rdcindex].primary.file;
635fcf3ce44SJohn Forte shost = rdc_info[rdcindex].secondary.intf;
636fcf3ce44SJohn Forte sfile = rdc_info[rdcindex].secondary.file;
637fcf3ce44SJohn Forte
638fcf3ce44SJohn Forte if ((len = strlen(phost)) > 8) {
639fcf3ce44SJohn Forte (void) mvprintw(4 + k, 0, ".%+7s:",
640fcf3ce44SJohn Forte phost + len - 7);
641fcf3ce44SJohn Forte } else
642fcf3ce44SJohn Forte (void) mvprintw(4 + k, 0, "%+8s:", phost);
643fcf3ce44SJohn Forte
644fcf3ce44SJohn Forte if ((len = strlen(pfile)) > DISPLEN) {
645fcf3ce44SJohn Forte (void) mvprintw(4 + k, 9, "...%-13s",
646fcf3ce44SJohn Forte pfile + len - DISPLEN + 3);
647fcf3ce44SJohn Forte } else
648fcf3ce44SJohn Forte (void) mvprintw(4 + k, 9, "%-16s", pfile);
649fcf3ce44SJohn Forte
650fcf3ce44SJohn Forte (void) attron(A_BOLD);
651fcf3ce44SJohn Forte (void) mvprintw(4 + k, 26, "*");
652fcf3ce44SJohn Forte (void) mvprintw(4 + k, 28, "*");
653fcf3ce44SJohn Forte
654fcf3ce44SJohn Forte (void) mvprintw(4 + k, 56, "%-8s", status[ind]);
655fcf3ce44SJohn Forte (void) attroff(A_BOLD);
656fcf3ce44SJohn Forte
657fcf3ce44SJohn Forte if (ind == IND_RESYNC_REVERSE) {
658fcf3ce44SJohn Forte if (bright && !(rdc_info[rdcindex].flags & RDC_LOGGING))
659fcf3ce44SJohn Forte (void) mvprintw(4 + k, 27, "<");
660fcf3ce44SJohn Forte if (rdc_info[rdcindex].flags & RDC_PRIMARY &&
661fcf3ce44SJohn Forte !(rdc_info[rdcindex].flags & RDC_LOGGING))
662fcf3ce44SJohn Forte calc_completion(rdcindex,
663fcf3ce44SJohn Forte rdc_info[rdcindex].bits_set, 4 + k);
664fcf3ce44SJohn Forte } else if (ind == IND_RESYNC) {
665fcf3ce44SJohn Forte if (bright && !(rdc_info[rdcindex].flags & RDC_LOGGING))
666fcf3ce44SJohn Forte (void) mvprintw(4 + k, 27, ">");
667fcf3ce44SJohn Forte if (rdc_info[rdcindex].flags & RDC_PRIMARY &&
668fcf3ce44SJohn Forte !(rdc_info[rdcindex].flags & RDC_LOGGING))
669fcf3ce44SJohn Forte calc_completion(rdcindex,
670fcf3ce44SJohn Forte rdc_info[rdcindex].bits_set, 4 + k);
671fcf3ce44SJohn Forte } else if (ind == IND_LOGGING)
672fcf3ce44SJohn Forte (void) mvprintw(4 + k, 27, ".");
673fcf3ce44SJohn Forte else if (ind == IND_ENABLED)
674fcf3ce44SJohn Forte (void) mvprintw(4 + k, 27, "=");
675fcf3ce44SJohn Forte
676fcf3ce44SJohn Forte if ((len = strlen(shost)) > 8) {
677fcf3ce44SJohn Forte (void) mvprintw(4 + k, 30, ".%+7s:",
678fcf3ce44SJohn Forte shost + len - 7);
679fcf3ce44SJohn Forte } else
680fcf3ce44SJohn Forte (void) mvprintw(4 + k, 30, "%+8s:", shost);
681fcf3ce44SJohn Forte
682fcf3ce44SJohn Forte if ((len = strlen(sfile)) > DISPLEN) {
683fcf3ce44SJohn Forte (void) mvprintw(4 + k, 39, "...%-13s",
684fcf3ce44SJohn Forte sfile + len - DISPLEN + 3);
685fcf3ce44SJohn Forte } else
686fcf3ce44SJohn Forte (void) mvprintw(4 + k, 39, "%-16s", sfile);
687fcf3ce44SJohn Forte
688fcf3ce44SJohn Forte k++;
689fcf3ce44SJohn Forte }
690fcf3ce44SJohn Forte
691fcf3ce44SJohn Forte k += 5;
692fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
693fcf3ce44SJohn Forte for (i = 0; i < 80; i++)
694fcf3ce44SJohn Forte (void) mvprintw(k, i, " ");
695fcf3ce44SJohn Forte k += 2;
696fcf3ce44SJohn Forte (void) mvprintw(k, 0, "partition");
697fcf3ce44SJohn Forte (void) mvprintw(k, 16, "recovery needed");
698fcf3ce44SJohn Forte (void) mvprintw(k, 48, "recovery completed");
699fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
700fcf3ce44SJohn Forte k += 2;
701fcf3ce44SJohn Forte
702fcf3ce44SJohn Forte for (rdcindex = 0; rdcindex < rdc_enabled_sets; rdcindex++) {
703fcf3ce44SJohn Forte if (!(rdc_info[rdcindex].flags & RDC_ENABLED) ||
704fcf3ce44SJohn Forte !dual_on_off[rdcindex])
705fcf3ce44SJohn Forte continue;
706fcf3ce44SJohn Forte
707fcf3ce44SJohn Forte if (!(rdc_info[rdcindex].flags & RDC_PRIMARY)) {
708fcf3ce44SJohn Forte continue;
709fcf3ce44SJohn Forte }
710fcf3ce44SJohn Forte if (!(rdc_info[rdcindex].flags & RDC_SLAVE) &&
711fcf3ce44SJohn Forte !(rdc_info[rdcindex].flags & RDC_SYNCING) &&
712fcf3ce44SJohn Forte !(rdc_info[rdcindex].flags & RDC_LOGGING)) {
713fcf3ce44SJohn Forte continue;
714fcf3ce44SJohn Forte }
715fcf3ce44SJohn Forte
716fcf3ce44SJohn Forte len = strlen(rdc_info[rdcindex].secondary.file);
717fcf3ce44SJohn Forte if (len > 15) {
718*570de38fSSurya Prakki (void) strcpy(fn, "...");
719*570de38fSSurya Prakki (void) strcat(fn,
720fcf3ce44SJohn Forte rdc_info[rdcindex].secondary.file + len - 12);
721fcf3ce44SJohn Forte } else
722*570de38fSSurya Prakki (void) strcpy(fn, rdc_info[rdcindex].secondary.file);
723fcf3ce44SJohn Forte (void) mvprintw(k, 0, "%-15s", fn);
724fcf3ce44SJohn Forte
725fcf3ce44SJohn Forte segs = FBA_TO_LOG_LEN(rdc_info[rdcindex].volume_size);
726fcf3ce44SJohn Forte pct = segs ?
727fcf3ce44SJohn Forte ((float)rdc_info[rdcindex].bits_set / (float)segs) : 0.0;
728fcf3ce44SJohn Forte stars = (int)(pct * 20.0);
729fcf3ce44SJohn Forte while (stars > 0) {
730fcf3ce44SJohn Forte (void) mvprintw(k, 16 + stars, "*");
731fcf3ce44SJohn Forte stars--;
732fcf3ce44SJohn Forte }
733fcf3ce44SJohn Forte (void) attron(A_BOLD);
734fcf3ce44SJohn Forte (void) mvprintw(k, 16, "[");
735fcf3ce44SJohn Forte (void) mvprintw(k, 37, "]");
736fcf3ce44SJohn Forte (void) attroff(A_BOLD);
737fcf3ce44SJohn Forte (void) mvprintw(k, 39, "%6.2f%%", pct * 100.0);
738fcf3ce44SJohn Forte
739fcf3ce44SJohn Forte if (rdc_info[rdcindex].flags & RDC_SYNCING)
740fcf3ce44SJohn Forte pct = ((float)rdc_info[rdcindex].sync_pos /
741fcf3ce44SJohn Forte (float)rdc_info[rdcindex].volume_size);
742fcf3ce44SJohn Forte else
743fcf3ce44SJohn Forte pct = 0.0;
744fcf3ce44SJohn Forte stars = (int)(pct * 20.0);
745fcf3ce44SJohn Forte while (stars > 0) {
746fcf3ce44SJohn Forte (void) mvprintw(k, 48 + stars, "*");
747fcf3ce44SJohn Forte stars--;
748fcf3ce44SJohn Forte }
749fcf3ce44SJohn Forte (void) attron(A_BOLD);
750fcf3ce44SJohn Forte (void) mvprintw(k, 48, "[");
751fcf3ce44SJohn Forte (void) mvprintw(k, 69, "]");
752fcf3ce44SJohn Forte (void) attroff(A_BOLD);
753fcf3ce44SJohn Forte (void) mvprintw(k, 70, "%6.2f%%", pct * 100.0);
754fcf3ce44SJohn Forte k++;
755fcf3ce44SJohn Forte }
756fcf3ce44SJohn Forte bright = !bright;
757fcf3ce44SJohn Forte return (0);
758fcf3ce44SJohn Forte }
759fcf3ce44SJohn Forte
760fcf3ce44SJohn Forte /*
761fcf3ce44SJohn Forte * Calculate a time interval in milliseconds using the
762fcf3ce44SJohn Forte * micosecond counter
763fcf3ce44SJohn Forte */
764fcf3ce44SJohn Forte void
calc_time(void)765fcf3ce44SJohn Forte calc_time(void)
766fcf3ce44SJohn Forte {
767fcf3ce44SJohn Forte unsigned int cur;
768fcf3ce44SJohn Forte
769fcf3ce44SJohn Forte cur = USEC_READ();
770fcf3ce44SJohn Forte dc_delta_time = cur > dc_prev_time ? cur - dc_prev_time :
771fcf3ce44SJohn Forte cur + 0xFFFFFFFF - dc_prev_time;
772fcf3ce44SJohn Forte dc_delta_time /= 1000;
773fcf3ce44SJohn Forte dc_prev_time = cur;
774fcf3ce44SJohn Forte }
775fcf3ce44SJohn Forte
776fcf3ce44SJohn Forte /*
777fcf3ce44SJohn Forte * Calculate estimated time of completion of resync
778fcf3ce44SJohn Forte */
779fcf3ce44SJohn Forte void
calc_completion(int cd,int updates_left,int l)780fcf3ce44SJohn Forte calc_completion(int cd, int updates_left, int l)
781fcf3ce44SJohn Forte {
782fcf3ce44SJohn Forte int delta_done;
783fcf3ce44SJohn Forte double rate;
784fcf3ce44SJohn Forte long time_left;
785fcf3ce44SJohn Forte long hours;
786fcf3ce44SJohn Forte long minutes;
787fcf3ce44SJohn Forte static int initted = 0;
788fcf3ce44SJohn Forte
789fcf3ce44SJohn Forte if (!initted) {
790fcf3ce44SJohn Forte updates_prev[cd] = updates_left;
791fcf3ce44SJohn Forte initted = 1;
792fcf3ce44SJohn Forte return;
793fcf3ce44SJohn Forte }
794fcf3ce44SJohn Forte
795fcf3ce44SJohn Forte /*
796fcf3ce44SJohn Forte * Caclulate updates since last check
797fcf3ce44SJohn Forte */
798fcf3ce44SJohn Forte delta_done = updates_prev[cd] - updates_left;
799fcf3ce44SJohn Forte updates_prev[cd] = updates_left;
800fcf3ce44SJohn Forte
801fcf3ce44SJohn Forte /*
802fcf3ce44SJohn Forte * If no updates, don't bother estimating completion time
803fcf3ce44SJohn Forte */
804fcf3ce44SJohn Forte if (delta_done <= 0) {
805fcf3ce44SJohn Forte samples[cd] = 0;
806fcf3ce44SJohn Forte return;
807fcf3ce44SJohn Forte }
808fcf3ce44SJohn Forte
809fcf3ce44SJohn Forte rate = delta_done * 1000.0 / dc_delta_time;
810fcf3ce44SJohn Forte
811fcf3ce44SJohn Forte /*
812fcf3ce44SJohn Forte * Calculate rate of updates as a weighted average
813fcf3ce44SJohn Forte * of previous and current rate
814fcf3ce44SJohn Forte */
815fcf3ce44SJohn Forte if (rate_prev[cd] && samples[cd] > SAMPLE_RATE)
816fcf3ce44SJohn Forte rate = (rate_prev[cd] * 4.0 + rate) / 5.0;
817fcf3ce44SJohn Forte rate_prev[cd] = rate;
818fcf3ce44SJohn Forte samples[cd]++;
819fcf3ce44SJohn Forte
820fcf3ce44SJohn Forte /*
821fcf3ce44SJohn Forte * Get enough samples before making estimate
822fcf3ce44SJohn Forte */
823fcf3ce44SJohn Forte if (samples[cd]++ < SAMPLE_RATE)
824fcf3ce44SJohn Forte return;
825fcf3ce44SJohn Forte
826fcf3ce44SJohn Forte time_left = (long)(updates_left/rate); /* time left in seconds */
827fcf3ce44SJohn Forte
828fcf3ce44SJohn Forte if (time_left < 0)
829fcf3ce44SJohn Forte return;
830fcf3ce44SJohn Forte
831fcf3ce44SJohn Forte hours = time_left / (60 * 60);
832fcf3ce44SJohn Forte time_left -= hours * (60 * 60);
833fcf3ce44SJohn Forte minutes = time_left / 60;
834fcf3ce44SJohn Forte time_left -= minutes * 60;
835fcf3ce44SJohn Forte (void) mvprintw(l, 67,
836fcf3ce44SJohn Forte "time %02d:%02d:%02d \n", hours, minutes, time_left);
837fcf3ce44SJohn Forte }
838fcf3ce44SJohn Forte
839fcf3ce44SJohn Forte void
disp_total_stats(void)840fcf3ce44SJohn Forte disp_total_stats(void)
841fcf3ce44SJohn Forte {
842fcf3ce44SJohn Forte unsigned int read_s, write_s, access_s;
843fcf3ce44SJohn Forte double readp, writep;
844fcf3ce44SJohn Forte unsigned int rmiss_s, wmiss_s;
845fcf3ce44SJohn Forte double kbps = 2.0;
846fcf3ce44SJohn Forte int rtotal, wtotal, i, j;
847fcf3ce44SJohn Forte unsigned int throughput = 0, rthroughput = 0, creads = 0, cwrites = 0;
848fcf3ce44SJohn Forte char status_bit, down = 0;
849fcf3ce44SJohn Forte int len;
850fcf3ce44SJohn Forte char fn[19];
851fcf3ce44SJohn Forte
852fcf3ce44SJohn Forte read_s = cs_cur->st_rdhits;
853fcf3ce44SJohn Forte write_s = cs_cur->st_wrhits;
854fcf3ce44SJohn Forte rmiss_s = cs_cur->st_rdmiss;
855fcf3ce44SJohn Forte wmiss_s = cs_cur->st_wrmiss;
856fcf3ce44SJohn Forte access_s = (read_s + write_s + rmiss_s + wmiss_s);
857fcf3ce44SJohn Forte
858fcf3ce44SJohn Forte rtotal = cs_cur->st_rdhits + cs_cur->st_rdmiss;
859fcf3ce44SJohn Forte wtotal = cs_cur->st_wrhits + cs_cur->st_wrmiss;
860fcf3ce44SJohn Forte if (rtotal != 0)
861fcf3ce44SJohn Forte readp = cs_cur->st_rdhits / (double)rtotal;
862fcf3ce44SJohn Forte else
863fcf3ce44SJohn Forte readp = 0.0;
864fcf3ce44SJohn Forte
865fcf3ce44SJohn Forte if (wtotal != 0)
866fcf3ce44SJohn Forte writep = cs_cur->st_wrhits / (double)wtotal;
867fcf3ce44SJohn Forte else
868fcf3ce44SJohn Forte writep = 0.0;
869fcf3ce44SJohn Forte
870fcf3ce44SJohn Forte set_on_off();
871fcf3ce44SJohn Forte (void) mvprintw(0, 14,
872fcf3ce44SJohn Forte "****** Storage Cache (Cumulative) ******");
873fcf3ce44SJohn Forte (void) mvprintw(2, 30, "disk_io cache");
874fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
875fcf3ce44SJohn Forte (void) mvprintw(3, 1,
876fcf3ce44SJohn Forte " cd cached_partition reads writes reads writes");
877fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
878fcf3ce44SJohn Forte for (i = 0, j = 0; j < cs_cur->st_count; i++) {
879fcf3ce44SJohn Forte if (i >= sdbc_max_devices)
880fcf3ce44SJohn Forte break;
881fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_alloc) {
882fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_disk_write /= kbps;
883fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_disk_read /= kbps;
884fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_cache_write /= kbps;
885fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_cache_read /= kbps;
886fcf3ce44SJohn Forte rthroughput += cs_cur->st_shared[i].sh_disk_read;
887fcf3ce44SJohn Forte throughput += cs_cur->st_shared[i].sh_disk_write;
888fcf3ce44SJohn Forte creads += cs_cur->st_shared[i].sh_cache_read;
889fcf3ce44SJohn Forte cwrites += cs_cur->st_shared[i].sh_cache_write;
890fcf3ce44SJohn Forte if (!down)
891fcf3ce44SJohn Forte down = cs_cur->st_shared[i].sh_failed;
892fcf3ce44SJohn Forte if (cs_cur->st_shared[i].sh_failed && bright)
893fcf3ce44SJohn Forte status_bit = '*';
894fcf3ce44SJohn Forte else
895fcf3ce44SJohn Forte status_bit = ' ';
896fcf3ce44SJohn Forte if ((len =
897fcf3ce44SJohn Forte strlen(cs_cur->st_shared[i].sh_filename)) > 15) {
898*570de38fSSurya Prakki (void) strcpy(fn, "...");
899*570de38fSSurya Prakki (void) strcat(fn,
900*570de38fSSurya Prakki cs_cur->st_shared[i].sh_filename +
901fcf3ce44SJohn Forte len - 12);
902fcf3ce44SJohn Forte } else
903*570de38fSSurya Prakki (void) strcpy(fn,
904*570de38fSSurya Prakki cs_cur->st_shared[i].sh_filename);
905fcf3ce44SJohn Forte
906fcf3ce44SJohn Forte if (on_off[i]) {
907fcf3ce44SJohn Forte (void) mvprintw(4 + j, 1,
908fcf3ce44SJohn Forte "%3d %-15s%c %10u %10u %10u %10u",
909fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_cd,
910fcf3ce44SJohn Forte fn,
911fcf3ce44SJohn Forte status_bit,
912fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_disk_read,
913fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_disk_write,
914fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_cache_read,
915fcf3ce44SJohn Forte cs_cur->st_shared[i].sh_cache_write);
916fcf3ce44SJohn Forte j++;
917fcf3ce44SJohn Forte }
918fcf3ce44SJohn Forte }
919fcf3ce44SJohn Forte }
920fcf3ce44SJohn Forte bright = !bright;
921fcf3ce44SJohn Forte
922fcf3ce44SJohn Forte (void) mvprintw(4 + j, 22,
923fcf3ce44SJohn Forte "---------- ---------- ---------- ----------");
924fcf3ce44SJohn Forte (void) mvprintw(5 + j, 8, " Kbytes total:%10u %10u %10u %10u",
925fcf3ce44SJohn Forte (int)rthroughput, (int)throughput,
926fcf3ce44SJohn Forte (int)creads, (int)cwrites);
927fcf3ce44SJohn Forte (void) mvprintw(7 + j, 1, " accesses");
928fcf3ce44SJohn Forte (void) mvprintw(7 + j, 18, "read write %%readh %%writeh");
929fcf3ce44SJohn Forte
930fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
931fcf3ce44SJohn Forte (void) mvprintw(8 + j, 1, " ");
932fcf3ce44SJohn Forte (void) mvprintw(8 + j, 13,
933fcf3ce44SJohn Forte " ");
934fcf3ce44SJohn Forte (void) mvprintw(8 + j, 11, "( misses) ( misses)");
935fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
936fcf3ce44SJohn Forte
937fcf3ce44SJohn Forte (void) mvprintw(9 + j, 0, "%10u %10u %10u %6.1f %6.1f",
938fcf3ce44SJohn Forte access_s, read_s, write_s, readp*100.0, writep*100.0);
939fcf3ce44SJohn Forte (void) mvprintw(10 + j, 0,
940fcf3ce44SJohn Forte " (%10u) (%10u)\n\n", rmiss_s, wmiss_s);
941fcf3ce44SJohn Forte
942fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
943fcf3ce44SJohn Forte (void) mvprintw(13 + j, 1, "cachesize blocksize");
944fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
945fcf3ce44SJohn Forte (void) mvprintw(14 + j, 1, "%8dK %10d", cs_cur->st_cachesize / 1024,
946fcf3ce44SJohn Forte cs_cur->st_blksize);
947fcf3ce44SJohn Forte
948fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
949fcf3ce44SJohn Forte (void) mvprintw(16 + j, 1, "Write blocks available:");
950fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
951fcf3ce44SJohn Forte (void) mvprintw(17 + j, 1, "Net 0: %6d", cs_cur->st_wlru_inq);
952fcf3ce44SJohn Forte
953fcf3ce44SJohn Forte (void) attron(A_UNDERLINE);
954fcf3ce44SJohn Forte (void) mvprintw(19 + j, 1, "LRU stats: Blocks Requeued Optimized");
955fcf3ce44SJohn Forte (void) attroff(A_UNDERLINE);
956fcf3ce44SJohn Forte (void) mvprintw(20 + j, 7, "%12d %12u %12u", cs_cur->st_lru_blocks,
957fcf3ce44SJohn Forte cs_cur->st_lru_req, cs_cur->st_lru_noreq);
958fcf3ce44SJohn Forte
959fcf3ce44SJohn Forte if (down)
960fcf3ce44SJohn Forte (void) mvprintw(25 + j, 1, "* -- disk off-line");
961fcf3ce44SJohn Forte }
962