14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
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 *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * or http://www.opensolaris.org/os/licensing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
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 *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/errno.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/stat.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/modctl.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/conf.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/systm.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/ddi.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/sunddi.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/cpuvar.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/kmem.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/strsubr.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/dtrace.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/cyclic.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/atomic.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dev_info_t *profile_devi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dtrace_provider_id_t profile_id;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Regardless of platform, the stack frames look like this in the case of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * profile provider:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * profile_fire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * cyclic_expire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * cyclic_fire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * [ cbe ]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * [ interrupt code ]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
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 * 10.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * On SPARC, the picture is further complicated because the compiler
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * optimizes away tail-calls -- so the following frames are optimized away:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * profile_fire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * cyclic_expire
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
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 *
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.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __x86
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_ARTIFICIAL_FRAMES 10
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __sparc
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef DEBUG
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_ARTIFICIAL_FRAMES 4
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_ARTIFICIAL_FRAMES 3
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_NAMELEN 15
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_PROFILE 0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_TICK 1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_PREFIX_PROFILE "profile-"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define PROF_PREFIX_TICK "tick-"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct profile_probe {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char prof_name[PROF_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_id_t prof_id;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int prof_kind;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t prof_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cyclic_id_t prof_cyclic;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} profile_probe_t;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct profile_probe_percpu {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t profc_expected;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t profc_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *profc_probe;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} profile_probe_percpu_t;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynchrtime_t profile_interval_min = NANOSEC / 5000; /* 5000 hz */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint profile_aframes = 0; /* override */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int profile_rates[] = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 97, 199, 499, 997, 1999,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 4001, 4999, 0, 0, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, 0, 0, 0, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, 0, 0, 0, 0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int profile_ticks[] = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 1, 10, 100, 500, 1000,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 5000, 0, 0, 0, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, 0, 0, 0, 0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
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 */
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_fire(void *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_percpu_t *pcpu = arg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *prof = pcpu->profc_probe;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t late;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync late = dtrace_gethrtime() - pcpu->profc_expected;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pcpu->profc_expected += pcpu->profc_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_probe(prof->prof_id, CPU->cpu_profile_pc,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU->cpu_profile_upc, late, 0, 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_tick(void *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *prof = arg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_probe(prof->prof_id, CPU->cpu_profile_pc,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU->cpu_profile_upc, 0, 0, 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_create(hrtime_t interval, const char *name, int kind)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *prof;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int nr_frames = PROF_ARTIFICIAL_FRAMES + dtrace_mach_aframes();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (profile_aframes)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nr_frames = profile_aframes;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (interval < profile_interval_min)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_probe_lookup(profile_id, NULL, NULL, name) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync atomic_add_32(&profile_total, 1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (profile_total > profile_max) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync atomic_add_32(&profile_total, -1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof = kmem_zalloc(sizeof (profile_probe_t), KM_SLEEP);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcpy(prof->prof_name, name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof->prof_interval = interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof->prof_cyclic = CYCLIC_NONE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof->prof_kind = kind;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof->prof_id = dtrace_probe_create(profile_id,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL, NULL, name, nr_frames, prof);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_provide(void *arg, const dtrace_probedesc_t *desc)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i, j, rate, kind;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t val = 0, mult = 1, len;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *name, *suffix = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const struct {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *prefix;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int kind;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } types[] = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { PROF_PREFIX_PROFILE, PROF_PROFILE },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { PROF_PREFIX_TICK, PROF_TICK },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { NULL, NULL }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync };
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const struct {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t mult;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } suffixes[] = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "ns", NANOSEC / NANOSEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "nsec", NANOSEC / NANOSEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "us", NANOSEC / MICROSEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "usec", NANOSEC / MICROSEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "ms", NANOSEC / MILLISEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "msec", NANOSEC / MILLISEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "s", NANOSEC / SEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "sec", NANOSEC / SEC },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "m", NANOSEC * (hrtime_t)60 },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "min", NANOSEC * (hrtime_t)60 },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "h", NANOSEC * (hrtime_t)(60 * 60) },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "hour", NANOSEC * (hrtime_t)(60 * 60) },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "d", NANOSEC * (hrtime_t)(24 * 60 * 60) },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "day", NANOSEC * (hrtime_t)(24 * 60 * 60) },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { "hz", 0 },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { NULL }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync };
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (desc == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char n[PROF_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If no description was provided, provide all of our probes.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < sizeof (profile_rates) / sizeof (int); i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((rate = profile_rates[i]) == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(n, PROF_NAMELEN, "%s%d",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync PROF_PREFIX_PROFILE, rate);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_create(NANOSEC / rate, n, PROF_PROFILE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < sizeof (profile_ticks) / sizeof (int); i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((rate = profile_ticks[i]) == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(n, PROF_NAMELEN, "%s%d",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync PROF_PREFIX_TICK, rate);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_create(NANOSEC / rate, n, PROF_TICK);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync name = desc->dtpd_name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; types[i].prefix != NULL; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync len = strlen(types[i].prefix);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strncmp(name, types[i].prefix, len) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (types[i].prefix == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kind = types[i].kind;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync j = strlen(name) - len;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We need to start before any time suffix.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (j = strlen(name); j >= len; j--) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (name[j] >= '0' && name[j] <= '9')
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync suffix = &name[j];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(suffix != NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Now determine the numerical value present in the probe name.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; j >= len; j--) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (name[j] < '0' || name[j] > '9')
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val += (name[j] - '0') * mult;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync mult *= (hrtime_t)10;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (val == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Look-up the suffix to determine the multiplier.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0, mult = 0; suffixes[i].name != NULL; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcasecmp(suffixes[i].name, suffix) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync mult = suffixes[i].mult;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (suffixes[i].name == NULL && *suffix != '\0')
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (mult == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The default is frequency-per-second.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val = NANOSEC / val;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val *= mult;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_create(val, name, kind);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_destroy(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *prof = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(prof->prof_cyclic == CYCLIC_NONE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kmem_free(prof, sizeof (profile_probe_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(profile_total >= 1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync atomic_add_32(&profile_total, -1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_online(void *arg, cpu_t *cpu, cyc_handler_t *hdlr, cyc_time_t *when)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *prof = arg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_percpu_t *pcpu;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pcpu = kmem_zalloc(sizeof (profile_probe_percpu_t), KM_SLEEP);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pcpu->profc_probe = prof;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hdlr->cyh_func = profile_fire;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hdlr->cyh_arg = pcpu;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hdlr->cyh_level = CY_HIGH_LEVEL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync when->cyt_interval = prof->prof_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync when->cyt_when = dtrace_gethrtime() + when->cyt_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pcpu->profc_expected = when->cyt_when;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pcpu->profc_interval = when->cyt_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_offline(void *arg, cpu_t *cpu, void *oarg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_percpu_t *pcpu = oarg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(pcpu->profc_probe == arg);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kmem_free(pcpu, sizeof (profile_probe_percpu_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_enable(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *prof = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cyc_omni_handler_t omni;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cyc_handler_t hdlr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cyc_time_t when;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(prof->prof_interval != 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(MUTEX_HELD(&cpu_lock));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (prof->prof_kind == PROF_TICK) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hdlr.cyh_func = profile_tick;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hdlr.cyh_arg = prof;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hdlr.cyh_level = CY_HIGH_LEVEL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync when.cyt_interval = prof->prof_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync when.cyt_when = dtrace_gethrtime() + when.cyt_interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(prof->prof_kind == PROF_PROFILE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync omni.cyo_online = profile_online;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync omni.cyo_offline = profile_offline;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync omni.cyo_arg = prof;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (prof->prof_kind == PROF_TICK) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof->prof_cyclic = cyclic_add(&hdlr, &when);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof->prof_cyclic = cyclic_add_omni(&omni);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_disable(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_probe_t *prof = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(prof->prof_cyclic != CYCLIC_NONE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(MUTEX_HELD(&cpu_lock));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cyclic_remove(prof->prof_cyclic);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync prof->prof_cyclic = CYCLIC_NONE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_usermode(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (CPU->cpu_profile_pc == 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dtrace_pattr_t profile_attr = {
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 },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dtrace_pops_t profile_pops = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_provide,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_enable,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_disable,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_usermode,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_destroy
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (cmd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_ATTACH:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_RESUME:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ddi_create_minor_node(devi, "profile", S_IFCHR, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DDI_PSEUDO, NULL) == DDI_FAILURE ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_register("profile", &profile_attr,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACE_PRIV_KERNEL | DTRACE_PRIV_USER, NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &profile_pops, NULL, &profile_id) != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_remove_minor_node(devi, NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_max = ddi_getprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "profile-max-probes", PROFILE_MAX_DEFAULT);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_report_dev(devi);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_devi = devi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (cmd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_DETACH:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_SUSPEND:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_unregister(profile_id) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_remove_minor_node(devi, NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int error;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (infocmd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_INFO_DEVT2DEVINFO:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *result = (void *)profile_devi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync error = DDI_SUCCESS;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_INFO_DEVT2INSTANCE:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *result = (void *)0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync error = DDI_SUCCESS;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync error = DDI_FAILURE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (error);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncprofile_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct cb_ops profile_cb_ops = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_open, /* open */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* close */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* strategy */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* print */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* dump */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* read */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* write */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* ioctl */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* devmap */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* mmap */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* segmap */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nochpoll, /* poll */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_prop_op, /* cb_prop_op */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, /* streamtab */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync D_NEW | D_MP /* Driver compatibility flag */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct dev_ops profile_ops = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DEVO_REV, /* devo_rev, */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, /* refcnt */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_info, /* get_dev_info */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* identify */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* probe */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_attach, /* attach */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync profile_detach, /* detach */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* reset */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &profile_cb_ops, /* driver operations */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL, /* bus operations */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* dev power */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_quiesce_not_needed, /* quiesce */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Module linkage information for the kernel.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct modldrv modldrv = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &mod_driverops, /* module type (this is a pseudo driver) */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "Profile Interrupt Tracing", /* name of module */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &profile_ops, /* driver ops */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct modlinkage modlinkage = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync MODREV_1,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void *)&modldrv,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync_init(void)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (mod_install(&modlinkage));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync_info(struct modinfo *modinfop)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (mod_info(&modlinkage, modinfop));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync_fini(void)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (mod_remove(&modlinkage));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}