FreeBSD kernel kern code
kern_boottrace.c File Reference
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/boottrace.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/sbuf.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <machine/stdarg.h>
Include dependency graph for kern_boottrace.c:

Go to the source code of this file.

Data Structures

struct  bt_event
 
struct  bt_table
 

Macros

#define dprintf(fmt, ...)
 
#define BT_TABLE_DEFSIZE   3000
 
#define BT_TABLE_RUNSIZE   2000
 
#define BT_TABLE_SHTSIZE   1000
 
#define BT_TABLE_MINSIZE   500
 
#define BTC_DELTA_PRINT(bte, msecs, delta)
 

Functions

static MALLOC_DEFINE (M_BOOTTRACE, "boottrace", "memory for boot tracing")
 
 TUNABLE_BOOL ("debug.boottrace.dotrace_debugging", &dotrace_debugging)
 
 TUNABLE_BOOL ("kern.boottrace.dotrace_kernel", &dotrace_kernel)
 
 TUNABLE_BOOL ("kern.boottrace.dotrace_user", &dotrace_user)
 
static int sysctl_log (SYSCTL_HANDLER_ARGS)
 
static int sysctl_boottrace (SYSCTL_HANDLER_ARGS)
 
static int sysctl_runtrace (SYSCTL_HANDLER_ARGS)
 
static int sysctl_shuttrace (SYSCTL_HANDLER_ARGS)
 
static int sysctl_boottrace_reset (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_NODE (_kern, OID_AUTO, boottrace, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "boottrace statistics")
 
 SYSCTL_PROC (_kern_boottrace, OID_AUTO, log, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE|CTLFLAG_SKIP, 0, 0, sysctl_log, "A", "Print a log of the boottrace trace data")
 
 SYSCTL_PROC (_kern_boottrace, OID_AUTO, boottrace, CTLTYPE_STRING|CTLFLAG_WR|CTLFLAG_MPSAFE, 0, 0, sysctl_boottrace, "A", "Capture a boot-time trace event")
 
 SYSCTL_PROC (_kern_boottrace, OID_AUTO, runtrace, CTLTYPE_STRING|CTLFLAG_WR|CTLFLAG_MPSAFE, 0, 0, sysctl_runtrace, "A", "Capture a run-time trace event")
 
 SYSCTL_PROC (_kern_boottrace, OID_AUTO, shuttrace, CTLTYPE_STRING|CTLFLAG_WR|CTLFLAG_MPSAFE, 0, 0, sysctl_shuttrace, "A", "Capture a shutdown-time trace event")
 
 SYSCTL_PROC (_kern_boottrace, OID_AUTO, reset, CTLTYPE_INT|CTLFLAG_WR|CTLFLAG_MPSAFE, 0, 0, sysctl_boottrace_reset, "A", "Reset run-time tracing table")
 
 SYSCTL_BOOL (_kern_boottrace, OID_AUTO, enabled, CTLFLAG_RDTUN, &boottrace_enabled, 0, "Boot-time and shutdown-time tracing enabled")
 
 SYSCTL_BOOL (_kern_boottrace, OID_AUTO, shutdown_trace, CTLFLAG_RWTUN, &shutdown_trace, 0, "Enable kernel shutdown tracing to the console")
 
 SYSCTL_INT (_kern_boottrace, OID_AUTO, shutdown_trace_threshold, CTLFLAG_RWTUN, &shutdown_trace_threshold, 0, "Tracing threshold (ms) below which tracing is ignored")
 
static void boottrace_display (struct sbuf *sbp, struct bt_table *btp, uint64_t dthres)
 
void boottrace_dump_console (void)
 
static int dotrace (struct bt_table *btp, const char *eventname, const char *tdname)
 
int boottrace (const char *tdname, const char *fmt,...)
 
static int runtrace (const char *eventname, const char *tdname)
 
static void boottrace_parse_message (char *message, char **eventname, char **tdname)
 
static int _boottrace_sysctl (struct bt_table *btp, struct sysctl_oid *oidp, struct sysctl_req *req)
 
void boottrace_reset (const char *actor)
 
int boottrace_resize (u_int newsize)
 
static void boottrace_init (void)
 
 SYSINIT (boottrace, SI_SUB_CPU, SI_ORDER_ANY, boottrace_init, 0)
 

Variables

static struct bt_table bt
 
static struct bt_table rt
 
static struct bt_table st
 
static bool bootdone
 
static bool shutdown
 
static bool dotrace_debugging
 
static bool dotrace_kernel = true
 
static bool dotrace_user = true
 
bool __read_mostly boottrace_enabled = false
 
bool shutdown_trace = false
 
static int shutdown_trace_threshold
 

Macro Definition Documentation

◆ BT_TABLE_DEFSIZE

#define BT_TABLE_DEFSIZE   3000

Definition at line 50 of file kern_boottrace.c.

◆ BT_TABLE_MINSIZE

#define BT_TABLE_MINSIZE   500

Definition at line 53 of file kern_boottrace.c.

◆ BT_TABLE_RUNSIZE

#define BT_TABLE_RUNSIZE   2000

Definition at line 51 of file kern_boottrace.c.

◆ BT_TABLE_SHTSIZE

#define BT_TABLE_SHTSIZE   1000

Definition at line 52 of file kern_boottrace.c.

◆ BTC_DELTA_PRINT

#define BTC_DELTA_PRINT (   bte,
  msecs,
  delta 
)
Value:
do { \
if (sbp) { \
sbuf_printf(sbp, fmt, (bte)->cpuid, msecs, delta, \
(bte)->tdname, (bte)->name, (bte)->pid, \
(bte)->cputime / 1000000, \
((bte)->cputime % 1000000) / 10000, \
(bte)->inblock, (bte)->oublock); \
} else { \
printf(fmt, (bte)->cpuid, msecs, delta, \
(bte)->tdname, (bte)->name, (bte)->pid, \
(bte)->cputime / 1000000, \
((bte)->cputime % 1000000) / 10000, \
(bte)->inblock, (bte)->oublock); \
} \
} while (0)
const char * name
Definition: kern_fail.c:145

Definition at line 189 of file kern_boottrace.c.

◆ dprintf

#define dprintf (   fmt,
  ... 
)
Value:
do { \
printf(fmt, ##__VA_ARGS__); \
} while (0);
static bool dotrace_debugging

Definition at line 42 of file kern_boottrace.c.

Function Documentation

◆ _boottrace_sysctl()

static int _boottrace_sysctl ( struct bt_table btp,
struct sysctl_oid *  oidp,
struct sysctl_req *  req 
)
static

Definition at line 441 of file kern_boottrace.c.

References boottrace_parse_message(), dotrace(), dotrace_user, and sysctl_handle_string().

Referenced by sysctl_boottrace(), sysctl_runtrace(), and sysctl_shuttrace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boottrace()

int boottrace ( const char *  tdname,
const char *  fmt,
  ... 
)

Definition at line 383 of file kern_boottrace.c.

References bootdone, bt, dotrace(), dotrace_kernel, rebooting, rt, shutdown, st, and vsnprintf().

Here is the call graph for this function:

◆ boottrace_display()

static void boottrace_display ( struct sbuf *  sbp,
struct bt_table btp,
uint64_t  dthres 
)
static

Definition at line 211 of file kern_boottrace.c.

References BTC_DELTA_PRINT, cputick2usec(), bt_table::curr, maybe_yield(), printf(), sbuf_printf(), bt_table::size, bt_table::table, bt_event::tick, and bt_event::tsc.

Referenced by boottrace_dump_console(), and sysctl_log().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boottrace_dump_console()

void boottrace_dump_console ( void  )

Definition at line 298 of file kern_boottrace.c.

References boottrace_display(), boottrace_enabled, bt, rebooting, rt, shutdown, shutdown_trace_threshold, and st.

Referenced by kern_reboot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boottrace_init()

static void boottrace_init ( void  )
static

◆ boottrace_parse_message()

static void boottrace_parse_message ( char *  message,
char **  eventname,
char **  tdname 
)
static

Definition at line 425 of file kern_boottrace.c.

Referenced by _boottrace_sysctl().

Here is the caller graph for this function:

◆ boottrace_reset()

void boottrace_reset ( const char *  actor)

Definition at line 539 of file kern_boottrace.c.

References runtrace(), and snprintf().

Referenced by boottrace_resize(), and sysctl_boottrace_reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boottrace_resize()

int boottrace_resize ( u_int  newsize)

Definition at line 552 of file kern_boottrace.c.

References boottrace_reset(), realloc(), rt, bt_table::size, and bt_table::table.

Here is the call graph for this function:

◆ dotrace()

static int dotrace ( struct bt_table btp,
const char *  eventname,
const char *  tdname 
)
static

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_BOOTTRACE  ,
"boottrace"  ,
"memory for boot tracing"   
)
static

◆ runtrace()

static int runtrace ( const char *  eventname,
const char *  tdname 
)
static

Definition at line 409 of file kern_boottrace.c.

References bootdone, dotrace(), and rt.

Referenced by boottrace_reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SYSCTL_BOOL() [1/2]

SYSCTL_BOOL ( _kern_boottrace  ,
OID_AUTO  ,
enabled  ,
CTLFLAG_RDTUN  ,
boottrace_enabled,
,
"Boot-time and shutdown-time tracing enabled"   
)

◆ SYSCTL_BOOL() [2/2]

SYSCTL_BOOL ( _kern_boottrace  ,
OID_AUTO  ,
shutdown_trace  ,
CTLFLAG_RWTUN  ,
shutdown_trace,
,
"Enable kernel shutdown tracing to the console"   
)

◆ sysctl_boottrace()

static int sysctl_boottrace ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 485 of file kern_boottrace.c.

References _boottrace_sysctl(), bootdone, boottrace_enabled, bt, and rt.

Here is the call graph for this function:

◆ sysctl_boottrace_reset()

static int sysctl_boottrace_reset ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 569 of file kern_boottrace.c.

References boottrace_enabled, and boottrace_reset().

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _kern_boottrace  ,
OID_AUTO  ,
shutdown_trace_threshold  ,
CTLFLAG_RWTUN  ,
shutdown_trace_threshold,
,
"Tracing threshold (ms) below which tracing is ignored"   
)

◆ sysctl_log()

static int sysctl_log ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 466 of file kern_boottrace.c.

References boottrace_display(), boottrace_enabled, bt, rt, sbuf_data(), sbuf_delete(), sbuf_finish(), sbuf_len(), and sbuf_new().

Here is the call graph for this function:

◆ SYSCTL_NODE()

SYSCTL_NODE ( _kern  ,
OID_AUTO  ,
boottrace  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"boottrace statistics"   
)

◆ SYSCTL_PROC() [1/5]

SYSCTL_PROC ( _kern_boottrace  ,
OID_AUTO  ,
boottrace  ,
CTLTYPE_STRING|CTLFLAG_WR|  CTLFLAG_MPSAFE,
,
,
sysctl_boottrace  ,
"A"  ,
"Capture a boot-time trace event"   
)

◆ SYSCTL_PROC() [2/5]

SYSCTL_PROC ( _kern_boottrace  ,
OID_AUTO  ,
log  ,
CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE|  CTLFLAG_SKIP,
,
,
sysctl_log  ,
"A"  ,
"Print a log of the boottrace trace data  
)

◆ SYSCTL_PROC() [3/5]

SYSCTL_PROC ( _kern_boottrace  ,
OID_AUTO  ,
reset  ,
CTLTYPE_INT|CTLFLAG_WR|  CTLFLAG_MPSAFE,
,
,
sysctl_boottrace_reset  ,
"A"  ,
"Reset run-time tracing table"   
)

◆ SYSCTL_PROC() [4/5]

SYSCTL_PROC ( _kern_boottrace  ,
OID_AUTO  ,
runtrace  ,
CTLTYPE_STRING|CTLFLAG_WR|  CTLFLAG_MPSAFE,
,
,
sysctl_runtrace  ,
"A"  ,
"Capture a run-time trace event"   
)

◆ SYSCTL_PROC() [5/5]

SYSCTL_PROC ( _kern_boottrace  ,
OID_AUTO  ,
shuttrace  ,
CTLTYPE_STRING|CTLFLAG_WR|  CTLFLAG_MPSAFE,
,
,
sysctl_shuttrace  ,
"A"  ,
"Capture a shutdown-time trace event"   
)

◆ sysctl_runtrace()

static int sysctl_runtrace ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 503 of file kern_boottrace.c.

References _boottrace_sysctl(), bootdone, boottrace_enabled, and rt.

Here is the call graph for this function:

◆ sysctl_shuttrace()

static int sysctl_shuttrace ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 521 of file kern_boottrace.c.

References _boottrace_sysctl(), boottrace_enabled, shutdown, and st.

Here is the call graph for this function:

◆ SYSINIT()

SYSINIT ( boottrace  ,
SI_SUB_CPU  ,
SI_ORDER_ANY  ,
boottrace_init  ,
 
)

◆ TUNABLE_BOOL() [1/3]

TUNABLE_BOOL ( "debug.boottrace.dotrace_debugging"  ,
dotrace_debugging 
)

◆ TUNABLE_BOOL() [2/3]

TUNABLE_BOOL ( "kern.boottrace.dotrace_kernel"  ,
dotrace_kernel 
)

◆ TUNABLE_BOOL() [3/3]

TUNABLE_BOOL ( "kern.boottrace.dotrace_user"  ,
dotrace_user 
)

Variable Documentation

◆ bootdone

bool bootdone
static

Definition at line 89 of file kern_boottrace.c.

Referenced by boottrace(), runtrace(), sysctl_boottrace(), and sysctl_runtrace().

◆ boottrace_enabled

◆ bt

◆ dotrace_debugging

bool dotrace_debugging
static

Definition at line 95 of file kern_boottrace.c.

◆ dotrace_kernel

bool dotrace_kernel = true
static

Definition at line 99 of file kern_boottrace.c.

Referenced by boottrace().

◆ dotrace_user

bool dotrace_user = true
static

Definition at line 103 of file kern_boottrace.c.

Referenced by _boottrace_sysctl().

◆ rt

◆ shutdown

bool shutdown
static

Definition at line 92 of file kern_boottrace.c.

Referenced by boottrace(), boottrace_dump_console(), and sysctl_shuttrace().

◆ shutdown_trace

bool shutdown_trace = false

Definition at line 147 of file kern_boottrace.c.

Referenced by kern_reboot().

◆ shutdown_trace_threshold

int shutdown_trace_threshold
static

Definition at line 156 of file kern_boottrace.c.

Referenced by boottrace_dump_console().

◆ st