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, Version 1.0 only
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (the "License"). You may not use this file except in compliance
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * 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/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#pragma ident "%Z%%M% %I% %E% SMI"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <dt_impl.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <stddef.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <errno.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <assert.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <time.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#else /* VBOX */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync# include <dt_impl.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync//# include <stddef.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync//# include <time.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync# include <iprt/semaphore.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif /* VBOX */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const struct {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int dtslt_option;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size_t dtslt_offs;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} _dtrace_sleeptab[] = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { DTRACEOPT_STATUSRATE, offsetof(dtrace_hdl_t, dt_laststatus) },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { DTRACEOPT_AGGRATE, offsetof(dtrace_hdl_t, dt_lastagg) },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { DTRACEOPT_SWITCHRATE, offsetof(dtrace_hdl_t, dt_lastswitch) },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync { DTRACEOPT_MAX, 0 }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_sleep(dtrace_hdl_t *dtp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_proc_hash_t *dph = dtp->dt_procs;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_optval_t policy = dtp->dt_options[DTRACEOPT_BUFPOLICY];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_proc_notify_t *dprn;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t earliest = INT64_MAX;
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct timespec tv;
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t now;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; _dtrace_sleeptab[i].dtslt_option < DTRACEOPT_MAX; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uintptr_t a = (uintptr_t)dtp + _dtrace_sleeptab[i].dtslt_offs;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int opt = _dtrace_sleeptab[i].dtslt_option;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_optval_t interval = dtp->dt_options[opt];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the buffering policy is set to anything other than
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * "switch", we ignore the aggrate and switchrate -- they're
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * meaningless.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (policy != DTRACEOPT_BUFPOLICY_SWITCH &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync _dtrace_sleeptab[i].dtslt_option != DTRACEOPT_STATUSRATE)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (*((hrtime_t *)a) + interval < earliest)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync earliest = *((hrtime_t *)a) + interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) pthread_mutex_lock(&dph->dph_lock);
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync now = gethrtime();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (earliest < now) {
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) pthread_mutex_unlock(&dph->dph_lock);
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return; /* sleep duration has already past */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync tv.tv_sec = (earliest - now) / NANOSEC;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync tv.tv_nsec = (earliest - now) % NANOSEC;
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Wait for either 'tv' nanoseconds to pass or to receive notification
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * that a process is in an interesting state. Regardless of why we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * awaken, iterate over any pending notifications and process them.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) pthread_cond_reltimedwait_np(&dph->dph_cv, &dph->dph_lock, &tv);
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#else
e3de7948c4ce365719e80faad164a0fad245bbbbvboxsync if (dph->dph_event)
e3de7948c4ce365719e80faad164a0fad245bbbbvboxsync RTSemEventWait(dph->dph_event, (earliest - now) / RT_NS_1MS);
e3de7948c4ce365719e80faad164a0fad245bbbbvboxsync else
e3de7948c4ce365719e80faad164a0fad245bbbbvboxsync RTThreadSleep((earliest - now) / RT_NS_1MS);
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while ((dprn = dph->dph_notify) != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_prochdlr != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *err = dprn->dprn_errmsg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (*err == '\0')
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync err = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_prochdlr(dprn->dprn_dpr->dpr_proc, err,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_procarg);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dph->dph_notify = dprn->dprn_next;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_free(dtp, dprn);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) pthread_mutex_unlock(&dph->dph_lock);
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_status(dtrace_hdl_t *dtp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int gen = dtp->dt_statusgen;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_optval_t interval = dtp->dt_options[DTRACEOPT_STATUSRATE];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t now = gethrtime();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!dtp->dt_active)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_STATUS_NONE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_stopped)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_STATUS_STOPPED);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_laststatus != 0) {
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync if (now - dtp->dt_laststatus < VBDTCAST(hrtime_t)interval)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_STATUS_NONE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_laststatus += interval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_laststatus = now;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_ioctl(dtp, DTRACEIOC_STATUS, &dtp->dt_status[gen]) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_statusgen ^= 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_handle_status(dtp, &dtp->dt_status[dtp->dt_statusgen],
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &dtp->dt_status[gen]) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_status[gen].dtst_exiting) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!dtp->dt_stopped)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dtrace_stop(dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_STATUS_EXITED);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_status[gen].dtst_filled == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_STATUS_OKAY);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_options[DTRACEOPT_BUFPOLICY] != DTRACEOPT_BUFPOLICY_FILL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_STATUS_OKAY);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!dtp->dt_stopped) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_stop(dtp) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_STATUS_FILLED);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_go(dtrace_hdl_t *dtp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync void *dof;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_active)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EINVAL));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If a dtrace:::ERROR program and callback are registered, enable the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * program before we start tracing. If this fails for a vector open
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * with ENOTTY, we permit dtrace_go() to succeed so that vector clients
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * such as mdb's dtrace module can execute the rest of dtrace_go() even
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * though they do not provide support for the DTRACEIOC_ENABLE ioctl.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_errprog != NULL &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_program_exec(dtp, dtp->dt_errprog, NULL) == -1 && (
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_errno != ENOTTY || dtp->dt_vector == NULL))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* dt_errno has been set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dof = dtrace_getopt_dof(dtp)) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* dt_errno has been set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync err = dt_ioctl(dtp, DTRACEIOC_ENABLE, dof);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_dof_destroy(dtp, dof);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (err == -1 && (errno != ENOTTY || dtp->dt_vector == NULL))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (errno == EACCES)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DESTRUCTIVE));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (errno == EALREADY)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_ISANON));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (errno == ENOENT)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_NOANON));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (errno == E2BIG)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_ENDTOOBIG));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (errno == ENOSPC)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_BUFTOOSMALL));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_active = 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_options_load(dtp) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_aggregate_go(dtp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_stop(dtrace_hdl_t *dtp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int gen = dtp->dt_statusgen;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_stopped)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_ioctl(dtp, DTRACEIOC_STOP, &dtp->dt_endedon) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_stopped = 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Now that we're stopped, we're going to get status one final time.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_ioctl(dtp, DTRACEIOC_STATUS, &dtp->dt_status[gen]) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_handle_status(dtp, &dtp->dt_status[gen ^ 1],
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &dtp->dt_status[gen]) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_workstatus_t
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_work(dtrace_hdl_t *dtp, FILE *fp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_consume_probe_f *pfunc, dtrace_consume_rec_f *rfunc, void *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int status = dtrace_status(dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_optval_t policy = dtp->dt_options[DTRACEOPT_BUFPOLICY];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_workstatus_t rval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (status) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACE_STATUS_EXITED:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACE_STATUS_FILLED:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACE_STATUS_STOPPED:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Tracing is stopped. We now want to force dtrace_consume()
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and dtrace_aggregate_snap() to proceed, regardless of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * switchrate and aggrate. We do this by clearing the times.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_lastswitch = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_lastagg = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval = DTRACE_WORKSTATUS_DONE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACE_STATUS_NONE:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACE_STATUS_OKAY:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval = DTRACE_WORKSTATUS_OKAY;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case -1:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_WORKSTATUS_ERROR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((status == DTRACE_STATUS_NONE || status == DTRACE_STATUS_OKAY) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync policy != DTRACEOPT_BUFPOLICY_SWITCH) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * There either isn't any status or things are fine -- and
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * this is a "ring" or "fill" buffer. We don't want to consume
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * any of the trace data or snapshot the aggregations; we just
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * return.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(rval == DTRACE_WORKSTATUS_OKAY);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_aggregate_snap(dtp) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_WORKSTATUS_ERROR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_consume(dtp, fp, pfunc, rfunc, arg) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DTRACE_WORKSTATUS_ERROR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}