Index: stable/10/sys/cddl/contrib/opensolaris/uts/common/dtrace/systrace.c =================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/dtrace/systrace.c (revision 270997) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/dtrace/systrace.c (revision 270998) @@ -1,373 +1,373 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" #include #include #include #include #include #include #include #include #define SYSTRACE_ARTIFICIAL_FRAMES 1 #define SYSTRACE_SHIFT 16 #define SYSTRACE_ISENTRY(x) ((int)(x) >> SYSTRACE_SHIFT) #define SYSTRACE_SYSNUM(x) ((int)(x) & ((1 << SYSTRACE_SHIFT) - 1)) #define SYSTRACE_ENTRY(id) ((1 << SYSTRACE_SHIFT) | (id)) #define SYSTRACE_RETURN(id) (id) #if ((1 << SYSTRACE_SHIFT) <= NSYSCALL) #error 1 << SYSTRACE_SHIFT must exceed number of system calls #endif static dev_info_t *systrace_devi; static dtrace_provider_id_t systrace_id; static void systrace_init(struct sysent *actual, systrace_sysent_t **interposed) { systrace_sysent_t *sysent = *interposed; int i; if (sysent == NULL) { *interposed = sysent = kmem_zalloc(sizeof (systrace_sysent_t) * NSYSCALL, KM_SLEEP); } for (i = 0; i < NSYSCALL; i++) { struct sysent *a = &actual[i]; systrace_sysent_t *s = &sysent[i]; if (LOADABLE_SYSCALL(a) && !LOADED_SYSCALL(a)) continue; if (a->sy_callc == dtrace_systrace_syscall) continue; #ifdef _SYSCALL32_IMPL if (a->sy_callc == dtrace_systrace_syscall32) continue; #endif s->stsy_underlying = a->sy_callc; } } /*ARGSUSED*/ static void systrace_provide(void *arg, const dtrace_probedesc_t *desc) { int i; if (desc != NULL) return; systrace_init(sysent, &systrace_sysent); #ifdef _SYSCALL32_IMPL systrace_init(sysent32, &systrace_sysent32); #endif for (i = 0; i < NSYSCALL; i++) { if (systrace_sysent[i].stsy_underlying == NULL) continue; if (dtrace_probe_lookup(systrace_id, NULL, syscallnames[i], "entry") != 0) continue; (void) dtrace_probe_create(systrace_id, NULL, syscallnames[i], "entry", SYSTRACE_ARTIFICIAL_FRAMES, (void *)((uintptr_t)SYSTRACE_ENTRY(i))); (void) dtrace_probe_create(systrace_id, NULL, syscallnames[i], "return", SYSTRACE_ARTIFICIAL_FRAMES, (void *)((uintptr_t)SYSTRACE_RETURN(i))); systrace_sysent[i].stsy_entry = DTRACE_IDNONE; systrace_sysent[i].stsy_return = DTRACE_IDNONE; #ifdef _SYSCALL32_IMPL systrace_sysent32[i].stsy_entry = DTRACE_IDNONE; systrace_sysent32[i].stsy_return = DTRACE_IDNONE; #endif } } /*ARGSUSED*/ static void systrace_destroy(void *arg, dtrace_id_t id, void *parg) { int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg); /* * There's nothing to do here but assert that we have actually been * disabled. */ if (SYSTRACE_ISENTRY((uintptr_t)parg)) { ASSERT(systrace_sysent[sysnum].stsy_entry == DTRACE_IDNONE); #ifdef _SYSCALL32_IMPL ASSERT(systrace_sysent32[sysnum].stsy_entry == DTRACE_IDNONE); #endif } else { ASSERT(systrace_sysent[sysnum].stsy_return == DTRACE_IDNONE); #ifdef _SYSCALL32_IMPL ASSERT(systrace_sysent32[sysnum].stsy_return == DTRACE_IDNONE); #endif } } /*ARGSUSED*/ static void systrace_enable(void *arg, dtrace_id_t id, void *parg) { int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg); int enabled = (systrace_sysent[sysnum].stsy_entry != DTRACE_IDNONE || systrace_sysent[sysnum].stsy_return != DTRACE_IDNONE); if (SYSTRACE_ISENTRY((uintptr_t)parg)) { systrace_sysent[sysnum].stsy_entry = id; #ifdef _SYSCALL32_IMPL systrace_sysent32[sysnum].stsy_entry = id; #endif } else { systrace_sysent[sysnum].stsy_return = id; #ifdef _SYSCALL32_IMPL systrace_sysent32[sysnum].stsy_return = id; #endif } if (enabled) { ASSERT(sysent[sysnum].sy_callc == dtrace_systrace_syscall); return; } - (void) casptr(&sysent[sysnum].sy_callc, + (void) atomic_cas_ptr(&sysent[sysnum].sy_callc, (void *)systrace_sysent[sysnum].stsy_underlying, (void *)dtrace_systrace_syscall); #ifdef _SYSCALL32_IMPL - (void) casptr(&sysent32[sysnum].sy_callc, + (void) atomic_cas_ptr(&sysent32[sysnum].sy_callc, (void *)systrace_sysent32[sysnum].stsy_underlying, (void *)dtrace_systrace_syscall32); #endif } /*ARGSUSED*/ static void systrace_disable(void *arg, dtrace_id_t id, void *parg) { int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg); int disable = (systrace_sysent[sysnum].stsy_entry == DTRACE_IDNONE || systrace_sysent[sysnum].stsy_return == DTRACE_IDNONE); if (disable) { - (void) casptr(&sysent[sysnum].sy_callc, + (void) atomic_cas_ptr(&sysent[sysnum].sy_callc, (void *)dtrace_systrace_syscall, (void *)systrace_sysent[sysnum].stsy_underlying); #ifdef _SYSCALL32_IMPL - (void) casptr(&sysent32[sysnum].sy_callc, + (void) atomic_cas_ptr(&sysent32[sysnum].sy_callc, (void *)dtrace_systrace_syscall32, (void *)systrace_sysent32[sysnum].stsy_underlying); #endif } if (SYSTRACE_ISENTRY((uintptr_t)parg)) { systrace_sysent[sysnum].stsy_entry = DTRACE_IDNONE; #ifdef _SYSCALL32_IMPL systrace_sysent32[sysnum].stsy_entry = DTRACE_IDNONE; #endif } else { systrace_sysent[sysnum].stsy_return = DTRACE_IDNONE; #ifdef _SYSCALL32_IMPL systrace_sysent32[sysnum].stsy_return = DTRACE_IDNONE; #endif } } static dtrace_pattr_t systrace_attr = { { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA }, { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA }, }; static dtrace_pops_t systrace_pops = { systrace_provide, NULL, systrace_enable, systrace_disable, NULL, NULL, NULL, NULL, NULL, systrace_destroy }; static int systrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) { switch (cmd) { case DDI_ATTACH: break; case DDI_RESUME: return (DDI_SUCCESS); default: return (DDI_FAILURE); } systrace_probe = (void (*)())dtrace_probe; membar_enter(); if (ddi_create_minor_node(devi, "systrace", S_IFCHR, 0, DDI_PSEUDO, NULL) == DDI_FAILURE || dtrace_register("syscall", &systrace_attr, DTRACE_PRIV_USER, NULL, &systrace_pops, NULL, &systrace_id) != 0) { systrace_probe = systrace_stub; ddi_remove_minor_node(devi, NULL); return (DDI_FAILURE); } ddi_report_dev(devi); systrace_devi = devi; return (DDI_SUCCESS); } static int systrace_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) { switch (cmd) { case DDI_DETACH: break; case DDI_SUSPEND: return (DDI_SUCCESS); default: return (DDI_FAILURE); } if (dtrace_unregister(systrace_id) != 0) return (DDI_FAILURE); ddi_remove_minor_node(devi, NULL); systrace_probe = systrace_stub; return (DDI_SUCCESS); } /*ARGSUSED*/ static int systrace_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) { int error; switch (infocmd) { case DDI_INFO_DEVT2DEVINFO: *result = (void *)systrace_devi; error = DDI_SUCCESS; break; case DDI_INFO_DEVT2INSTANCE: *result = (void *)0; error = DDI_SUCCESS; break; default: error = DDI_FAILURE; } return (error); } /*ARGSUSED*/ static int systrace_open(dev_t *devp, int flag, int otyp, cred_t *cred_p) { return (0); } static struct cb_ops systrace_cb_ops = { systrace_open, /* open */ nodev, /* close */ nulldev, /* strategy */ nulldev, /* print */ nodev, /* dump */ nodev, /* read */ nodev, /* write */ nodev, /* ioctl */ nodev, /* devmap */ nodev, /* mmap */ nodev, /* segmap */ nochpoll, /* poll */ ddi_prop_op, /* cb_prop_op */ 0, /* streamtab */ D_NEW | D_MP /* Driver compatibility flag */ }; static struct dev_ops systrace_ops = { DEVO_REV, /* devo_rev, */ 0, /* refcnt */ systrace_info, /* get_dev_info */ nulldev, /* identify */ nulldev, /* probe */ systrace_attach, /* attach */ systrace_detach, /* detach */ nodev, /* reset */ &systrace_cb_ops, /* driver operations */ NULL, /* bus operations */ nodev /* dev power */ }; /* * Module linkage information for the kernel. */ static struct modldrv modldrv = { &mod_driverops, /* module type (this is a pseudo driver) */ "System Call Tracing", /* name of module */ &systrace_ops, /* driver ops */ }; static struct modlinkage modlinkage = { MODREV_1, (void *)&modldrv, NULL }; int _init(void) { return (mod_install(&modlinkage)); } int _info(struct modinfo *modinfop) { return (mod_info(&modlinkage, modinfop)); } int _fini(void) { return (mod_remove(&modlinkage)); } Index: stable/10/sys/cddl/contrib/opensolaris/uts/common/os/fm.c =================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/os/fm.c (revision 270997) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/os/fm.c (revision 270998) @@ -1,1402 +1,1402 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. */ /* * Fault Management Architecture (FMA) Resource and Protocol Support * * The routines contained herein provide services to support kernel subsystems * in publishing fault management telemetry (see PSARC 2002/412 and 2003/089). * * Name-Value Pair Lists * * The embodiment of an FMA protocol element (event, fmri or authority) is a * name-value pair list (nvlist_t). FMA-specific nvlist construtor and * destructor functions, fm_nvlist_create() and fm_nvlist_destroy(), are used * to create an nvpair list using custom allocators. Callers may choose to * allocate either from the kernel memory allocator, or from a preallocated * buffer, useful in constrained contexts like high-level interrupt routines. * * Protocol Event and FMRI Construction * * Convenience routines are provided to construct nvlist events according to * the FMA Event Protocol and Naming Schema specification for ereports and * FMRIs for the dev, cpu, hc, mem, legacy hc and de schemes. * * ENA Manipulation * * Routines to generate ENA formats 0, 1 and 2 are available as well as * routines to increment formats 1 and 2. Individual fields within the * ENA are extractable via fm_ena_time_get(), fm_ena_id_get(), * fm_ena_format_get() and fm_ena_gen_get(). */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * URL and SUNW-MSG-ID value to display for fm_panic(), defined below. These * values must be kept in sync with the FMA source code in usr/src/cmd/fm. */ static const char *fm_url = "http://www.sun.com/msg"; static const char *fm_msgid = "SUNOS-8000-0G"; static char *volatile fm_panicstr = NULL; #ifdef sun errorq_t *ereport_errorq; #endif void *ereport_dumpbuf; size_t ereport_dumplen; static uint_t ereport_chanlen = ERPT_EVCH_MAX; static evchan_t *ereport_chan = NULL; static ulong_t ereport_qlen = 0; static size_t ereport_size = 0; static int ereport_cols = 80; extern void fastreboot_disable_highpil(void); /* * Common fault management kstats to record ereport generation * failures */ struct erpt_kstat { kstat_named_t erpt_dropped; /* num erpts dropped on post */ kstat_named_t erpt_set_failed; /* num erpt set failures */ kstat_named_t fmri_set_failed; /* num fmri set failures */ kstat_named_t payload_set_failed; /* num payload set failures */ }; static struct erpt_kstat erpt_kstat_data = { { "erpt-dropped", KSTAT_DATA_UINT64 }, { "erpt-set-failed", KSTAT_DATA_UINT64 }, { "fmri-set-failed", KSTAT_DATA_UINT64 }, { "payload-set-failed", KSTAT_DATA_UINT64 } }; #ifdef sun /*ARGSUSED*/ static void fm_drain(void *private, void *data, errorq_elem_t *eep) { nvlist_t *nvl = errorq_elem_nvl(ereport_errorq, eep); if (!panicstr) (void) fm_ereport_post(nvl, EVCH_TRYHARD); else fm_nvprint(nvl); } #endif void fm_init(void) { kstat_t *ksp; #ifdef sun (void) sysevent_evc_bind(FM_ERROR_CHAN, &ereport_chan, EVCH_CREAT | EVCH_HOLD_PEND); (void) sysevent_evc_control(ereport_chan, EVCH_SET_CHAN_LEN, &ereport_chanlen); #endif if (ereport_qlen == 0) ereport_qlen = ERPT_MAX_ERRS * MAX(max_ncpus, 4); if (ereport_size == 0) ereport_size = ERPT_DATA_SZ; #ifdef sun ereport_errorq = errorq_nvcreate("fm_ereport_queue", (errorq_func_t)fm_drain, NULL, ereport_qlen, ereport_size, FM_ERR_PIL, ERRORQ_VITAL); if (ereport_errorq == NULL) panic("failed to create required ereport error queue"); #endif ereport_dumpbuf = kmem_alloc(ereport_size, KM_SLEEP); ereport_dumplen = ereport_size; /* Initialize ereport allocation and generation kstats */ ksp = kstat_create("unix", 0, "fm", "misc", KSTAT_TYPE_NAMED, sizeof (struct erpt_kstat) / sizeof (kstat_named_t), KSTAT_FLAG_VIRTUAL); if (ksp != NULL) { ksp->ks_data = &erpt_kstat_data; kstat_install(ksp); } else { cmn_err(CE_NOTE, "failed to create fm/misc kstat\n"); } } #ifdef sun /* * Formatting utility function for fm_nvprintr. We attempt to wrap chunks of * output so they aren't split across console lines, and return the end column. */ /*PRINTFLIKE4*/ static int fm_printf(int depth, int c, int cols, const char *format, ...) { va_list ap; int width; char c1; va_start(ap, format); width = vsnprintf(&c1, sizeof (c1), format, ap); va_end(ap); if (c + width >= cols) { console_printf("\n\r"); c = 0; if (format[0] != ' ' && depth > 0) { console_printf(" "); c++; } } va_start(ap, format); console_vprintf(format, ap); va_end(ap); return ((c + width) % cols); } /* * Recursively print a nvlist in the specified column width and return the * column we end up in. This function is called recursively by fm_nvprint(), * below. We generically format the entire nvpair using hexadecimal * integers and strings, and elide any integer arrays. Arrays are basically * used for cache dumps right now, so we suppress them so as not to overwhelm * the amount of console output we produce at panic time. This can be further * enhanced as FMA technology grows based upon the needs of consumers. All * FMA telemetry is logged using the dump device transport, so the console * output serves only as a fallback in case this procedure is unsuccessful. */ static int fm_nvprintr(nvlist_t *nvl, int d, int c, int cols) { nvpair_t *nvp; for (nvp = nvlist_next_nvpair(nvl, NULL); nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) { data_type_t type = nvpair_type(nvp); const char *name = nvpair_name(nvp); boolean_t b; uint8_t i8; uint16_t i16; uint32_t i32; uint64_t i64; char *str; nvlist_t *cnv; if (strcmp(name, FM_CLASS) == 0) continue; /* already printed by caller */ c = fm_printf(d, c, cols, " %s=", name); switch (type) { case DATA_TYPE_BOOLEAN: c = fm_printf(d + 1, c, cols, " 1"); break; case DATA_TYPE_BOOLEAN_VALUE: (void) nvpair_value_boolean_value(nvp, &b); c = fm_printf(d + 1, c, cols, b ? "1" : "0"); break; case DATA_TYPE_BYTE: (void) nvpair_value_byte(nvp, &i8); c = fm_printf(d + 1, c, cols, "%x", i8); break; case DATA_TYPE_INT8: (void) nvpair_value_int8(nvp, (void *)&i8); c = fm_printf(d + 1, c, cols, "%x", i8); break; case DATA_TYPE_UINT8: (void) nvpair_value_uint8(nvp, &i8); c = fm_printf(d + 1, c, cols, "%x", i8); break; case DATA_TYPE_INT16: (void) nvpair_value_int16(nvp, (void *)&i16); c = fm_printf(d + 1, c, cols, "%x", i16); break; case DATA_TYPE_UINT16: (void) nvpair_value_uint16(nvp, &i16); c = fm_printf(d + 1, c, cols, "%x", i16); break; case DATA_TYPE_INT32: (void) nvpair_value_int32(nvp, (void *)&i32); c = fm_printf(d + 1, c, cols, "%x", i32); break; case DATA_TYPE_UINT32: (void) nvpair_value_uint32(nvp, &i32); c = fm_printf(d + 1, c, cols, "%x", i32); break; case DATA_TYPE_INT64: (void) nvpair_value_int64(nvp, (void *)&i64); c = fm_printf(d + 1, c, cols, "%llx", (u_longlong_t)i64); break; case DATA_TYPE_UINT64: (void) nvpair_value_uint64(nvp, &i64); c = fm_printf(d + 1, c, cols, "%llx", (u_longlong_t)i64); break; case DATA_TYPE_HRTIME: (void) nvpair_value_hrtime(nvp, (void *)&i64); c = fm_printf(d + 1, c, cols, "%llx", (u_longlong_t)i64); break; case DATA_TYPE_STRING: (void) nvpair_value_string(nvp, &str); c = fm_printf(d + 1, c, cols, "\"%s\"", str ? str : ""); break; case DATA_TYPE_NVLIST: c = fm_printf(d + 1, c, cols, "["); (void) nvpair_value_nvlist(nvp, &cnv); c = fm_nvprintr(cnv, d + 1, c, cols); c = fm_printf(d + 1, c, cols, " ]"); break; case DATA_TYPE_NVLIST_ARRAY: { nvlist_t **val; uint_t i, nelem; c = fm_printf(d + 1, c, cols, "["); (void) nvpair_value_nvlist_array(nvp, &val, &nelem); for (i = 0; i < nelem; i++) { c = fm_nvprintr(val[i], d + 1, c, cols); } c = fm_printf(d + 1, c, cols, " ]"); } break; case DATA_TYPE_BOOLEAN_ARRAY: case DATA_TYPE_BYTE_ARRAY: case DATA_TYPE_INT8_ARRAY: case DATA_TYPE_UINT8_ARRAY: case DATA_TYPE_INT16_ARRAY: case DATA_TYPE_UINT16_ARRAY: case DATA_TYPE_INT32_ARRAY: case DATA_TYPE_UINT32_ARRAY: case DATA_TYPE_INT64_ARRAY: case DATA_TYPE_UINT64_ARRAY: case DATA_TYPE_STRING_ARRAY: c = fm_printf(d + 1, c, cols, "[...]"); break; case DATA_TYPE_UNKNOWN: c = fm_printf(d + 1, c, cols, ""); break; } } return (c); } void fm_nvprint(nvlist_t *nvl) { char *class; int c = 0; console_printf("\r"); if (nvlist_lookup_string(nvl, FM_CLASS, &class) == 0) c = fm_printf(0, c, ereport_cols, "%s", class); if (fm_nvprintr(nvl, 0, c, ereport_cols) != 0) console_printf("\n"); console_printf("\n"); } /* * Wrapper for panic() that first produces an FMA-style message for admins. * Normally such messages are generated by fmd(1M)'s syslog-msgs agent: this * is the one exception to that rule and the only error that gets messaged. * This function is intended for use by subsystems that have detected a fatal * error and enqueued appropriate ereports and wish to then force a panic. */ /*PRINTFLIKE1*/ void fm_panic(const char *format, ...) { va_list ap; - (void) casptr((void *)&fm_panicstr, NULL, (void *)format); + (void) atomic_cas_ptr((void *)&fm_panicstr, NULL, (void *)format); #if defined(__i386) || defined(__amd64) fastreboot_disable_highpil(); #endif /* __i386 || __amd64 */ va_start(ap, format); vpanic(format, ap); va_end(ap); } /* * Simply tell the caller if fm_panicstr is set, ie. an fma event has * caused the panic. If so, something other than the default panic * diagnosis method will diagnose the cause of the panic. */ int is_fm_panic() { if (fm_panicstr) return (1); else return (0); } /* * Print any appropriate FMA banner message before the panic message. This * function is called by panicsys() and prints the message for fm_panic(). * We print the message here so that it comes after the system is quiesced. * A one-line summary is recorded in the log only (cmn_err(9F) with "!" prefix). * The rest of the message is for the console only and not needed in the log, * so it is printed using console_printf(). We break it up into multiple * chunks so as to avoid overflowing any small legacy prom_printf() buffers. */ void fm_banner(void) { timespec_t tod; hrtime_t now; if (!fm_panicstr) return; /* panic was not initiated by fm_panic(); do nothing */ if (panicstr) { tod = panic_hrestime; now = panic_hrtime; } else { gethrestime(&tod); now = gethrtime_waitfree(); } cmn_err(CE_NOTE, "!SUNW-MSG-ID: %s, " "TYPE: Error, VER: 1, SEVERITY: Major\n", fm_msgid); console_printf( "\n\rSUNW-MSG-ID: %s, TYPE: Error, VER: 1, SEVERITY: Major\n" "EVENT-TIME: 0x%lx.0x%lx (0x%llx)\n", fm_msgid, tod.tv_sec, tod.tv_nsec, (u_longlong_t)now); console_printf( "PLATFORM: %s, CSN: -, HOSTNAME: %s\n" "SOURCE: %s, REV: %s %s\n", platform, utsname.nodename, utsname.sysname, utsname.release, utsname.version); console_printf( "DESC: Errors have been detected that require a reboot to ensure system\n" "integrity. See %s/%s for more information.\n", fm_url, fm_msgid); console_printf( "AUTO-RESPONSE: Solaris will attempt to save and diagnose the error telemetry\n" "IMPACT: The system will sync files, save a crash dump if needed, and reboot\n" "REC-ACTION: Save the error summary below in case telemetry cannot be saved\n"); console_printf("\n"); } /* * Utility function to write all of the pending ereports to the dump device. * This function is called at either normal reboot or panic time, and simply * iterates over the in-transit messages in the ereport sysevent channel. */ void fm_ereport_dump(void) { evchanq_t *chq; sysevent_t *sep; erpt_dump_t ed; timespec_t tod; hrtime_t now; char *buf; size_t len; if (panicstr) { tod = panic_hrestime; now = panic_hrtime; } else { if (ereport_errorq != NULL) errorq_drain(ereport_errorq); gethrestime(&tod); now = gethrtime_waitfree(); } /* * In the panic case, sysevent_evc_walk_init() will return NULL. */ if ((chq = sysevent_evc_walk_init(ereport_chan, NULL)) == NULL && !panicstr) return; /* event channel isn't initialized yet */ while ((sep = sysevent_evc_walk_step(chq)) != NULL) { if ((buf = sysevent_evc_event_attr(sep, &len)) == NULL) break; ed.ed_magic = ERPT_MAGIC; ed.ed_chksum = checksum32(buf, len); ed.ed_size = (uint32_t)len; ed.ed_pad = 0; ed.ed_hrt_nsec = SE_TIME(sep); ed.ed_hrt_base = now; ed.ed_tod_base.sec = tod.tv_sec; ed.ed_tod_base.nsec = tod.tv_nsec; dumpvp_write(&ed, sizeof (ed)); dumpvp_write(buf, len); } sysevent_evc_walk_fini(chq); } #endif /* * Post an error report (ereport) to the sysevent error channel. The error * channel must be established with a prior call to sysevent_evc_create() * before publication may occur. */ void fm_ereport_post(nvlist_t *ereport, int evc_flag) { size_t nvl_size = 0; evchan_t *error_chan; sysevent_id_t eid; (void) nvlist_size(ereport, &nvl_size, NV_ENCODE_NATIVE); if (nvl_size > ERPT_DATA_SZ || nvl_size == 0) { atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); return; } #ifdef sun if (sysevent_evc_bind(FM_ERROR_CHAN, &error_chan, EVCH_CREAT|EVCH_HOLD_PEND) != 0) { atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); return; } if (sysevent_evc_publish(error_chan, EC_FM, ESC_FM_ERROR, SUNW_VENDOR, FM_PUB, ereport, evc_flag) != 0) { atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1); (void) sysevent_evc_unbind(error_chan); return; } (void) sysevent_evc_unbind(error_chan); #else (void) ddi_log_sysevent(NULL, SUNW_VENDOR, EC_DEV_STATUS, ESC_DEV_DLE, ereport, &eid, DDI_SLEEP); #endif } /* * Wrapppers for FM nvlist allocators */ /* ARGSUSED */ static void * i_fm_alloc(nv_alloc_t *nva, size_t size) { return (kmem_zalloc(size, KM_SLEEP)); } /* ARGSUSED */ static void i_fm_free(nv_alloc_t *nva, void *buf, size_t size) { kmem_free(buf, size); } const nv_alloc_ops_t fm_mem_alloc_ops = { NULL, NULL, i_fm_alloc, i_fm_free, NULL }; /* * Create and initialize a new nv_alloc_t for a fixed buffer, buf. A pointer * to the newly allocated nv_alloc_t structure is returned upon success or NULL * is returned to indicate that the nv_alloc structure could not be created. */ nv_alloc_t * fm_nva_xcreate(char *buf, size_t bufsz) { nv_alloc_t *nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); if (bufsz == 0 || nv_alloc_init(nvhdl, nv_fixed_ops, buf, bufsz) != 0) { kmem_free(nvhdl, sizeof (nv_alloc_t)); return (NULL); } return (nvhdl); } /* * Destroy a previously allocated nv_alloc structure. The fixed buffer * associated with nva must be freed by the caller. */ void fm_nva_xdestroy(nv_alloc_t *nva) { nv_alloc_fini(nva); kmem_free(nva, sizeof (nv_alloc_t)); } /* * Create a new nv list. A pointer to a new nv list structure is returned * upon success or NULL is returned to indicate that the structure could * not be created. The newly created nv list is created and managed by the * operations installed in nva. If nva is NULL, the default FMA nva * operations are installed and used. * * When called from the kernel and nva == NULL, this function must be called * from passive kernel context with no locks held that can prevent a * sleeping memory allocation from occurring. Otherwise, this function may * be called from other kernel contexts as long a valid nva created via * fm_nva_create() is supplied. */ nvlist_t * fm_nvlist_create(nv_alloc_t *nva) { int hdl_alloced = 0; nvlist_t *nvl; nv_alloc_t *nvhdl; if (nva == NULL) { nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP); if (nv_alloc_init(nvhdl, &fm_mem_alloc_ops, NULL, 0) != 0) { kmem_free(nvhdl, sizeof (nv_alloc_t)); return (NULL); } hdl_alloced = 1; } else { nvhdl = nva; } if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nvhdl) != 0) { if (hdl_alloced) { nv_alloc_fini(nvhdl); kmem_free(nvhdl, sizeof (nv_alloc_t)); } return (NULL); } return (nvl); } /* * Destroy a previously allocated nvlist structure. flag indicates whether * or not the associated nva structure should be freed (FM_NVA_FREE) or * retained (FM_NVA_RETAIN). Retaining the nv alloc structure allows * it to be re-used for future nvlist creation operations. */ void fm_nvlist_destroy(nvlist_t *nvl, int flag) { nv_alloc_t *nva = nvlist_lookup_nv_alloc(nvl); nvlist_free(nvl); if (nva != NULL) { if (flag == FM_NVA_FREE) fm_nva_xdestroy(nva); } } int i_fm_payload_set(nvlist_t *payload, const char *name, va_list ap) { int nelem, ret = 0; data_type_t type; while (ret == 0 && name != NULL) { type = va_arg(ap, data_type_t); switch (type) { case DATA_TYPE_BYTE: ret = nvlist_add_byte(payload, name, va_arg(ap, uint_t)); break; case DATA_TYPE_BYTE_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_byte_array(payload, name, va_arg(ap, uchar_t *), nelem); break; case DATA_TYPE_BOOLEAN_VALUE: ret = nvlist_add_boolean_value(payload, name, va_arg(ap, boolean_t)); break; case DATA_TYPE_BOOLEAN_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_boolean_array(payload, name, va_arg(ap, boolean_t *), nelem); break; case DATA_TYPE_INT8: ret = nvlist_add_int8(payload, name, va_arg(ap, int)); break; case DATA_TYPE_INT8_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_int8_array(payload, name, va_arg(ap, int8_t *), nelem); break; case DATA_TYPE_UINT8: ret = nvlist_add_uint8(payload, name, va_arg(ap, uint_t)); break; case DATA_TYPE_UINT8_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_uint8_array(payload, name, va_arg(ap, uint8_t *), nelem); break; case DATA_TYPE_INT16: ret = nvlist_add_int16(payload, name, va_arg(ap, int)); break; case DATA_TYPE_INT16_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_int16_array(payload, name, va_arg(ap, int16_t *), nelem); break; case DATA_TYPE_UINT16: ret = nvlist_add_uint16(payload, name, va_arg(ap, uint_t)); break; case DATA_TYPE_UINT16_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_uint16_array(payload, name, va_arg(ap, uint16_t *), nelem); break; case DATA_TYPE_INT32: ret = nvlist_add_int32(payload, name, va_arg(ap, int32_t)); break; case DATA_TYPE_INT32_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_int32_array(payload, name, va_arg(ap, int32_t *), nelem); break; case DATA_TYPE_UINT32: ret = nvlist_add_uint32(payload, name, va_arg(ap, uint32_t)); break; case DATA_TYPE_UINT32_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_uint32_array(payload, name, va_arg(ap, uint32_t *), nelem); break; case DATA_TYPE_INT64: ret = nvlist_add_int64(payload, name, va_arg(ap, int64_t)); break; case DATA_TYPE_INT64_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_int64_array(payload, name, va_arg(ap, int64_t *), nelem); break; case DATA_TYPE_UINT64: ret = nvlist_add_uint64(payload, name, va_arg(ap, uint64_t)); break; case DATA_TYPE_UINT64_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_uint64_array(payload, name, va_arg(ap, uint64_t *), nelem); break; case DATA_TYPE_STRING: ret = nvlist_add_string(payload, name, va_arg(ap, char *)); break; case DATA_TYPE_STRING_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_string_array(payload, name, va_arg(ap, char **), nelem); break; case DATA_TYPE_NVLIST: ret = nvlist_add_nvlist(payload, name, va_arg(ap, nvlist_t *)); break; case DATA_TYPE_NVLIST_ARRAY: nelem = va_arg(ap, int); ret = nvlist_add_nvlist_array(payload, name, va_arg(ap, nvlist_t **), nelem); break; default: ret = EINVAL; } name = va_arg(ap, char *); } return (ret); } void fm_payload_set(nvlist_t *payload, ...) { int ret; const char *name; va_list ap; va_start(ap, payload); name = va_arg(ap, char *); ret = i_fm_payload_set(payload, name, ap); va_end(ap); if (ret) atomic_add_64( &erpt_kstat_data.payload_set_failed.value.ui64, 1); } /* * Set-up and validate the members of an ereport event according to: * * Member name Type Value * ==================================================== * class string ereport * version uint8_t 0 * ena uint64_t * detector nvlist_t * ereport-payload nvlist_t * * We don't actually add a 'version' member to the payload. Really, * the version quoted to us by our caller is that of the category 1 * "ereport" event class (and we require FM_EREPORT_VERS0) but * the payload version of the actual leaf class event under construction * may be something else. Callers should supply a version in the varargs, * or (better) we could take two version arguments - one for the * ereport category 1 classification (expect FM_EREPORT_VERS0) and one * for the leaf class. */ void fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class, uint64_t ena, const nvlist_t *detector, ...) { char ereport_class[FM_MAX_CLASS]; const char *name; va_list ap; int ret; if (version != FM_EREPORT_VERS0) { atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); return; } (void) snprintf(ereport_class, FM_MAX_CLASS, "%s.%s", FM_EREPORT_CLASS, erpt_class); if (nvlist_add_string(ereport, FM_CLASS, ereport_class) != 0) { atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); return; } if (nvlist_add_uint64(ereport, FM_EREPORT_ENA, ena)) { atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); } if (nvlist_add_nvlist(ereport, FM_EREPORT_DETECTOR, (nvlist_t *)detector) != 0) { atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); } va_start(ap, detector); name = va_arg(ap, const char *); ret = i_fm_payload_set(ereport, name, ap); va_end(ap); if (ret) atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1); } /* * Set-up and validate the members of an hc fmri according to; * * Member name Type Value * =================================================== * version uint8_t 0 * auth nvlist_t * hc-name string * hc-id string * * Note that auth and hc-id are optional members. */ #define HC_MAXPAIRS 20 #define HC_MAXNAMELEN 50 static int fm_fmri_hc_set_common(nvlist_t *fmri, int version, const nvlist_t *auth) { if (version != FM_HC_SCHEME_VERSION) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return (0); } if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0 || nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return (0); } if (auth != NULL && nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, (nvlist_t *)auth) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return (0); } return (1); } void fm_fmri_hc_set(nvlist_t *fmri, int version, const nvlist_t *auth, nvlist_t *snvl, int npairs, ...) { nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri); nvlist_t *pairs[HC_MAXPAIRS]; va_list ap; int i; if (!fm_fmri_hc_set_common(fmri, version, auth)) return; npairs = MIN(npairs, HC_MAXPAIRS); va_start(ap, npairs); for (i = 0; i < npairs; i++) { const char *name = va_arg(ap, const char *); uint32_t id = va_arg(ap, uint32_t); char idstr[11]; (void) snprintf(idstr, sizeof (idstr), "%u", id); pairs[i] = fm_nvlist_create(nva); if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 || nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); } } va_end(ap); if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs) != 0) atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); for (i = 0; i < npairs; i++) fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN); if (snvl != NULL) { if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); } } } /* * Set-up and validate the members of an dev fmri according to: * * Member name Type Value * ==================================================== * version uint8_t 0 * auth nvlist_t * devpath string * [devid] string * [target-port-l0id] string * * Note that auth and devid are optional members. */ void fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth, const char *devpath, const char *devid, const char *tpl0) { int err = 0; if (version != DEV_SCHEME_VERSION0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } err |= nvlist_add_uint8(fmri_dev, FM_VERSION, version); err |= nvlist_add_string(fmri_dev, FM_FMRI_SCHEME, FM_FMRI_SCHEME_DEV); if (auth != NULL) { err |= nvlist_add_nvlist(fmri_dev, FM_FMRI_AUTHORITY, (nvlist_t *)auth); } err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_PATH, devpath); if (devid != NULL) err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_ID, devid); if (tpl0 != NULL) err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_TGTPTLUN0, tpl0); if (err) atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); } /* * Set-up and validate the members of an cpu fmri according to: * * Member name Type Value * ==================================================== * version uint8_t 0 * auth nvlist_t * cpuid uint32_t * cpumask uint8_t * serial uint64_t * * Note that auth, cpumask, serial are optional members. * */ void fm_fmri_cpu_set(nvlist_t *fmri_cpu, int version, const nvlist_t *auth, uint32_t cpu_id, uint8_t *cpu_maskp, const char *serial_idp) { uint64_t *failedp = &erpt_kstat_data.fmri_set_failed.value.ui64; if (version < CPU_SCHEME_VERSION1) { atomic_add_64(failedp, 1); return; } if (nvlist_add_uint8(fmri_cpu, FM_VERSION, version) != 0) { atomic_add_64(failedp, 1); return; } if (nvlist_add_string(fmri_cpu, FM_FMRI_SCHEME, FM_FMRI_SCHEME_CPU) != 0) { atomic_add_64(failedp, 1); return; } if (auth != NULL && nvlist_add_nvlist(fmri_cpu, FM_FMRI_AUTHORITY, (nvlist_t *)auth) != 0) atomic_add_64(failedp, 1); if (nvlist_add_uint32(fmri_cpu, FM_FMRI_CPU_ID, cpu_id) != 0) atomic_add_64(failedp, 1); if (cpu_maskp != NULL && nvlist_add_uint8(fmri_cpu, FM_FMRI_CPU_MASK, *cpu_maskp) != 0) atomic_add_64(failedp, 1); if (serial_idp == NULL || nvlist_add_string(fmri_cpu, FM_FMRI_CPU_SERIAL_ID, (char *)serial_idp) != 0) atomic_add_64(failedp, 1); } /* * Set-up and validate the members of a mem according to: * * Member name Type Value * ==================================================== * version uint8_t 0 * auth nvlist_t [optional] * unum string * serial string [optional*] * offset uint64_t [optional] * * * serial is required if offset is present */ void fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth, const char *unum, const char *serial, uint64_t offset) { if (version != MEM_SCHEME_VERSION0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (!serial && (offset != (uint64_t)-1)) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (auth != NULL) { if (nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, (nvlist_t *)auth) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); } } if (nvlist_add_string(fmri, FM_FMRI_MEM_UNUM, unum) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); } if (serial != NULL) { if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID, (char **)&serial, 1) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); } if (offset != (uint64_t)-1) { if (nvlist_add_uint64(fmri, FM_FMRI_MEM_OFFSET, offset) != 0) { atomic_add_64(&erpt_kstat_data. fmri_set_failed.value.ui64, 1); } } } } void fm_fmri_zfs_set(nvlist_t *fmri, int version, uint64_t pool_guid, uint64_t vdev_guid) { if (version != ZFS_SCHEME_VERSION0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_ZFS) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_POOL, pool_guid) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); } if (vdev_guid != 0) { if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_VDEV, vdev_guid) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); } } } uint64_t fm_ena_increment(uint64_t ena) { uint64_t new_ena; switch (ENA_FORMAT(ena)) { case FM_ENA_FMT1: new_ena = ena + (1 << ENA_FMT1_GEN_SHFT); break; case FM_ENA_FMT2: new_ena = ena + (1 << ENA_FMT2_GEN_SHFT); break; default: new_ena = 0; } return (new_ena); } uint64_t fm_ena_generate_cpu(uint64_t timestamp, processorid_t cpuid, uchar_t format) { uint64_t ena = 0; switch (format) { case FM_ENA_FMT1: if (timestamp) { ena = (uint64_t)((format & ENA_FORMAT_MASK) | ((cpuid << ENA_FMT1_CPUID_SHFT) & ENA_FMT1_CPUID_MASK) | ((timestamp << ENA_FMT1_TIME_SHFT) & ENA_FMT1_TIME_MASK)); } else { ena = (uint64_t)((format & ENA_FORMAT_MASK) | ((cpuid << ENA_FMT1_CPUID_SHFT) & ENA_FMT1_CPUID_MASK) | ((gethrtime_waitfree() << ENA_FMT1_TIME_SHFT) & ENA_FMT1_TIME_MASK)); } break; case FM_ENA_FMT2: ena = (uint64_t)((format & ENA_FORMAT_MASK) | ((timestamp << ENA_FMT2_TIME_SHFT) & ENA_FMT2_TIME_MASK)); break; default: break; } return (ena); } uint64_t fm_ena_generate(uint64_t timestamp, uchar_t format) { return (fm_ena_generate_cpu(timestamp, PCPU_GET(cpuid), format)); } uint64_t fm_ena_generation_get(uint64_t ena) { uint64_t gen; switch (ENA_FORMAT(ena)) { case FM_ENA_FMT1: gen = (ena & ENA_FMT1_GEN_MASK) >> ENA_FMT1_GEN_SHFT; break; case FM_ENA_FMT2: gen = (ena & ENA_FMT2_GEN_MASK) >> ENA_FMT2_GEN_SHFT; break; default: gen = 0; break; } return (gen); } uchar_t fm_ena_format_get(uint64_t ena) { return (ENA_FORMAT(ena)); } uint64_t fm_ena_id_get(uint64_t ena) { uint64_t id; switch (ENA_FORMAT(ena)) { case FM_ENA_FMT1: id = (ena & ENA_FMT1_ID_MASK) >> ENA_FMT1_ID_SHFT; break; case FM_ENA_FMT2: id = (ena & ENA_FMT2_ID_MASK) >> ENA_FMT2_ID_SHFT; break; default: id = 0; } return (id); } uint64_t fm_ena_time_get(uint64_t ena) { uint64_t time; switch (ENA_FORMAT(ena)) { case FM_ENA_FMT1: time = (ena & ENA_FMT1_TIME_MASK) >> ENA_FMT1_TIME_SHFT; break; case FM_ENA_FMT2: time = (ena & ENA_FMT2_TIME_MASK) >> ENA_FMT2_TIME_SHFT; break; default: time = 0; } return (time); } #ifdef sun /* * Convert a getpcstack() trace to symbolic name+offset, and add the resulting * string array to a Fault Management ereport as FM_EREPORT_PAYLOAD_NAME_STACK. */ void fm_payload_stack_add(nvlist_t *payload, const pc_t *stack, int depth) { int i; char *sym; ulong_t off; char *stkpp[FM_STK_DEPTH]; char buf[FM_STK_DEPTH * FM_SYM_SZ]; char *stkp = buf; for (i = 0; i < depth && i != FM_STK_DEPTH; i++, stkp += FM_SYM_SZ) { if ((sym = kobj_getsymname(stack[i], &off)) != NULL) (void) snprintf(stkp, FM_SYM_SZ, "%s+%lx", sym, off); else (void) snprintf(stkp, FM_SYM_SZ, "%lx", (long)stack[i]); stkpp[i] = stkp; } fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_STACK, DATA_TYPE_STRING_ARRAY, depth, stkpp, NULL); } #endif #ifdef sun void print_msg_hwerr(ctid_t ct_id, proc_t *p) { uprintf("Killed process %d (%s) in contract id %d " "due to hardware error\n", p->p_pid, p->p_user.u_comm, ct_id); } #endif void fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth, nvlist_t *snvl, nvlist_t *bboard, int npairs, ...) { nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri); nvlist_t *pairs[HC_MAXPAIRS]; nvlist_t **hcl; uint_t n; int i, j; va_list ap; char *hcname, *hcid; if (!fm_fmri_hc_set_common(fmri, version, auth)) return; /* * copy the bboard nvpairs to the pairs array */ if (nvlist_lookup_nvlist_array(bboard, FM_FMRI_HC_LIST, &hcl, &n) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } for (i = 0; i < n; i++) { if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME, &hcname) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &hcid) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } pairs[i] = fm_nvlist_create(nva); if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, hcname) != 0 || nvlist_add_string(pairs[i], FM_FMRI_HC_ID, hcid) != 0) { for (j = 0; j <= i; j++) { if (pairs[j] != NULL) fm_nvlist_destroy(pairs[j], FM_NVA_RETAIN); } atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } } /* * create the pairs from passed in pairs */ npairs = MIN(npairs, HC_MAXPAIRS); va_start(ap, npairs); for (i = n; i < npairs + n; i++) { const char *name = va_arg(ap, const char *); uint32_t id = va_arg(ap, uint32_t); char idstr[11]; (void) snprintf(idstr, sizeof (idstr), "%u", id); pairs[i] = fm_nvlist_create(nva); if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 || nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) { for (j = 0; j <= i; j++) { if (pairs[j] != NULL) fm_nvlist_destroy(pairs[j], FM_NVA_RETAIN); } atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } } va_end(ap); /* * Create the fmri hc list */ if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs + n) != 0) { atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } for (i = 0; i < npairs + n; i++) { fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN); } if (snvl != NULL) { if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) { atomic_add_64( &erpt_kstat_data.fmri_set_failed.value.ui64, 1); return; } } } Index: stable/10/sys/cddl/contrib/opensolaris/uts/common/sys/bitmap.h =================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/sys/bitmap.h (revision 270997) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/sys/bitmap.h (revision 270998) @@ -1,197 +1,197 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2014 by Delphix. All rights reserved. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #ifndef _SYS_BITMAP_H #define _SYS_BITMAP_H #ifdef __cplusplus extern "C" { #endif #include #if defined(__GNUC__) && defined(_ASM_INLINES) && \ (defined(__i386) || defined(__amd64)) #include #endif /* * Operations on bitmaps of arbitrary size * A bitmap is a vector of 1 or more ulong_t's. * The user of the package is responsible for range checks and keeping * track of sizes. */ #ifdef _LP64 #define BT_ULSHIFT 6 /* log base 2 of BT_NBIPUL, to extract word index */ #define BT_ULSHIFT32 5 /* log base 2 of BT_NBIPUL, to extract word index */ #else #define BT_ULSHIFT 5 /* log base 2 of BT_NBIPUL, to extract word index */ #endif #define BT_NBIPUL (1 << BT_ULSHIFT) /* n bits per ulong_t */ #define BT_ULMASK (BT_NBIPUL - 1) /* to extract bit index */ #ifdef _LP64 #define BT_NBIPUL32 (1 << BT_ULSHIFT32) /* n bits per ulong_t */ #define BT_ULMASK32 (BT_NBIPUL32 - 1) /* to extract bit index */ #define BT_ULMAXMASK 0xffffffffffffffff /* used by bt_getlowbit */ #else #define BT_ULMAXMASK 0xffffffff #endif /* * bitmap is a ulong_t *, bitindex an index_t * * The macros BT_WIM and BT_BIW internal; there is no need * for users of this package to use them. */ /* * word in map */ #define BT_WIM(bitmap, bitindex) \ ((bitmap)[(bitindex) >> BT_ULSHIFT]) /* * bit in word */ #define BT_BIW(bitindex) \ (1UL << ((bitindex) & BT_ULMASK)) #ifdef _LP64 #define BT_WIM32(bitmap, bitindex) \ ((bitmap)[(bitindex) >> BT_ULSHIFT32]) #define BT_BIW32(bitindex) \ (1UL << ((bitindex) & BT_ULMASK32)) #endif /* * These are public macros * * BT_BITOUL == n bits to n ulong_t's */ #define BT_BITOUL(nbits) \ (((nbits) + BT_NBIPUL - 1l) / BT_NBIPUL) #define BT_SIZEOFMAP(nbits) \ (BT_BITOUL(nbits) * sizeof (ulong_t)) #define BT_TEST(bitmap, bitindex) \ ((BT_WIM((bitmap), (bitindex)) & BT_BIW(bitindex)) ? 1 : 0) #define BT_SET(bitmap, bitindex) \ { BT_WIM((bitmap), (bitindex)) |= BT_BIW(bitindex); } #define BT_CLEAR(bitmap, bitindex) \ { BT_WIM((bitmap), (bitindex)) &= ~BT_BIW(bitindex); } #ifdef _LP64 #define BT_BITOUL32(nbits) \ (((nbits) + BT_NBIPUL32 - 1l) / BT_NBIPUL32) #define BT_SIZEOFMAP32(nbits) \ (BT_BITOUL32(nbits) * sizeof (uint_t)) #define BT_TEST32(bitmap, bitindex) \ ((BT_WIM32((bitmap), (bitindex)) & BT_BIW32(bitindex)) ? 1 : 0) #define BT_SET32(bitmap, bitindex) \ { BT_WIM32((bitmap), (bitindex)) |= BT_BIW32(bitindex); } #define BT_CLEAR32(bitmap, bitindex) \ { BT_WIM32((bitmap), (bitindex)) &= ~BT_BIW32(bitindex); } #endif /* _LP64 */ /* * BIT_ONLYONESET is a private macro not designed for bitmaps of * arbitrary size. u must be an unsigned integer/long. It returns * true if one and only one bit is set in u. */ #define BIT_ONLYONESET(u) \ ((((u) == 0) ? 0 : ((u) & ((u) - 1)) == 0)) #if defined(_KERNEL) && !defined(_ASM) #include /* * return next available bit index from map with specified number of bits */ extern index_t bt_availbit(ulong_t *bitmap, size_t nbits); /* * find the highest order bit that is on, and is within or below * the word specified by wx */ extern int bt_gethighbit(ulong_t *mapp, int wx); extern int bt_range(ulong_t *bitmap, size_t *pos1, size_t *pos2, size_t end_pos); /* * Find highest and lowest one bit set. * Returns bit number + 1 of bit that is set, otherwise returns 0. * Low order bit is 0, high order bit is 31. */ extern int highbit(ulong_t); extern int highbit64(uint64_t); extern int lowbit(ulong_t); extern int bt_getlowbit(ulong_t *bitmap, size_t start, size_t stop); extern void bt_copy(ulong_t *, ulong_t *, ulong_t); /* * find the parity */ extern int odd_parity(ulong_t); /* * Atomically set/clear bits * Atomic exclusive operations will set "result" to "-1" * if the bit is already set/cleared. "result" will be set * to 0 otherwise. */ #define BT_ATOMIC_SET(bitmap, bitindex) \ - { atomic_or_long(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); } + { atomic_or_ulong(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); } #define BT_ATOMIC_CLEAR(bitmap, bitindex) \ - { atomic_and_long(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); } + { atomic_and_ulong(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); } #define BT_ATOMIC_SET_EXCL(bitmap, bitindex, result) \ { result = atomic_set_long_excl(&(BT_WIM(bitmap, bitindex)), \ (bitindex) % BT_NBIPUL); } #define BT_ATOMIC_CLEAR_EXCL(bitmap, bitindex, result) \ { result = atomic_clear_long_excl(&(BT_WIM(bitmap, bitindex)), \ (bitindex) % BT_NBIPUL); } /* * Extracts bits between index h (high, inclusive) and l (low, exclusive) from * u, which must be an unsigned integer. */ #define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU)) #endif /* _KERNEL && !_ASM */ #ifdef __cplusplus } #endif #endif /* _SYS_BITMAP_H */ Index: stable/10/sys/cddl/contrib/opensolaris/uts/common/sys/cpuvar.h =================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/sys/cpuvar.h (revision 270997) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/sys/cpuvar.h (revision 270998) @@ -1,835 +1,835 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. */ #ifndef _SYS_CPUVAR_H #define _SYS_CPUVAR_H #include #include /* has cpu_stat_t definition */ #include #include #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) #include #endif #include #include #include #include #include #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL) && \ (defined(__i386) || defined(__amd64)) #include #endif #ifdef __cplusplus extern "C" { #endif struct squeue_set_s; #define CPU_CACHE_COHERENCE_SIZE 64 #define S_LOADAVG_SZ 11 #define S_MOVAVG_SZ 10 struct loadavg_s { int lg_cur; /* current loadavg entry */ unsigned int lg_len; /* number entries recorded */ hrtime_t lg_total; /* used to temporarily hold load totals */ hrtime_t lg_loads[S_LOADAVG_SZ]; /* table of recorded entries */ }; /* * For fast event tracing. */ struct ftrace_record; typedef struct ftrace_data { int ftd_state; /* ftrace flags */ kmutex_t ftd_unused; /* ftrace buffer lock, unused */ struct ftrace_record *ftd_cur; /* current record */ struct ftrace_record *ftd_first; /* first record */ struct ftrace_record *ftd_last; /* last record */ } ftrace_data_t; struct cyc_cpu; struct nvlist; /* * Per-CPU data. * * Be careful adding new members: if they are not the same in all modules (e.g. * change size depending on a #define), CTF uniquification can fail to work * properly. Furthermore, this is transitive in that it applies recursively to * all types pointed to by cpu_t. */ typedef struct cpu { processorid_t cpu_id; /* CPU number */ processorid_t cpu_seqid; /* sequential CPU id (0..ncpus-1) */ volatile cpu_flag_t cpu_flags; /* flags indicating CPU state */ struct cpu *cpu_self; /* pointer to itself */ kthread_t *cpu_thread; /* current thread */ kthread_t *cpu_idle_thread; /* idle thread for this CPU */ kthread_t *cpu_pause_thread; /* pause thread for this CPU */ klwp_id_t cpu_lwp; /* current lwp (if any) */ klwp_id_t cpu_fpowner; /* currently loaded fpu owner */ struct cpupart *cpu_part; /* partition with this CPU */ struct lgrp_ld *cpu_lpl; /* pointer to this cpu's load */ int cpu_cache_offset; /* see kmem.c for details */ /* * Links to other CPUs. It is safe to walk these lists if * one of the following is true: * - cpu_lock held * - preemption disabled via kpreempt_disable * - PIL >= DISP_LEVEL * - acting thread is an interrupt thread * - all other CPUs are paused */ struct cpu *cpu_next; /* next existing CPU */ struct cpu *cpu_prev; /* prev existing CPU */ struct cpu *cpu_next_onln; /* next online (enabled) CPU */ struct cpu *cpu_prev_onln; /* prev online (enabled) CPU */ struct cpu *cpu_next_part; /* next CPU in partition */ struct cpu *cpu_prev_part; /* prev CPU in partition */ struct cpu *cpu_next_lgrp; /* next CPU in latency group */ struct cpu *cpu_prev_lgrp; /* prev CPU in latency group */ struct cpu *cpu_next_lpl; /* next CPU in lgrp partition */ struct cpu *cpu_prev_lpl; struct cpu_pg *cpu_pg; /* cpu's processor groups */ void *cpu_reserved[4]; /* reserved for future use */ /* * Scheduling variables. */ disp_t *cpu_disp; /* dispatch queue data */ /* * Note that cpu_disp is set before the CPU is added to the system * and is never modified. Hence, no additional locking is needed * beyond what's necessary to access the cpu_t structure. */ char cpu_runrun; /* scheduling flag - set to preempt */ char cpu_kprunrun; /* force kernel preemption */ pri_t cpu_chosen_level; /* priority at which cpu */ /* was chosen for scheduling */ kthread_t *cpu_dispthread; /* thread selected for dispatch */ disp_lock_t cpu_thread_lock; /* dispatcher lock on current thread */ uint8_t cpu_disp_flags; /* flags used by dispatcher */ /* * The following field is updated when ever the cpu_dispthread * changes. Also in places, where the current thread(cpu_dispthread) * priority changes. This is used in disp_lowpri_cpu() */ pri_t cpu_dispatch_pri; /* priority of cpu_dispthread */ clock_t cpu_last_swtch; /* last time switched to new thread */ /* * Interrupt data. */ caddr_t cpu_intr_stack; /* interrupt stack */ kthread_t *cpu_intr_thread; /* interrupt thread list */ uint_t cpu_intr_actv; /* interrupt levels active (bitmask) */ int cpu_base_spl; /* priority for highest rupt active */ /* * Statistics. */ cpu_stats_t cpu_stats; /* per-CPU statistics */ struct kstat *cpu_info_kstat; /* kstat for cpu info */ uintptr_t cpu_profile_pc; /* kernel PC in profile interrupt */ uintptr_t cpu_profile_upc; /* user PC in profile interrupt */ uintptr_t cpu_profile_pil; /* PIL when profile interrupted */ ftrace_data_t cpu_ftrace; /* per cpu ftrace data */ clock_t cpu_deadman_counter; /* used by deadman() */ uint_t cpu_deadman_countdown; /* used by deadman() */ kmutex_t cpu_cpc_ctxlock; /* protects context for idle thread */ kcpc_ctx_t *cpu_cpc_ctx; /* performance counter context */ /* * Configuration information for the processor_info system call. */ processor_info_t cpu_type_info; /* config info */ time_t cpu_state_begin; /* when CPU entered current state */ char cpu_cpr_flags; /* CPR related info */ struct cyc_cpu *cpu_cyclic; /* per cpu cyclic subsystem data */ struct squeue_set_s *cpu_squeue_set; /* per cpu squeue set */ struct nvlist *cpu_props; /* pool-related properties */ krwlock_t cpu_ft_lock; /* DTrace: fasttrap lock */ uintptr_t cpu_dtrace_caller; /* DTrace: caller, if any */ hrtime_t cpu_dtrace_chillmark; /* DTrace: chill mark time */ hrtime_t cpu_dtrace_chilled; /* DTrace: total chill time */ volatile uint16_t cpu_mstate; /* cpu microstate */ volatile uint16_t cpu_mstate_gen; /* generation counter */ volatile hrtime_t cpu_mstate_start; /* cpu microstate start time */ volatile hrtime_t cpu_acct[NCMSTATES]; /* cpu microstate data */ hrtime_t cpu_intracct[NCMSTATES]; /* interrupt mstate data */ hrtime_t cpu_waitrq; /* cpu run-queue wait time */ struct loadavg_s cpu_loadavg; /* loadavg info for this cpu */ char *cpu_idstr; /* for printing and debugging */ char *cpu_brandstr; /* for printing */ /* * Sum of all device interrupt weights that are currently directed at * this cpu. Cleared at start of interrupt redistribution. */ int32_t cpu_intr_weight; void *cpu_vm_data; struct cpu_physid *cpu_physid; /* physical associations */ uint64_t cpu_curr_clock; /* current clock freq in Hz */ char *cpu_supp_freqs; /* supported freqs in Hz */ uintptr_t cpu_cpcprofile_pc; /* kernel PC in cpc interrupt */ uintptr_t cpu_cpcprofile_upc; /* user PC in cpc interrupt */ /* * Interrupt load factor used by dispatcher & softcall */ hrtime_t cpu_intrlast; /* total interrupt time (nsec) */ int cpu_intrload; /* interrupt load factor (0-99%) */ uint_t cpu_rotor; /* for cheap pseudo-random numbers */ struct cu_cpu_info *cpu_cu_info; /* capacity & util. info */ /* * cpu_generation is updated whenever CPU goes on-line or off-line. * Updates to cpu_generation are protected by cpu_lock. * * See CPU_NEW_GENERATION() macro below. */ volatile uint_t cpu_generation; /* tracking on/off-line */ /* * New members must be added /before/ this member, as the CTF tools * rely on this being the last field before cpu_m, so they can * correctly calculate the offset when synthetically adding the cpu_m * member in objects that do not have it. This fixup is required for * uniquification to work correctly. */ uintptr_t cpu_m_pad; #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) struct machcpu cpu_m; /* per architecture info */ #endif } cpu_t; /* * The cpu_core structure consists of per-CPU state available in any context. * On some architectures, this may mean that the page(s) containing the * NCPU-sized array of cpu_core structures must be locked in the TLB -- it * is up to the platform to assure that this is performed properly. Note that * the structure is sized to avoid false sharing. */ #define CPUC_SIZE (sizeof (uint16_t) + sizeof (uint8_t) + \ sizeof (uintptr_t) + sizeof (kmutex_t)) #define CPUC_PADSIZE CPU_CACHE_COHERENCE_SIZE - CPUC_SIZE typedef struct cpu_core { uint16_t cpuc_dtrace_flags; /* DTrace flags */ uint8_t cpuc_dcpc_intr_state; /* DCPC provider intr state */ uint8_t cpuc_pad[CPUC_PADSIZE]; /* padding */ uintptr_t cpuc_dtrace_illval; /* DTrace illegal value */ kmutex_t cpuc_pid_lock; /* DTrace pid provider lock */ } cpu_core_t; #ifdef _KERNEL extern cpu_core_t cpu_core[]; #endif /* _KERNEL */ /* * CPU_ON_INTR() macro. Returns non-zero if currently on interrupt stack. * Note that this isn't a test for a high PIL. For example, cpu_intr_actv * does not get updated when we go through sys_trap from TL>0 at high PIL. * getpil() should be used instead to check for PIL levels. */ #define CPU_ON_INTR(cpup) ((cpup)->cpu_intr_actv >> (LOCK_LEVEL + 1)) /* * Check to see if an interrupt thread might be active at a given ipl. * If so return true. * We must be conservative--it is ok to give a false yes, but a false no * will cause disaster. (But if the situation changes after we check it is * ok--the caller is trying to ensure that an interrupt routine has been * exited). * This is used when trying to remove an interrupt handler from an autovector * list in avintr.c. */ #define INTR_ACTIVE(cpup, level) \ ((level) <= LOCK_LEVEL ? \ ((cpup)->cpu_intr_actv & (1 << (level))) : (CPU_ON_INTR(cpup))) /* * CPU_PSEUDO_RANDOM() returns a per CPU value that changes each time one * looks at it. It's meant as a cheap mechanism to be incorporated in routines * wanting to avoid biasing, but where true randomness isn't needed (just * something that changes). */ #define CPU_PSEUDO_RANDOM() (CPU->cpu_rotor++) #if defined(_KERNEL) || defined(_KMEMUSER) #define INTR_STACK_SIZE MAX(DEFAULTSTKSZ, PAGESIZE) /* MEMBERS PROTECTED BY "atomicity": cpu_flags */ /* * Flags in the CPU structure. * * These are protected by cpu_lock (except during creation). * * Offlined-CPUs have three stages of being offline: * * CPU_ENABLE indicates that the CPU is participating in I/O interrupts * that can be directed at a number of different CPUs. If CPU_ENABLE * is off, the CPU will not be given interrupts that can be sent elsewhere, * but will still get interrupts from devices associated with that CPU only, * and from other CPUs. * * CPU_OFFLINE indicates that the dispatcher should not allow any threads * other than interrupt threads to run on that CPU. A CPU will not have * CPU_OFFLINE set if there are any bound threads (besides interrupts). * * CPU_QUIESCED is set if p_offline was able to completely turn idle the * CPU and it will not have to run interrupt threads. In this case it'll * stay in the idle loop until CPU_QUIESCED is turned off. * * CPU_FROZEN is used only by CPR to mark CPUs that have been successfully * suspended (in the suspend path), or have yet to be resumed (in the resume * case). * * On some platforms CPUs can be individually powered off. * The following flags are set for powered off CPUs: CPU_QUIESCED, * CPU_OFFLINE, and CPU_POWEROFF. The following flags are cleared: * CPU_RUNNING, CPU_READY, CPU_EXISTS, and CPU_ENABLE. */ #define CPU_RUNNING 0x001 /* CPU running */ #define CPU_READY 0x002 /* CPU ready for cross-calls */ #define CPU_QUIESCED 0x004 /* CPU will stay in idle */ #define CPU_EXISTS 0x008 /* CPU is configured */ #define CPU_ENABLE 0x010 /* CPU enabled for interrupts */ #define CPU_OFFLINE 0x020 /* CPU offline via p_online */ #define CPU_POWEROFF 0x040 /* CPU is powered off */ #define CPU_FROZEN 0x080 /* CPU is frozen via CPR suspend */ #define CPU_SPARE 0x100 /* CPU offline available for use */ #define CPU_FAULTED 0x200 /* CPU offline diagnosed faulty */ #define FMT_CPU_FLAGS \ "\20\12fault\11spare\10frozen" \ "\7poweroff\6offline\5enable\4exist\3quiesced\2ready\1run" #define CPU_ACTIVE(cpu) (((cpu)->cpu_flags & CPU_OFFLINE) == 0) /* * Flags for cpu_offline(), cpu_faulted(), and cpu_spare(). */ #define CPU_FORCED 0x0001 /* Force CPU offline */ /* * DTrace flags. */ #define CPU_DTRACE_NOFAULT 0x0001 /* Don't fault */ #define CPU_DTRACE_DROP 0x0002 /* Drop this ECB */ #define CPU_DTRACE_BADADDR 0x0004 /* DTrace fault: bad address */ #define CPU_DTRACE_BADALIGN 0x0008 /* DTrace fault: bad alignment */ #define CPU_DTRACE_DIVZERO 0x0010 /* DTrace fault: divide by zero */ #define CPU_DTRACE_ILLOP 0x0020 /* DTrace fault: illegal operation */ #define CPU_DTRACE_NOSCRATCH 0x0040 /* DTrace fault: out of scratch */ #define CPU_DTRACE_KPRIV 0x0080 /* DTrace fault: bad kernel access */ #define CPU_DTRACE_UPRIV 0x0100 /* DTrace fault: bad user access */ #define CPU_DTRACE_TUPOFLOW 0x0200 /* DTrace fault: tuple stack overflow */ #if defined(__sparc) #define CPU_DTRACE_FAKERESTORE 0x0400 /* pid provider hint to getreg */ #endif #define CPU_DTRACE_ENTRY 0x0800 /* pid provider hint to ustack() */ #define CPU_DTRACE_BADSTACK 0x1000 /* DTrace fault: bad stack */ #define CPU_DTRACE_FAULT (CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \ CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \ CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \ CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \ CPU_DTRACE_BADSTACK) #define CPU_DTRACE_ERROR (CPU_DTRACE_FAULT | CPU_DTRACE_DROP) /* * Dispatcher flags * These flags must be changed only by the current CPU. */ #define CPU_DISP_DONTSTEAL 0x01 /* CPU undergoing context swtch */ #define CPU_DISP_HALTED 0x02 /* CPU halted waiting for interrupt */ #endif /* _KERNEL || _KMEMUSER */ #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) /* * Macros for manipulating sets of CPUs as a bitmap. Note that this * bitmap may vary in size depending on the maximum CPU id a specific * platform supports. This may be different than the number of CPUs * the platform supports, since CPU ids can be sparse. We define two * sets of macros; one for platforms where the maximum CPU id is less * than the number of bits in a single word (32 in a 32-bit kernel, * 64 in a 64-bit kernel), and one for platforms that require bitmaps * of more than one word. */ #define CPUSET_WORDS BT_BITOUL(NCPU) #define CPUSET_NOTINSET ((uint_t)-1) #if CPUSET_WORDS > 1 typedef struct cpuset { ulong_t cpub[CPUSET_WORDS]; } cpuset_t; /* * Private functions for manipulating cpusets that do not fit in a * single word. These should not be used directly; instead the * CPUSET_* macros should be used so the code will be portable * across different definitions of NCPU. */ extern void cpuset_all(cpuset_t *); extern void cpuset_all_but(cpuset_t *, uint_t); extern int cpuset_isnull(cpuset_t *); extern int cpuset_cmp(cpuset_t *, cpuset_t *); extern void cpuset_only(cpuset_t *, uint_t); extern uint_t cpuset_find(cpuset_t *); extern void cpuset_bounds(cpuset_t *, uint_t *, uint_t *); #define CPUSET_ALL(set) cpuset_all(&(set)) #define CPUSET_ALL_BUT(set, cpu) cpuset_all_but(&(set), cpu) #define CPUSET_ONLY(set, cpu) cpuset_only(&(set), cpu) #define CPU_IN_SET(set, cpu) BT_TEST((set).cpub, cpu) #define CPUSET_ADD(set, cpu) BT_SET((set).cpub, cpu) #define CPUSET_DEL(set, cpu) BT_CLEAR((set).cpub, cpu) #define CPUSET_ISNULL(set) cpuset_isnull(&(set)) #define CPUSET_ISEQUAL(set1, set2) cpuset_cmp(&(set1), &(set2)) /* * Find one CPU in the cpuset. * Sets "cpu" to the id of the found CPU, or CPUSET_NOTINSET if no cpu * could be found. (i.e. empty set) */ #define CPUSET_FIND(set, cpu) { \ cpu = cpuset_find(&(set)); \ } /* * Determine the smallest and largest CPU id in the set. Returns * CPUSET_NOTINSET in smallest and largest when set is empty. */ #define CPUSET_BOUNDS(set, smallest, largest) { \ cpuset_bounds(&(set), &(smallest), &(largest)); \ } /* * Atomic cpuset operations * These are safe to use for concurrent cpuset manipulations. * "xdel" and "xadd" are exclusive operations, that set "result" to "0" * if the add or del was successful, or "-1" if not successful. * (e.g. attempting to add a cpu to a cpuset that's already there, or * deleting a cpu that's not in the cpuset) */ #define CPUSET_ATOMIC_DEL(set, cpu) BT_ATOMIC_CLEAR((set).cpub, (cpu)) #define CPUSET_ATOMIC_ADD(set, cpu) BT_ATOMIC_SET((set).cpub, (cpu)) #define CPUSET_ATOMIC_XADD(set, cpu, result) \ BT_ATOMIC_SET_EXCL((set).cpub, cpu, result) #define CPUSET_ATOMIC_XDEL(set, cpu, result) \ BT_ATOMIC_CLEAR_EXCL((set).cpub, cpu, result) #define CPUSET_OR(set1, set2) { \ int _i; \ for (_i = 0; _i < CPUSET_WORDS; _i++) \ (set1).cpub[_i] |= (set2).cpub[_i]; \ } #define CPUSET_XOR(set1, set2) { \ int _i; \ for (_i = 0; _i < CPUSET_WORDS; _i++) \ (set1).cpub[_i] ^= (set2).cpub[_i]; \ } #define CPUSET_AND(set1, set2) { \ int _i; \ for (_i = 0; _i < CPUSET_WORDS; _i++) \ (set1).cpub[_i] &= (set2).cpub[_i]; \ } #define CPUSET_ZERO(set) { \ int _i; \ for (_i = 0; _i < CPUSET_WORDS; _i++) \ (set).cpub[_i] = 0; \ } #elif CPUSET_WORDS == 1 typedef ulong_t cpuset_t; /* a set of CPUs */ #define CPUSET(cpu) (1UL << (cpu)) #define CPUSET_ALL(set) ((void)((set) = ~0UL)) #define CPUSET_ALL_BUT(set, cpu) ((void)((set) = ~CPUSET(cpu))) #define CPUSET_ONLY(set, cpu) ((void)((set) = CPUSET(cpu))) #define CPU_IN_SET(set, cpu) ((set) & CPUSET(cpu)) #define CPUSET_ADD(set, cpu) ((void)((set) |= CPUSET(cpu))) #define CPUSET_DEL(set, cpu) ((void)((set) &= ~CPUSET(cpu))) #define CPUSET_ISNULL(set) ((set) == 0) #define CPUSET_ISEQUAL(set1, set2) ((set1) == (set2)) #define CPUSET_OR(set1, set2) ((void)((set1) |= (set2))) #define CPUSET_XOR(set1, set2) ((void)((set1) ^= (set2))) #define CPUSET_AND(set1, set2) ((void)((set1) &= (set2))) #define CPUSET_ZERO(set) ((void)((set) = 0)) #define CPUSET_FIND(set, cpu) { \ cpu = (uint_t)(lowbit(set) - 1); \ } #define CPUSET_BOUNDS(set, smallest, largest) { \ smallest = (uint_t)(lowbit(set) - 1); \ largest = (uint_t)(highbit(set) - 1); \ } -#define CPUSET_ATOMIC_DEL(set, cpu) atomic_and_long(&(set), ~CPUSET(cpu)) -#define CPUSET_ATOMIC_ADD(set, cpu) atomic_or_long(&(set), CPUSET(cpu)) +#define CPUSET_ATOMIC_DEL(set, cpu) atomic_and_ulong(&(set), ~CPUSET(cpu)) +#define CPUSET_ATOMIC_ADD(set, cpu) atomic_or_ulong(&(set), CPUSET(cpu)) #define CPUSET_ATOMIC_XADD(set, cpu, result) \ { result = atomic_set_long_excl(&(set), (cpu)); } #define CPUSET_ATOMIC_XDEL(set, cpu, result) \ { result = atomic_clear_long_excl(&(set), (cpu)); } #else /* CPUSET_WORDS <= 0 */ #error NCPU is undefined or invalid #endif /* CPUSET_WORDS */ extern cpuset_t cpu_seqid_inuse; #endif /* (_KERNEL || _KMEMUSER) && _MACHDEP */ #define CPU_CPR_OFFLINE 0x0 #define CPU_CPR_ONLINE 0x1 #define CPU_CPR_IS_OFFLINE(cpu) (((cpu)->cpu_cpr_flags & CPU_CPR_ONLINE) == 0) #define CPU_CPR_IS_ONLINE(cpu) ((cpu)->cpu_cpr_flags & CPU_CPR_ONLINE) #define CPU_SET_CPR_FLAGS(cpu, flag) ((cpu)->cpu_cpr_flags |= flag) #if defined(_KERNEL) || defined(_KMEMUSER) extern struct cpu *cpu[]; /* indexed by CPU number */ extern struct cpu **cpu_seq; /* indexed by sequential CPU id */ extern cpu_t *cpu_list; /* list of CPUs */ extern cpu_t *cpu_active; /* list of active CPUs */ extern int ncpus; /* number of CPUs present */ extern int ncpus_online; /* number of CPUs not quiesced */ extern int max_ncpus; /* max present before ncpus is known */ extern int boot_max_ncpus; /* like max_ncpus but for real */ extern int boot_ncpus; /* # cpus present @ boot */ extern processorid_t max_cpuid; /* maximum CPU number */ extern struct cpu *cpu_inmotion; /* offline or partition move target */ extern cpu_t *clock_cpu_list; extern processorid_t max_cpu_seqid_ever; /* maximum seqid ever given */ #if defined(__i386) || defined(__amd64) extern struct cpu *curcpup(void); #define CPU (curcpup()) /* Pointer to current CPU */ #else #define CPU (curthread->t_cpu) /* Pointer to current CPU */ #endif /* * CPU_CURRENT indicates to thread_affinity_set to use CPU->cpu_id * as the target and to grab cpu_lock instead of requiring the caller * to grab it. */ #define CPU_CURRENT -3 /* * Per-CPU statistics * * cpu_stats_t contains numerous system and VM-related statistics, in the form * of gauges or monotonically-increasing event occurrence counts. */ #define CPU_STATS_ENTER_K() kpreempt_disable() #define CPU_STATS_EXIT_K() kpreempt_enable() #define CPU_STATS_ADD_K(class, stat, amount) \ { kpreempt_disable(); /* keep from switching CPUs */\ CPU_STATS_ADDQ(CPU, class, stat, amount); \ kpreempt_enable(); \ } #define CPU_STATS_ADDQ(cp, class, stat, amount) { \ extern void __dtrace_probe___cpu_##class##info_##stat(uint_t, \ uint64_t *, cpu_t *); \ uint64_t *stataddr = &((cp)->cpu_stats.class.stat); \ __dtrace_probe___cpu_##class##info_##stat((amount), \ stataddr, cp); \ *(stataddr) += (amount); \ } #define CPU_STATS(cp, stat) \ ((cp)->cpu_stats.stat) /* * Increment CPU generation value. * This macro should be called whenever CPU goes on-line or off-line. * Updates to cpu_generation should be protected by cpu_lock. */ #define CPU_NEW_GENERATION(cp) ((cp)->cpu_generation++) #endif /* _KERNEL || _KMEMUSER */ /* * CPU support routines. */ #if defined(_KERNEL) && defined(__STDC__) /* not for genassym.c */ struct zone; void cpu_list_init(cpu_t *); void cpu_add_unit(cpu_t *); void cpu_del_unit(int cpuid); void cpu_add_active(cpu_t *); void cpu_kstat_init(cpu_t *); void cpu_visibility_add(cpu_t *, struct zone *); void cpu_visibility_remove(cpu_t *, struct zone *); void cpu_visibility_configure(cpu_t *, struct zone *); void cpu_visibility_unconfigure(cpu_t *, struct zone *); void cpu_visibility_online(cpu_t *, struct zone *); void cpu_visibility_offline(cpu_t *, struct zone *); void cpu_create_intrstat(cpu_t *); void cpu_delete_intrstat(cpu_t *); int cpu_kstat_intrstat_update(kstat_t *, int); void cpu_intr_swtch_enter(kthread_t *); void cpu_intr_swtch_exit(kthread_t *); void mbox_lock_init(void); /* initialize cross-call locks */ void mbox_init(int cpun); /* initialize cross-calls */ void poke_cpu(int cpun); /* interrupt another CPU (to preempt) */ /* * values for safe_list. Pause state that CPUs are in. */ #define PAUSE_IDLE 0 /* normal state */ #define PAUSE_READY 1 /* paused thread ready to spl */ #define PAUSE_WAIT 2 /* paused thread is spl-ed high */ #define PAUSE_DIE 3 /* tell pause thread to leave */ #define PAUSE_DEAD 4 /* pause thread has left */ void mach_cpu_pause(volatile char *); void pause_cpus(cpu_t *off_cp); void start_cpus(void); int cpus_paused(void); void cpu_pause_init(void); cpu_t *cpu_get(processorid_t cpun); /* get the CPU struct associated */ int cpu_online(cpu_t *cp); /* take cpu online */ int cpu_offline(cpu_t *cp, int flags); /* take cpu offline */ int cpu_spare(cpu_t *cp, int flags); /* take cpu to spare */ int cpu_faulted(cpu_t *cp, int flags); /* take cpu to faulted */ int cpu_poweron(cpu_t *cp); /* take powered-off cpu to offline */ int cpu_poweroff(cpu_t *cp); /* take offline cpu to powered-off */ cpu_t *cpu_intr_next(cpu_t *cp); /* get next online CPU taking intrs */ int cpu_intr_count(cpu_t *cp); /* count # of CPUs handling intrs */ int cpu_intr_on(cpu_t *cp); /* CPU taking I/O interrupts? */ void cpu_intr_enable(cpu_t *cp); /* enable I/O interrupts */ int cpu_intr_disable(cpu_t *cp); /* disable I/O interrupts */ void cpu_intr_alloc(cpu_t *cp, int n); /* allocate interrupt threads */ /* * Routines for checking CPU states. */ int cpu_is_online(cpu_t *); /* check if CPU is online */ int cpu_is_nointr(cpu_t *); /* check if CPU can service intrs */ int cpu_is_active(cpu_t *); /* check if CPU can run threads */ int cpu_is_offline(cpu_t *); /* check if CPU is offline */ int cpu_is_poweredoff(cpu_t *); /* check if CPU is powered off */ int cpu_flagged_online(cpu_flag_t); /* flags show CPU is online */ int cpu_flagged_nointr(cpu_flag_t); /* flags show CPU not handling intrs */ int cpu_flagged_active(cpu_flag_t); /* flags show CPU scheduling threads */ int cpu_flagged_offline(cpu_flag_t); /* flags show CPU is offline */ int cpu_flagged_poweredoff(cpu_flag_t); /* flags show CPU is powered off */ /* * The processor_info(2) state of a CPU is a simplified representation suitable * for use by an application program. Kernel subsystems should utilize the * internal per-CPU state as given by the cpu_flags member of the cpu structure, * as this information may include platform- or architecture-specific state * critical to a subsystem's disposition of a particular CPU. */ void cpu_set_state(cpu_t *); /* record/timestamp current state */ int cpu_get_state(cpu_t *); /* get current cpu state */ const char *cpu_get_state_str(cpu_t *); /* get current cpu state as string */ void cpu_set_curr_clock(uint64_t); /* indicate the current CPU's freq */ void cpu_set_supp_freqs(cpu_t *, const char *); /* set the CPU supported */ /* frequencies */ int cpu_configure(int); int cpu_unconfigure(int); void cpu_destroy_bound_threads(cpu_t *cp); extern int cpu_bind_thread(kthread_t *tp, processorid_t bind, processorid_t *obind, int *error); extern int cpu_unbind(processorid_t cpu_id, boolean_t force); extern void thread_affinity_set(kthread_t *t, int cpu_id); extern void thread_affinity_clear(kthread_t *t); extern void affinity_set(int cpu_id); extern void affinity_clear(void); extern void init_cpu_mstate(struct cpu *, int); extern void term_cpu_mstate(struct cpu *); extern void new_cpu_mstate(int, hrtime_t); extern void get_cpu_mstate(struct cpu *, hrtime_t *); extern void thread_nomigrate(void); extern void thread_allowmigrate(void); extern void weakbinding_stop(void); extern void weakbinding_start(void); /* * The following routines affect the CPUs participation in interrupt processing, * if that is applicable on the architecture. This only affects interrupts * which aren't directed at the processor (not cross calls). * * cpu_disable_intr returns non-zero if interrupts were previously enabled. */ int cpu_disable_intr(struct cpu *cp); /* stop issuing interrupts to cpu */ void cpu_enable_intr(struct cpu *cp); /* start issuing interrupts to cpu */ /* * The mutex cpu_lock protects cpu_flags for all CPUs, as well as the ncpus * and ncpus_online counts. */ extern kmutex_t cpu_lock; /* lock protecting CPU data */ /* * CPU state change events * * Various subsystems need to know when CPUs change their state. They get this * information by registering CPU state change callbacks using * register_cpu_setup_func(). Whenever any CPU changes its state, the callback * function is called. The callback function is passed three arguments: * * Event, described by cpu_setup_t * CPU ID * Transparent pointer passed when registering the callback * * The callback function is called with cpu_lock held. The return value from the * callback function is usually ignored, except for CPU_CONFIG and CPU_UNCONFIG * events. For these two events, non-zero return value indicates a failure and * prevents successful completion of the operation. * * New events may be added in the future. Callback functions should ignore any * events that they do not understand. * * The following events provide notification callbacks: * * CPU_INIT A new CPU is started and added to the list of active CPUs * This event is only used during boot * * CPU_CONFIG A newly inserted CPU is prepared for starting running code * This event is called by DR code * * CPU_UNCONFIG CPU has been powered off and needs cleanup * This event is called by DR code * * CPU_ON CPU is enabled but does not run anything yet * * CPU_INTR_ON CPU is enabled and has interrupts enabled * * CPU_OFF CPU is going offline but can still run threads * * CPU_CPUPART_OUT CPU is going to move out of its partition * * CPU_CPUPART_IN CPU is going to move to a new partition * * CPU_SETUP CPU is set up during boot and can run threads */ typedef enum { CPU_INIT, CPU_CONFIG, CPU_UNCONFIG, CPU_ON, CPU_OFF, CPU_CPUPART_IN, CPU_CPUPART_OUT, CPU_SETUP, CPU_INTR_ON } cpu_setup_t; typedef int cpu_setup_func_t(cpu_setup_t, int, void *); /* * Routines used to register interest in cpu's being added to or removed * from the system. */ extern void register_cpu_setup_func(cpu_setup_func_t *, void *); extern void unregister_cpu_setup_func(cpu_setup_func_t *, void *); extern void cpu_state_change_notify(int, cpu_setup_t); /* * Call specified function on the given CPU */ typedef void (*cpu_call_func_t)(uintptr_t, uintptr_t); extern void cpu_call(cpu_t *, cpu_call_func_t, uintptr_t, uintptr_t); /* * Create various strings that describe the given CPU for the * processor_info system call and configuration-related kstats. */ #define CPU_IDSTRLEN 100 extern void init_cpu_info(struct cpu *); extern void populate_idstr(struct cpu *); extern void cpu_vm_data_init(struct cpu *); extern void cpu_vm_data_destroy(struct cpu *); #endif /* _KERNEL */ #ifdef __cplusplus } #endif #endif /* _SYS_CPUVAR_H */ Index: stable/10 =================================================================== --- stable/10 (revision 270997) +++ stable/10 (revision 270998) Property changes on: stable/10 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r270239