ftrace.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
* 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 1998-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Tunable parameters:
*
* ftrace_atboot - whether to start fast tracing at boot.
* ftrace_nent - size of the per-CPU event ring buffer.
*/
int ftrace_atboot = 0;
int ftrace_nent = FTRACE_NENT;
/*
* The current overall state of the ftrace subsystem.
* If FTRACE_READY is set, then tracing can be enabled.
* If FTRACE_ENABLED is set, tracing is enabled on the set of CPUs
* which are currently FTRACE_READY.
*/
static int ftrace_state = 0;
/*
* Protects assignments to:
* ftrace_state
* cpu[N]->cpu_ftrace.ftd_state
* cpu[N]->cpu_ftrace.ftd_cur
* cpu[N]->cpu_ftrace.ftd_first
* cpu[N]->cpu_ftrace.ftd_last
* Does _not_ protect readers of cpu[N]->cpu_ftrace.ftd_state.
* Does not protect reading the FTRACE_READY bit in ftrace_state,
* since non-READY to READY is a stable transition. This is used
* to ensure ftrace_init() has been called.
*/
static kmutex_t ftrace_lock;
/*
* Check whether a CPU is installed.
*/
static void
ftrace_cpu_init(int cpuid)
{
/*
* This can be called with "cpu[cpuid]->cpu_flags & CPU_EXISTS"
* being false - e.g. when a CPU is DR'ed in.
*/
return;
/*
* We don't allocate the buffers until the first time
* ftrace_cpu_start() is called, so that they're not
* allocated if ftrace is never enabled.
*/
}
/*
* Only called from cpu_unconfigure() (and cpu_configure() on error).
* At this point, cpu[cpuid] is about to be freed and NULLed out,
* so we'd better clean up after ourselves.
*/
static void
ftrace_cpu_fini(int cpuid)
{
return;
/*
* Do not free mutex and the the trace buffer once they are
* allocated. A thread, preempted from the now powered-off CPU
* may be holding the mutex and in the middle of adding a trace
* record.
*/
}
static void
ftrace_cpu_start(int cpuid)
{
sizeof (ftrace_record_t), KM_SLEEP);
}
}
}
static void
ftrace_cpu_stop(int cpuid)
{
}
/*
* Hook for DR.
*/
/*ARGSUSED*/
int
{
if (!(ftrace_state & FTRACE_READY))
return (0);
switch (what) {
case CPU_CONFIG:
if (ftrace_state & FTRACE_ENABLED)
break;
case CPU_UNCONFIG:
break;
default:
break;
}
return (0);
}
void
ftrace_init(void)
{
int i;
for (i = 0; i < NCPU; i++) {
if (IS_CPU(i)) {
/* should have been kmem_zalloc()'ed */
}
}
if (ftrace_nent < 1) {
return;
}
for (i = 0; i < NCPU; i++)
if (IS_CPU(i))
ftrace_cpu_init(i);
if (ftrace_atboot)
(void) ftrace_start();
}
int
ftrace_start(void)
{
int i, was_enabled = 0;
if (ftrace_state & FTRACE_READY) {
for (i = 0; i < NCPU; i++)
if (IS_CPU(i))
ftrace_cpu_start(i);
}
return (was_enabled);
}
int
ftrace_stop(void)
{
int i, was_enabled = 0;
if (ftrace_state & FTRACE_READY) {
if (ftrace_state & FTRACE_ENABLED) {
was_enabled = 1;
for (i = 0; i < NCPU; i++)
if (IS_CPU(i))
ftrace_cpu_stop(i);
ftrace_state &= ~(FTRACE_ENABLED);
}
}
return (was_enabled);
}
void
{
ftrace_record_t *r;
if (CPU_ON_INTR(cp))
return;
else
}
r->ftr_thread = curthread;
r->ftr_tick = gethrtime_unscaled();
r->ftr_caller = caller();
}
void
{
ftrace_record_t *r;
if (CPU_ON_INTR(cp))
return;
else
}
r->ftr_thread = curthread;
r->ftr_tick = gethrtime_unscaled();
r->ftr_caller = caller();
}
void
{
ftrace_record_t *r;
if (CPU_ON_INTR(cp))
return;
else
}
r->ftr_thread = curthread;
r->ftr_tick = gethrtime_unscaled();
r->ftr_caller = caller();
}
void
{
ftrace_record_t *r;
if (CPU_ON_INTR(cp))
return;
else
}
r->ftr_thread = curthread;
r->ftr_tick = gethrtime_unscaled();
r->ftr_caller = caller();
}
void
{
ftrace_record_t *r;
if (CPU_ON_INTR(cp))
return;
else
}
r->ftr_thread = curthread;
r->ftr_tick = 0;
r->ftr_caller = caller();
}