FreeBSD kernel kern code
kern_ktr.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include "opt_ktr.h"
#include "opt_alq.h"
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/alq.h>
#include <sys/cons.h>
#include <sys/cpuset.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/libkern.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/time.h>
#include <machine/cpu.h>
Include dependency graph for kern_ktr.c:

Go to the source code of this file.

Macros

#define KTR_BOOT_ENTRIES   1024
 
#define KTR_ENTRIES   1024
 
#define KTR_ENTRIES_MAX   (8 * 1024 * 1024)
 
#define KTR_MASK   (0)
 
#define KTR_CPUMASK   CPUSET_FSET
 
#define KTR_TIME   get_cyclecount()
 
#define KTR_CPU   PCPU_GET(cpuid)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_KTR, "KTR", "KTR")
 
 FEATURE (ktr, "Kernel support for KTR kernel tracing facility")
 
static SYSCTL_NODE (_debug, OID_AUTO, ktr, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "KTR options")
 
 SYSCTL_INT (_debug_ktr, OID_AUTO, version, CTLFLAG_RD, &ktr_version, 0, "Version of the KTR interface")
 
 SYSCTL_UQUAD (_debug_ktr, OID_AUTO, compile, CTLFLAG_RD, &ktr_compile, 0, "Bitmask of KTR event classes compiled into the kernel")
 
static int sysctl_debug_ktr_cpumask (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_debug_ktr, OID_AUTO, cpumask, CTLFLAG_RWTUN|CTLFLAG_MPSAFE|CTLTYPE_STRING, NULL, 0, sysctl_debug_ktr_cpumask, "S", "Bitmask of CPUs on which KTR logging is enabled")
 
static int sysctl_debug_ktr_clear (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_debug_ktr, OID_AUTO, clear, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_NEEDGIANT, 0, 0, sysctl_debug_ktr_clear, "I", "Clear KTR Buffer")
 
static int sysctl_debug_ktr_mask (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_debug_ktr, OID_AUTO, mask, CTLTYPE_U64|CTLFLAG_RWTUN|CTLFLAG_NEEDGIANT, 0, 0, sysctl_debug_ktr_mask, "QU", "Bitmask of KTR event classes for which logging is enabled")
 
static int sysctl_debug_ktr_entries (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_debug_ktr, OID_AUTO, entries, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_NEEDGIANT, 0, 0, sysctl_debug_ktr_entries, "I", "Number of entries in the KTR buffer")
 
void ktr_tracepoint (uint64_t mask, const char *file, int line, const char *format, u_long arg1, u_long arg2, u_long arg3, u_long arg4, u_long arg5, u_long arg6)
 

Variables

volatile int ktr_idx = 0
 
uint64_t ktr_mask = KTR_MASK
 
uint64_t ktr_compile = KTR_COMPILE
 
int ktr_entries = KTR_BOOT_ENTRIES
 
int ktr_version = KTR_VERSION
 
struct ktr_entry ktr_buf_init [KTR_BOOT_ENTRIES]
 
struct ktr_entry * ktr_buf = ktr_buf_init
 
cpuset_t ktr_cpumask = CPUSET_T_INITIALIZER(KTR_CPUMASK)
 

Macro Definition Documentation

◆ KTR_BOOT_ENTRIES

#define KTR_BOOT_ENTRIES   1024

Definition at line 66 of file kern_ktr.c.

◆ KTR_CPU

#define KTR_CPU   PCPU_GET(cpuid)

Definition at line 89 of file kern_ktr.c.

◆ KTR_CPUMASK

#define KTR_CPUMASK   CPUSET_FSET

Definition at line 81 of file kern_ktr.c.

◆ KTR_ENTRIES

#define KTR_ENTRIES   1024

Definition at line 70 of file kern_ktr.c.

◆ KTR_ENTRIES_MAX

#define KTR_ENTRIES_MAX   (8 * 1024 * 1024)

Definition at line 74 of file kern_ktr.c.

◆ KTR_MASK

#define KTR_MASK   (0)

Definition at line 77 of file kern_ktr.c.

◆ KTR_TIME

#define KTR_TIME   get_cyclecount()

Definition at line 85 of file kern_ktr.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ FEATURE()

FEATURE ( ktr  ,
"Kernel support for KTR kernel tracing facility  
)

◆ ktr_tracepoint()

void ktr_tracepoint ( uint64_t  mask,
const char *  file,
int  line,
const char *  format,
u_long  arg1,
u_long  arg2,
u_long  arg3,
u_long  arg4,
u_long  arg5,
u_long  arg6 
)

Definition at line 320 of file kern_ktr.c.

References alq_get(), kdb_active, ktr_buf, KTR_CPU, ktr_cpumask, ktr_entries, ktr_idx, ktr_mask, KTR_TIME, mask, and printf().

Here is the call graph for this function:

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_KTR  ,
"KTR"  ,
"KTR"   
)
static

◆ sysctl_debug_ktr_clear()

static int sysctl_debug_ktr_clear ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 138 of file kern_ktr.c.

References ktr_buf, ktr_entries, ktr_idx, and sysctl_handle_int().

Here is the call graph for this function:

◆ sysctl_debug_ktr_cpumask()

static int sysctl_debug_ktr_cpumask ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 115 of file kern_ktr.c.

References cpusetobj_strprint(), cpusetobj_strscan(), ktr_cpumask, and sysctl_handle_string().

Here is the call graph for this function:

◆ sysctl_debug_ktr_entries()

static int sysctl_debug_ktr_entries ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 212 of file kern_ktr.c.

References buf, free(), ktr_buf, ktr_buf_init, ktr_entries, KTR_ENTRIES_MAX, ktr_idx, ktr_mask, malloc(), mask, quiesce_all_cpus(), and sysctl_handle_int().

Here is the call graph for this function:

◆ sysctl_debug_ktr_mask()

static int sysctl_debug_ktr_mask ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 164 of file kern_ktr.c.

References ktr_mask, mask, and sysctl_handle_64().

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _debug_ktr  ,
OID_AUTO  ,
version  ,
CTLFLAG_RD  ,
ktr_version,
,
"Version of the KTR interface"   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _debug  ,
OID_AUTO  ,
ktr  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"KTR options"   
)
static

◆ SYSCTL_PROC() [1/4]

SYSCTL_PROC ( _debug_ktr  ,
OID_AUTO  ,
clear  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_NEEDGIANT,
,
,
sysctl_debug_ktr_clear  ,
"I"  ,
"Clear KTR Buffer"   
)

◆ SYSCTL_PROC() [2/4]

SYSCTL_PROC ( _debug_ktr  ,
OID_AUTO  ,
cpumask  ,
CTLFLAG_RWTUN|CTLFLAG_MPSAFE|  CTLTYPE_STRING,
NULL  ,
,
sysctl_debug_ktr_cpumask  ,
"S"  ,
"Bitmask of CPUs on which KTR logging is enabled"   
)

◆ SYSCTL_PROC() [3/4]

SYSCTL_PROC ( _debug_ktr  ,
OID_AUTO  ,
entries  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_NEEDGIANT,
,
,
sysctl_debug_ktr_entries  ,
"I"  ,
"Number of entries in the KTR buffer"   
)

◆ SYSCTL_PROC() [4/4]

SYSCTL_PROC ( _debug_ktr  ,
OID_AUTO  ,
mask  ,
CTLTYPE_U64|CTLFLAG_RWTUN|  CTLFLAG_NEEDGIANT,
,
,
sysctl_debug_ktr_mask  ,
"QU"  ,
"Bitmask of KTR event classes for which logging is enabled"   
)

◆ SYSCTL_UQUAD()

SYSCTL_UQUAD ( _debug_ktr  ,
OID_AUTO  ,
compile  ,
CTLFLAG_RD  ,
ktr_compile,
,
"Bitmask of KTR event classes compiled into the kernel"   
)

Variable Documentation

◆ ktr_buf

struct ktr_entry* ktr_buf = ktr_buf_init

Definition at line 102 of file kern_ktr.c.

Referenced by ktr_tracepoint(), sysctl_debug_ktr_clear(), and sysctl_debug_ktr_entries().

◆ ktr_buf_init

struct ktr_entry ktr_buf_init[KTR_BOOT_ENTRIES]

Definition at line 101 of file kern_ktr.c.

Referenced by sysctl_debug_ktr_entries().

◆ ktr_compile

uint64_t ktr_compile = KTR_COMPILE

Definition at line 98 of file kern_ktr.c.

◆ ktr_cpumask

cpuset_t ktr_cpumask = CPUSET_T_INITIALIZER(KTR_CPUMASK)

Definition at line 103 of file kern_ktr.c.

Referenced by ktr_tracepoint(), and sysctl_debug_ktr_cpumask().

◆ ktr_entries

int ktr_entries = KTR_BOOT_ENTRIES

Definition at line 99 of file kern_ktr.c.

Referenced by ktr_tracepoint(), sysctl_debug_ktr_clear(), and sysctl_debug_ktr_entries().

◆ ktr_idx

volatile int ktr_idx = 0

Definition at line 96 of file kern_ktr.c.

Referenced by ktr_tracepoint(), sysctl_debug_ktr_clear(), and sysctl_debug_ktr_entries().

◆ ktr_mask

uint64_t ktr_mask = KTR_MASK

Definition at line 97 of file kern_ktr.c.

Referenced by ktr_tracepoint(), sysctl_debug_ktr_entries(), and sysctl_debug_ktr_mask().

◆ ktr_version

int ktr_version = KTR_VERSION

Definition at line 100 of file kern_ktr.c.