[Midnightbsd-cvs] src [10868] trunk/lib/libdevstat: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jun 13 19:45:14 EDT 2018


Revision: 10868
          http://svnweb.midnightbsd.org/src/?rev=10868
Author:   laffer1
Date:     2018-06-13 19:45:14 -0400 (Wed, 13 Jun 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/lib/libdevstat/Makefile
    trunk/lib/libdevstat/devstat.3
    trunk/lib/libdevstat/devstat.c
    trunk/lib/libdevstat/devstat.h

Property Changed:
----------------
    trunk/lib/libdevstat/devstat.3

Modified: trunk/lib/libdevstat/Makefile
===================================================================
--- trunk/lib/libdevstat/Makefile	2018-06-13 22:42:07 UTC (rev 10867)
+++ trunk/lib/libdevstat/Makefile	2018-06-13 23:45:14 UTC (rev 10868)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/lib/libdevstat/Makefile 201381 2010-01-02 09:58:07Z ed $
 
 LIB=	devstat
 SHLIBDIR?= /lib

Modified: trunk/lib/libdevstat/devstat.3
===================================================================
--- trunk/lib/libdevstat/devstat.3	2018-06-13 22:42:07 UTC (rev 10867)
+++ trunk/lib/libdevstat/devstat.3	2018-06-13 23:45:14 UTC (rev 10868)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" Copyright (c) 1998, 1999, 2001 Kenneth D. Merry.
 .\" All rights reserved.
@@ -25,9 +26,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/lib/libdevstat/devstat.3 244270 2012-12-15 18:19:48Z trociny $
 .\"
-.Dd March 18, 2003
+.Dd December 15, 2012
 .Dt DEVSTAT 3
 .Os
 .Sh NAME
@@ -193,7 +194,7 @@
 .Bd -literal -offset indent
 struct devinfo {
 	struct devstat	*devices;
-	u_int8_t	*mem_ptr;
+	uint8_t		*mem_ptr;
 	long		generation;
 	int		numdevs;
 };
@@ -472,7 +473,7 @@
 For each statistics to be calculated, the user should supply the proper
 enumerated type (listed below), and a variable of the indicated type.
 All statistics are either integer values, for which a
-.Vt u_int64_t
+.Vt uint64_t
 is used,
 or floating point, for which a
 .Vt "long double"
@@ -489,7 +490,7 @@
 It is an argument list terminator.
 .It Dv DSM_TOTAL_BYTES
 type:
-.Vt "u_int64_t *"
+.Vt "uint64_t *"
 .Pp
 The total number of bytes transferred between the acquisition of
 .Fa previous
@@ -499,7 +500,7 @@
 .It Dv DSM_TOTAL_BYTES_WRITE
 .It Dv DSM_TOTAL_BYTES_FREE
 type:
-.Vt "u_int64_t *"
+.Vt "uint64_t *"
 .Pp
 The total number of bytes in transactions of the specified type
 between the acquisition of
@@ -508,7 +509,7 @@
 .Fa current .
 .It Dv DSM_TOTAL_TRANSFERS
 type:
-.Vt "u_int64_t *"
+.Vt "uint64_t *"
 .Pp
 The total number of transfers between the acquisition of
 .Fa previous
@@ -519,7 +520,7 @@
 .It Dv DSM_TOTAL_TRANSFERS_WRITE
 .It Dv DSM_TOTAL_TRANSFERS_FREE
 type:
-.Vt "u_int64_t *"
+.Vt "uint64_t *"
 .Pp
 The total number of transactions of the specified type between
 the acquisition of
@@ -526,9 +527,38 @@
 .Fa previous
 and
 .Fa current .
+.It Dv DSM_TOTAL_DURATION
+type:
+.Vt "long double *"
+.Pp
+The total duration of transactions, in seconds, between the acquisition of
+.Fa previous
+and
+.Fa current .
+.It Dv DSM_TOTAL_DURATION_OTHER
+.It Dv DSM_TOTAL_DURATION_READ
+.It Dv DSM_TOTAL_DURATION_WRITE
+.It Dv DSM_TOTAL_DURATION_FREE
+type:
+.Vt "long double *"
+.Pp
+The total duration of transactions of the specified type between
+the acquisition of
+.Fa previous
+and
+.Fa current .
+.It Dv DSM_TOTAL_BUSY_TIME
+type:
+.Vt "long double *"
+.Pp
+Total time the device had one or more transactions outstanding
+between the acquisition of
+.Fa previous
+and
+.Fa current .
 .It Dv DSM_TOTAL_BLOCKS
 type:
-.Vt "u_int64_t *"
+.Vt "uint64_t *"
 .Pp
 The total number of blocks transferred between the acquisition of
 .Fa previous
@@ -541,7 +571,7 @@
 .It Dv DSM_TOTAL_BLOCKS_WRITE
 .It Dv DSM_TOTAL_BLOCKS_FREE
 type:
-.Vt "u_int64_t *"
+.Vt "uint64_t *"
 .Pp
 The total number of blocks of the specified type between the acquisition of
 .Fa previous
@@ -665,7 +695,7 @@
 .Fa current .
 .It Dv DSM_QUEUE_LENGTH
 type:
-.Vt "u_int64_t *"
+.Vt "uint64_t *"
 .Pp
 The number of not yet completed transactions at the time when
 .Fa current


Property changes on: trunk/lib/libdevstat/devstat.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libdevstat/devstat.c
===================================================================
--- trunk/lib/libdevstat/devstat.c	2018-06-13 22:42:07 UTC (rev 10867)
+++ trunk/lib/libdevstat/devstat.c	2018-06-13 23:45:14 UTC (rev 10868)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1997, 1998 Kenneth D. Merry.
  * All rights reserved.
@@ -27,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libdevstat/devstat.c 279545 2015-03-02 21:00:54Z ken $");
 
 #include <sys/types.h>
 #include <sys/sysctl.h>
@@ -133,6 +134,12 @@
 	{ DSM_MS_PER_TRANSACTION_FREE, DEVSTAT_ARG_LD },
 	{ DSM_BUSY_PCT, DEVSTAT_ARG_LD },
 	{ DSM_QUEUE_LENGTH, DEVSTAT_ARG_UINT64 },
+	{ DSM_TOTAL_DURATION, DEVSTAT_ARG_LD },
+	{ DSM_TOTAL_DURATION_READ, DEVSTAT_ARG_LD },
+	{ DSM_TOTAL_DURATION_WRITE, DEVSTAT_ARG_LD },
+	{ DSM_TOTAL_DURATION_FREE, DEVSTAT_ARG_LD },
+	{ DSM_TOTAL_DURATION_OTHER, DEVSTAT_ARG_LD },
+	{ DSM_TOTAL_BUSY_TIME, DEVSTAT_ARG_LD },
 };
 
 static const char *namelist[] = {
@@ -365,6 +372,12 @@
 			dssize = (dinfo->numdevs * sizeof(struct devstat)) +
 				 sizeof(long);
 			dinfo->mem_ptr = (u_int8_t *)malloc(dssize);
+			if (dinfo->mem_ptr == NULL) {
+				snprintf(devstat_errbuf, sizeof(devstat_errbuf),
+					 "%s: Cannot allocate memory for mem_ptr element",
+					 __func__);
+				return(-1);
+			}
 		} else
 			dssize = (dinfo->numdevs * sizeof(struct devstat)) +
 				 sizeof(long);
@@ -567,7 +580,7 @@
 	 * either enlarge or reduce the size of the device selection list.
 	 */
 	} else if (*num_selections != numdevs) {
-		*dev_select = (struct device_selection *)realloc(*dev_select,
+		*dev_select = (struct device_selection *)reallocf(*dev_select,
 			numdevs * sizeof(struct device_selection));
 		*select_generation = current_generation;
 		init_selections = 1;
@@ -581,6 +594,13 @@
 		init_selections = 1;
 	}
 
+	if (*dev_select == NULL) {
+		snprintf(devstat_errbuf, sizeof(devstat_errbuf),
+			 "%s: Cannot (re)allocate memory for dev_select argument",
+			 __func__);
+		return(-1);
+	}
+
 	/*
 	 * If we're in "only" mode, we want to clear out the selected
 	 * variable since we're going to select exactly what the user wants
@@ -608,6 +628,12 @@
 	 || (perf_select != 0)) && (changed == 0)){
 		old_dev_select = (struct device_selection *)malloc(
 		    *num_selections * sizeof(struct device_selection));
+		if (old_dev_select == NULL) {
+			snprintf(devstat_errbuf, sizeof(devstat_errbuf),
+				 "%s: Cannot allocate memory for selection list backup",
+				 __func__);
+			return(-1);
+		}
 		old_num_selections = *num_selections;
 		bcopy(*dev_select, old_dev_select, 
 		    sizeof(struct device_selection) * *num_selections);
@@ -1028,16 +1054,17 @@
 		return(-1);
 	}
 
-	/*
-	 * Since you can't realloc a pointer that hasn't been malloced
-	 * first, we malloc first and then realloc.
-	 */
 	if (*num_matches == 0)
-		*matches = (struct devstat_match *)malloc(
-			   sizeof(struct devstat_match));
-	else
-		*matches = (struct devstat_match *)realloc(*matches,
-			  sizeof(struct devstat_match) * (*num_matches + 1));
+		*matches = NULL;
+
+	*matches = (struct devstat_match *)reallocf(*matches,
+		  sizeof(struct devstat_match) * (*num_matches + 1));
+
+	if (*matches == NULL) {
+		snprintf(devstat_errbuf, sizeof(devstat_errbuf),
+			 "%s: Cannot allocate memory for matches list", __func__);
+		return(-1);
+	}
 			  
 	/* Make sure the current entry is clear */
 	bzero(&matches[0][*num_matches], sizeof(struct devstat_match));
@@ -1197,11 +1224,13 @@
 	u_int64_t totaltransfers, totaltransfersread, totaltransferswrite;
 	u_int64_t totaltransfersother, totalblocks, totalblocksread;
 	u_int64_t totalblockswrite, totaltransfersfree, totalblocksfree;
+	long double totalduration, totaldurationread, totaldurationwrite;
+	long double totaldurationfree, totaldurationother;
 	va_list ap;
 	devstat_metric metric;
 	u_int64_t *destu64;
 	long double *destld;
-	int retval, i;
+	int retval;
 
 	retval = 0;
 
@@ -1243,6 +1272,13 @@
 		totalblocksfree /= 512;
 	}
 
+	totaldurationread = DELTA_T(duration[DEVSTAT_READ]);
+	totaldurationwrite = DELTA_T(duration[DEVSTAT_WRITE]);
+	totaldurationfree = DELTA_T(duration[DEVSTAT_FREE]);
+	totaldurationother = DELTA_T(duration[DEVSTAT_NO_DATA]);
+	totalduration = totaldurationread + totaldurationwrite +
+	    totaldurationfree + totaldurationother;
+
 	va_start(ap, etime);
 
 	while ((metric = (devstat_metric)va_arg(ap, devstat_metric)) != 0) {
@@ -1445,41 +1481,21 @@
 				*destld = 0.0;
 			break;
 		/*
-		 * This calculation is somewhat bogus.  It simply divides
-		 * the elapsed time by the total number of transactions
-		 * completed.  While that does give the caller a good
-		 * picture of the average rate of transaction completion,
-		 * it doesn't necessarily give the caller a good view of
-		 * how long transactions took to complete on average.
-		 * Those two numbers will be different for a device that
-		 * can handle more than one transaction at a time.  e.g.
-		 * SCSI disks doing tagged queueing.
-		 *
-		 * The only way to accurately determine the real average
-		 * time per transaction would be to compute and store the
-		 * time on a per-transaction basis.  That currently isn't
-		 * done in the kernel, and would only be desireable if it
-		 * could be implemented in a somewhat non-intrusive and high
-		 * performance way.
+		 * Some devstat callers update the duration and some don't.
+		 * So this will only be accurate if they provide the
+		 * duration. 
 		 */
 		case DSM_MS_PER_TRANSACTION:
 			if (totaltransfers > 0) {
-				*destld = 0;
-				for (i = 0; i < DEVSTAT_N_TRANS_FLAGS; i++)
-					*destld += DELTA_T(duration[i]);
+				*destld = totalduration;
 				*destld /= totaltransfers;
 				*destld *= 1000;
 			} else
 				*destld = 0.0;
 			break;
-		/*
-		 * As above, these next two really only give the average
-		 * rate of completion for read and write transactions, not
-		 * the average time the transaction took to complete.
-		 */
 		case DSM_MS_PER_TRANSACTION_READ:
 			if (totaltransfersread > 0) {
-				*destld = DELTA_T(duration[DEVSTAT_READ]);
+				*destld = totaldurationread;
 				*destld /= totaltransfersread;
 				*destld *= 1000;
 			} else
@@ -1487,7 +1503,7 @@
 			break;
 		case DSM_MS_PER_TRANSACTION_WRITE:
 			if (totaltransferswrite > 0) {
-				*destld = DELTA_T(duration[DEVSTAT_WRITE]);
+				*destld = totaldurationwrite;
 				*destld /= totaltransferswrite;
 				*destld *= 1000;
 			} else
@@ -1495,7 +1511,7 @@
 			break;
 		case DSM_MS_PER_TRANSACTION_FREE:
 			if (totaltransfersfree > 0) {
-				*destld = DELTA_T(duration[DEVSTAT_FREE]);
+				*destld = totaldurationfree;
 				*destld /= totaltransfersfree;
 				*destld *= 1000;
 			} else
@@ -1503,7 +1519,7 @@
 			break;
 		case DSM_MS_PER_TRANSACTION_OTHER:
 			if (totaltransfersother > 0) {
-				*destld = DELTA_T(duration[DEVSTAT_NO_DATA]);
+				*destld = totaldurationother;
 				*destld /= totaltransfersother;
 				*destld *= 1000;
 			} else
@@ -1521,6 +1537,24 @@
 		case DSM_QUEUE_LENGTH:
 			*destu64 = current->start_count - current->end_count;
 			break;
+		case DSM_TOTAL_DURATION:
+			*destld = totalduration;
+			break;
+		case DSM_TOTAL_DURATION_READ:
+			*destld = totaldurationread;
+			break;
+		case DSM_TOTAL_DURATION_WRITE:
+			*destld = totaldurationwrite;
+			break;
+		case DSM_TOTAL_DURATION_FREE:
+			*destld = totaldurationfree;
+			break;
+		case DSM_TOTAL_DURATION_OTHER:
+			*destld = totaldurationother;
+			break;
+		case DSM_TOTAL_BUSY_TIME:
+			*destld = DELTA_T(busy_time);
+			break;
 /*
  * XXX: comment out the default block to see if any case's are missing.
  */

Modified: trunk/lib/libdevstat/devstat.h
===================================================================
--- trunk/lib/libdevstat/devstat.h	2018-06-13 22:42:07 UTC (rev 10867)
+++ trunk/lib/libdevstat/devstat.h	2018-06-13 23:45:14 UTC (rev 10868)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1997, 1998 Kenneth D. Merry.
  * All rights reserved.
@@ -26,6 +27,7 @@
  * SUCH DAMAGE.
  *
  * $MidnightBSD$
+ * $FreeBSD: stable/10/lib/libdevstat/devstat.h 244270 2012-12-15 18:19:48Z trociny $
  */
 
 #ifndef _DEVSTAT_H
@@ -97,6 +99,12 @@
 	DSM_MS_PER_TRANSACTION_FREE,
 	DSM_BUSY_PCT,
 	DSM_QUEUE_LENGTH,
+	DSM_TOTAL_DURATION,
+	DSM_TOTAL_DURATION_READ,
+	DSM_TOTAL_DURATION_WRITE,
+	DSM_TOTAL_DURATION_FREE,
+	DSM_TOTAL_DURATION_OTHER,
+	DSM_TOTAL_BUSY_TIME,
 	DSM_MAX
 } devstat_metric;
 



More information about the Midnightbsd-cvs mailing list