Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Oct 2018 16:23:52 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r339777 - in head/sys/cam: ata nvme scsi
Message-ID:  <201810261623.w9QGNqwu047424@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Fri Oct 26 16:23:51 2018
New Revision: 339777
URL: https://svnweb.freebsd.org/changeset/base/339777

Log:
  Add statistics for TRIM comands
  
  Add a counter for the LBAs, Ranges and hardware commands so that we
  can provide additional color to the statistics we provide to vendors.
  
  Sponsored by: Netflix, Inc

Modified:
  head/sys/cam/ata/ata_da.c
  head/sys/cam/nvme/nvme_da.c
  head/sys/cam/scsi/scsi_da.c

Modified: head/sys/cam/ata/ata_da.c
==============================================================================
--- head/sys/cam/ata/ata_da.c	Fri Oct 26 16:03:30 2018	(r339776)
+++ head/sys/cam/ata/ata_da.c	Fri Oct 26 16:23:51 2018	(r339777)
@@ -251,6 +251,9 @@ struct ada_softc {
 	struct sysctl_oid	*sysctl_tree;
 	struct callout		sendordered_c;
 	struct trim_request	trim_req;
+	uint64_t		trim_count;
+	uint64_t		trim_ranges;
+	uint64_t		trim_lbas;
 #ifdef CAM_IO_STATS
 	struct sysctl_ctx_list	sysctl_stats_ctx;
 	struct sysctl_oid	*sysctl_stats_tree;
@@ -1440,6 +1443,18 @@ adasysctlinit(void *context, int pending)
 		OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RW,
 		softc, 0, adadeletemethodsysctl, "A",
 		"BIO_DELETE execution method");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_count", CTLFLAG_RD, &softc->trim_count,
+		"Total number of dsm commands sent");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
+		"Total number of ranges in dsm commands");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
+		"Total lbas in the dsm commands sent");
 	SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
 		OID_AUTO, "read_ahead", CTLFLAG_RW | CTLFLAG_MPSAFE,
 		&softc->read_ahead, 0, "Enable disk read ahead.");
@@ -1918,7 +1933,7 @@ adaregister(struct cam_periph *periph, void *arg)
 static int
 ada_dsmtrim_req_create(struct ada_softc *softc, struct bio *bp, struct trim_request *req)
 {
-	uint64_t lastlba = (uint64_t)-1;
+	uint64_t lastlba = (uint64_t)-1, lbas = 0;
 	int c, lastcount = 0, off, ranges = 0;
 
 	bzero(req, sizeof(*req));
@@ -1937,6 +1952,7 @@ ada_dsmtrim_req_create(struct ada_softc *softc, struct
 				(lastcount >> 8) & 0xff;
 			count -= c;
 			lba += c;
+			lbas += c;
 		}
 
 		while (count > 0) {
@@ -1951,6 +1967,7 @@ ada_dsmtrim_req_create(struct ada_softc *softc, struct
 			req->data[off + 6] = c & 0xff;
 			req->data[off + 7] = (c >> 8) & 0xff;
 			lba += c;
+			lbas += c;
 			count -= c;
 			lastcount = c;
 			ranges++;
@@ -1972,6 +1989,9 @@ ada_dsmtrim_req_create(struct ada_softc *softc, struct
 			break;
 		}
 	} while (1);
+	softc->trim_count++;
+	softc->trim_ranges += ranges;
+	softc->trim_lbas += lbas;
 
 	return (ranges);
 }

Modified: head/sys/cam/nvme/nvme_da.c
==============================================================================
--- head/sys/cam/nvme/nvme_da.c	Fri Oct 26 16:03:30 2018	(r339776)
+++ head/sys/cam/nvme/nvme_da.c	Fri Oct 26 16:23:51 2018	(r339777)
@@ -105,12 +105,14 @@ struct nda_softc {
 	nda_quirks		quirks;
 	int			unmappedio;
 	quad_t			deletes;
-	quad_t			dsm_req;
 	uint32_t		nsid;			/* Namespace ID for this nda device */
 	struct disk		*disk;
 	struct task		sysctl_task;
 	struct sysctl_ctx_list	sysctl_ctx;
 	struct sysctl_oid	*sysctl_tree;
+	uint64_t		trim_count;
+	uint64_t		trim_ranges;
+	uint64_t		trim_lbas;
 #ifdef CAM_TEST_FAILURE
 	int			force_read_error;
 	int			force_write_error;
@@ -637,9 +639,18 @@ ndasysctlinit(void *context, int pending)
 	    OID_AUTO, "deletes", CTLFLAG_RD,
 	    &softc->deletes, "Number of BIO_DELETE requests");
 
-	SYSCTL_ADD_QUAD(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
-	    OID_AUTO, "dsm_req", CTLFLAG_RD,
-	    &softc->dsm_req, "Number of DSM requests sent to SIM");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_count", CTLFLAG_RD, &softc->trim_count,
+		"Total number of unmap/dsm commands sent");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
+		"Total number of ranges in unmap/dsm commands");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
+		"Total lbas in the unmap/dsm commands sent");
 
 	SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
 	    OID_AUTO, "rotating", CTLFLAG_RD, &nda_rotating_media, 1,
@@ -939,6 +950,7 @@ ndastart(struct cam_periph *periph, union ccb *start_c
 			struct nda_trim_request *trim;
 			struct bio *bp1;
 			int ents;
+			uint32_t totalcount = 0, ranges = 0;
 
 			trim = malloc(sizeof(*trim), M_NVMEDA, M_ZERO | M_NOWAIT);
 			if (trim == NULL) {
@@ -959,6 +971,8 @@ ndastart(struct cam_periph *periph, union ccb *start_c
 				    htole32(bp1->bio_bcount / softc->disk->d_sectorsize);
 				dsm_range->starting_lba =
 				    htole64(bp1->bio_offset / softc->disk->d_sectorsize);
+				ranges++;
+				totalcount += dsm_range->length;
 				dsm_range++;
 				if (dsm_range >= dsm_end)
 					break;
@@ -967,10 +981,12 @@ ndastart(struct cam_periph *periph, union ccb *start_c
 				/* XXX -- Could limit based on total payload size */
 			} while (bp1 != NULL);
 			start_ccb->ccb_trim = trim;
-			softc->dsm_req++;
 			nda_nvme_trim(softc, &start_ccb->nvmeio, &trim->dsm,
 			    dsm_range - &trim->dsm);
 			start_ccb->ccb_state = NDA_CCB_TRIM;
+			softc->trim_count++;
+			softc->trim_ranges += ranges;
+			softc->trim_lbas += totalcount;
 			/*
 			 * Note: We can have multiple TRIMs in flight, so we don't call
 			 * cam_iosched_submit_trim(softc->cam_iosched);

Modified: head/sys/cam/scsi/scsi_da.c
==============================================================================
--- head/sys/cam/scsi/scsi_da.c	Fri Oct 26 16:03:30 2018	(r339776)
+++ head/sys/cam/scsi/scsi_da.c	Fri Oct 26 16:23:51 2018	(r339777)
@@ -334,6 +334,9 @@ struct da_softc {
 	uint32_t		unmap_gran;
 	uint32_t		unmap_gran_align;
 	uint64_t		ws_max_blks;
+	uint64_t		trim_count;
+	uint64_t		trim_ranges;
+	uint64_t		trim_lbas;
 	da_delete_methods	delete_method_pref;
 	da_delete_methods	delete_method;
 	da_delete_func_t	*delete_func;
@@ -2182,6 +2185,18 @@ dasysctlinit(void *context, int pending)
 		OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
 		&softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
 		"Minimum CDB size");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_count", CTLFLAG_RD, &softc->trim_count,
+		"Total number of unmap/dsm commands sent");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
+		"Total number of ranges in unmap/dsm commands");
+	SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
+		SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
+		"trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
+		"Total lbas in the unmap/dsm commands sent");
 
 	SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
 		OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
@@ -3934,6 +3949,9 @@ da_delete_unmap(struct cam_periph *periph, union ccb *
 		   da_default_timeout * 1000);
 	ccb->ccb_h.ccb_state = DA_CCB_DELETE;
 	ccb->ccb_h.flags |= CAM_UNLOCKED;
+	softc->trim_count++;
+	softc->trim_ranges += ranges;
+	softc->trim_lbas += totalcount;
 	cam_iosched_submit_trim(softc->cam_iosched);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810261623.w9QGNqwu047424>