FreeBSD kernel kern code
subr_devstat.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/disk.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/bio.h>
#include <sys/devicestat.h>
#include <sys/sdt.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/conf.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/atomic.h>
Include dependency graph for subr_devstat.c:

Go to the source code of this file.

Data Structures

struct  statspage
 

Macros

#define DTRACE_DEVSTAT_START()   SDT_PROBE2(io, , , start, NULL, ds)
 
#define DTRACE_DEVSTAT_BIO_START()   SDT_PROBE2(io, , , start, bp, ds)
 
#define DTRACE_DEVSTAT_DONE()   SDT_PROBE2(io, , , done, NULL, ds)
 
#define DTRACE_DEVSTAT_BIO_DONE()   SDT_PROBE2(io, , , done, bp, ds)
 
#define DTRACE_DEVSTAT_WAIT_START()   SDT_PROBE2(io, , , wait__start, NULL, ds)
 
#define DTRACE_DEVSTAT_WAIT_DONE()   SDT_PROBE2(io, , , wait__done, NULL, ds)
 
#define statsperpage   (PAGE_SIZE / sizeof(struct devstat))
 

Functions

 __FBSDID ("$FreeBSD$")
 
 SDT_PROVIDER_DEFINE (io)
 
 SDT_PROBE_DEFINE2 (io,,, start, "struct bio *", "struct devstat *")
 
 SDT_PROBE_DEFINE2 (io,,, done, "struct bio *", "struct devstat *")
 
 SDT_PROBE_DEFINE2 (io,,, wait__start, "struct bio *", "struct devstat *")
 
 SDT_PROBE_DEFINE2 (io,,, wait__done, "struct bio *", "struct devstat *")
 
 MTX_SYSINIT (devstat_mutex, &devstat_mutex, "devstat", MTX_DEF)
 
static struct devstat * devstat_alloc (void)
 
static void devstat_free (struct devstat *)
 
static void devstat_add_entry (struct devstat *ds, const void *dev_name, int unit_number, uint32_t block_size, devstat_support_flags flags, devstat_type_flags device_type, devstat_priority priority)
 
struct devstat * devstat_new_entry (const void *dev_name, int unit_number, uint32_t block_size, devstat_support_flags flags, devstat_type_flags device_type, devstat_priority priority)
 
void devstat_remove_entry (struct devstat *ds)
 
void devstat_start_transaction (struct devstat *ds, const struct bintime *now)
 
void devstat_start_transaction_bio (struct devstat *ds, struct bio *bp)
 
void devstat_start_transaction_bio_t0 (struct devstat *ds, struct bio *bp)
 
void devstat_end_transaction (struct devstat *ds, uint32_t bytes, devstat_tag_type tag_type, devstat_trans_flags flags, const struct bintime *now, const struct bintime *then)
 
void devstat_end_transaction_bio (struct devstat *ds, const struct bio *bp)
 
void devstat_end_transaction_bio_bt (struct devstat *ds, const struct bio *bp, const struct bintime *now)
 
static int sysctl_devstat (SYSCTL_HANDLER_ARGS)
 
static SYSCTL_NODE (_kern, OID_AUTO, devstat, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "Device Statistics")
 
 SYSCTL_PROC (_kern_devstat, OID_AUTO, all, CTLFLAG_RD|CTLTYPE_OPAQUE|CTLFLAG_MPSAFE, NULL, 0, sysctl_devstat, "S,devstat", "All devices in the devstat list")
 
 SYSCTL_INT (_kern_devstat, OID_AUTO, numdevs, CTLFLAG_RD, &devstat_num_devs, 0, "Number of devices in the devstat list")
 
 SYSCTL_LONG (_kern_devstat, OID_AUTO, generation, CTLFLAG_RD, &devstat_generation, 0, "Devstat list generation")
 
 SYSCTL_INT (_kern_devstat, OID_AUTO, version, CTLFLAG_RD, &devstat_version, 0, "Devstat list version number")
 
static TAILQ_HEAD (statspage)
 
static int devstat_mmap (struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr)
 
 SYSCTL_INT (_debug_sizeof, OID_AUTO, devstat, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, sizeof(struct devstat), "sizeof(struct devstat)")
 

Variables

static int devstat_num_devs
 
static long devstat_generation = 1
 
static int devstat_version = DEVSTAT_VERSION
 
static int devstat_current_devnumber
 
static struct mtx devstat_mutex
 
static struct devstatlist device_statq = STAILQ_HEAD_INITIALIZER(device_statq)
 
static d_ioctl_t devstat_ioctl
 
static d_mmap_t devstat_mmap
 
static struct cdevsw devstat_cdevsw
 
static size_t pagelist_pages = 0
 

Macro Definition Documentation

◆ DTRACE_DEVSTAT_BIO_DONE

#define DTRACE_DEVSTAT_BIO_DONE ( )    SDT_PROBE2(io, , , done, bp, ds)

Definition at line 63 of file subr_devstat.c.

◆ DTRACE_DEVSTAT_BIO_START

#define DTRACE_DEVSTAT_BIO_START ( )    SDT_PROBE2(io, , , start, bp, ds)

Definition at line 61 of file subr_devstat.c.

◆ DTRACE_DEVSTAT_DONE

#define DTRACE_DEVSTAT_DONE ( )    SDT_PROBE2(io, , , done, NULL, ds)

Definition at line 62 of file subr_devstat.c.

◆ DTRACE_DEVSTAT_START

#define DTRACE_DEVSTAT_START ( )    SDT_PROBE2(io, , , start, NULL, ds)

Definition at line 60 of file subr_devstat.c.

◆ DTRACE_DEVSTAT_WAIT_DONE

#define DTRACE_DEVSTAT_WAIT_DONE ( )    SDT_PROBE2(io, , , wait__done, NULL, ds)

Definition at line 65 of file subr_devstat.c.

◆ DTRACE_DEVSTAT_WAIT_START

#define DTRACE_DEVSTAT_WAIT_START ( )    SDT_PROBE2(io, , , wait__start, NULL, ds)

Definition at line 64 of file subr_devstat.c.

◆ statsperpage

#define statsperpage   (PAGE_SIZE / sizeof(struct devstat))

Definition at line 475 of file subr_devstat.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ devstat_add_entry()

static void devstat_add_entry ( struct devstat *  ds,
const void *  dev_name,
int  unit_number,
uint32_t  block_size,
devstat_support_flags  flags,
devstat_type_flags  device_type,
devstat_priority  priority 
)
static

Definition at line 117 of file subr_devstat.c.

References binuptime(), device_statq, devstat_current_devnumber, devstat_generation, devstat_mutex, devstat_num_devs, flags, printf(), and priority.

Referenced by devstat_new_entry().

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

◆ devstat_alloc()

static struct devstat * devstat_alloc ( void  )
static

Definition at line 535 of file subr_devstat.c.

References devstat_cdevsw, devstat_mutex, free(), make_dev_credf(), malloc(), pagelist_pages, and statsperpage.

Referenced by devstat_new_entry().

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

◆ devstat_end_transaction()

void devstat_end_transaction ( struct devstat *  ds,
uint32_t  bytes,
devstat_tag_type  tag_type,
devstat_trans_flags  flags,
const struct bintime now,
const struct bintime then 
)

Definition at line 302 of file subr_devstat.c.

References bintime(), binuptime(), DTRACE_DEVSTAT_DONE, and flags.

Referenced by devstat_end_transaction_bio_bt().

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

◆ devstat_end_transaction_bio()

void devstat_end_transaction_bio ( struct devstat *  ds,
const struct bio *  bp 
)

Definition at line 348 of file subr_devstat.c.

References devstat_end_transaction_bio_bt().

Referenced by biofinish().

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

◆ devstat_end_transaction_bio_bt()

void devstat_end_transaction_bio_bt ( struct devstat *  ds,
const struct bio *  bp,
const struct bintime now 
)

Definition at line 355 of file subr_devstat.c.

References devstat_end_transaction(), and DTRACE_DEVSTAT_BIO_DONE.

Referenced by devstat_end_transaction_bio().

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

◆ devstat_free()

static void devstat_free ( struct devstat *  dsp)
static

Definition at line 601 of file subr_devstat.c.

References devstat_mutex, and statsperpage.

Referenced by devstat_remove_entry().

Here is the caller graph for this function:

◆ devstat_mmap()

static int devstat_mmap ( struct cdev *  dev,
vm_ooffset_t  offset,
vm_paddr_t *  paddr,
int  nprot,
vm_memattr_t *  memattr 
)
static

Definition at line 514 of file subr_devstat.c.

References devstat_mutex.

◆ devstat_new_entry()

struct devstat * devstat_new_entry ( const void *  dev_name,
int  unit_number,
uint32_t  block_size,
devstat_support_flags  flags,
devstat_type_flags  device_type,
devstat_priority  priority 
)

Definition at line 87 of file subr_devstat.c.

References binuptime(), devstat_add_entry(), devstat_alloc(), devstat_generation, devstat_mutex, flags, and priority.

Here is the call graph for this function:

◆ devstat_remove_entry()

void devstat_remove_entry ( struct devstat *  ds)

Definition at line 198 of file subr_devstat.c.

References device_statq, devstat_free(), devstat_generation, devstat_mutex, and devstat_num_devs.

Here is the call graph for this function:

◆ devstat_start_transaction()

void devstat_start_transaction ( struct devstat *  ds,
const struct bintime now 
)

Definition at line 228 of file subr_devstat.c.

References binuptime(), and DTRACE_DEVSTAT_START.

Referenced by devstat_start_transaction_bio_t0().

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

◆ devstat_start_transaction_bio()

void devstat_start_transaction_bio ( struct devstat *  ds,
struct bio *  bp 
)

Definition at line 252 of file subr_devstat.c.

References binuptime(), and devstat_start_transaction_bio_t0().

Here is the call graph for this function:

◆ devstat_start_transaction_bio_t0()

void devstat_start_transaction_bio_t0 ( struct devstat *  ds,
struct bio *  bp 
)

Definition at line 264 of file subr_devstat.c.

References devstat_start_transaction(), and DTRACE_DEVSTAT_BIO_START.

Referenced by devstat_start_transaction_bio().

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

◆ MTX_SYSINIT()

MTX_SYSINIT ( devstat_mutex  ,
devstat_mutex,
"devstat"  ,
MTX_DEF   
)

◆ SDT_PROBE_DEFINE2() [1/4]

SDT_PROBE_DEFINE2 ( io  ,
done  ,
"struct bio *"  ,
"struct devstat *"   
)

◆ SDT_PROBE_DEFINE2() [2/4]

SDT_PROBE_DEFINE2 ( io  ,
start  ,
"struct bio *"  ,
"struct devstat *"   
)

◆ SDT_PROBE_DEFINE2() [3/4]

SDT_PROBE_DEFINE2 ( io  ,
wait__done  ,
"struct bio *"  ,
"struct devstat *"   
)

◆ SDT_PROBE_DEFINE2() [4/4]

SDT_PROBE_DEFINE2 ( io  ,
wait__start  ,
"struct bio *"  ,
"struct devstat *"   
)

◆ SDT_PROVIDER_DEFINE()

SDT_PROVIDER_DEFINE ( io  )

◆ sysctl_devstat()

static int sysctl_devstat ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 396 of file subr_devstat.c.

References device_statq, devstat_generation, devstat_mutex, and devstat_num_devs.

◆ SYSCTL_INT() [1/3]

SYSCTL_INT ( _debug_sizeof  ,
OID_AUTO  ,
devstat  ,
CTLFLAG_RD  ,
SYSCTL_NULL_INT_PTR  ,
sizeof(struct devstat)  ,
"sizeof(struct devstat)"   
)

◆ SYSCTL_INT() [2/3]

SYSCTL_INT ( _kern_devstat  ,
OID_AUTO  ,
numdevs  ,
CTLFLAG_RD  ,
devstat_num_devs,
,
"Number of devices in the devstat list"   
)

◆ SYSCTL_INT() [3/3]

SYSCTL_INT ( _kern_devstat  ,
OID_AUTO  ,
version  ,
CTLFLAG_RD  ,
devstat_version,
,
"Devstat list version number"   
)

◆ SYSCTL_LONG()

SYSCTL_LONG ( _kern_devstat  ,
OID_AUTO  ,
generation  ,
CTLFLAG_RD  ,
devstat_generation,
,
"Devstat list generation"   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _kern  ,
OID_AUTO  ,
devstat  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
"Device Statistics"   
)
static

◆ SYSCTL_PROC()

SYSCTL_PROC ( _kern_devstat  ,
OID_AUTO  ,
all  ,
CTLFLAG_RD|CTLTYPE_OPAQUE|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_devstat  ,
S,
devstat"  ,
"All devices in the devstat list"   
)

◆ TAILQ_HEAD()

static TAILQ_HEAD ( statspage  )
static

Definition at line 494 of file subr_devstat.c.

Variable Documentation

◆ device_statq

struct devstatlist device_statq = STAILQ_HEAD_INITIALIZER(device_statq)
static

Definition at line 74 of file subr_devstat.c.

Referenced by devstat_add_entry(), devstat_remove_entry(), and sysctl_devstat().

◆ devstat_cdevsw

struct cdevsw devstat_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_ioctl = devstat_ioctl,
.d_mmap = devstat_mmap,
.d_name = "devstat",
}
static d_ioctl_t devstat_ioctl
Definition: subr_devstat.c:477
static d_mmap_t devstat_mmap
Definition: subr_devstat.c:478

Definition at line 480 of file subr_devstat.c.

Referenced by devstat_alloc().

◆ devstat_current_devnumber

int devstat_current_devnumber
static

Definition at line 70 of file subr_devstat.c.

Referenced by devstat_add_entry().

◆ devstat_generation

long devstat_generation = 1
static

◆ devstat_ioctl

d_ioctl_t devstat_ioctl
static

Definition at line 477 of file subr_devstat.c.

◆ devstat_mmap

d_mmap_t devstat_mmap
static

Definition at line 478 of file subr_devstat.c.

◆ devstat_mutex

struct mtx devstat_mutex
static

◆ devstat_num_devs

int devstat_num_devs
static

Definition at line 67 of file subr_devstat.c.

Referenced by devstat_add_entry(), devstat_remove_entry(), and sysctl_devstat().

◆ devstat_version

int devstat_version = DEVSTAT_VERSION
static

Definition at line 69 of file subr_devstat.c.

◆ pagelist_pages

size_t pagelist_pages = 0
static

Definition at line 493 of file subr_devstat.c.

Referenced by devstat_alloc().