#include "opt_ddb.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bio.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_periph.h>
#include <cam/cam_xpt_periph.h>
#include <cam/cam_xpt_internal.h>
#include <cam/cam_iosched.h>
#include <ddb/ddb.h>
#include <geom/geom_disk.h>
static MALLOC_DEFINE(M_CAMSCHED, "CAM I/O Scheduler",
"CAM I/O Scheduler buffers");
static SYSCTL_NODE(_kern_cam, OID_AUTO, iosched, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
"CAM I/O Scheduler parameters");
#ifdef CAM_IOSCHED_DYNAMIC
static bool do_dynamic_iosched = true;
SYSCTL_BOOL(_kern_cam_iosched, OID_AUTO, dynamic, CTLFLAG_RDTUN,
&do_dynamic_iosched, 1,
"Enable Dynamic I/O scheduler optimizations.");
static int alpha_bits = 9;
SYSCTL_INT(_kern_cam_iosched, OID_AUTO, alpha_bits, CTLFLAG_RWTUN,
&alpha_bits, 1,
"Bits in EMA's alpha.");
#ifndef BUCKET_BASE
#define BUCKET_BASE ((SBT_1S / 50000) + 1)
#endif
static sbintime_t bucket_base = BUCKET_BASE;
SYSCTL_SBINTIME_USEC(_kern_cam_iosched, OID_AUTO, bucket_base_us, CTLFLAG_RD,
&bucket_base,
"Size of the smallest latency bucket");
static int bucket_ratio = 200;
SYSCTL_INT(_kern_cam_iosched, OID_AUTO, bucket_ratio, CTLFLAG_RD,
&bucket_ratio, 200,
"Latency Bucket Ratio for geometric progression.");
#ifndef LAT_BUCKETS
#define LAT_BUCKETS 20
#endif
static int lat_buckets = LAT_BUCKETS;
SYSCTL_INT(_kern_cam_iosched, OID_AUTO, buckets, CTLFLAG_RD,
&lat_buckets, LAT_BUCKETS,
"Total number of latency buckets published");
static int default_read_bias = 0;
SYSCTL_INT(_kern_cam_iosched, OID_AUTO, read_bias, CTLFLAG_RWTUN,
&default_read_bias, 0,
"Default read bias for new devices.");
struct iop_stats;
struct cam_iosched_softc;
int iosched_debug = 0;
typedef enum {
none = 0,
queue_depth,
iops,
bandwidth,
limiter_max
} io_limiter;
static const char *cam_iosched_limiter_names[] =
{ "none", "queue_depth", "iops", "bandwidth" };
typedef int l_init_t(struct iop_stats *);
typedef int l_tick_t(struct iop_stats *);
typedef int l_iop_t(struct iop_stats *, struct bio *);
typedef int l_iodone_t(struct iop_stats *, struct bio *);
static l_iop_t cam_iosched_qd_iop;
static l_iop_t cam_iosched_qd_caniop;
static l_iodone_t cam_iosched_qd_iodone;
static l_init_t cam_iosched_iops_init;
static l_tick_t cam_iosched_iops_tick;
static l_iop_t cam_iosched_iops_caniop;
static l_iop_t cam_iosched_iops_iop;
static l_init_t cam_iosched_bw_init;
static l_tick_t cam_iosched_bw_tick;
static l_iop_t cam_iosched_bw_caniop;
static l_iop_t cam_iosched_bw_iop;
struct limswitch {
l_init_t *l_init;
l_tick_t *l_tick;
l_iop_t *l_iop;
l_iop_t *l_caniop;
l_iodone_t *l_iodone;
} limsw[] =
{
{
.l_init = NULL,
.l_tick = NULL,
.l_iop = NULL,
.l_iodone= NULL,
},
{
.l_init = NULL,
.l_tick = NULL,
.l_caniop = cam_iosched_qd_caniop,
.l_iop = cam_iosched_qd_iop,
.l_iodone= cam_iosched_qd_iodone,
},
{
.l_init = cam_iosched_iops_init,
.l_tick = cam_iosched_iops_tick,
.l_caniop = cam_iosched_iops_caniop,
.l_iop = cam_iosched_iops_iop,
.l_iodone= NULL,
},
{
.l_init = cam_iosched_bw_init,
.l_tick = cam_iosched_bw_tick,
.l_caniop = cam_iosched_bw_caniop,
.l_iop = cam_iosched_bw_iop,
.l_iodone= NULL,
},
};
struct iop_stats {
struct sysctl_ctx_list sysctl_ctx;
struct sysctl_oid *sysctl_tree;
io_limiter limiter;
int min;
int max;
int current;
int l_value1;
int l_value2;
int pending;
int queued;
int total;
int in;
int out;
int errs;
sbintime_t ema;
sbintime_t emvar;
sbintime_t sd;
uint64_t too_long;
sbintime_t bad_latency;
uint32_t state_flags;
#define IOP_RATE_LIMITED 1u
uint64_t latencies[LAT_BUCKETS];
struct cam_iosched_softc *softc;
};
typedef enum {
set_max = 0,
read_latency,
cl_max
} control_type;
static const char *cam_iosched_control_type_names[] =
{ "set_max", "read_latency" };
struct control_loop {
struct sysctl_ctx_list sysctl_ctx;
struct sysctl_oid *sysctl_tree;
sbintime_t next_steer;
sbintime_t steer_interval;
sbintime_t lolat;
sbintime_t hilat;
int alpha;
control_type type;
int last_count;
struct cam_iosched_softc *softc;
};
#endif
struct cam_iosched_softc {
struct bio_queue_head bio_queue;
struct bio_queue_head trim_queue;
const struct disk *disk;
cam_iosched_schedule_t schedfnc;
uint32_t flags;
int sort_io_queue;
int trim_goal;
int trim_ticks;
int last_trim_tick;
int queued_trims;
#ifdef CAM_IOSCHED_DYNAMIC
int read_bias;
int current_read_bias;
int total_ticks;
int load;
struct bio_queue_head write_queue;
struct iop_stats read_stats, write_stats, trim_stats;
struct sysctl_ctx_list sysctl_ctx;
struct sysctl_oid *sysctl_tree;
int quanta;
struct callout ticker;
struct cam_periph *periph;
uint32_t this_frac;
sbintime_t last_time;
struct control_loop cl;
sbintime_t max_lat;
cam_iosched_latfcn_t latfcn;
void *latarg;
#endif
};
#ifdef CAM_IOSCHED_DYNAMIC
static int
cam_iosched_limiter_init(struct iop_stats *ios)
{
int lim = ios->limiter;
if (lim < none || lim >= limiter_max)
return EINVAL;
if (limsw[lim].l_init)
return limsw[lim].l_init(ios);
return 0;
}
static int
cam_iosched_limiter_tick(struct iop_stats *ios)
{
int lim = ios->limiter;
if (lim < none || lim >= limiter_max)
return EINVAL;
if (limsw[lim].l_tick)
return limsw[lim].l_tick(ios);
return 0;
}
static int
cam_iosched_limiter_iop(struct iop_stats *ios, struct bio *bp)
{
int lim = ios->limiter;
if (lim < none || lim >= limiter_max)
return EINVAL;
if (limsw[lim].l_iop)
return limsw[lim].l_iop(ios, bp);
return 0;
}
static int
cam_iosched_limiter_caniop(struct iop_stats *ios, struct bio *bp)
{
int lim = ios->limiter;
if (lim < none || lim >= limiter_max)
return EINVAL;
if (limsw[lim].l_caniop)
return limsw[lim].l_caniop(ios, bp);
return 0;
}
static int
cam_iosched_limiter_iodone(struct iop_stats *ios, struct bio *bp)
{
int lim = ios->limiter;
if (lim < none || lim >= limiter_max)
return 0;
if (limsw[lim].l_iodone)
return limsw[lim].l_iodone(ios, bp);
return 0;
}
static int
cam_iosched_qd_iop(struct iop_stats *ios, struct bio *bp)
{
if (ios->current <= 0 || ios->pending < ios->current)
return 0;
return EAGAIN;
}
static int
cam_iosched_qd_caniop(struct iop_stats *ios, struct bio *bp)
{
if (ios->current <= 0 || ios->pending < ios->current)
return 0;
return EAGAIN;
}
static int
cam_iosched_qd_iodone(struct iop_stats *ios, struct bio *bp)
{
if (ios->current <= 0 || ios->pending != ios->current)
return 0;
return 1;
}
static int
cam_iosched_iops_init(struct iop_stats *ios)
{
ios->l_value1 = ios->current / ios->softc->quanta;
if (ios->l_value1 <= 0)
ios->l_value1 = 1;
ios->l_value2 = 0;
return 0;
}
static int
cam_iosched_iops_tick(struct iop_stats *ios)
{
int new_ios;
new_ios = (int)((ios->current * (uint64_t)ios->softc->this_frac) >> 16);
if (new_ios < 1 && ios->l_value2 < ios->current) {
new_ios = 1;
ios->l_value2++;
}
if ((ios->softc->total_ticks % ios->softc->quanta) == 0) {
ios->l_value1 = new_ios;
ios->l_value2 = 1;
} else {
ios->l_value1 += new_ios;
}
return 0;
}
static int
cam_iosched_iops_caniop(struct iop_stats *ios, struct bio *bp)
{
if (ios->current > 0 && ios->l_value1 <= 0)
return EAGAIN;
return 0;
}
static int
cam_iosched_iops_iop(struct iop_stats *ios, struct bio *bp)
{
int rv;
rv = cam_iosched_limiter_caniop(ios, bp);
if (rv == 0)
ios->l_value1--;
return rv;
}
static int
cam_iosched_bw_init(struct iop_stats *ios)
{
ios->l_value1 = ios->current * 1000 / ios->softc->quanta;
return 0;
}
static int
cam_iosched_bw_tick(struct iop_stats *ios)
{
int bw;
bw = (int)((ios->current * 1000ull * (uint64_t)ios->softc->this_frac) >> 16);
if (ios->l_value1 < bw * 4)
ios->l_value1 += bw;
return 0;
}
static int
cam_iosched_bw_caniop(struct iop_stats *ios, struct bio *bp)
{
if (ios->current > 0 && ios->l_value1 <= 0)
return EAGAIN;
return 0;
}
static int
cam_iosched_bw_iop(struct iop_stats *ios, struct bio *bp)
{
int rv;
rv = cam_iosched_limiter_caniop(ios, bp);
if (rv == 0)
ios->l_value1 -= bp->bio_length;
return rv;
}
static void cam_iosched_cl_maybe_steer(struct control_loop *clp);
static void
cam_iosched_ticker(void *arg)
{
struct cam_iosched_softc *isc = arg;
sbintime_t now, delta;
int pending;
callout_reset(&isc->ticker, hz / isc->quanta, cam_iosched_ticker, isc);
now = sbinuptime();
delta = now - isc->last_time;
isc->this_frac = (uint32_t)delta >> 16;
isc->last_time = now;
cam_iosched_cl_maybe_steer(&isc->cl);
cam_iosched_limiter_tick(&isc->read_stats);
cam_iosched_limiter_tick(&isc->write_stats);
cam_iosched_limiter_tick(&isc->trim_stats);
isc->schedfnc(isc->periph);
pending = isc->read_stats.pending + isc->write_stats.pending ;
pending += !!(isc->read_stats.state_flags & IOP_RATE_LIMITED) * isc->read_stats.queued +
!!(isc->write_stats.state_flags & IOP_RATE_LIMITED) * isc->write_stats.queued
;
pending <<= 16;
pending /= isc->periph->path->device->ccbq.total_openings;
isc->load = (pending + (isc->load << 13) - isc->load) >> 13;
isc->total_ticks++;
}
static void
cam_iosched_cl_init(struct control_loop *clp, struct cam_iosched_softc *isc)
{
clp->next_steer = sbinuptime();
clp->softc = isc;
clp->steer_interval = SBT_1S * 5;
clp->lolat = 5 * SBT_1MS;
clp->hilat = 15 * SBT_1MS;
clp->alpha = 20;
clp->type = set_max;
}
static void
cam_iosched_cl_maybe_steer(struct control_loop *clp)
{
struct cam_iosched_softc *isc;
sbintime_t now, lat;
int old;
isc = clp->softc;
now = isc->last_time;
if (now < clp->next_steer)
return;
clp->next_steer = now + clp->steer_interval;
switch (clp->type) {
case set_max:
if (isc->write_stats.current != isc->write_stats.max)
printf("Steering write from %d kBps to %d kBps\n",
isc->write_stats.current, isc->write_stats.max);
isc->read_stats.current = isc->read_stats.max;
isc->write_stats.current = isc->write_stats.max;
isc->trim_stats.current = isc->trim_stats.max;
break;
case read_latency:
old = isc->write_stats.current;
lat = isc->read_stats.ema;
if (lat < clp->lolat || isc->read_stats.total - clp->last_count < 10)
isc->write_stats.current = isc->write_stats.current *
(100 + clp->alpha) / 100;
else if (lat > clp->hilat)
isc->write_stats.current = isc->write_stats.current *
(100 - clp->alpha) / 100;
clp->last_count = isc->read_stats.total;
if (isc->write_stats.current < isc->write_stats.min)
isc->write_stats.current = isc->write_stats.min;
if (isc->write_stats.current > isc->write_stats.max)
isc->write_stats.current = isc->write_stats.max;
if (old != isc->write_stats.current && iosched_debug)
printf("Steering write from %d kBps to %d kBps due to latency of %jdus\n",
old, isc->write_stats.current,
(uintmax_t)((uint64_t)1000000 * (uint32_t)lat) >> 32);
break;
case cl_max:
break;
}
}
#endif
#define CAM_IOSCHED_FLAG_TRIM_ACTIVE (1ul << 0)
#define CAM_IOSCHED_FLAG_CALLOUT_ACTIVE (1ul << 1)
#define CAM_IOSCHED_FLAG_WORK_FLAGS ((0xffffu) << 16)
#ifdef CAM_IOSCHED_DYNAMIC
static void
cam_iosched_io_metric_update(struct cam_iosched_softc *isc,
sbintime_t sim_latency, const struct bio *bp);
#endif
static inline bool
cam_iosched_has_flagged_work(struct cam_iosched_softc *isc)
{
return !!(isc->flags & CAM_IOSCHED_FLAG_WORK_FLAGS);
}
static inline bool
cam_iosched_has_io(struct cam_iosched_softc *isc)
{
#ifdef CAM_IOSCHED_DYNAMIC
if (do_dynamic_iosched) {
struct bio *rbp = bioq_first(&isc->bio_queue);
struct bio *wbp = bioq_first(&isc->write_queue);
bool can_write = wbp != NULL &&
cam_iosched_limiter_caniop(&isc->write_stats, wbp) == 0;
bool can_read = rbp != NULL &&
cam_iosched_limiter_caniop(&isc->read_stats, rbp) == 0;
if (iosched_debug > 2) {
printf("can write %d: pending_writes %d max_writes %d\n", can_write, isc->write_stats.pending, isc->write_stats.max);
printf("can read %d: read_stats.pending %d max_reads %d\n", can_read, isc->read_stats.pending, isc->read_stats.max);
printf("Queued reads %d writes %d\n", isc->read_stats.queued, isc->write_stats.queued);
}
return can_read || can_write;
}
#endif
return bioq_first(&isc->bio_queue) != NULL;
}
static inline bool
cam_iosched_has_more_trim(struct cam_iosched_softc *isc)
{
struct bio *bp;
bp = bioq_first(&isc->trim_queue);
#ifdef CAM_IOSCHED_DYNAMIC
if (do_dynamic_iosched) {
if (bp == NULL || cam_iosched_limiter_caniop(&isc->trim_stats, bp) != 0)
return false;
}
#endif
if (isc->trim_goal > 0) {
if (isc->queued_trims >= isc->trim_goal)
return true;
if (isc->queued_trims > 0 &&
isc->trim_ticks > 0 &&
ticks - isc->last_trim_tick > isc->trim_ticks)
return true;
return false;
}
return !(isc->flags & CAM_IOSCHED_FLAG_TRIM_ACTIVE) && bp != NULL;
}
#define cam_iosched_sort_queue(isc) ((isc)->sort_io_queue >= 0 ? \
(isc)->sort_io_queue : cam_sort_io_queues)
static inline bool
cam_iosched_has_work(struct cam_iosched_softc *isc)
{
#ifdef CAM_IOSCHED_DYNAMIC
if (iosched_debug > 2)
printf("has work: %d %d %d\n", cam_iosched_has_io(isc),
cam_iosched_has_more_trim(isc),
cam_iosched_has_flagged_work(isc));
#endif
return cam_iosched_has_io(isc) ||
cam_iosched_has_more_trim(isc) ||
cam_iosched_has_flagged_work(isc);
}
#ifdef CAM_IOSCHED_DYNAMIC
static void
cam_iosched_iop_stats_init(struct cam_iosched_softc *isc, struct iop_stats *ios)
{
ios->limiter = none;
ios->in = 0;
ios->max = ios->current = 300000;
ios->min = 1;
ios->out = 0;
ios->errs = 0;
ios->pending = 0;
ios->queued = 0;
ios->total = 0;
ios->ema = 0;
ios->emvar = 0;
ios->bad_latency = SBT_1S / 2;
ios->softc = isc;
cam_iosched_limiter_init(ios);
}
static int
cam_iosched_limiter_sysctl(SYSCTL_HANDLER_ARGS)
{
char buf[16];
struct iop_stats *ios;
struct cam_iosched_softc *isc;
int value, i, error;
const char *p;
ios = arg1;
isc = ios->softc;
value = ios->limiter;
if (value < none || value >= limiter_max)
p = "UNKNOWN";
else
p = cam_iosched_limiter_names[value];
strlcpy(buf, p, sizeof(buf));
error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
if (error != 0 || req->newptr == NULL)
return error;
cam_periph_lock(isc->periph);
for (i = none; i < limiter_max; i++) {
if (strcmp(buf, cam_iosched_limiter_names[i]) != 0)
continue;
ios->limiter = i;
error = cam_iosched_limiter_init(ios);
if (error != 0) {
ios->limiter = value;
cam_periph_unlock(isc->periph);
return error;
}
callout_reset(&isc->ticker, hz / isc->quanta, cam_iosched_ticker, isc);
isc->flags |= CAM_IOSCHED_FLAG_CALLOUT_ACTIVE;
cam_periph_unlock(isc->periph);
return 0;
}
cam_periph_unlock(isc->periph);
return EINVAL;
}
static int
cam_iosched_control_type_sysctl(SYSCTL_HANDLER_ARGS)
{
char buf[16];
struct control_loop *clp;
struct cam_iosched_softc *isc;
int value, i, error;
const char *p;
clp = arg1;
isc = clp->softc;
value = clp->type;
if (value < none || value >= cl_max)
p = "UNKNOWN";
else
p = cam_iosched_control_type_names[value];
strlcpy(buf, p, sizeof(buf));
error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
if (error != 0 || req->newptr == NULL)
return error;
for (i = set_max; i < cl_max; i++) {
if (strcmp(buf, cam_iosched_control_type_names[i]) != 0)
continue;
cam_periph_lock(isc->periph);
clp->type = i;
cam_periph_unlock(isc->periph);
return 0;
}
return EINVAL;
}
static int
cam_iosched_sbintime_sysctl(SYSCTL_HANDLER_ARGS)
{
char buf[16];
sbintime_t value;
int error;
uint64_t us;
value = *(sbintime_t *)arg1;
us = (uint64_t)value / SBT_1US;
snprintf(buf, sizeof(buf), "%ju", (intmax_t)us);
error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
if (error != 0 || req->newptr == NULL)
return error;
us = strtoul(buf, NULL, 10);
if (us == 0)
return EINVAL;
*(sbintime_t *)arg1 = us * SBT_1US;
return 0;
}
static int
cam_iosched_sysctl_latencies(SYSCTL_HANDLER_ARGS)
{
int i, error;
struct sbuf sb;
uint64_t *latencies;
latencies = arg1;
sbuf_new_for_sysctl(&sb, NULL, LAT_BUCKETS * 16, req);
for (i = 0; i < LAT_BUCKETS - 1; i++)
sbuf_printf(&sb, "%jd,", (intmax_t)latencies[i]);
sbuf_printf(&sb, "%jd", (intmax_t)latencies[LAT_BUCKETS - 1]);
error = sbuf_finish(&sb);
sbuf_delete(&sb);
return (error);
}
static int
cam_iosched_quanta_sysctl(SYSCTL_HANDLER_ARGS)
{
int *quanta;
int error, value;
quanta = (unsigned *)arg1;
value = *quanta;
error = sysctl_handle_int(oidp, (int *)&value, 0, req);
if ((error != 0) || (req->newptr == NULL))
return (error);
if (value < 1 || value > hz)
return (EINVAL);
*quanta = value;
return (0);
}
static void
cam_iosched_iop_stats_sysctl_init(struct cam_iosched_softc *isc, struct iop_stats *ios, char *name)
{
struct sysctl_oid_list *n;
struct sysctl_ctx_list *ctx;
ios->sysctl_tree = SYSCTL_ADD_NODE(&isc->sysctl_ctx,
SYSCTL_CHILDREN(isc->sysctl_tree), OID_AUTO, name,
CTLFLAG_RD | CTLFLAG_MPSAFE, 0, name);
n = SYSCTL_CHILDREN(ios->sysctl_tree);
ctx = &ios->sysctl_ctx;
SYSCTL_ADD_UQUAD(ctx, n,
OID_AUTO, "ema", CTLFLAG_RD,
&ios->ema,
"Fast Exponentially Weighted Moving Average");
SYSCTL_ADD_UQUAD(ctx, n,
OID_AUTO, "emvar", CTLFLAG_RD,
&ios->emvar,
"Fast Exponentially Weighted Moving Variance");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "pending", CTLFLAG_RD,
&ios->pending, 0,
"Instantaneous # of pending transactions");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "count", CTLFLAG_RD,
&ios->total, 0,
"# of transactions submitted to hardware");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "queued", CTLFLAG_RD,
&ios->queued, 0,
"# of transactions in the queue");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "in", CTLFLAG_RD,
&ios->in, 0,
"# of transactions queued to driver");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "out", CTLFLAG_RD,
&ios->out, 0,
"# of transactions completed (including with error)");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "errs", CTLFLAG_RD,
&ios->errs, 0,
"# of transactions completed with an error");
SYSCTL_ADD_U64(ctx, n,
OID_AUTO, "too_long", CTLFLAG_RD,
&ios->too_long, 0,
"# of transactions completed took too long");
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "bad_latency",
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
&ios->bad_latency, 0, cam_iosched_sbintime_sysctl, "A",
"Threshold for counting transactions that took too long (in us)");
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "limiter",
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
ios, 0, cam_iosched_limiter_sysctl, "A",
"Current limiting type.");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "min", CTLFLAG_RW,
&ios->min, 0,
"min resource");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "max", CTLFLAG_RW,
&ios->max, 0,
"max resource");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "current", CTLFLAG_RW,
&ios->current, 0,
"current resource");
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "latencies",
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
&ios->latencies, 0,
cam_iosched_sysctl_latencies, "A",
"Array of latencies, a geometric progresson from\n"
"kern.cam.iosched.bucket_base_us with a ratio of\n"
"kern.cam.iosched.bucket_ration / 100 from one to\n"
"the next. By default 20 steps from 20us to 10.485s\n"
"by doubling.");
}
static void
cam_iosched_iop_stats_fini(struct iop_stats *ios)
{
if (ios->sysctl_tree)
if (sysctl_ctx_free(&ios->sysctl_ctx) != 0)
printf("can't remove iosched sysctl stats context\n");
}
static void
cam_iosched_cl_sysctl_init(struct cam_iosched_softc *isc)
{
struct sysctl_oid_list *n;
struct sysctl_ctx_list *ctx;
struct control_loop *clp;
clp = &isc->cl;
clp->sysctl_tree = SYSCTL_ADD_NODE(&isc->sysctl_ctx,
SYSCTL_CHILDREN(isc->sysctl_tree), OID_AUTO, "control",
CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Control loop info");
n = SYSCTL_CHILDREN(clp->sysctl_tree);
ctx = &clp->sysctl_ctx;
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "type",
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
clp, 0, cam_iosched_control_type_sysctl, "A",
"Control loop algorithm");
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "steer_interval",
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
&clp->steer_interval, 0, cam_iosched_sbintime_sysctl, "A",
"How often to steer (in us)");
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "lolat",
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
&clp->lolat, 0, cam_iosched_sbintime_sysctl, "A",
"Low water mark for Latency (in us)");
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "hilat",
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
&clp->hilat, 0, cam_iosched_sbintime_sysctl, "A",
"Hi water mark for Latency (in us)");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "alpha", CTLFLAG_RW,
&clp->alpha, 0,
"Alpha for PLL (x100) aka gain");
}
static void
cam_iosched_cl_sysctl_fini(struct control_loop *clp)
{
if (clp->sysctl_tree)
if (sysctl_ctx_free(&clp->sysctl_ctx) != 0)
printf("can't remove iosched sysctl control loop context\n");
}
#endif
int
cam_iosched_init(struct cam_iosched_softc **iscp, struct cam_periph *periph,
const struct disk *dp, cam_iosched_schedule_t schedfnc)
{
struct cam_iosched_softc *isc;
isc = malloc(sizeof(*isc), M_CAMSCHED, M_NOWAIT | M_ZERO);
if (isc == NULL)
return ENOMEM;
isc->disk = dp;
isc->schedfnc = schedfnc;
#ifdef CAM_IOSCHED_DYNAMIC
if (iosched_debug)
printf("CAM IOSCHEDULER Allocating entry at %p\n", isc);
#endif
isc->sort_io_queue = -1;
bioq_init(&isc->bio_queue);
bioq_init(&isc->trim_queue);
#ifdef CAM_IOSCHED_DYNAMIC
if (do_dynamic_iosched) {
bioq_init(&isc->write_queue);
isc->read_bias = default_read_bias;
isc->current_read_bias = 0;
isc->quanta = min(hz, 200);
cam_iosched_iop_stats_init(isc, &isc->read_stats);
cam_iosched_iop_stats_init(isc, &isc->write_stats);
cam_iosched_iop_stats_init(isc, &isc->trim_stats);
isc->trim_stats.max = 1;
isc->last_time = sbinuptime();
callout_init_mtx(&isc->ticker, cam_periph_mtx(periph), 0);
isc->periph = periph;
cam_iosched_cl_init(&isc->cl, isc);
callout_reset(&isc->ticker, hz / isc->quanta, cam_iosched_ticker, isc);
isc->flags |= CAM_IOSCHED_FLAG_CALLOUT_ACTIVE;
}
#endif
*iscp = isc;
return 0;
}
void
cam_iosched_fini(struct cam_iosched_softc *isc)
{
if (isc) {
cam_iosched_flush(isc, NULL, ENXIO);
#ifdef CAM_IOSCHED_DYNAMIC
cam_iosched_iop_stats_fini(&isc->read_stats);
cam_iosched_iop_stats_fini(&isc->write_stats);
cam_iosched_iop_stats_fini(&isc->trim_stats);
cam_iosched_cl_sysctl_fini(&isc->cl);
if (isc->sysctl_tree)
if (sysctl_ctx_free(&isc->sysctl_ctx) != 0)
printf("can't remove iosched sysctl stats context\n");
if (isc->flags & CAM_IOSCHED_FLAG_CALLOUT_ACTIVE) {
callout_drain(&isc->ticker);
isc->flags &= ~ CAM_IOSCHED_FLAG_CALLOUT_ACTIVE;
}
#endif
free(isc, M_CAMSCHED);
}
}
void cam_iosched_sysctl_init(struct cam_iosched_softc *isc,
struct sysctl_ctx_list *ctx, struct sysctl_oid *node)
{
struct sysctl_oid_list *n;
n = SYSCTL_CHILDREN(node);
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "sort_io_queue", CTLFLAG_RW | CTLFLAG_MPSAFE,
&isc->sort_io_queue, 0,
"Sort IO queue to try and optimise disk access patterns");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "trim_goal", CTLFLAG_RW,
&isc->trim_goal, 0,
"Number of trims to try to accumulate before sending to hardware");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "trim_ticks", CTLFLAG_RW,
&isc->trim_goal, 0,
"IO Schedul qaunta to hold back trims for when accumulating");
#ifdef CAM_IOSCHED_DYNAMIC
if (!do_dynamic_iosched)
return;
isc->sysctl_tree = SYSCTL_ADD_NODE(&isc->sysctl_ctx,
SYSCTL_CHILDREN(node), OID_AUTO, "iosched",
CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "I/O scheduler statistics");
n = SYSCTL_CHILDREN(isc->sysctl_tree);
ctx = &isc->sysctl_ctx;
cam_iosched_iop_stats_sysctl_init(isc, &isc->read_stats, "read");
cam_iosched_iop_stats_sysctl_init(isc, &isc->write_stats, "write");
cam_iosched_iop_stats_sysctl_init(isc, &isc->trim_stats, "trim");
cam_iosched_cl_sysctl_init(isc);
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "read_bias", CTLFLAG_RW,
&isc->read_bias, default_read_bias,
"How biased towards read should we be independent of limits");
SYSCTL_ADD_PROC(ctx, n,
OID_AUTO, "quanta", CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
&isc->quanta, 0, cam_iosched_quanta_sysctl, "I",
"How many quanta per second do we slice the I/O up into");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "total_ticks", CTLFLAG_RD,
&isc->total_ticks, 0,
"Total number of ticks we've done");
SYSCTL_ADD_INT(ctx, n,
OID_AUTO, "load", CTLFLAG_RD,
&isc->load, 0,
"scaled load average / 100");
SYSCTL_ADD_U64(ctx, n,
OID_AUTO, "latency_trigger", CTLFLAG_RW,
&isc->max_lat, 0,
"Latency treshold to trigger callbacks");
#endif
}
void
cam_iosched_set_latfcn(struct cam_iosched_softc *isc,
cam_iosched_latfcn_t fnp, void *argp)
{
#ifdef CAM_IOSCHED_DYNAMIC
isc->latfcn = fnp;
isc->latarg = argp;
#endif
}
void
cam_iosched_set_trim_goal(struct cam_iosched_softc *isc, int goal)
{
isc->trim_goal = goal;
}
void
cam_iosched_set_trim_ticks(struct cam_iosched_softc *isc, int trim_ticks)
{
isc->trim_ticks = trim_ticks;
}
void
cam_iosched_flush(struct cam_iosched_softc *isc, struct devstat *stp, int err)
{
bioq_flush(&isc->bio_queue, stp, err);
bioq_flush(&isc->trim_queue, stp, err);
#ifdef CAM_IOSCHED_DYNAMIC
if (do_dynamic_iosched)
bioq_flush(&isc->write_queue, stp, err);
#endif
}
#ifdef CAM_IOSCHED_DYNAMIC
static struct bio *
cam_iosched_get_write(struct cam_iosched_softc *isc)
{
struct bio *bp;
bp = bioq_first(&isc->write_queue);
if (bp == NULL) {
if (iosched_debug > 3)
printf("No writes present in write_queue\n");
return NULL;
}
if (bioq_first(&isc->bio_queue) && isc->current_read_bias) {
if (iosched_debug)
printf(
"Reads present and current_read_bias is %d queued writes %d queued reads %d\n",
isc->current_read_bias, isc->write_stats.queued,
isc->read_stats.queued);
isc->current_read_bias--;
return NULL;
}
if (cam_iosched_limiter_iop(&isc->write_stats, bp) != 0) {
if (iosched_debug)
printf("Can't write because limiter says no.\n");
isc->write_stats.state_flags |= IOP_RATE_LIMITED;
return NULL;
}
isc->current_read_bias = isc->read_bias;
bioq_remove(&isc->write_queue, bp);
if (bp->bio_cmd == BIO_WRITE) {
isc->write_stats.queued--;
isc->write_stats.total++;
isc->write_stats.pending++;
}
if (iosched_debug > 9)
printf("HWQ : %p %#x\n", bp, bp->bio_cmd);
isc->write_stats.state_flags &= ~IOP_RATE_LIMITED;
return bp;
}
#endif
void
cam_iosched_put_back_trim(struct cam_iosched_softc *isc, struct bio *bp)
{
bioq_insert_head(&isc->trim_queue, bp);
if (isc->queued_trims == 0)
isc->last_trim_tick = ticks;
isc->queued_trims++;
#ifdef CAM_IOSCHED_DYNAMIC
isc->trim_stats.queued++;
isc->trim_stats.total--;
isc->trim_stats.pending--;
#endif
}
struct bio *
cam_iosched_next_trim(struct cam_iosched_softc *isc)
{
struct bio *bp;
bp = bioq_first(&isc->trim_queue);
if (bp == NULL)
return NULL;
bioq_remove(&isc->trim_queue, bp);
isc->queued_trims--;
isc->last_trim_tick = ticks;
#ifdef CAM_IOSCHED_DYNAMIC
isc->trim_stats.queued--;
isc->trim_stats.total++;
isc->trim_stats.pending++;
#endif
return bp;
}
struct bio *
cam_iosched_get_trim(struct cam_iosched_softc *isc)
{
#ifdef CAM_IOSCHED_DYNAMIC
struct bio *bp;
#endif
if (!cam_iosched_has_more_trim(isc))
return NULL;
#ifdef CAM_IOSCHED_DYNAMIC
bp = bioq_first(&isc->trim_queue);
if (bp == NULL)
return NULL;
if (do_dynamic_iosched) {
if (bioq_first(&isc->bio_queue) && isc->current_read_bias) {
if (iosched_debug)
printf(
"Reads present and current_read_bias is %d queued trims %d queued reads %d\n",
isc->current_read_bias, isc->trim_stats.queued,
isc->read_stats.queued);
isc->current_read_bias--;
return NULL;
}
isc->current_read_bias = isc->read_bias;
}
if (cam_iosched_limiter_iop(&isc->trim_stats, bp) != 0) {
if (iosched_debug)
printf("Can't trim because limiter says no.\n");
isc->trim_stats.state_flags |= IOP_RATE_LIMITED;
return NULL;
}
isc->current_read_bias = isc->read_bias;
isc->trim_stats.state_flags &= ~IOP_RATE_LIMITED;
#endif
return cam_iosched_next_trim(isc);
}
#ifdef CAM_IOSCHED_DYNAMIC
static struct bio *
bio_next(struct bio *bp)
{
bp = TAILQ_NEXT(bp, bio_queue);
if (bp == NULL || bp->bio_flags & BIO_ORDERED)
return NULL;
return bp;
}
static bool
cam_iosched_rate_limited(struct iop_stats *ios)
{
return ios->state_flags & IOP_RATE_LIMITED;
}
#endif
struct bio *
cam_iosched_next_bio(struct cam_iosched_softc *isc)
{
struct bio *bp;
if ((bp = cam_iosched_get_trim(isc)) != NULL)
return bp;
#ifdef CAM_IOSCHED_DYNAMIC
if (do_dynamic_iosched) {
if ((bp = cam_iosched_get_write(isc)) != NULL)
return bp;
}
#endif
#ifdef CAM_IOSCHED_DYNAMIC
if (do_dynamic_iosched) {
for (bp = bioq_first(&isc->bio_queue); bp != NULL;
bp = bio_next(bp)) {
if (bp->bio_cmd == BIO_READ) {
if (cam_iosched_rate_limited(&isc->read_stats) ||
cam_iosched_limiter_iop(&isc->read_stats, bp) != 0) {
isc->read_stats.state_flags |= IOP_RATE_LIMITED;
continue;
}
isc->read_stats.state_flags &= ~IOP_RATE_LIMITED;
}
if (bp->bio_cmd == BIO_WRITE) {
if (cam_iosched_rate_limited(&isc->write_stats) ||
cam_iosched_limiter_iop(&isc->write_stats, bp) != 0) {
isc->write_stats.state_flags |= IOP_RATE_LIMITED;
continue;
}
isc->write_stats.state_flags &= ~IOP_RATE_LIMITED;
}
break;
}
} else
#endif
bp = bioq_first(&isc->bio_queue);
if (bp == NULL)
return (NULL);
bioq_remove(&isc->bio_queue, bp);
#ifdef CAM_IOSCHED_DYNAMIC
if (do_dynamic_iosched) {
if (bp->bio_cmd == BIO_READ) {
isc->read_stats.queued--;
isc->read_stats.total++;
isc->read_stats.pending++;
} else if (bp->bio_cmd == BIO_WRITE) {
isc->write_stats.queued--;
isc->write_stats.total++;
isc->write_stats.pending++;
}
}
if (iosched_debug > 9)
printf("HWQ : %p %#x\n", bp, bp->bio_cmd);
#endif
return bp;
}
void
cam_iosched_queue_work(struct cam_iosched_softc *isc, struct bio *bp)
{
if (bp->bio_cmd == BIO_SPEEDUP) {
off_t len;
struct bio *nbp;
len = 0;
while (bioq_first(&isc->trim_queue) &&
(bp->bio_length == 0 || len < bp->bio_length)) {
nbp = bioq_takefirst(&isc->trim_queue);
len += nbp->bio_length;
nbp->bio_error = 0;
biodone(nbp);
}
if (bp->bio_length > 0) {
if (bp->bio_length > len)
bp->bio_resid = bp->bio_length - len;
else
bp->bio_resid = 0;
}
bp->bio_error = 0;
biodone(bp);
return;
}
if (bp->bio_cmd == BIO_FLUSH && isc->trim_ticks > 0)
isc->last_trim_tick = ticks - isc->trim_ticks - 1;
if (bp->bio_cmd == BIO_DELETE) {
bioq_insert_tail(&isc->trim_queue, bp);
if (isc->queued_trims == 0)
isc->last_trim_tick = ticks;
isc->queued_trims++;
#ifdef CAM_IOSCHED_DYNAMIC
isc->trim_stats.in++;
isc->trim_stats.queued++;
#endif
}
#ifdef CAM_IOSCHED_DYNAMIC
else if (do_dynamic_iosched && isc->read_bias != 0 &&
(bp->bio_cmd != BIO_READ)) {
if (cam_iosched_sort_queue(isc))
bioq_disksort(&isc->write_queue, bp);
else
bioq_insert_tail(&isc->write_queue, bp);
if (iosched_debug > 9)
printf("Qw : %p %#x\n", bp, bp->bio_cmd);
if (bp->bio_cmd == BIO_WRITE) {
isc->write_stats.in++;
isc->write_stats.queued++;
}
}
#endif
else {
if (cam_iosched_sort_queue(isc))
bioq_disksort(&isc->bio_queue, bp);
else
bioq_insert_tail(&isc->bio_queue, bp);
#ifdef CAM_IOSCHED_DYNAMIC
if (iosched_debug > 9)
printf("Qr : %p %#x\n", bp, bp->bio_cmd);
if (bp->bio_cmd == BIO_READ) {
isc->read_stats.in++;
isc->read_stats.queued++;
} else if (bp->bio_cmd == BIO_WRITE) {
isc->write_stats.in++;
isc->write_stats.queued++;
}
#endif
}
}
void
cam_iosched_schedule(struct cam_iosched_softc *isc, struct cam_periph *periph)
{
if (cam_iosched_has_work(isc))
xpt_schedule(periph, CAM_PRIORITY_NORMAL);
}
void
cam_iosched_trim_done(struct cam_iosched_softc *isc)
{
isc->flags &= ~CAM_IOSCHED_FLAG_TRIM_ACTIVE;
}
int
cam_iosched_bio_complete(struct cam_iosched_softc *isc, struct bio *bp,
union ccb *done_ccb)
{
int retval = 0;
#ifdef CAM_IOSCHED_DYNAMIC
if (!do_dynamic_iosched)
return retval;
if (iosched_debug > 10)
printf("done: %p %#x\n", bp, bp->bio_cmd);
if (bp->bio_cmd == BIO_WRITE) {
retval = cam_iosched_limiter_iodone(&isc->write_stats, bp);
if ((bp->bio_flags & BIO_ERROR) != 0)
isc->write_stats.errs++;
isc->write_stats.out++;
isc->write_stats.pending--;
} else if (bp->bio_cmd == BIO_READ) {
retval = cam_iosched_limiter_iodone(&isc->read_stats, bp);
if ((bp->bio_flags & BIO_ERROR) != 0)
isc->read_stats.errs++;
isc->read_stats.out++;
isc->read_stats.pending--;
} else if (bp->bio_cmd == BIO_DELETE) {
if ((bp->bio_flags & BIO_ERROR) != 0)
isc->trim_stats.errs++;
isc->trim_stats.out++;
isc->trim_stats.pending--;
} else if (bp->bio_cmd != BIO_FLUSH) {
if (iosched_debug)
printf("Completing command with bio_cmd == %#x\n", bp->bio_cmd);
}
if ((bp->bio_flags & BIO_ERROR) == 0 && done_ccb != NULL &&
(done_ccb->ccb_h.status & CAM_QOS_VALID) != 0) {
sbintime_t sim_latency;
sim_latency = cam_iosched_sbintime_t(done_ccb->ccb_h.qos.periph_data);
cam_iosched_io_metric_update(isc, sim_latency, bp);
if (isc->latfcn && isc->max_lat != 0 && sim_latency > isc->max_lat)
isc->latfcn(isc->latarg, sim_latency, bp);
}
#endif
return retval;
}
void
cam_iosched_submit_trim(struct cam_iosched_softc *isc)
{
isc->flags |= CAM_IOSCHED_FLAG_TRIM_ACTIVE;
}
void
cam_iosched_set_sort_queue(struct cam_iosched_softc *isc, int val)
{
isc->sort_io_queue = val;
}
int
cam_iosched_has_work_flags(struct cam_iosched_softc *isc, uint32_t flags)
{
return isc->flags & flags;
}
void
cam_iosched_set_work_flags(struct cam_iosched_softc *isc, uint32_t flags)
{
isc->flags |= flags;
}
void
cam_iosched_clr_work_flags(struct cam_iosched_softc *isc, uint32_t flags)
{
isc->flags &= ~flags;
}
#ifdef CAM_IOSCHED_DYNAMIC
static uint64_t
isqrt64(uint64_t val)
{
uint64_t res = 0;
uint64_t bit = 1ULL << (sizeof(uint64_t) * NBBY - 2);
while (bit > val)
bit >>= 2;
while (bit != 0) {
if (val >= res + bit) {
val -= res + bit;
res = (res >> 1) + bit;
} else
res >>= 1;
bit >>= 2;
}
return res;
}
static sbintime_t latencies[LAT_BUCKETS - 1] = {
BUCKET_BASE << 0,
BUCKET_BASE << 1,
BUCKET_BASE << 2,
BUCKET_BASE << 3,
BUCKET_BASE << 4,
BUCKET_BASE << 5,
BUCKET_BASE << 6,
BUCKET_BASE << 7,
BUCKET_BASE << 8,
BUCKET_BASE << 9,
BUCKET_BASE << 10,
BUCKET_BASE << 11,
BUCKET_BASE << 12,
BUCKET_BASE << 13,
BUCKET_BASE << 14,
BUCKET_BASE << 15,
BUCKET_BASE << 16,
BUCKET_BASE << 17,
BUCKET_BASE << 18
};
#define CAM_IOSCHED_DEVD_MSG_SIZE 256
static void
cam_iosched_devctl_outlier(struct iop_stats *iop, sbintime_t sim_latency,
const struct bio *bp)
{
daddr_t lba = bp->bio_pblkno;
daddr_t cnt = bp->bio_bcount / iop->softc->disk->d_sectorsize;
char *sbmsg;
struct sbuf sb;
sbmsg = malloc(CAM_IOSCHED_DEVD_MSG_SIZE, M_CAMSCHED, M_NOWAIT);
if (sbmsg == NULL)
return;
sbuf_new(&sb, sbmsg, CAM_IOSCHED_DEVD_MSG_SIZE, SBUF_FIXEDLEN);
sbuf_printf(&sb, "device=%s%d lba=%jd blocks=%jd latency=%jd",
iop->softc->periph->periph_name,
iop->softc->periph->unit_number,
lba, cnt, sbttons(sim_latency));
if (sbuf_finish(&sb) == 0)
devctl_notify("CAM", "iosched", "latency", sbuf_data(&sb));
sbuf_delete(&sb);
free(sbmsg, M_CAMSCHED);
}
static void
cam_iosched_update(struct iop_stats *iop, sbintime_t sim_latency,
const struct bio *bp)
{
sbintime_t y, deltasq, delta;
int i;
if (sim_latency > iop->bad_latency) {
cam_iosched_devctl_outlier(iop, sim_latency, bp);
iop->too_long++;
}
for (i = 0; i < LAT_BUCKETS - 1; i++) {
if (sim_latency < latencies[i]) {
iop->latencies[i]++;
break;
}
}
if (i == LAT_BUCKETS - 1)
iop->latencies[i]++;
y = sim_latency;
delta = (y - iop->ema);
iop->ema = ((iop->ema << alpha_bits) + delta) >> alpha_bits;
delta >>= 12;
deltasq = delta * delta;
iop->emvar = ((iop->emvar << (2 * alpha_bits)) +
((deltasq - iop->emvar) << alpha_bits) +
deltasq)
>> (2 * alpha_bits);
iop->sd = (sbintime_t)isqrt64((uint64_t)iop->emvar) << 12;
}
static void
cam_iosched_io_metric_update(struct cam_iosched_softc *isc,
sbintime_t sim_latency, const struct bio *bp)
{
switch (bp->bio_cmd) {
case BIO_READ:
cam_iosched_update(&isc->read_stats, sim_latency, bp);
break;
case BIO_WRITE:
cam_iosched_update(&isc->write_stats, sim_latency, bp);
break;
case BIO_DELETE:
cam_iosched_update(&isc->trim_stats, sim_latency, bp);
break;
default:
break;
}
}
#ifdef DDB
static int biolen(struct bio_queue_head *bq)
{
int i = 0;
struct bio *bp;
TAILQ_FOREACH(bp, &bq->queue, bio_queue) {
i++;
}
return i;
}
DB_SHOW_COMMAND(iosched, cam_iosched_db_show)
{
struct cam_iosched_softc *isc;
if (!have_addr) {
db_printf("Need addr\n");
return;
}
isc = (struct cam_iosched_softc *)addr;
db_printf("pending_reads: %d\n", isc->read_stats.pending);
db_printf("min_reads: %d\n", isc->read_stats.min);
db_printf("max_reads: %d\n", isc->read_stats.max);
db_printf("reads: %d\n", isc->read_stats.total);
db_printf("in_reads: %d\n", isc->read_stats.in);
db_printf("out_reads: %d\n", isc->read_stats.out);
db_printf("queued_reads: %d\n", isc->read_stats.queued);
db_printf("Read Q len %d\n", biolen(&isc->bio_queue));
db_printf("pending_writes: %d\n", isc->write_stats.pending);
db_printf("min_writes: %d\n", isc->write_stats.min);
db_printf("max_writes: %d\n", isc->write_stats.max);
db_printf("writes: %d\n", isc->write_stats.total);
db_printf("in_writes: %d\n", isc->write_stats.in);
db_printf("out_writes: %d\n", isc->write_stats.out);
db_printf("queued_writes: %d\n", isc->write_stats.queued);
db_printf("Write Q len %d\n", biolen(&isc->write_queue));
db_printf("pending_trims: %d\n", isc->trim_stats.pending);
db_printf("min_trims: %d\n", isc->trim_stats.min);
db_printf("max_trims: %d\n", isc->trim_stats.max);
db_printf("trims: %d\n", isc->trim_stats.total);
db_printf("in_trims: %d\n", isc->trim_stats.in);
db_printf("out_trims: %d\n", isc->trim_stats.out);
db_printf("queued_trims: %d\n", isc->trim_stats.queued);
db_printf("Trim Q len %d\n", biolen(&isc->trim_queue));
db_printf("read_bias: %d\n", isc->read_bias);
db_printf("current_read_bias: %d\n", isc->current_read_bias);
db_printf("Trim active? %s\n",
(isc->flags & CAM_IOSCHED_FLAG_TRIM_ACTIVE) ? "yes" : "no");
}
#endif
#endif