cam/iosched: Make each periph driver provide schedule fnp

When we init the iosched instance, require clients to provide a schedule
function. We have almost, but not quite everything to know when it is
safe to schedule new I/O. The periph drivers, however, have all the
information, so make them do it when the I/O Scheduler needs to maybe
schedule I/O for rate limiting, etc. and use it to do that.

Sponsored by:		Netflix
Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D46038
This commit is contained in:
Warner Losh 2024-07-19 20:53:17 -06:00
parent dd6123ebf0
commit 9cbf3d6182
5 changed files with 12 additions and 6 deletions

View file

@ -1913,7 +1913,8 @@ adaregister(struct cam_periph *periph, void *arg)
softc->disk->d_drv1 = periph;
softc->disk->d_unit = periph->unit_number;
if (cam_iosched_init(&softc->cam_iosched, periph, softc->disk) != 0) {
if (cam_iosched_init(&softc->cam_iosched, periph, softc->disk,
adaschedule) != 0) {
printf("adaregister: Unable to probe new device. "
"Unable to allocate iosched memory\n");
free(softc, M_DEVBUF);

View file

@ -315,6 +315,7 @@ 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;
/* scheduler flags < 16, user flags >= 16 */
uint32_t flags;
int sort_io_queue;
@ -619,7 +620,7 @@ cam_iosched_ticker(void *arg)
cam_iosched_limiter_tick(&isc->write_stats);
cam_iosched_limiter_tick(&isc->trim_stats);
cam_iosched_schedule(isc, isc->periph);
isc->schedfnc(isc->periph);
/*
* isc->load is an EMA of the pending I/Os at each tick. The number of
@ -1155,13 +1156,14 @@ cam_iosched_cl_sysctl_fini(struct control_loop *clp)
*/
int
cam_iosched_init(struct cam_iosched_softc **iscp, struct cam_periph *periph,
const struct disk *dp)
const struct disk *dp, cam_iosched_schedule_t schedfnc)
{
*iscp = malloc(sizeof(**iscp), M_CAMSCHED, M_NOWAIT | M_ZERO);
if (*iscp == NULL)
return ENOMEM;
(*iscp)->disk = dp;
(*iscp)->schedfnc = schedfnc;
#ifdef CAM_IOSCHED_DYNAMIC
if (iosched_debug)
printf("CAM IOSCHEDULER Allocating entry at %p\n", *iscp);

View file

@ -79,9 +79,10 @@ cam_iosched_sbintime_t(uintptr_t delta)
}
typedef void (*cam_iosched_latfcn_t)(void *, sbintime_t, struct bio *);
typedef void (*cam_iosched_schedule_t)(struct cam_periph *periph);
int cam_iosched_init(struct cam_iosched_softc **, struct cam_periph *periph,
const struct disk *dp);
const struct disk *dp, cam_iosched_schedule_t schedfnp);
void cam_iosched_fini(struct cam_iosched_softc *);
void cam_iosched_sysctl_init(struct cam_iosched_softc *, struct sysctl_ctx_list *, struct sysctl_oid *);
struct bio *cam_iosched_next_trim(struct cam_iosched_softc *isc);

View file

@ -946,7 +946,8 @@ ndaregister(struct cam_periph *periph, void *arg)
DEVSTAT_TYPE_DIRECT | XPORT_DEVSTAT_TYPE(cpi.transport),
DEVSTAT_PRIORITY_DISK);
if (cam_iosched_init(&softc->cam_iosched, periph, disk) != 0) {
if (cam_iosched_init(&softc->cam_iosched, periph, disk,
ndaschedule) != 0) {
printf("ndaregister: Unable to probe new device. "
"Unable to allocate iosched memory\n");
free(softc, M_DEVBUF);

View file

@ -2973,7 +2973,8 @@ daregister(struct cam_periph *periph, void *arg)
snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
"%s%d", cpi.dev_name, cpi.unit_number);
if (cam_iosched_init(&softc->cam_iosched, periph, softc->disk) != 0) {
if (cam_iosched_init(&softc->cam_iosched, periph, softc->disk,
daschedule) != 0) {
printf("daregister: Unable to probe new device. "
"Unable to allocate iosched memory\n");
free(softc, M_DEVBUF);