10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2235Skk112340 * Common Development and Distribution License (the "License"). 6*2235Skk112340 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2235Skk112340 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/time.h> 290Sstevel@tonic-gate #include <stdio.h> 300Sstevel@tonic-gate #include <stdlib.h> 310Sstevel@tonic-gate #include <inttypes.h> 320Sstevel@tonic-gate #include <unistd.h> 330Sstevel@tonic-gate #include <string.h> 340Sstevel@tonic-gate #include <strings.h> 350Sstevel@tonic-gate #include <limits.h> 360Sstevel@tonic-gate #include <libintl.h> 370Sstevel@tonic-gate #include <locale.h> 380Sstevel@tonic-gate #include <errno.h> 390Sstevel@tonic-gate #include <kstat.h> 400Sstevel@tonic-gate #include <libcpc.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include "cpucmds.h" 430Sstevel@tonic-gate 440Sstevel@tonic-gate static struct options { 450Sstevel@tonic-gate int debug; 460Sstevel@tonic-gate int verbose; 470Sstevel@tonic-gate int dotitle; 480Sstevel@tonic-gate int dohelp; 490Sstevel@tonic-gate int dotick; 500Sstevel@tonic-gate int cpuver; 510Sstevel@tonic-gate char *pgmname; 520Sstevel@tonic-gate uint_t mseconds; 530Sstevel@tonic-gate uint_t nsamples; 540Sstevel@tonic-gate uint_t nsets; 550Sstevel@tonic-gate cpc_setgrp_t *master; 560Sstevel@tonic-gate int followfork; 570Sstevel@tonic-gate int followexec; 580Sstevel@tonic-gate pid_t pid; 590Sstevel@tonic-gate FILE *log; 600Sstevel@tonic-gate } __options; 610Sstevel@tonic-gate 620Sstevel@tonic-gate static const struct options *opts = (const struct options *)&__options; 630Sstevel@tonic-gate 640Sstevel@tonic-gate static cpc_t *cpc; 650Sstevel@tonic-gate 660Sstevel@tonic-gate /*ARGSUSED*/ 670Sstevel@tonic-gate static void 680Sstevel@tonic-gate cputrack_errfn(const char *fn, int subcode, const char *fmt, va_list ap) 690Sstevel@tonic-gate { 700Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", opts->pgmname); 710Sstevel@tonic-gate if (opts->debug) 720Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", fn); 730Sstevel@tonic-gate (void) vfprintf(stderr, fmt, ap); 740Sstevel@tonic-gate } 750Sstevel@tonic-gate 760Sstevel@tonic-gate static void 770Sstevel@tonic-gate cputrack_pctx_errfn(const char *fn, const char *fmt, va_list ap) 780Sstevel@tonic-gate { 790Sstevel@tonic-gate cputrack_errfn(fn, -1, fmt, ap); 800Sstevel@tonic-gate } 810Sstevel@tonic-gate 820Sstevel@tonic-gate static int cputrack(int argc, char *argv[], int optind); 830Sstevel@tonic-gate static void p4_ht_error(void); 840Sstevel@tonic-gate 850Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 860Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 870Sstevel@tonic-gate #endif 880Sstevel@tonic-gate 890Sstevel@tonic-gate int 900Sstevel@tonic-gate main(int argc, char *argv[]) 910Sstevel@tonic-gate { 920Sstevel@tonic-gate struct options *opts = &__options; 930Sstevel@tonic-gate int c, errcnt = 0; 940Sstevel@tonic-gate int nsamples; 950Sstevel@tonic-gate cpc_setgrp_t *sgrp; 960Sstevel@tonic-gate char *errstr; 970Sstevel@tonic-gate int ret; 980Sstevel@tonic-gate 990Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 1000Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate if ((opts->pgmname = strrchr(argv[0], '/')) == NULL) 1030Sstevel@tonic-gate opts->pgmname = argv[0]; 1040Sstevel@tonic-gate else 1050Sstevel@tonic-gate opts->pgmname++; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate if ((cpc = cpc_open(CPC_VER_CURRENT)) == NULL) { 1080Sstevel@tonic-gate errstr = strerror(errno); 1090Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot access performance " 1100Sstevel@tonic-gate "counter library - %s\n"), opts->pgmname, errstr); 1110Sstevel@tonic-gate return (1); 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate (void) cpc_seterrhndlr(cpc, cputrack_errfn); 1150Sstevel@tonic-gate strtoset_errfn = cputrack_errfn; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * Establish (non-zero) defaults 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate opts->mseconds = 1000; 1210Sstevel@tonic-gate opts->dotitle = 1; 1220Sstevel@tonic-gate opts->log = stdout; 1230Sstevel@tonic-gate if ((opts->master = cpc_setgrp_new(cpc, 0)) == NULL) { 1240Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: no memory available\n"), 1250Sstevel@tonic-gate opts->pgmname); 1260Sstevel@tonic-gate exit(1); 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate while ((c = getopt(argc, argv, "T:N:Defhntvo:r:c:p:")) != EOF) 1300Sstevel@tonic-gate switch (c) { 1310Sstevel@tonic-gate case 'T': /* sample time, seconds */ 1320Sstevel@tonic-gate opts->mseconds = (uint_t)(atof(optarg) * 1000.0); 1330Sstevel@tonic-gate break; 1340Sstevel@tonic-gate case 'N': /* number of samples */ 1350Sstevel@tonic-gate nsamples = atoi(optarg); 1360Sstevel@tonic-gate if (nsamples < 0) 1370Sstevel@tonic-gate errcnt++; 1380Sstevel@tonic-gate else 1390Sstevel@tonic-gate opts->nsamples = (uint_t)nsamples; 1400Sstevel@tonic-gate break; 1410Sstevel@tonic-gate case 'D': /* enable debugging */ 1420Sstevel@tonic-gate opts->debug++; 1430Sstevel@tonic-gate break; 1440Sstevel@tonic-gate case 'f': /* follow fork */ 1450Sstevel@tonic-gate opts->followfork++; 1460Sstevel@tonic-gate break; 1470Sstevel@tonic-gate case 'e': /* follow exec */ 1480Sstevel@tonic-gate opts->followexec++; 1490Sstevel@tonic-gate break; 1500Sstevel@tonic-gate case 'n': /* no titles */ 1510Sstevel@tonic-gate opts->dotitle = 0; 1520Sstevel@tonic-gate break; 1530Sstevel@tonic-gate case 't': /* print %tick */ 1540Sstevel@tonic-gate opts->dotick = 1; 1550Sstevel@tonic-gate break; 1560Sstevel@tonic-gate case 'v': 1570Sstevel@tonic-gate opts->verbose = 1; /* more chatty */ 1580Sstevel@tonic-gate break; 1590Sstevel@tonic-gate case 'o': 1600Sstevel@tonic-gate if (optarg == NULL) { 1610Sstevel@tonic-gate errcnt++; 1620Sstevel@tonic-gate break; 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate if ((opts->log = fopen(optarg, "w")) == NULL) { 1650Sstevel@tonic-gate (void) fprintf(stderr, gettext( 1660Sstevel@tonic-gate "%s: cannot open '%s' for writing\n"), 1670Sstevel@tonic-gate opts->pgmname, optarg); 1680Sstevel@tonic-gate return (1); 1690Sstevel@tonic-gate } 1700Sstevel@tonic-gate break; 1710Sstevel@tonic-gate case 'c': /* specify statistics */ 1720Sstevel@tonic-gate if ((sgrp = cpc_setgrp_newset(opts->master, 1730Sstevel@tonic-gate optarg, &errcnt)) != NULL) 1740Sstevel@tonic-gate opts->master = sgrp; 1750Sstevel@tonic-gate break; 1760Sstevel@tonic-gate case 'p': /* grab given pid */ 1770Sstevel@tonic-gate if ((opts->pid = atoi(optarg)) <= 0) 1780Sstevel@tonic-gate errcnt++; 1790Sstevel@tonic-gate break; 1800Sstevel@tonic-gate case 'h': 1810Sstevel@tonic-gate opts->dohelp = 1; 1820Sstevel@tonic-gate break; 1830Sstevel@tonic-gate case '?': 1840Sstevel@tonic-gate default: 1850Sstevel@tonic-gate errcnt++; 1860Sstevel@tonic-gate break; 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate if (opts->nsamples == 0) 1900Sstevel@tonic-gate opts->nsamples = UINT_MAX; 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate if (errcnt != 0 || 1930Sstevel@tonic-gate opts->dohelp || 1940Sstevel@tonic-gate (argc == optind && opts->pid == 0) || 1950Sstevel@tonic-gate (argc > optind && opts->pid != 0) || 1960Sstevel@tonic-gate (opts->nsets = cpc_setgrp_numsets(opts->master)) == 0) { 1970Sstevel@tonic-gate (void) fprintf(opts->dohelp ? stdout : stderr, gettext( 1980Sstevel@tonic-gate "Usage:\n\t%s [-T secs] [-N count] [-Defhnv] [-o file]\n" 1990Sstevel@tonic-gate "\t\t-c events [command [args] | -p pid]\n\n" 2000Sstevel@tonic-gate "\t-T secs\t seconds between samples, default 1\n" 2010Sstevel@tonic-gate "\t-N count number of samples, default unlimited\n" 2020Sstevel@tonic-gate "\t-D\t enable debug mode\n" 2030Sstevel@tonic-gate "\t-e\t follow exec(2), and execve(2)\n" 2040Sstevel@tonic-gate "\t-f\t follow fork(2), fork1(2), and vfork(2)\n" 2050Sstevel@tonic-gate "\t-h\t print extended usage information\n" 2060Sstevel@tonic-gate "\t-n\t suppress titles\n" 2070Sstevel@tonic-gate "\t-t\t include virtualized %s register\n" 2080Sstevel@tonic-gate "\t-v\t verbose mode\n" 2090Sstevel@tonic-gate "\t-o file\t write cpu statistics to this file\n" 2100Sstevel@tonic-gate "\t-c events specify processor events to be monitored\n" 2110Sstevel@tonic-gate "\t-p pid\t pid of existing process to capture\n\n" 2120Sstevel@tonic-gate "\tUse cpustat(1M) to monitor system-wide statistics.\n"), 2130Sstevel@tonic-gate opts->pgmname, CPC_TICKREG_NAME); 2140Sstevel@tonic-gate if (opts->dohelp) { 2150Sstevel@tonic-gate (void) putchar('\n'); 2160Sstevel@tonic-gate (void) capabilities(cpc, stdout); 2170Sstevel@tonic-gate exit(0); 2180Sstevel@tonic-gate } 2190Sstevel@tonic-gate exit(2); 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate cpc_setgrp_reset(opts->master); 2230Sstevel@tonic-gate (void) setvbuf(opts->log, NULL, _IOLBF, 0); 2240Sstevel@tonic-gate ret = cputrack(argc, argv, optind); 2250Sstevel@tonic-gate (void) cpc_close(cpc); 2260Sstevel@tonic-gate return (ret); 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate static void 2300Sstevel@tonic-gate print_title(cpc_setgrp_t *sgrp) 2310Sstevel@tonic-gate { 2320Sstevel@tonic-gate (void) fprintf(opts->log, "%7s ", "time"); 2330Sstevel@tonic-gate if (opts->followfork) 2340Sstevel@tonic-gate (void) fprintf(opts->log, "%6s ", "pid"); 2350Sstevel@tonic-gate (void) fprintf(opts->log, "%3s %10s ", "lwp", "event"); 2360Sstevel@tonic-gate if (opts->dotick) 2370Sstevel@tonic-gate (void) fprintf(opts->log, "%9s ", CPC_TICKREG_NAME); 2380Sstevel@tonic-gate (void) fprintf(opts->log, "%s\n", cpc_setgrp_gethdr(sgrp)); 2390Sstevel@tonic-gate (void) fflush(opts->log); 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate static void 2430Sstevel@tonic-gate print_exec(float now, pid_t pid, char *name) 2440Sstevel@tonic-gate { 2450Sstevel@tonic-gate if (name == NULL) 2460Sstevel@tonic-gate name = "(unknown)"; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate (void) fprintf(opts->log, "%7.3f ", now); 2490Sstevel@tonic-gate if (opts->followfork) 2500Sstevel@tonic-gate (void) fprintf(opts->log, "%6d ", (int)pid); 2510Sstevel@tonic-gate (void) fprintf(opts->log, "%3d %10s ", 1, "exec"); 2520Sstevel@tonic-gate if (opts->dotick) 2530Sstevel@tonic-gate (void) fprintf(opts->log, "%9s ", ""); 2540Sstevel@tonic-gate (void) fprintf(opts->log, "%9s %9s # '%s'\n", "", "", name); 2550Sstevel@tonic-gate (void) fflush(opts->log); 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate static void 2590Sstevel@tonic-gate print_fork(float now, pid_t newpid, id_t lwpid, pid_t oldpid) 2600Sstevel@tonic-gate { 2610Sstevel@tonic-gate (void) fprintf(opts->log, "%7.3f ", now); 2620Sstevel@tonic-gate if (opts->followfork) 2630Sstevel@tonic-gate (void) fprintf(opts->log, "%6d ", (int)oldpid); 2640Sstevel@tonic-gate (void) fprintf(opts->log, "%3d %10s ", (int)lwpid, "fork"); 2650Sstevel@tonic-gate if (opts->dotick) 2660Sstevel@tonic-gate (void) fprintf(opts->log, "%9s ", ""); 2670Sstevel@tonic-gate (void) fprintf(opts->log, "%9s %9s # %d\n", "", "", (int)newpid); 2680Sstevel@tonic-gate (void) fflush(opts->log); 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate static void 2720Sstevel@tonic-gate print_sample(pid_t pid, id_t lwpid, 2730Sstevel@tonic-gate char *pevent, cpc_buf_t *buf, int nreq, const char *evname) 2740Sstevel@tonic-gate { 2750Sstevel@tonic-gate uint64_t val; 2760Sstevel@tonic-gate int i; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate (void) fprintf(opts->log, "%7.3f ", 2790Sstevel@tonic-gate mstimestamp(cpc_buf_hrtime(cpc, buf))); 2800Sstevel@tonic-gate if (opts->followfork) 2810Sstevel@tonic-gate (void) fprintf(opts->log, "%6d ", (int)pid); 2820Sstevel@tonic-gate (void) fprintf(opts->log, "%3d %10s ", (int)lwpid, pevent); 2830Sstevel@tonic-gate if (opts->dotick) 2840Sstevel@tonic-gate (void) fprintf(opts->log, "%9" PRId64 " ", 2850Sstevel@tonic-gate cpc_buf_tick(cpc, buf)); 2860Sstevel@tonic-gate for (i = 0; i < nreq; i++) { 2870Sstevel@tonic-gate (void) cpc_buf_get(cpc, buf, i, &val); 2880Sstevel@tonic-gate (void) fprintf(opts->log, "%9" PRId64 " ", val); 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate if (opts->nsets > 1) 2910Sstevel@tonic-gate (void) fprintf(opts->log, " # %s\n", evname); 2920Sstevel@tonic-gate else 2930Sstevel@tonic-gate (void) fputc('\n', opts->log); 2940Sstevel@tonic-gate } 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate struct pstate { 2970Sstevel@tonic-gate cpc_setgrp_t *accum; 2980Sstevel@tonic-gate cpc_setgrp_t **sgrps; 2990Sstevel@tonic-gate int maxlwpid; 3000Sstevel@tonic-gate }; 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate static int 3030Sstevel@tonic-gate pinit_lwp(pctx_t *pctx, pid_t pid, id_t lwpid, void *arg) 3040Sstevel@tonic-gate { 3050Sstevel@tonic-gate struct pstate *state = arg; 3060Sstevel@tonic-gate cpc_setgrp_t *sgrp; 3070Sstevel@tonic-gate cpc_set_t *set; 3080Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 3090Sstevel@tonic-gate char *errstr; 3100Sstevel@tonic-gate int nreq; 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate if (state->maxlwpid < lwpid) { 3130Sstevel@tonic-gate state->sgrps = realloc(state->sgrps, 3140Sstevel@tonic-gate lwpid * sizeof (state->sgrps)); 3150Sstevel@tonic-gate if (state->sgrps == NULL) { 3160Sstevel@tonic-gate (void) fprintf(stderr, gettext( 3170Sstevel@tonic-gate "%6d: init_lwp: out of memory\n"), (int)pid); 3180Sstevel@tonic-gate return (-1); 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate while (state->maxlwpid < lwpid) { 3210Sstevel@tonic-gate state->sgrps[state->maxlwpid] = NULL; 3220Sstevel@tonic-gate state->maxlwpid++; 3230Sstevel@tonic-gate } 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate if ((sgrp = state->sgrps[lwpid-1]) == NULL) { 3270Sstevel@tonic-gate if ((sgrp = cpc_setgrp_clone(opts->master)) == NULL) { 3280Sstevel@tonic-gate (void) fprintf(stderr, gettext( 3290Sstevel@tonic-gate "%6d: init_lwp: out of memory\n"), (int)pid); 3300Sstevel@tonic-gate return (-1); 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate state->sgrps[lwpid-1] = sgrp; 3330Sstevel@tonic-gate set = cpc_setgrp_getset(sgrp); 3340Sstevel@tonic-gate } else { 3350Sstevel@tonic-gate cpc_setgrp_reset(sgrp); 3360Sstevel@tonic-gate set = cpc_setgrp_getset(sgrp); 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate nreq = cpc_setgrp_getbufs(sgrp, &data1, &data2, &scratch); 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate if (cpc_bind_pctx(cpc, pctx, lwpid, set, 0) != 0 || 3420Sstevel@tonic-gate cpc_set_sample(cpc, set, *data2) != 0) { 3430Sstevel@tonic-gate errstr = strerror(errno); 3440Sstevel@tonic-gate if (errno == EAGAIN) 3450Sstevel@tonic-gate (void) cpc_unbind(cpc, set); 3460Sstevel@tonic-gate if (errno == EACCES) 3470Sstevel@tonic-gate p4_ht_error(); 3480Sstevel@tonic-gate else 3490Sstevel@tonic-gate (void) fprintf(stderr, gettext( 3500Sstevel@tonic-gate "%6d: init_lwp: can't bind perf counters " 3510Sstevel@tonic-gate "to lwp%d - %s\n"), (int)pid, (int)lwpid, 3520Sstevel@tonic-gate errstr); 3530Sstevel@tonic-gate return (-1); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate if (opts->verbose) 3570Sstevel@tonic-gate print_sample(pid, lwpid, "init_lwp", 3580Sstevel@tonic-gate *data2, nreq, cpc_setgrp_getname(sgrp)); 3590Sstevel@tonic-gate return (0); 3600Sstevel@tonic-gate } 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate /*ARGSUSED*/ 3630Sstevel@tonic-gate static int 3640Sstevel@tonic-gate pfini_lwp(pctx_t *pctx, pid_t pid, id_t lwpid, void *arg) 3650Sstevel@tonic-gate { 3660Sstevel@tonic-gate struct pstate *state = arg; 3670Sstevel@tonic-gate cpc_setgrp_t *sgrp = state->sgrps[lwpid-1]; 3680Sstevel@tonic-gate cpc_set_t *set; 3690Sstevel@tonic-gate char *errstr; 3700Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 3710Sstevel@tonic-gate int nreq; 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate set = cpc_setgrp_getset(sgrp); 3740Sstevel@tonic-gate nreq = cpc_setgrp_getbufs(sgrp, &data1, &data2, &scratch); 3750Sstevel@tonic-gate if (cpc_set_sample(cpc, set, *data1) == 0) { 3760Sstevel@tonic-gate if (opts->verbose) 3770Sstevel@tonic-gate print_sample(pid, lwpid, "fini_lwp", 3780Sstevel@tonic-gate *data1, nreq, cpc_setgrp_getname(sgrp)); 3790Sstevel@tonic-gate cpc_setgrp_accum(state->accum, sgrp); 3800Sstevel@tonic-gate if (cpc_unbind(cpc, set) == 0) 3810Sstevel@tonic-gate return (0); 3820Sstevel@tonic-gate } 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate switch (errno) { 3850Sstevel@tonic-gate case EAGAIN: 3860Sstevel@tonic-gate (void) fprintf(stderr, gettext("%6d: fini_lwp: " 3870Sstevel@tonic-gate "lwp%d: perf counter contents invalidated\n"), 3880Sstevel@tonic-gate (int)pid, (int)lwpid); 3890Sstevel@tonic-gate break; 3900Sstevel@tonic-gate default: 3910Sstevel@tonic-gate errstr = strerror(errno); 3920Sstevel@tonic-gate (void) fprintf(stderr, gettext("%6d: fini_lwp: " 3930Sstevel@tonic-gate "lwp%d: can't access perf counters - %s\n"), 3940Sstevel@tonic-gate (int)pid, (int)lwpid, errstr); 3950Sstevel@tonic-gate break; 3960Sstevel@tonic-gate } 397*2235Skk112340 return (-1); 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate /*ARGSUSED*/ 4010Sstevel@tonic-gate static int 4020Sstevel@tonic-gate plwp_create(pctx_t *pctx, pid_t pid, id_t lwpid, void *arg) 4030Sstevel@tonic-gate { 4040Sstevel@tonic-gate cpc_setgrp_t *sgrp = opts->master; 4050Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 4060Sstevel@tonic-gate int nreq; 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate nreq = cpc_setgrp_getbufs(sgrp, &data1, &data2, &scratch); 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate print_sample(pid, lwpid, "lwp_create", 4110Sstevel@tonic-gate *data1, nreq, cpc_setgrp_getname(sgrp)); 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate return (0); 4140Sstevel@tonic-gate } 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate /*ARGSUSED*/ 4170Sstevel@tonic-gate static int 4180Sstevel@tonic-gate plwp_exit(pctx_t *pctx, pid_t pid, id_t lwpid, void *arg) 4190Sstevel@tonic-gate { 4200Sstevel@tonic-gate struct pstate *state = arg; 4210Sstevel@tonic-gate cpc_setgrp_t *sgrp = state->sgrps[lwpid-1]; 4220Sstevel@tonic-gate cpc_set_t *start; 4230Sstevel@tonic-gate int nreq; 4240Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate start = cpc_setgrp_getset(sgrp); 4270Sstevel@tonic-gate do { 4280Sstevel@tonic-gate nreq = cpc_setgrp_getbufs(sgrp, &data1, &data2, &scratch); 4290Sstevel@tonic-gate if (cpc_buf_hrtime(cpc, *data1) == 0) 4300Sstevel@tonic-gate continue; 4310Sstevel@tonic-gate print_sample(pid, lwpid, "lwp_exit", 4320Sstevel@tonic-gate *data1, nreq, cpc_setgrp_getname(sgrp)); 4330Sstevel@tonic-gate } while (cpc_setgrp_nextset(sgrp) != start); 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate return (0); 4360Sstevel@tonic-gate } 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /*ARGSUSED*/ 4390Sstevel@tonic-gate static int 4400Sstevel@tonic-gate pexec(pctx_t *pctx, pid_t pid, id_t lwpid, char *name, void *arg) 4410Sstevel@tonic-gate { 4420Sstevel@tonic-gate struct pstate *state = arg; 4430Sstevel@tonic-gate float now = 0.0; 4440Sstevel@tonic-gate cpc_set_t *start; 4450Sstevel@tonic-gate int nreq; 4460Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 4470Sstevel@tonic-gate hrtime_t hrt; 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate /* 4500Sstevel@tonic-gate * Print the accumulated results from the previous program image 4510Sstevel@tonic-gate */ 4520Sstevel@tonic-gate cpc_setgrp_reset(state->accum); 4530Sstevel@tonic-gate start = cpc_setgrp_getset(state->accum); 4540Sstevel@tonic-gate do { 4550Sstevel@tonic-gate nreq = cpc_setgrp_getbufs(state->accum, &data1, &data2, 4560Sstevel@tonic-gate &scratch); 4570Sstevel@tonic-gate hrt = cpc_buf_hrtime(cpc, *data1); 4580Sstevel@tonic-gate if (hrt == 0) 4590Sstevel@tonic-gate continue; 4600Sstevel@tonic-gate print_sample(pid, lwpid, "exec", 4610Sstevel@tonic-gate *data1, nreq, cpc_setgrp_getname(state->accum)); 4620Sstevel@tonic-gate if (now < mstimestamp(hrt)) 4630Sstevel@tonic-gate now = mstimestamp(hrt); 4640Sstevel@tonic-gate } while (cpc_setgrp_nextset(state->accum) != start); 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate print_exec(now, pid, name); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate if (state->accum != NULL) { 4690Sstevel@tonic-gate cpc_setgrp_free(state->accum); 4700Sstevel@tonic-gate state->accum = NULL; 4710Sstevel@tonic-gate } 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate if (opts->followexec) { 4740Sstevel@tonic-gate state->accum = cpc_setgrp_clone(opts->master); 4750Sstevel@tonic-gate return (0); 4760Sstevel@tonic-gate } 4770Sstevel@tonic-gate return (-1); 4780Sstevel@tonic-gate } 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate /*ARGSUSED*/ 4810Sstevel@tonic-gate static void 4820Sstevel@tonic-gate pexit(pctx_t *pctx, pid_t pid, id_t lwpid, int status, void *arg) 4830Sstevel@tonic-gate { 4840Sstevel@tonic-gate struct pstate *state = arg; 4850Sstevel@tonic-gate cpc_set_t *start; 4860Sstevel@tonic-gate int nreq; 4870Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate cpc_setgrp_reset(state->accum); 4900Sstevel@tonic-gate start = cpc_setgrp_getset(state->accum); 4910Sstevel@tonic-gate do { 4920Sstevel@tonic-gate nreq = cpc_setgrp_getbufs(state->accum, &data1, &data2, 4930Sstevel@tonic-gate &scratch); 4940Sstevel@tonic-gate if (cpc_buf_hrtime(cpc, *data1) == 0) 4950Sstevel@tonic-gate continue; 4960Sstevel@tonic-gate print_sample(pid, lwpid, "exit", 4970Sstevel@tonic-gate *data1, nreq, cpc_setgrp_getname(state->accum)); 4980Sstevel@tonic-gate } while (cpc_setgrp_nextset(state->accum) != start); 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate cpc_setgrp_free(state->accum); 5010Sstevel@tonic-gate state->accum = NULL; 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate for (lwpid = 1; lwpid < state->maxlwpid; lwpid++) 5040Sstevel@tonic-gate if (state->sgrps[lwpid-1] != NULL) { 5050Sstevel@tonic-gate cpc_setgrp_free(state->sgrps[lwpid-1]); 5060Sstevel@tonic-gate state->sgrps[lwpid-1] = NULL; 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate free(state->sgrps); 5090Sstevel@tonic-gate state->sgrps = NULL; 5100Sstevel@tonic-gate } 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate static int 5130Sstevel@tonic-gate ptick(pctx_t *pctx, pid_t pid, id_t lwpid, void *arg) 5140Sstevel@tonic-gate { 5150Sstevel@tonic-gate struct pstate *state = arg; 5160Sstevel@tonic-gate cpc_setgrp_t *sgrp = state->sgrps[lwpid-1]; 5170Sstevel@tonic-gate cpc_set_t *this = cpc_setgrp_getset(sgrp); 5180Sstevel@tonic-gate const char *name = cpc_setgrp_getname(sgrp); 5190Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch, *tmp; 5200Sstevel@tonic-gate char *errstr; 5210Sstevel@tonic-gate int nreqs; 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate nreqs = cpc_setgrp_getbufs(sgrp, &data1, &data2, &scratch); 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate if (opts->nsets == 1) { 5260Sstevel@tonic-gate /* 5270Sstevel@tonic-gate * If we're dealing with one set, buffer usage is: 5280Sstevel@tonic-gate * 5290Sstevel@tonic-gate * data1 = most recent data snapshot 5300Sstevel@tonic-gate * data2 = previous data snapshot 5310Sstevel@tonic-gate * scratch = used for diffing data1 and data2 5320Sstevel@tonic-gate * 5330Sstevel@tonic-gate * Save the snapshot from the previous sample in data2 5340Sstevel@tonic-gate * before putting the current sample in data1. 5350Sstevel@tonic-gate */ 5360Sstevel@tonic-gate tmp = *data1; 5370Sstevel@tonic-gate *data1 = *data2; 5380Sstevel@tonic-gate *data2 = tmp; 5390Sstevel@tonic-gate if (cpc_set_sample(cpc, this, *data1) != 0) 5400Sstevel@tonic-gate goto broken; 5410Sstevel@tonic-gate cpc_buf_sub(cpc, *scratch, *data1, *data2); 5420Sstevel@tonic-gate } else { 5430Sstevel@tonic-gate cpc_set_t *next = cpc_setgrp_nextset(sgrp); 5440Sstevel@tonic-gate /* 5450Sstevel@tonic-gate * If there is more than set in use, we will need to 5460Sstevel@tonic-gate * unbind and re-bind on each go-around because each 5470Sstevel@tonic-gate * time a counter is bound, it is preset to 0 (as it was 5480Sstevel@tonic-gate * specified when the requests were added to the set). 5490Sstevel@tonic-gate * 5500Sstevel@tonic-gate * Buffer usage in this case is: 5510Sstevel@tonic-gate * 5520Sstevel@tonic-gate * data1 = total counts for this set since program began 5530Sstevel@tonic-gate * data2 = unused 5540Sstevel@tonic-gate * scratch = most recent data snapshot 5550Sstevel@tonic-gate */ 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate if (cpc_set_sample(cpc, this, *scratch) != 0) 5580Sstevel@tonic-gate goto broken; 5590Sstevel@tonic-gate cpc_buf_add(cpc, *data1, *data1, *scratch); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate /* 5620Sstevel@tonic-gate * No need to unbind the previous set, as binding another set 5630Sstevel@tonic-gate * automatically unbinds the most recently bound set. 5640Sstevel@tonic-gate */ 5650Sstevel@tonic-gate if (cpc_bind_pctx(cpc, pctx, lwpid, next, 0) != 0) 5660Sstevel@tonic-gate goto broken; 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate print_sample(pid, lwpid, "tick", *scratch, nreqs, name); 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate return (0); 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate broken: 5730Sstevel@tonic-gate switch (errno) { 5740Sstevel@tonic-gate case EAGAIN: 5750Sstevel@tonic-gate (void) fprintf(stderr, gettext( 5760Sstevel@tonic-gate "%6d: tick: lwp%d: perf counter contents invalidated\n"), 5770Sstevel@tonic-gate (int)pid, (int)lwpid); 5780Sstevel@tonic-gate break; 5790Sstevel@tonic-gate default: 5800Sstevel@tonic-gate errstr = strerror(errno); 5810Sstevel@tonic-gate (void) fprintf(stderr, gettext( 5820Sstevel@tonic-gate "%6d: tick: lwp%d: can't access perf counter - %s\n"), 5830Sstevel@tonic-gate (int)pid, (int)lwpid, errstr); 5840Sstevel@tonic-gate break; 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate (void) cpc_unbind(cpc, this); 5870Sstevel@tonic-gate return (-1); 5880Sstevel@tonic-gate } 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate /* 5910Sstevel@tonic-gate * The system has just created a new address space that has a new pid. 5920Sstevel@tonic-gate * We're running in a child of the controlling process, with a new 5930Sstevel@tonic-gate * pctx handle already opened on the child of the original controlled process. 5940Sstevel@tonic-gate */ 5950Sstevel@tonic-gate static void 5960Sstevel@tonic-gate pfork(pctx_t *pctx, pid_t oldpid, pid_t pid, id_t lwpid, void *arg) 5970Sstevel@tonic-gate { 5980Sstevel@tonic-gate struct pstate *state = arg; 5990Sstevel@tonic-gate 6000Sstevel@tonic-gate print_fork(mstimestamp(0), pid, lwpid, oldpid); 6010Sstevel@tonic-gate 6020Sstevel@tonic-gate if (!opts->followfork) 6030Sstevel@tonic-gate return; 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate if (pctx_set_events(pctx, 6060Sstevel@tonic-gate PCTX_SYSC_EXEC_EVENT, pexec, 6070Sstevel@tonic-gate PCTX_SYSC_FORK_EVENT, pfork, 6080Sstevel@tonic-gate PCTX_SYSC_EXIT_EVENT, pexit, 6090Sstevel@tonic-gate PCTX_SYSC_LWP_CREATE_EVENT, plwp_create, 6100Sstevel@tonic-gate PCTX_INIT_LWP_EVENT, pinit_lwp, 6110Sstevel@tonic-gate PCTX_FINI_LWP_EVENT, pfini_lwp, 6120Sstevel@tonic-gate PCTX_SYSC_LWP_EXIT_EVENT, plwp_exit, 6130Sstevel@tonic-gate PCTX_NULL_EVENT) == 0) { 6140Sstevel@tonic-gate state->accum = cpc_setgrp_clone(opts->master); 6150Sstevel@tonic-gate (void) pctx_run(pctx, opts->mseconds, opts->nsamples, ptick); 6160Sstevel@tonic-gate if (state->accum) { 6170Sstevel@tonic-gate free(state->accum); 6180Sstevel@tonic-gate state->accum = NULL; 6190Sstevel@tonic-gate } 6200Sstevel@tonic-gate } 6210Sstevel@tonic-gate } 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate /* 6240Sstevel@tonic-gate * Translate the incoming options into actions, and get the 6250Sstevel@tonic-gate * tool and the process to control running. 6260Sstevel@tonic-gate */ 6270Sstevel@tonic-gate static int 6280Sstevel@tonic-gate cputrack(int argc, char *argv[], int optind) 6290Sstevel@tonic-gate { 6300Sstevel@tonic-gate struct pstate __state, *state = &__state; 6310Sstevel@tonic-gate pctx_t *pctx; 6320Sstevel@tonic-gate int err; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate bzero(state, sizeof (*state)); 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate if (opts->pid == 0) { 6370Sstevel@tonic-gate if (argc <= optind) { 6380Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s\n", 6390Sstevel@tonic-gate opts->pgmname, 6400Sstevel@tonic-gate gettext("no program to start")); 6410Sstevel@tonic-gate return (1); 6420Sstevel@tonic-gate } 6430Sstevel@tonic-gate pctx = pctx_create(argv[optind], 6440Sstevel@tonic-gate &argv[optind], state, 1, cputrack_pctx_errfn); 6450Sstevel@tonic-gate if (pctx == NULL) { 6460Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s '%s'\n", 6470Sstevel@tonic-gate opts->pgmname, 6480Sstevel@tonic-gate gettext("failed to start program"), 6490Sstevel@tonic-gate argv[optind]); 6500Sstevel@tonic-gate return (1); 6510Sstevel@tonic-gate } 6520Sstevel@tonic-gate } else { 6530Sstevel@tonic-gate pctx = pctx_capture(opts->pid, state, 1, cputrack_pctx_errfn); 6540Sstevel@tonic-gate if (pctx == NULL) { 6550Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s %d\n", 6560Sstevel@tonic-gate opts->pgmname, 6570Sstevel@tonic-gate gettext("failed to capture pid"), 6580Sstevel@tonic-gate (int)opts->pid); 6590Sstevel@tonic-gate return (1); 6600Sstevel@tonic-gate } 6610Sstevel@tonic-gate } 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate err = pctx_set_events(pctx, 6640Sstevel@tonic-gate PCTX_SYSC_EXEC_EVENT, pexec, 6650Sstevel@tonic-gate PCTX_SYSC_FORK_EVENT, pfork, 6660Sstevel@tonic-gate PCTX_SYSC_EXIT_EVENT, pexit, 6670Sstevel@tonic-gate PCTX_SYSC_LWP_CREATE_EVENT, plwp_create, 6680Sstevel@tonic-gate PCTX_INIT_LWP_EVENT, pinit_lwp, 6690Sstevel@tonic-gate PCTX_FINI_LWP_EVENT, pfini_lwp, 6700Sstevel@tonic-gate PCTX_SYSC_LWP_EXIT_EVENT, plwp_exit, 6710Sstevel@tonic-gate PCTX_NULL_EVENT); 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate if (err != 0) { 6740Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s\n", 6750Sstevel@tonic-gate opts->pgmname, 6760Sstevel@tonic-gate gettext("can't bind process context ops to process")); 6770Sstevel@tonic-gate } else { 6780Sstevel@tonic-gate if (opts->dotitle) 6790Sstevel@tonic-gate print_title(opts->master); 6800Sstevel@tonic-gate state->accum = cpc_setgrp_clone(opts->master); 6810Sstevel@tonic-gate zerotime(); 6820Sstevel@tonic-gate err = pctx_run(pctx, opts->mseconds, opts->nsamples, ptick); 6830Sstevel@tonic-gate if (state->accum) { 6840Sstevel@tonic-gate cpc_setgrp_free(state->accum); 6850Sstevel@tonic-gate state->accum = NULL; 6860Sstevel@tonic-gate } 6870Sstevel@tonic-gate } 6880Sstevel@tonic-gate pctx_release(pctx); 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate return (err != 0 ? 1 : 0); 6910Sstevel@tonic-gate } 6920Sstevel@tonic-gate 6930Sstevel@tonic-gate #define OFFLINE_CMD "/usr/sbin/psradm -f " 6940Sstevel@tonic-gate #define BUFSIZE 5 /* enough for "n " where n is a cpuid */ 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate /* 6970Sstevel@tonic-gate * cpc_bind_pctx() failed with EACCES, which means the user must first offline 6980Sstevel@tonic-gate * all but one logical processor on each physical processor. Print to stderr the 6990Sstevel@tonic-gate * psradm command string to do this. 7000Sstevel@tonic-gate */ 7010Sstevel@tonic-gate static void 7020Sstevel@tonic-gate p4_ht_error(void) 7030Sstevel@tonic-gate { 7040Sstevel@tonic-gate kstat_ctl_t *kc; 7050Sstevel@tonic-gate kstat_t *ksp; 7060Sstevel@tonic-gate kstat_named_t *k; 7070Sstevel@tonic-gate int i; 7080Sstevel@tonic-gate int max; 7090Sstevel@tonic-gate int stat; 7100Sstevel@tonic-gate int *designees; 7110Sstevel@tonic-gate int *must_offline; 7120Sstevel@tonic-gate char buf[BUFSIZE]; 7130Sstevel@tonic-gate char *cmd; 7140Sstevel@tonic-gate int noffline = 0; 7150Sstevel@tonic-gate int ndone = 0; 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", 7180Sstevel@tonic-gate gettext("Pentium 4 processors with HyperThreading present.\nOffline" 7190Sstevel@tonic-gate " all but one logical processor on each physical processor in" 7200Sstevel@tonic-gate " order to use\ncputrack.\n")); 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate 7230Sstevel@tonic-gate if ((kc = kstat_open()) == NULL) 7240Sstevel@tonic-gate return; 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate max = sysconf(_SC_CPUID_MAX); 7270Sstevel@tonic-gate if ((designees = malloc(max * sizeof (*designees))) == NULL) { 7280Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: no memory available\n"), 7290Sstevel@tonic-gate opts->pgmname); 7300Sstevel@tonic-gate exit(0); 7310Sstevel@tonic-gate } 7320Sstevel@tonic-gate 7330Sstevel@tonic-gate if ((must_offline = malloc(max * sizeof (*designees))) == NULL) { 7340Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: no memory available\n"), 7350Sstevel@tonic-gate opts->pgmname); 7360Sstevel@tonic-gate exit(0); 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate for (i = 0; i < max; i++) { 7400Sstevel@tonic-gate designees[i] = -1; 7410Sstevel@tonic-gate must_offline[i] = 0; 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate for (i = 0; i < max; i++) { 7450Sstevel@tonic-gate stat = p_online(i, P_STATUS); 7460Sstevel@tonic-gate if (stat != P_ONLINE && stat != P_NOINTR) 7470Sstevel@tonic-gate continue; 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate if ((ksp = kstat_lookup(kc, "cpu_info", i, NULL)) == NULL) { 7500Sstevel@tonic-gate free(designees); 7510Sstevel@tonic-gate free(must_offline); 7520Sstevel@tonic-gate return; 7530Sstevel@tonic-gate } 7540Sstevel@tonic-gate 7550Sstevel@tonic-gate if (kstat_read(kc, ksp, NULL) == -1) { 7560Sstevel@tonic-gate free(designees); 7570Sstevel@tonic-gate free(must_offline); 7580Sstevel@tonic-gate return; 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate if ((k = (kstat_named_t *)kstat_data_lookup(ksp, "chip_id")) 7620Sstevel@tonic-gate == NULL) { 7630Sstevel@tonic-gate free(designees); 7640Sstevel@tonic-gate free(must_offline); 7650Sstevel@tonic-gate return; 7660Sstevel@tonic-gate } 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate if (designees[k->value.i32] == -1) 7690Sstevel@tonic-gate /* 7700Sstevel@tonic-gate * This chip doesn't yet have a CPU designated to remain 7710Sstevel@tonic-gate * online; let this one be it. 7720Sstevel@tonic-gate */ 7730Sstevel@tonic-gate designees[k->value.i32] = i; 7740Sstevel@tonic-gate else { 7750Sstevel@tonic-gate /* 7760Sstevel@tonic-gate * This chip already has a designated CPU; this CPU must 7770Sstevel@tonic-gate * go offline. 7780Sstevel@tonic-gate */ 7790Sstevel@tonic-gate must_offline[i] = 1; 7800Sstevel@tonic-gate noffline++; 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate /* 7850Sstevel@tonic-gate * Now construct a string containing the command line used to offline 7860Sstevel@tonic-gate * the appropriate processors. 7870Sstevel@tonic-gate */ 7880Sstevel@tonic-gate 7890Sstevel@tonic-gate if ((cmd = malloc(strlen(OFFLINE_CMD) + (noffline * BUFSIZE) + 1)) 7900Sstevel@tonic-gate == NULL) { 7910Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: no memory available\n"), 7920Sstevel@tonic-gate opts->pgmname); 7930Sstevel@tonic-gate exit(0); 7940Sstevel@tonic-gate } 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate (void) strcpy(cmd, OFFLINE_CMD); 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate for (i = 0; i < max; i++) { 7990Sstevel@tonic-gate if (must_offline[i] == 0) 8000Sstevel@tonic-gate continue; 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate ndone++; 8030Sstevel@tonic-gate (void) snprintf(buf, BUFSIZE, "%d", i); 8040Sstevel@tonic-gate if (ndone < noffline) 8050Sstevel@tonic-gate (void) strcat(buf, " "); 8060Sstevel@tonic-gate (void) strcat(cmd, buf); 8070Sstevel@tonic-gate } 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("The following command " 8100Sstevel@tonic-gate "will configure the system appropriately"), cmd); 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate exit(1); 8130Sstevel@tonic-gate } 814