Lines Matching +full:device +full:- +full:version
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
68 * Table to match descriptive strings with device types. These are in
182 &numdevsize, NULL, 0) == -1) { in devstat_getnumdevs()
187 return(-1); in devstat_getnumdevs()
192 if (KREADNL(kd, X_NUMDEVS, numdevs) == -1) in devstat_getnumdevs()
193 return(-1); in devstat_getnumdevs()
203 * the device list and the generation could change between the time that
204 * this function is called and the device list is retrieved.
219 &gensize, NULL, 0) == -1) { in devstat_getgeneration()
223 return(-1); in devstat_getgeneration()
227 if (KREADNL(kd, X_GENERATION, generation) == -1) in devstat_getgeneration()
228 return(-1); in devstat_getgeneration()
235 * Get the current devstat version. The return value of this function
244 int version; in devstat_getversion() local
249 * Get the current devstat version. in devstat_getversion()
252 if (sysctlbyname("kern.devstat.version", &version, &versize, in devstat_getversion()
253 NULL, 0) == -1) { in devstat_getversion()
255 "%s: error getting devstat version\n%s: %s", in devstat_getversion()
257 return(-1); in devstat_getversion()
259 return(version); in devstat_getversion()
261 if (KREADNL(kd, X_VERSION, version) == -1) in devstat_getversion()
262 return(-1); in devstat_getversion()
264 return(version); in devstat_getversion()
269 * Check the devstat version we know about against the devstat version the
271 * devstat error buffer, and return -1. If they match, return 0.
276 int buflen, res, retval = 0, version; in devstat_checkversion() local
278 version = devstat_getversion(kd); in devstat_checkversion()
280 if (version != DEVSTAT_VERSION) { in devstat_checkversion()
282 * If getversion() returns an error (i.e. -1), then it in devstat_checkversion()
287 if (version == -1) in devstat_checkversion()
293 DEVSTAT_ERRBUF_SIZE - buflen, in devstat_checkversion()
294 "%s%s: userland devstat version %d is not " in devstat_checkversion()
296 "version %d\n", version == -1 ? "\n" : "", in devstat_checkversion()
297 __func__, DEVSTAT_VERSION, __func__, version); in devstat_checkversion()
303 if (version < DEVSTAT_VERSION) in devstat_checkversion()
305 DEVSTAT_ERRBUF_SIZE - buflen, in devstat_checkversion()
310 DEVSTAT_ERRBUF_SIZE - buflen, in devstat_checkversion()
317 retval = -1; in devstat_checkversion()
328 * -1 -- error
329 * 0 -- device list is unchanged
330 * 1 -- device list has changed
342 dinfo = stats->dinfo; in devstat_getdevs()
346 "%s: stats->dinfo was NULL", __func__); in devstat_getdevs()
347 return(-1); in devstat_getdevs()
350 oldgeneration = dinfo->generation; in devstat_getdevs()
354 stats->snap_time = ts.tv_sec + ts.tv_nsec * 1e-9; in devstat_getdevs()
357 if (dinfo->mem_ptr == NULL) { in devstat_getdevs()
363 if ((dinfo->numdevs = devstat_getnumdevs(kd)) < 0) in devstat_getdevs()
364 return(-1); in devstat_getdevs()
371 dssize = (dinfo->numdevs * sizeof(struct devstat)) + in devstat_getdevs()
373 dinfo->mem_ptr = (u_int8_t *)malloc(dssize); in devstat_getdevs()
374 if (dinfo->mem_ptr == NULL) { in devstat_getdevs()
378 return(-1); in devstat_getdevs()
381 dssize = (dinfo->numdevs * sizeof(struct devstat)) + in devstat_getdevs()
387 * in a loop and keep reallocing the device structure until we in devstat_getdevs()
394 dinfo->mem_ptr, in devstat_getdevs()
396 if (error != -1 || errno != EBUSY) in devstat_getdevs()
399 if (error == -1) { in devstat_getdevs()
403 * space for the device array. in devstat_getdevs()
410 if ((dinfo->numdevs = devstat_getnumdevs(kd)) < 0) in devstat_getdevs()
411 return(-1); in devstat_getdevs()
413 dssize = (dinfo->numdevs * in devstat_getdevs()
415 dinfo->mem_ptr = (u_int8_t *) in devstat_getdevs()
416 realloc(dinfo->mem_ptr, dssize); in devstat_getdevs()
418 dinfo->mem_ptr, &dssize, NULL, 0)) == -1) { in devstat_getdevs()
421 "%s: error getting device " in devstat_getdevs()
424 return(-1); in devstat_getdevs()
428 "%s: error getting device stats\n" in devstat_getdevs()
431 return(-1); in devstat_getdevs()
436 if (KREADNL(kd, X_TIME_UPTIME, ts.tv_sec) == -1) in devstat_getdevs()
437 return(-1); in devstat_getdevs()
439 stats->snap_time = ts.tv_sec; in devstat_getdevs()
442 * This is of course non-atomic, but since we are working in devstat_getdevs()
445 if ((dinfo->numdevs = devstat_getnumdevs(kd)) == -1) in devstat_getdevs()
446 return(-1); in devstat_getdevs()
447 if ((dinfo->mem_ptr = (u_int8_t *)get_devstat_kvm(kd)) == NULL) in devstat_getdevs()
448 return(-1); in devstat_getdevs()
452 * then all of the device statistics structures. in devstat_getdevs()
454 dinfo->generation = *(long *)dinfo->mem_ptr; in devstat_getdevs()
459 * devinfo structure, it is likely that the device list has shrunk. in devstat_getdevs()
460 * The reason that it is likely that the device list has shrunk in in devstat_getdevs()
461 * this case is that if the device list has grown, the sysctl above in devstat_getdevs()
463 * devices and reallocate the device array. If the second sysctl in devstat_getdevs()
465 * point. If the device list has shrunk, the sysctl will not in devstat_getdevs()
471 if (oldgeneration != dinfo->generation) { in devstat_getdevs()
472 if (devstat_getnumdevs(kd) != dinfo->numdevs) { in devstat_getdevs()
473 if ((dinfo->numdevs = devstat_getnumdevs(kd)) < 0) in devstat_getdevs()
474 return(-1); in devstat_getdevs()
475 dssize = (dinfo->numdevs * sizeof(struct devstat)) + in devstat_getdevs()
477 dinfo->mem_ptr = (u_int8_t *)realloc(dinfo->mem_ptr, in devstat_getdevs()
483 dinfo->devices = (struct devstat *)(dinfo->mem_ptr + sizeof(long)); in devstat_getdevs()
492 * - devices specified by the user on the command line
493 * - devices matching any device type expressions given on the command line
494 * - devices with the highest I/O, if 'top' mode is enabled
495 * - the first n unselected devices in the device list, if maxshowdevs
500 * - device selection list (dev_select)
501 * - current number of devices selected (num_selected)
502 * - total number of devices in the selection list (num_selections)
503 * - devstat generation as of the last time selectdevs() was called
505 * - current devstat generation (current_generation)
506 * - current list of devices and statistics (devices)
507 * - number of devices in the current device list (numdevs)
508 * - compiled version of the command line device type arguments (matches)
509 * - This is optional. If the number of devices is 0, this will be ignored.
510 * - The matching code pays attention to the current selection mode. So
513 * - number of device type matching expressions (num_matches)
514 * - Set to 0 to disable the matching code.
515 * - list of devices specified on the command line by the user (dev_selections)
516 * - number of devices selected on the command line by the user
518 * - Our selection mode. There are four different selection modes:
519 * - add mode. (DS_SELECT_ADD) Any devices matching devices explicitly
524 * - only mode. (DS_SELECT_ONLY) Only devices matching devices
528 * - addonly mode. (DS_SELECT_ADDONLY) This is similar to add and
529 * only. Basically, this will not de-select any devices that are
532 * - remove mode. (DS_SELECT_REMOVE) Any devices matching devices
534 * given by the user will be de-selected.
535 * - maximum number of devices we can select (maxshowdevs)
536 * - flag indicating whether or not we're in 'top' mode (perf_select)
539 * - the device selection list may be modified and passed back out
540 * - the number of devices selected and the total number of items in the
541 * device selection list may be changed
542 * - the selection generation may be changed to match the current generation
545 * -1 -- error
546 * 0 -- selected devices are unchanged
547 * 1 -- selected devices changed
566 return(-1); in devstat_selectdevs()
582 * In this case, we have selected devices before, but the device in devstat_selectdevs()
584 * either enlarge or reduce the size of the device selection list. in devstat_selectdevs()
593 * list is the same size as it was the last time, but the device in devstat_selectdevs()
605 return(-1); in devstat_selectdevs()
639 return(-1); in devstat_selectdevs()
660 (*dev_select)[i].device_name[DEVSTAT_NAME_LEN - 1]='\0'; in devstat_selectdevs()
690 * addonly mode, we only select this device in devstat_selectdevs()
696 * select this device, since in only mode in devstat_selectdevs()
700 * mode, we de-select the specified device and in devstat_selectdevs()
716 (*num_selected)--; in devstat_selectdevs()
722 num_dev_selections--; in devstat_selectdevs()
731 * Go through the user's device type expressions and select devices in devstat_selectdevs()
747 * Determine whether or not the current device in devstat_selectdevs()
750 * - the device type check in devstat_selectdevs()
751 * - the device interface check in devstat_selectdevs()
752 * - the passthrough check in devstat_selectdevs()
767 && (--num_match_categories == 0)) in devstat_selectdevs()
776 && (--num_match_categories == 0)) in devstat_selectdevs()
779 && (--num_match_categories == 0))) { in devstat_selectdevs()
782 * This is probably a non-optimal solution in devstat_selectdevs()
784 * device list will not be in the same in devstat_selectdevs()
796 * There shouldn't be a case where a device in devstat_selectdevs()
797 * in the device list is not in the in devstat_selectdevs()
812 * mode, we go ahead and select this device in devstat_selectdevs()
820 * mode, we de-select the given device and in devstat_selectdevs()
835 (*num_selected)--; in devstat_selectdevs()
852 * select every device in the case where the user hasn't specified in devstat_selectdevs()
854 * difference in the device sorting. In that particular case (i.e. in devstat_selectdevs()
863 /* Sort the device array by throughput */ in devstat_selectdevs()
870 * Here we select every device in the array, if it in devstat_selectdevs()
930 * If the device at index i in both the new and old in devstat_selectdevs()
931 * selection arrays has the same device number and in devstat_selectdevs()
944 * check here to see if the device at index i in in devstat_selectdevs()
945 * the current array is the same as the device at in devstat_selectdevs()
956 * If we get here, then the device at index i in in devstat_selectdevs()
957 * the current array isn't the same device as the in devstat_selectdevs()
958 * device at index i in the old array. in devstat_selectdevs()
965 * looking for a device with the same in devstat_selectdevs()
966 * device number as the device at index i in devstat_selectdevs()
999 * backwards -- generally, it should return a value to indicate whether
1005 * selected device is automatically more important than the unselected
1006 * device. If neither device is selected, we judge the devices based upon
1012 if ((((const struct device_selection *)arg1)->selected) in compare_select()
1013 && (((const struct device_selection *)arg2)->selected == 0)) in compare_select()
1014 return(-1); in compare_select()
1015 else if ((((const struct device_selection *)arg1)->selected == 0) in compare_select()
1016 && (((const struct device_selection *)arg2)->selected)) in compare_select()
1018 else if (((const struct device_selection *)arg2)->bytes < in compare_select()
1019 ((const struct device_selection *)arg1)->bytes) in compare_select()
1020 return(-1); in compare_select()
1021 else if (((const struct device_selection *)arg2)->bytes > in compare_select()
1022 ((const struct device_selection *)arg1)->bytes) in compare_select()
1030 * device matching expression from it.
1045 return(-1); in devstat_buildmatch()
1063 return(-1); in devstat_buildmatch()
1075 return(-1); in devstat_buildmatch()
1082 * Step through the arguments the user gave us and build a device in devstat_buildmatch()
1098 tempstr3 = &tempstr2[strlen(tempstr2) - 1]; in devstat_buildmatch()
1103 tempstr3--; in devstat_buildmatch()
1108 * arguments to known device types, interfaces, etc. in devstat_buildmatch()
1112 * We do case-insensitive matching, in case someone in devstat_buildmatch()
1117 * a super-long match expression. in devstat_buildmatch()
1124 * "cd". One device cannot be both. in devstat_buildmatch()
1133 return(-1); in devstat_buildmatch()
1150 * not, that means the user entered an invalid device type in devstat_buildmatch()
1157 return(-1); in devstat_buildmatch()
1167 * Compute a number of device statistics. Only one field is mandatory, and
1172 * 0 -- success
1173 * -1 -- failure
1205 #define BINTIME_SCALE 5.42101086242752217003726400434970855712890625e-20
1212 etime = cur_time->sec; in devstat_compute_etime()
1213 etime += cur_time->frac * BINTIME_SCALE; in devstat_compute_etime()
1215 etime -= prev_time->sec; in devstat_compute_etime()
1216 etime -= prev_time->frac * BINTIME_SCALE; in devstat_compute_etime()
1222 (current->field[(index)] - (previous ? previous->field[(index)] : 0))
1225 devstat_compute_etime(¤t->field, \
1226 (previous ? &previous->field : NULL))
1252 return(-1); in devstat_compute_statistics()
1272 if (current->block_size > 0) { in devstat_compute_statistics()
1273 totalblocks /= current->block_size; in devstat_compute_statistics()
1274 totalblocksread /= current->block_size; in devstat_compute_statistics()
1275 totalblockswrite /= current->block_size; in devstat_compute_statistics()
1276 totalblocksfree /= current->block_size; in devstat_compute_statistics()
1302 retval = -1; in devstat_compute_statistics()
1317 retval = -1; in devstat_compute_statistics()
1547 *destu64 = current->start_count - current->end_count; in devstat_compute_statistics()
1579 retval = -1; in devstat_compute_statistics()
1596 if (kvm_read(kd, addr, buf, nbytes) == -1) { in readkmem()
1600 return(-1); in readkmem()
1613 if (kvm_nlist(kd, nl) == -1) { in readkmem_nl()
1617 return(-1); in readkmem_nl()
1639 if (KREADNL(kd, X_DEVICE_STATQ, dhead) == -1) in get_devstat_kvm()
1658 if (readkmem(kd, (long)nds, &ds, sizeof(ds)) == -1) { in get_devstat_kvm()