git: 9cbf3d618273 - main - cam/iosched: Make each periph driver provide schedule fnp

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sat, 20 Jul 2024 02:59:10 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=9cbf3d618273e09cdc7e18e878b33b9305836ad8

commit 9cbf3d618273e09cdc7e18e878b33b9305836ad8
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-07-20 02:53:17 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-07-20 02:53:37 +0000

    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
---
 sys/cam/ata/ata_da.c   | 3 ++-
 sys/cam/cam_iosched.c  | 6 ++++--
 sys/cam/cam_iosched.h  | 3 ++-
 sys/cam/nvme/nvme_da.c | 3 ++-
 sys/cam/scsi/scsi_da.c | 3 ++-
 5 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c
index 2c1183b74c1d..ae7cf14c8f8e 100644
--- a/sys/cam/ata/ata_da.c
+++ b/sys/cam/ata/ata_da.c
@@ -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);
diff --git a/sys/cam/cam_iosched.c b/sys/cam/cam_iosched.c
index 28b5375ae246..5f171e402ed2 100644
--- a/sys/cam/cam_iosched.c
+++ b/sys/cam/cam_iosched.c
@@ -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);
diff --git a/sys/cam/cam_iosched.h b/sys/cam/cam_iosched.h
index e1019c531579..54f9a7c02a25 100644
--- a/sys/cam/cam_iosched.h
+++ b/sys/cam/cam_iosched.h
@@ -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);
diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c
index 1a93ea71ba77..1c0d5e8381d8 100644
--- a/sys/cam/nvme/nvme_da.c
+++ b/sys/cam/nvme/nvme_da.c
@@ -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);
diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c
index 4ecf8c35aca2..1a6df6171b66 100644
--- a/sys/cam/scsi/scsi_da.c
+++ b/sys/cam/scsi/scsi_da.c
@@ -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);