14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Regardless of platform, the stack frames look like this in the case of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * profile provider:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * profile_fire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * cyclic_expire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * cyclic_fire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * [ interrupt code ]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * On x86, there are five frames from the generic interrupt code; further, the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * interrupted instruction appears as its own stack frame, giving us a total of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * On SPARC, the picture is further complicated because the compiler
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * optimizes away tail-calls -- so the following frames are optimized away:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * profile_fire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * cyclic_expire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This gives three frames. However, on DEBUG kernels, the cyclic_expire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * frame cannot be tail-call eliminated, yielding four frames in this case.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * All of the above constraints lead to the mess below. Yes, the profile
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * provider should ideally figure this out on-the-fly by hitting one of its own
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * probes and then walking its own stack trace. This is complicated, however,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and the static definition doesn't seem to be overly brittle. Still, we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * allow for a manual override in case we get it completely wrong.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynchrtime_t profile_interval_min = NANOSEC / 5000; /* 5000 hz */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, 0, 0, 0, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, 0, 0, 0, 0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 5000, 0, 0, 0, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, 0, 0, 0, 0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * profile_max defines the upper bound on the number of profile probes that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * can exist (this is to prevent malicious or clumsy users from exhausing
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * system resources by creating a slew of profile probes). At mod load time,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * this gets its value from PROFILE_MAX_DEFAULT or profile-max-probes if it's
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * present in the profile.conf file.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROFILE_MAX_DEFAULT 1000 /* default max. number of probes */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic uint32_t profile_max; /* maximum number of profile probes */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic uint32_t profile_total; /* current number of profile probes */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_create(hrtime_t interval, const char *name, int kind)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int nr_frames = PROF_ARTIFICIAL_FRAMES + dtrace_mach_aframes();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_probe_lookup(profile_id, NULL, NULL, name) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof = kmem_zalloc(sizeof (profile_probe_t), KM_SLEEP);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_provide(void *arg, const dtrace_probedesc_t *desc)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const struct {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const struct {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "hz", 0 },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If no description was provided, provide all of our probes.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < sizeof (profile_rates) / sizeof (int); i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < sizeof (profile_ticks) / sizeof (int); i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We need to start before any time suffix.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Now determine the numerical value present in the probe name.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; j >= len; j--) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Look-up the suffix to determine the multiplier.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0, mult = 0; suffixes[i].name != NULL; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (mult == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The default is frequency-per-second.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_destroy(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_online(void *arg, cpu_t *cpu, cyc_handler_t *hdlr, cyc_time_t *when)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pcpu = kmem_zalloc(sizeof (profile_probe_percpu_t), KM_SLEEP);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync when->cyt_when = dtrace_gethrtime() + when->cyt_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_enable(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync when.cyt_when = dtrace_gethrtime() + when.cyt_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_disable(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_usermode(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_UNKNOWN },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ddi_create_minor_node(devi, "profile", S_IFCHR, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_max = ddi_getprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *result = (void *)0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, /* streamtab */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, /* refcnt */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Module linkage information for the kernel.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &mod_driverops, /* module type (this is a pseudo driver) */