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*3438Sas198278 * Common Development and Distribution License (the "License"). 6*3438Sas198278 * 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*3438Sas198278 * Copyright 2007 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/types.h> 290Sstevel@tonic-gate #include <sys/processor.h> 300Sstevel@tonic-gate #include <sys/pset.h> 310Sstevel@tonic-gate #include <sys/lwp.h> 320Sstevel@tonic-gate #include <sys/priocntl.h> 330Sstevel@tonic-gate #include <sys/fxpriocntl.h> 340Sstevel@tonic-gate #include <time.h> 350Sstevel@tonic-gate #include <stdio.h> 360Sstevel@tonic-gate #include <stdlib.h> 370Sstevel@tonic-gate #include <inttypes.h> 380Sstevel@tonic-gate #include <unistd.h> 390Sstevel@tonic-gate #include <limits.h> 400Sstevel@tonic-gate #include <string.h> 410Sstevel@tonic-gate #include <strings.h> 420Sstevel@tonic-gate #include <thread.h> 430Sstevel@tonic-gate #include <errno.h> 440Sstevel@tonic-gate #include <libintl.h> 450Sstevel@tonic-gate #include <locale.h> 460Sstevel@tonic-gate #include <kstat.h> 470Sstevel@tonic-gate #include <synch.h> 480Sstevel@tonic-gate #include <libcpc.h> 49*3438Sas198278 #include <sys/resource.h> 500Sstevel@tonic-gate 510Sstevel@tonic-gate #include "cpucmds.h" 520Sstevel@tonic-gate 530Sstevel@tonic-gate static struct options { 540Sstevel@tonic-gate int debug; 550Sstevel@tonic-gate int dotitle; 560Sstevel@tonic-gate int dohelp; 570Sstevel@tonic-gate int dotick; 580Sstevel@tonic-gate int dosoaker; 590Sstevel@tonic-gate int doperiod; 600Sstevel@tonic-gate char *pgmname; 610Sstevel@tonic-gate uint_t mseconds; 620Sstevel@tonic-gate uint_t nsamples; 630Sstevel@tonic-gate uint_t nsets; 640Sstevel@tonic-gate uint_t mseconds_rest; 650Sstevel@tonic-gate cpc_setgrp_t *master; 660Sstevel@tonic-gate } __options; 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * States for soaker threads. 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate #define SOAK_PAUSE 0 720Sstevel@tonic-gate #define SOAK_RUN 1 730Sstevel@tonic-gate 740Sstevel@tonic-gate struct tstate { 750Sstevel@tonic-gate processorid_t cpuid; 760Sstevel@tonic-gate int chip_id; 770Sstevel@tonic-gate cpc_setgrp_t *sgrp; 780Sstevel@tonic-gate int status; 790Sstevel@tonic-gate thread_t tid; 800Sstevel@tonic-gate int soak_state; 810Sstevel@tonic-gate mutex_t soak_lock; 820Sstevel@tonic-gate cond_t soak_cv; 830Sstevel@tonic-gate }; 840Sstevel@tonic-gate 850Sstevel@tonic-gate static const struct options *opts = (const struct options *)&__options; 860Sstevel@tonic-gate 870Sstevel@tonic-gate static cpc_t *cpc; 880Sstevel@tonic-gate 890Sstevel@tonic-gate struct tstate *gstate; 900Sstevel@tonic-gate static int ncpus; 910Sstevel@tonic-gate static int max_chip_id; 920Sstevel@tonic-gate static int *chip_designees; /* cpuid of CPU which counts for phs chip */ 930Sstevel@tonic-gate static int smt = 0; /* If set, cpustat needs to be SMT-aware. */ 940Sstevel@tonic-gate static pcinfo_t fxinfo = { 0, "FX", NULL }; /* FX scheduler class info */ 950Sstevel@tonic-gate 960Sstevel@tonic-gate /*ARGSUSED*/ 970Sstevel@tonic-gate static void 980Sstevel@tonic-gate cpustat_errfn(const char *fn, int subcode, const char *fmt, va_list ap) 990Sstevel@tonic-gate { 1000Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", opts->pgmname); 1010Sstevel@tonic-gate if (opts->debug) 1020Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", fn); 1030Sstevel@tonic-gate (void) vfprintf(stderr, fmt, ap); 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate static int cpustat(void); 1070Sstevel@tonic-gate static int get_chipid(kstat_ctl_t *kc, processorid_t cpuid); 1080Sstevel@tonic-gate static void *soaker(void *arg); 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 1120Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 1130Sstevel@tonic-gate #endif 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate int 1160Sstevel@tonic-gate main(int argc, char *argv[]) 1170Sstevel@tonic-gate { 1180Sstevel@tonic-gate struct options *opts = &__options; 1190Sstevel@tonic-gate int c, errcnt = 0, ret; 1200Sstevel@tonic-gate cpc_setgrp_t *sgrp; 1210Sstevel@tonic-gate char *errstr; 1220Sstevel@tonic-gate double period; 1230Sstevel@tonic-gate char *endp; 124*3438Sas198278 struct rlimit rl; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 1270Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate if ((opts->pgmname = strrchr(argv[0], '/')) == NULL) 1300Sstevel@tonic-gate opts->pgmname = argv[0]; 1310Sstevel@tonic-gate else 1320Sstevel@tonic-gate opts->pgmname++; 1330Sstevel@tonic-gate 134*3438Sas198278 /* Make sure we can open enough files */ 135*3438Sas198278 rl.rlim_max = rl.rlim_cur = RLIM_INFINITY; 136*3438Sas198278 if (setrlimit(RLIMIT_NOFILE, &rl) != 0) { 137*3438Sas198278 errstr = strerror(errno); 138*3438Sas198278 (void) fprintf(stderr, 139*3438Sas198278 gettext("%s: setrlimit failed - %s\n"), 140*3438Sas198278 opts->pgmname, errstr); 141*3438Sas198278 } 142*3438Sas198278 1430Sstevel@tonic-gate if ((cpc = cpc_open(CPC_VER_CURRENT)) == NULL) { 1440Sstevel@tonic-gate errstr = strerror(errno); 1450Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot access performance " 1460Sstevel@tonic-gate "counters - %s\n"), opts->pgmname, errstr); 1470Sstevel@tonic-gate return (1); 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate (void) cpc_seterrhndlr(cpc, cpustat_errfn); 1510Sstevel@tonic-gate strtoset_errfn = cpustat_errfn; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* 1540Sstevel@tonic-gate * Check to see if cpustat needs to be SMT-aware. 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate smt = smt_limited_cpc_hw(cpc); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate /* 1590Sstevel@tonic-gate * Establish some defaults 1600Sstevel@tonic-gate */ 1610Sstevel@tonic-gate opts->mseconds = 5000; 1620Sstevel@tonic-gate opts->nsamples = UINT_MAX; 1630Sstevel@tonic-gate opts->dotitle = 1; 1640Sstevel@tonic-gate if ((opts->master = cpc_setgrp_new(cpc, smt)) == NULL) { 1650Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of heap\n"), 1660Sstevel@tonic-gate opts->pgmname); 1670Sstevel@tonic-gate return (1); 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate while ((c = getopt(argc, argv, "Dc:hntsp:")) != EOF && errcnt == 0) 1710Sstevel@tonic-gate switch (c) { 1720Sstevel@tonic-gate case 'D': /* enable debugging */ 1730Sstevel@tonic-gate opts->debug++; 1740Sstevel@tonic-gate break; 1750Sstevel@tonic-gate case 'c': /* specify statistics */ 1760Sstevel@tonic-gate if ((sgrp = cpc_setgrp_newset(opts->master, 1770Sstevel@tonic-gate optarg, &errcnt)) != NULL) 1780Sstevel@tonic-gate opts->master = sgrp; 1790Sstevel@tonic-gate break; 1800Sstevel@tonic-gate case 'n': /* no titles */ 1810Sstevel@tonic-gate opts->dotitle = 0; 1820Sstevel@tonic-gate break; 1830Sstevel@tonic-gate case 'p': /* periodic behavior */ 1840Sstevel@tonic-gate opts->doperiod = 1; 1850Sstevel@tonic-gate period = strtod(optarg, &endp); 1860Sstevel@tonic-gate if (*endp != '\0') { 1870Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: invalid " 1880Sstevel@tonic-gate "parameter \"%s\"\n"), opts->pgmname, 1890Sstevel@tonic-gate optarg); 1900Sstevel@tonic-gate errcnt++; 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate break; 1930Sstevel@tonic-gate case 's': /* run soaker thread */ 1940Sstevel@tonic-gate opts->dosoaker = 1; 1950Sstevel@tonic-gate break; 1960Sstevel@tonic-gate case 't': /* print %tick */ 1970Sstevel@tonic-gate opts->dotick = 1; 1980Sstevel@tonic-gate break; 1990Sstevel@tonic-gate case 'h': /* help */ 2000Sstevel@tonic-gate opts->dohelp = 1; 2010Sstevel@tonic-gate break; 2020Sstevel@tonic-gate case '?': 2030Sstevel@tonic-gate default: 2040Sstevel@tonic-gate errcnt++; 2050Sstevel@tonic-gate break; 2060Sstevel@tonic-gate } 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate switch (argc - optind) { 2090Sstevel@tonic-gate case 0: 2100Sstevel@tonic-gate break; 2110Sstevel@tonic-gate case 2: 2120Sstevel@tonic-gate opts->nsamples = strtol(argv[optind + 1], &endp, 10); 2130Sstevel@tonic-gate if (*endp != '\0') { 2140Sstevel@tonic-gate (void) fprintf(stderr, 2150Sstevel@tonic-gate gettext("%s: invalid argument \"%s\"\n"), 2160Sstevel@tonic-gate opts->pgmname, argv[optind + 1]); 2170Sstevel@tonic-gate errcnt++; 2180Sstevel@tonic-gate break; 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate /*FALLTHROUGH*/ 2210Sstevel@tonic-gate case 1: 2220Sstevel@tonic-gate opts->mseconds = (uint_t)(strtod(argv[optind], &endp) * 1000.0); 2230Sstevel@tonic-gate if (*endp != '\0') { 2240Sstevel@tonic-gate (void) fprintf(stderr, 2250Sstevel@tonic-gate gettext("%s: invalid argument \"%s\"\n"), 2260Sstevel@tonic-gate opts->pgmname, argv[optind]); 2270Sstevel@tonic-gate errcnt++; 2280Sstevel@tonic-gate } 2290Sstevel@tonic-gate break; 2300Sstevel@tonic-gate default: 2310Sstevel@tonic-gate errcnt++; 2320Sstevel@tonic-gate break; 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate if (opts->nsamples == 0 || opts->mseconds == 0) 2360Sstevel@tonic-gate errcnt++; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate if (errcnt != 0 || opts->dohelp || 2390Sstevel@tonic-gate (opts->nsets = cpc_setgrp_numsets(opts->master)) == 0) { 2400Sstevel@tonic-gate (void) fprintf(opts->dohelp ? stdout : stderr, gettext( 2410Sstevel@tonic-gate "Usage:\n\t%s [-c events] [-p period] [-nstD] " 2420Sstevel@tonic-gate "[interval [count]]\n\n" 2430Sstevel@tonic-gate "\t-c events specify processor events to be monitored\n" 2440Sstevel@tonic-gate "\t-n\t suppress titles\n" 2450Sstevel@tonic-gate "\t-p period cycle through event list periodically\n" 2460Sstevel@tonic-gate "\t-s\t run user soaker thread for system-only events\n" 2470Sstevel@tonic-gate "\t-t\t include %s register\n" 2480Sstevel@tonic-gate "\t-D\t enable debug mode\n" 2490Sstevel@tonic-gate "\t-h\t print extended usage information\n\n" 2500Sstevel@tonic-gate "\tUse cputrack(1) to monitor per-process statistics.\n"), 2510Sstevel@tonic-gate opts->pgmname, CPC_TICKREG_NAME); 2520Sstevel@tonic-gate if (opts->dohelp) { 2530Sstevel@tonic-gate (void) putchar('\n'); 2540Sstevel@tonic-gate (void) capabilities(cpc, stdout); 2550Sstevel@tonic-gate exit(0); 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate exit(2); 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * If the user requested periodic behavior, calculate the rest time 2620Sstevel@tonic-gate * between cycles. 2630Sstevel@tonic-gate */ 2640Sstevel@tonic-gate if (opts->doperiod) { 2650Sstevel@tonic-gate opts->mseconds_rest = (uint_t)((period * 1000.0) - 2660Sstevel@tonic-gate (opts->mseconds * opts->nsets)); 2670Sstevel@tonic-gate if ((int)opts->mseconds_rest < 0) 2680Sstevel@tonic-gate opts->mseconds_rest = 0; 2690Sstevel@tonic-gate if (opts->nsamples != UINT_MAX) 2700Sstevel@tonic-gate opts->nsamples *= opts->nsets; 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate cpc_setgrp_reset(opts->master); 2740Sstevel@tonic-gate (void) setvbuf(stdout, NULL, _IOLBF, 0); 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /* 2770Sstevel@tonic-gate * If no system-mode only sets were created, no soaker threads will be 2780Sstevel@tonic-gate * needed. 2790Sstevel@tonic-gate */ 2800Sstevel@tonic-gate if (opts->dosoaker == 1 && cpc_setgrp_has_sysonly(opts->master) == 0) 2810Sstevel@tonic-gate opts->dosoaker = 0; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate ret = cpustat(); 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate (void) cpc_close(cpc); 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate return (ret); 2880Sstevel@tonic-gate } 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate static void 2910Sstevel@tonic-gate print_title(cpc_setgrp_t *sgrp) 2920Sstevel@tonic-gate { 2930Sstevel@tonic-gate (void) printf("%7s %3s %5s ", "time", "cpu", "event"); 2940Sstevel@tonic-gate if (opts->dotick) 2950Sstevel@tonic-gate (void) printf("%9s ", CPC_TICKREG_NAME); 2960Sstevel@tonic-gate (void) printf("%s\n", cpc_setgrp_gethdr(sgrp)); 2970Sstevel@tonic-gate } 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate static void 3000Sstevel@tonic-gate print_sample(processorid_t cpuid, cpc_buf_t *buf, int nreq, const char *setname, 3010Sstevel@tonic-gate int sibling) 3020Sstevel@tonic-gate { 3030Sstevel@tonic-gate char line[1024]; 3040Sstevel@tonic-gate int ccnt; 3050Sstevel@tonic-gate int i; 3060Sstevel@tonic-gate uint64_t val; 3070Sstevel@tonic-gate uint64_t tick; 3080Sstevel@tonic-gate hrtime_t hrtime; 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate hrtime = cpc_buf_hrtime(cpc, buf); 3110Sstevel@tonic-gate tick = cpc_buf_tick(cpc, buf); 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate ccnt = snprintf(line, sizeof (line), "%7.3f %3d %5s ", 3140Sstevel@tonic-gate mstimestamp(hrtime), (int)cpuid, "tick"); 3150Sstevel@tonic-gate if (opts->dotick) 3160Sstevel@tonic-gate ccnt += snprintf(line + ccnt, sizeof (line) - ccnt, 3170Sstevel@tonic-gate "%9" PRId64 " ", tick); 3180Sstevel@tonic-gate for (i = 0; i < nreq; i++) { 3190Sstevel@tonic-gate (void) cpc_buf_get(cpc, buf, i, &val); 3200Sstevel@tonic-gate ccnt += snprintf(line + ccnt, sizeof (line) - ccnt, 3210Sstevel@tonic-gate "%9" PRId64 " ", val); 3220Sstevel@tonic-gate } 3230Sstevel@tonic-gate if (opts->nsets > 1) 3240Sstevel@tonic-gate ccnt += snprintf(line + ccnt, sizeof (line) - ccnt, 3250Sstevel@tonic-gate " # %s\n", setname); 3260Sstevel@tonic-gate else 3270Sstevel@tonic-gate ccnt += snprintf(line + ccnt, sizeof (line) - ccnt, "\n"); 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate if (sibling) { 3300Sstevel@tonic-gate /* 3310Sstevel@tonic-gate * This sample is being printed for a "sibling" CPU -- that is, 3320Sstevel@tonic-gate * a CPU which does not have its own CPC set bound. It is being 3330Sstevel@tonic-gate * measured via a set bound to another CPU sharing its physical 3340Sstevel@tonic-gate * processor. 3350Sstevel@tonic-gate */ 3360Sstevel@tonic-gate int designee = chip_designees[gstate[cpuid].chip_id]; 3370Sstevel@tonic-gate char *p; 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate if ((p = strrchr(line, '#')) == NULL) 3400Sstevel@tonic-gate p = strrchr(line, '\n'); 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate if (p != NULL) { 3430Sstevel@tonic-gate *p = '\0'; 3440Sstevel@tonic-gate ccnt = strlen(line); 3450Sstevel@tonic-gate ccnt += snprintf(line + ccnt, sizeof (line) - ccnt, 3460Sstevel@tonic-gate "# counter shared with CPU %d\n", designee); 3470Sstevel@tonic-gate } 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate if (ccnt > sizeof (line)) 3510Sstevel@tonic-gate ccnt = sizeof (line); 3520Sstevel@tonic-gate if (ccnt > 0) 3530Sstevel@tonic-gate (void) write(1, line, ccnt); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate /* 3560Sstevel@tonic-gate * If this CPU is the chip designee for any other CPUs, print a line for 3570Sstevel@tonic-gate * them here. 3580Sstevel@tonic-gate */ 3590Sstevel@tonic-gate if (smt && (sibling == 0)) { 3600Sstevel@tonic-gate for (i = 0; i < ncpus; i++) { 3610Sstevel@tonic-gate if ((i != cpuid) && (gstate[i].cpuid != -1) && 3620Sstevel@tonic-gate (chip_designees[gstate[i].chip_id] == cpuid)) 3630Sstevel@tonic-gate print_sample(i, buf, nreq, setname, 1); 3640Sstevel@tonic-gate } 3650Sstevel@tonic-gate } 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate static void 3690Sstevel@tonic-gate print_total(int ncpus, cpc_buf_t *buf, int nreq, const char *setname) 3700Sstevel@tonic-gate { 3710Sstevel@tonic-gate int i; 3720Sstevel@tonic-gate uint64_t val; 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate (void) printf("%7.3f %3d %5s ", mstimestamp(cpc_buf_hrtime(cpc, buf)), 3750Sstevel@tonic-gate ncpus, "total"); 3760Sstevel@tonic-gate if (opts->dotick) 3770Sstevel@tonic-gate (void) printf("%9" PRId64 " ", cpc_buf_tick(cpc, buf)); 3780Sstevel@tonic-gate for (i = 0; i < nreq; i++) { 3790Sstevel@tonic-gate (void) cpc_buf_get(cpc, buf, i, &val); 3800Sstevel@tonic-gate (void) printf("%9" PRId64 " ", val); 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate if (opts->nsets > 1) 3830Sstevel@tonic-gate (void) printf(" # %s", setname); 3840Sstevel@tonic-gate (void) fputc('\n', stdout); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate #define NSECS_PER_MSEC 1000000ll 3880Sstevel@tonic-gate #define NSECS_PER_SEC 1000000000ll 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate static void * 3910Sstevel@tonic-gate gtick(void *arg) 3920Sstevel@tonic-gate { 3930Sstevel@tonic-gate struct tstate *state = arg; 3940Sstevel@tonic-gate char *errstr; 3950Sstevel@tonic-gate uint_t nsamples; 3960Sstevel@tonic-gate uint_t sample_cnt = 1; 3970Sstevel@tonic-gate hrtime_t ht, htdelta, restdelta; 3980Sstevel@tonic-gate cpc_setgrp_t *sgrp = state->sgrp; 3990Sstevel@tonic-gate cpc_set_t *this = cpc_setgrp_getset(sgrp); 4000Sstevel@tonic-gate const char *name = cpc_setgrp_getname(sgrp); 4010Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 4020Sstevel@tonic-gate cpc_buf_t *tmp; 4030Sstevel@tonic-gate int nreqs; 4040Sstevel@tonic-gate thread_t tid; 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate htdelta = NSECS_PER_MSEC * opts->mseconds; 4070Sstevel@tonic-gate restdelta = NSECS_PER_MSEC * opts->mseconds_rest; 4080Sstevel@tonic-gate ht = gethrtime(); 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate /* 4110Sstevel@tonic-gate * If this CPU is SMT, we run one gtick() thread per _physical_ CPU, 4120Sstevel@tonic-gate * instead of per cpu_t. The following check returns if it detects that 4130Sstevel@tonic-gate * this cpu_t has not been designated to do the counting for this 4140Sstevel@tonic-gate * physical CPU. 4150Sstevel@tonic-gate */ 4160Sstevel@tonic-gate if (smt && chip_designees[state->chip_id] != state->cpuid) 4170Sstevel@tonic-gate return (NULL); 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate /* 4200Sstevel@tonic-gate * If we need to run a soaker thread on this CPU, start it here. 4210Sstevel@tonic-gate */ 4220Sstevel@tonic-gate if (opts->dosoaker) { 4230Sstevel@tonic-gate if (cond_init(&state->soak_cv, USYNC_THREAD, NULL) != 0) 4240Sstevel@tonic-gate goto bad; 4250Sstevel@tonic-gate if (mutex_init(&state->soak_lock, USYNC_THREAD, 4260Sstevel@tonic-gate NULL) != 0) 4270Sstevel@tonic-gate goto bad; 4280Sstevel@tonic-gate (void) mutex_lock(&state->soak_lock); 4290Sstevel@tonic-gate state->soak_state = SOAK_PAUSE; 4300Sstevel@tonic-gate if (thr_create(NULL, 0, soaker, state, NULL, &tid) != 0) 4310Sstevel@tonic-gate goto bad; 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate while (state->soak_state == SOAK_PAUSE) 4340Sstevel@tonic-gate (void) cond_wait(&state->soak_cv, 4350Sstevel@tonic-gate &state->soak_lock); 4360Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /* 4390Sstevel@tonic-gate * If the soaker needs to pause for the first set, stop it now. 4400Sstevel@tonic-gate */ 4410Sstevel@tonic-gate if (cpc_setgrp_sysonly(sgrp) == 0) { 4420Sstevel@tonic-gate (void) mutex_lock(&state->soak_lock); 4430Sstevel@tonic-gate state->soak_state = SOAK_PAUSE; 4440Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 4450Sstevel@tonic-gate } 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate if (cpc_bind_cpu(cpc, state->cpuid, this, 0) == -1) 4480Sstevel@tonic-gate goto bad; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate for (nsamples = opts->nsamples; nsamples; nsamples--, sample_cnt++) { 4510Sstevel@tonic-gate hrtime_t htnow; 4520Sstevel@tonic-gate struct timespec ts; 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate nreqs = cpc_setgrp_getbufs(sgrp, &data1, &data2, &scratch); 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate ht += htdelta; 4570Sstevel@tonic-gate htnow = gethrtime(); 4580Sstevel@tonic-gate if (ht <= htnow) 4590Sstevel@tonic-gate continue; 4600Sstevel@tonic-gate ts.tv_sec = (time_t)((ht - htnow) / NSECS_PER_SEC); 4610Sstevel@tonic-gate ts.tv_nsec = (suseconds_t)((ht - htnow) % NSECS_PER_SEC); 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate (void) nanosleep(&ts, NULL); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (opts->nsets == 1) { 4660Sstevel@tonic-gate /* 4670Sstevel@tonic-gate * If we're dealing with one set, buffer usage is: 4680Sstevel@tonic-gate * 4690Sstevel@tonic-gate * data1 = most recent data snapshot 4700Sstevel@tonic-gate * data2 = previous data snapshot 4710Sstevel@tonic-gate * scratch = used for diffing data1 and data2 4720Sstevel@tonic-gate * 4730Sstevel@tonic-gate * Save the snapshot from the previous sample in data2 4740Sstevel@tonic-gate * before putting the current sample in data1. 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate tmp = *data1; 4770Sstevel@tonic-gate *data1 = *data2; 4780Sstevel@tonic-gate *data2 = tmp; 4790Sstevel@tonic-gate if (cpc_set_sample(cpc, this, *data1) != 0) 4800Sstevel@tonic-gate goto bad; 4810Sstevel@tonic-gate cpc_buf_sub(cpc, *scratch, *data1, *data2); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate print_sample(state->cpuid, *scratch, nreqs, name, 0); 4840Sstevel@tonic-gate } else { 4850Sstevel@tonic-gate /* 4860Sstevel@tonic-gate * More than one set is in use (multiple -c options 4870Sstevel@tonic-gate * given). Buffer usage in this case is: 4880Sstevel@tonic-gate * 4890Sstevel@tonic-gate * data1 = total counts for this set since program began 4900Sstevel@tonic-gate * data2 = unused 4910Sstevel@tonic-gate * scratch = most recent data snapshot 4920Sstevel@tonic-gate */ 4930Sstevel@tonic-gate name = cpc_setgrp_getname(sgrp); 4940Sstevel@tonic-gate nreqs = cpc_setgrp_getbufs(sgrp, &data1, &data2, 4950Sstevel@tonic-gate &scratch); 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate if (cpc_set_sample(cpc, this, *scratch) != 0) 4980Sstevel@tonic-gate goto bad; 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate cpc_buf_add(cpc, *data1, *data1, *scratch); 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate if (cpc_unbind(cpc, this) != 0) 5030Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: error " 5040Sstevel@tonic-gate "unbinding on cpu %d - %s\n"), 5050Sstevel@tonic-gate opts->pgmname, state->cpuid, 5060Sstevel@tonic-gate strerror(errno)); 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate this = cpc_setgrp_nextset(sgrp); 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate print_sample(state->cpuid, *scratch, nreqs, name, 0); 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate /* 5130Sstevel@tonic-gate * If periodic behavior was requested, rest here. 5140Sstevel@tonic-gate */ 5150Sstevel@tonic-gate if (opts->doperiod && opts->mseconds_rest > 0 && 5160Sstevel@tonic-gate (sample_cnt % opts->nsets) == 0) { 5170Sstevel@tonic-gate /* 5180Sstevel@tonic-gate * Stop the soaker while the tool rests. 5190Sstevel@tonic-gate */ 5200Sstevel@tonic-gate if (opts->dosoaker) { 5210Sstevel@tonic-gate (void) mutex_lock(&state->soak_lock); 5220Sstevel@tonic-gate if (state->soak_state == SOAK_RUN) 5230Sstevel@tonic-gate state->soak_state = SOAK_PAUSE; 5240Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 5250Sstevel@tonic-gate } 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate htnow = gethrtime(); 5280Sstevel@tonic-gate ht += restdelta; 5290Sstevel@tonic-gate ts.tv_sec = (time_t)((ht - htnow) / 5300Sstevel@tonic-gate NSECS_PER_SEC); 5310Sstevel@tonic-gate ts.tv_nsec = (suseconds_t)((ht - htnow) % 5320Sstevel@tonic-gate NSECS_PER_SEC); 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate (void) nanosleep(&ts, NULL); 5350Sstevel@tonic-gate } 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate /* 5380Sstevel@tonic-gate * Start or stop the soaker if needed. 5390Sstevel@tonic-gate */ 5400Sstevel@tonic-gate if (opts->dosoaker) { 5410Sstevel@tonic-gate (void) mutex_lock(&state->soak_lock); 5420Sstevel@tonic-gate if (cpc_setgrp_sysonly(sgrp) && 5430Sstevel@tonic-gate state->soak_state == SOAK_PAUSE) { 5440Sstevel@tonic-gate /* 5450Sstevel@tonic-gate * Soaker is paused but the next set is 5460Sstevel@tonic-gate * sysonly: start the soaker. 5470Sstevel@tonic-gate */ 5480Sstevel@tonic-gate state->soak_state = SOAK_RUN; 5490Sstevel@tonic-gate (void) cond_signal(&state->soak_cv); 5500Sstevel@tonic-gate } else if (cpc_setgrp_sysonly(sgrp) == 0 && 5510Sstevel@tonic-gate state->soak_state == SOAK_RUN) 5520Sstevel@tonic-gate /* 5530Sstevel@tonic-gate * Soaker is running but the next set 5540Sstevel@tonic-gate * counts user events: stop the soaker. 5550Sstevel@tonic-gate */ 5560Sstevel@tonic-gate state->soak_state = SOAK_PAUSE; 5570Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 5580Sstevel@tonic-gate } 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate if (cpc_bind_cpu(cpc, state->cpuid, this, 0) != 0) 5610Sstevel@tonic-gate goto bad; 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate if (cpc_unbind(cpc, this) != 0) 5660Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: error unbinding on" 5670Sstevel@tonic-gate " cpu %d - %s\n"), opts->pgmname, 5680Sstevel@tonic-gate state->cpuid, strerror(errno)); 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate /* 5710Sstevel@tonic-gate * We're done, so stop the soaker if needed. 5720Sstevel@tonic-gate */ 5730Sstevel@tonic-gate if (opts->dosoaker) { 5740Sstevel@tonic-gate (void) mutex_lock(&state->soak_lock); 5750Sstevel@tonic-gate if (state->soak_state == SOAK_RUN) 5760Sstevel@tonic-gate state->soak_state = SOAK_PAUSE; 5770Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 5780Sstevel@tonic-gate } 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate return (NULL); 5810Sstevel@tonic-gate bad: 5820Sstevel@tonic-gate state->status = 3; 5830Sstevel@tonic-gate errstr = strerror(errno); 5840Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cpu%d - %s\n"), 5850Sstevel@tonic-gate opts->pgmname, state->cpuid, errstr); 5860Sstevel@tonic-gate return (NULL); 5870Sstevel@tonic-gate } 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate static int 5900Sstevel@tonic-gate cpustat(void) 5910Sstevel@tonic-gate { 5920Sstevel@tonic-gate cpc_setgrp_t *accum; 5930Sstevel@tonic-gate cpc_set_t *start; 5940Sstevel@tonic-gate int c, i, retval; 5950Sstevel@tonic-gate int lwps = 0; 5960Sstevel@tonic-gate psetid_t mypset, cpupset; 5970Sstevel@tonic-gate char *errstr; 5980Sstevel@tonic-gate cpc_buf_t **data1, **data2, **scratch; 5990Sstevel@tonic-gate int nreqs; 6000Sstevel@tonic-gate kstat_ctl_t *kc; 6010Sstevel@tonic-gate 6020Sstevel@tonic-gate ncpus = (int)sysconf(_SC_NPROCESSORS_CONF); 6030Sstevel@tonic-gate if ((gstate = calloc(ncpus, sizeof (*gstate))) == NULL) { 6040Sstevel@tonic-gate (void) fprintf(stderr, gettext( 6050Sstevel@tonic-gate "%s: out of heap\n"), opts->pgmname); 6060Sstevel@tonic-gate return (1); 6070Sstevel@tonic-gate } 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate max_chip_id = sysconf(_SC_CPUID_MAX); 6100Sstevel@tonic-gate if ((chip_designees = malloc(max_chip_id * sizeof (int))) == NULL) { 6110Sstevel@tonic-gate (void) fprintf(stderr, gettext( 6120Sstevel@tonic-gate "%s: out of heap\n"), opts->pgmname); 6130Sstevel@tonic-gate return (1); 6140Sstevel@tonic-gate } 6150Sstevel@tonic-gate for (i = 0; i < max_chip_id; i++) 6160Sstevel@tonic-gate chip_designees[i] = -1; 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate if (smt) { 6190Sstevel@tonic-gate if ((kc = kstat_open()) == NULL) { 6200Sstevel@tonic-gate (void) fprintf(stderr, gettext( 6210Sstevel@tonic-gate "%s: kstat_open() failed: %s\n"), opts->pgmname, 6220Sstevel@tonic-gate strerror(errno)); 6230Sstevel@tonic-gate return (1); 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate if (opts->dosoaker) 6280Sstevel@tonic-gate if (priocntl(0, 0, PC_GETCID, &fxinfo) == -1) { 6290Sstevel@tonic-gate (void) fprintf(stderr, gettext( 6300Sstevel@tonic-gate "%s: couldn't get FX scheduler class: %s\n"), 6310Sstevel@tonic-gate opts->pgmname, strerror(errno)); 6320Sstevel@tonic-gate return (1); 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate /* 6360Sstevel@tonic-gate * Only include processors that are participating in the system 6370Sstevel@tonic-gate */ 6380Sstevel@tonic-gate for (c = 0, i = 0; i < ncpus; c++) { 6390Sstevel@tonic-gate switch (p_online(c, P_STATUS)) { 6400Sstevel@tonic-gate case P_ONLINE: 6410Sstevel@tonic-gate case P_NOINTR: 6420Sstevel@tonic-gate if (smt) { 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate gstate[i].chip_id = get_chipid(kc, c); 6450Sstevel@tonic-gate if (gstate[i].chip_id != -1 && 6460Sstevel@tonic-gate chip_designees[gstate[i].chip_id] == -1) 6470Sstevel@tonic-gate chip_designees[gstate[i].chip_id] = c; 6480Sstevel@tonic-gate } 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate gstate[i++].cpuid = c; 6510Sstevel@tonic-gate break; 6520Sstevel@tonic-gate case P_OFFLINE: 6530Sstevel@tonic-gate case P_POWEROFF: 6540Sstevel@tonic-gate case P_FAULTED: 6550Sstevel@tonic-gate case P_SPARE: 6560Sstevel@tonic-gate gstate[i++].cpuid = -1; 6570Sstevel@tonic-gate break; 6580Sstevel@tonic-gate default: 6590Sstevel@tonic-gate gstate[i++].cpuid = -1; 6600Sstevel@tonic-gate (void) fprintf(stderr, 6610Sstevel@tonic-gate gettext("%s: cpu%d in unknown state\n"), 6620Sstevel@tonic-gate opts->pgmname, c); 6630Sstevel@tonic-gate break; 6640Sstevel@tonic-gate case -1: 6650Sstevel@tonic-gate break; 6660Sstevel@tonic-gate } 6670Sstevel@tonic-gate } 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate /* 6700Sstevel@tonic-gate * Examine the processor sets; if we're in one, only attempt 6710Sstevel@tonic-gate * to report on the set we're in. 6720Sstevel@tonic-gate */ 6730Sstevel@tonic-gate if (pset_bind(PS_QUERY, P_PID, P_MYID, &mypset) == -1) { 6740Sstevel@tonic-gate errstr = strerror(errno); 6750Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: pset_bind - %s\n"), 6760Sstevel@tonic-gate opts->pgmname, errstr); 6770Sstevel@tonic-gate } else { 6780Sstevel@tonic-gate for (i = 0; i < ncpus; i++) { 6790Sstevel@tonic-gate struct tstate *this = &gstate[i]; 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate if (this->cpuid == -1) 6820Sstevel@tonic-gate continue; 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate if (pset_assign(PS_QUERY, 6850Sstevel@tonic-gate this->cpuid, &cpupset) == -1) { 6860Sstevel@tonic-gate errstr = strerror(errno); 6870Sstevel@tonic-gate (void) fprintf(stderr, 6880Sstevel@tonic-gate gettext("%s: pset_assign - %s\n"), 6890Sstevel@tonic-gate opts->pgmname, errstr); 6900Sstevel@tonic-gate continue; 6910Sstevel@tonic-gate } 6920Sstevel@tonic-gate 6930Sstevel@tonic-gate if (mypset != cpupset) 6940Sstevel@tonic-gate this->cpuid = -1; 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate if (opts->dotitle) 6990Sstevel@tonic-gate print_title(opts->master); 7000Sstevel@tonic-gate zerotime(); 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate for (i = 0; i < ncpus; i++) { 7030Sstevel@tonic-gate struct tstate *this = &gstate[i]; 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate if (this->cpuid == -1) 7060Sstevel@tonic-gate continue; 7070Sstevel@tonic-gate this->sgrp = cpc_setgrp_clone(opts->master); 7080Sstevel@tonic-gate if (this->sgrp == NULL) { 7090Sstevel@tonic-gate this->cpuid = -1; 7100Sstevel@tonic-gate continue; 7110Sstevel@tonic-gate } 7120Sstevel@tonic-gate if (thr_create(NULL, 0, gtick, this, 7130Sstevel@tonic-gate THR_BOUND|THR_NEW_LWP, &this->tid) == 0) 7140Sstevel@tonic-gate lwps++; 7150Sstevel@tonic-gate else { 7160Sstevel@tonic-gate (void) fprintf(stderr, 7170Sstevel@tonic-gate gettext("%s: cannot create thread for cpu%d\n"), 7180Sstevel@tonic-gate opts->pgmname, this->cpuid); 7190Sstevel@tonic-gate this->status = 4; 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate } 7220Sstevel@tonic-gate 7230Sstevel@tonic-gate if (lwps != 0) 7240Sstevel@tonic-gate for (i = 0; i < ncpus; i++) 7250Sstevel@tonic-gate (void) thr_join(gstate[i].tid, NULL, NULL); 7260Sstevel@tonic-gate 7270Sstevel@tonic-gate if ((accum = cpc_setgrp_clone(opts->master)) == NULL) { 7280Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: out of heap\n"), 7290Sstevel@tonic-gate opts->pgmname); 7300Sstevel@tonic-gate return (1); 7310Sstevel@tonic-gate } 7320Sstevel@tonic-gate 7330Sstevel@tonic-gate retval = 0; 7340Sstevel@tonic-gate for (i = 0; i < ncpus; i++) { 7350Sstevel@tonic-gate struct tstate *this = &gstate[i]; 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate if (this->cpuid == -1) 7380Sstevel@tonic-gate continue; 7390Sstevel@tonic-gate cpc_setgrp_accum(accum, this->sgrp); 7400Sstevel@tonic-gate cpc_setgrp_free(this->sgrp); 7410Sstevel@tonic-gate this->sgrp = NULL; 7420Sstevel@tonic-gate if (this->status != 0) 7430Sstevel@tonic-gate retval = 1; 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate cpc_setgrp_reset(accum); 7470Sstevel@tonic-gate start = cpc_setgrp_getset(accum); 7480Sstevel@tonic-gate do { 7490Sstevel@tonic-gate nreqs = cpc_setgrp_getbufs(accum, &data1, &data2, &scratch); 7500Sstevel@tonic-gate print_total(lwps, *data1, nreqs, cpc_setgrp_getname(accum)); 7510Sstevel@tonic-gate } while (cpc_setgrp_nextset(accum) != start); 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate cpc_setgrp_free(accum); 7540Sstevel@tonic-gate accum = NULL; 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate free(gstate); 7570Sstevel@tonic-gate return (retval); 7580Sstevel@tonic-gate } 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate static int 7610Sstevel@tonic-gate get_chipid(kstat_ctl_t *kc, processorid_t cpuid) 7620Sstevel@tonic-gate { 7630Sstevel@tonic-gate kstat_t *ksp; 7640Sstevel@tonic-gate kstat_named_t *k; 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate if ((ksp = kstat_lookup(kc, "cpu_info", cpuid, NULL)) == NULL) 7670Sstevel@tonic-gate return (-1); 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate if (kstat_read(kc, ksp, NULL) == -1) { 7700Sstevel@tonic-gate (void) fprintf(stderr, 7710Sstevel@tonic-gate gettext("%s: kstat_read() failed for cpu %d: %s\n"), 7720Sstevel@tonic-gate opts->pgmname, cpuid, strerror(errno)); 7730Sstevel@tonic-gate return (-1); 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate if ((k = (kstat_named_t *)kstat_data_lookup(ksp, "chip_id")) == NULL) { 7770Sstevel@tonic-gate (void) fprintf(stderr, 7780Sstevel@tonic-gate gettext("%s: chip_id not found for cpu %d: %s\n"), 7790Sstevel@tonic-gate opts->pgmname, cpuid, strerror(errno)); 7800Sstevel@tonic-gate return (-1); 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate return (k->value.i32); 7840Sstevel@tonic-gate } 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate static void * 7870Sstevel@tonic-gate soaker(void *arg) 7880Sstevel@tonic-gate { 7890Sstevel@tonic-gate struct tstate *state = arg; 7900Sstevel@tonic-gate pcparms_t pcparms; 7910Sstevel@tonic-gate fxparms_t *fx = (fxparms_t *)pcparms.pc_clparms; 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate if (processor_bind(P_LWPID, P_MYID, state->cpuid, NULL) != 0) 7940Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: couldn't bind soaker " 7950Sstevel@tonic-gate "thread to cpu%d: %s\n"), opts->pgmname, state->cpuid, 7960Sstevel@tonic-gate strerror(errno)); 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate /* 7990Sstevel@tonic-gate * Put the soaker thread in the fixed priority (FX) class so it runs 8000Sstevel@tonic-gate * at the lowest possible global priority. 8010Sstevel@tonic-gate */ 8020Sstevel@tonic-gate pcparms.pc_cid = fxinfo.pc_cid; 8030Sstevel@tonic-gate fx->fx_upri = 0; 8040Sstevel@tonic-gate fx->fx_uprilim = 0; 8050Sstevel@tonic-gate fx->fx_tqsecs = fx->fx_tqnsecs = FX_TQDEF; 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate if (priocntl(P_LWPID, P_MYID, PC_SETPARMS, &pcparms) != 0) 8080Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: couldn't put soaker " 8090Sstevel@tonic-gate "thread in FX sched class: %s\n"), opts->pgmname, 8100Sstevel@tonic-gate strerror(errno)); 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate /* 8130Sstevel@tonic-gate * Let the parent thread know we're ready to roll. 8140Sstevel@tonic-gate */ 8150Sstevel@tonic-gate (void) mutex_lock(&state->soak_lock); 8160Sstevel@tonic-gate state->soak_state = SOAK_RUN; 8170Sstevel@tonic-gate (void) cond_signal(&state->soak_cv); 8180Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate for (;;) { 8210Sstevel@tonic-gate spin: 8220Sstevel@tonic-gate (void) mutex_lock(&state->soak_lock); 8230Sstevel@tonic-gate if (state->soak_state == SOAK_RUN) { 8240Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 8250Sstevel@tonic-gate goto spin; 8260Sstevel@tonic-gate } 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate while (state->soak_state == SOAK_PAUSE) 8290Sstevel@tonic-gate (void) cond_wait(&state->soak_cv, 8300Sstevel@tonic-gate &state->soak_lock); 8310Sstevel@tonic-gate (void) mutex_unlock(&state->soak_lock); 8320Sstevel@tonic-gate } 8330Sstevel@tonic-gate 8340Sstevel@tonic-gate /*NOTREACHED*/ 8350Sstevel@tonic-gate return (NULL); 8360Sstevel@tonic-gate } 837