Lines Matching +full:first +full:- +full:generation
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
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()
200 * This is an easy way to get the generation number, but the generation is
202 * Because this generation sysctl is separate from the statistics sysctl,
203 * the device list and the generation could change between the time that
210 long generation; in devstat_getgeneration() local
215 * Get the current generation number. in devstat_getgeneration()
218 if (sysctlbyname("kern.devstat.generation", &generation, in devstat_getgeneration()
219 &gensize, NULL, 0) == -1) { in devstat_getgeneration()
221 "%s: error getting devstat generation\n%s: %s", in devstat_getgeneration()
223 return(-1); in devstat_getgeneration()
225 return(generation); in devstat_getgeneration()
227 if (KREADNL(kd, X_GENERATION, generation) == -1) in devstat_getgeneration()
228 return(-1); in devstat_getgeneration()
230 return(generation); in devstat_getgeneration()
253 NULL, 0) == -1) { in devstat_getversion()
257 return(-1); in devstat_getversion()
261 if (KREADNL(kd, X_VERSION, version) == -1) in devstat_getversion()
262 return(-1); in devstat_getversion()
271 * devstat error buffer, and return -1. If they match, return 0.
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()
296 "version %d\n", version == -1 ? "\n" : "", 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()
325 * generation number.
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()
356 /* If this is our first time through, mem_ptr will be null. */ 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()
368 * generation number, as well as all the devices. 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()
394 dinfo->mem_ptr, in devstat_getdevs()
396 if (error != -1 || errno != EBUSY) in devstat_getdevs()
399 if (error == -1) { 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()
424 return(-1); 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()
443 * on a core dump, the generation is unlikely to change 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()
451 * The sysctl spits out the generation as the first four bytes, in devstat_getdevs()
454 dinfo->generation = *(long *)dinfo->mem_ptr; in devstat_getdevs()
457 * If the generation has changed, and if the current number of 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
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()
605 return(-1); in devstat_selectdevs()
628 * This is certainly the case if this is our first time through the in devstat_selectdevs()
639 return(-1); in devstat_selectdevs()
660 (*dev_select)[i].device_name[DEVSTAT_NAME_LEN - 1]='\0'; in devstat_selectdevs()
698 * manually specified devices are the first 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()
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()
820 * mode, we de-select the given device and in devstat_selectdevs()
835 (*num_selected)--; in devstat_selectdevs()
851 * At first glance, it may seem wrong that we don't go through and in devstat_selectdevs()
856 * specified anything) the first time through no devices will be in devstat_selectdevs()
874 * the devices that were selected first. in devstat_selectdevs()
999 * backwards -- generally, it should return a value to indicate whether
1002 * order of decreasing performance. We sort on two parameters. The first
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()
1045 return(-1); in devstat_buildmatch()
1063 return(-1); in devstat_buildmatch()
1075 return(-1); in devstat_buildmatch()
1098 tempstr3 = &tempstr2[strlen(tempstr2) - 1]; in devstat_buildmatch()
1103 tempstr3--; in devstat_buildmatch()
1112 * We do case-insensitive matching, in case someone in devstat_buildmatch()
1117 * a super-long match expression. in devstat_buildmatch()
1133 return(-1); in devstat_buildmatch()
1157 return(-1); in devstat_buildmatch()
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()