2005-01-06 23:35:40 +00:00
|
|
|
/*-
|
2017-11-27 15:20:12 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
|
1998-09-15 08:16:17 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-15 08:16:17 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
2003-03-18 09:20:20 +00:00
|
|
|
#include <sys/devicestat.h>
|
2013-10-24 02:39:07 +00:00
|
|
|
#include <sys/sdt.h>
|
1998-09-15 08:16:17 +00:00
|
|
|
#include <sys/sysctl.h>
|
2003-03-08 19:58:57 +00:00
|
|
|
#include <sys/malloc.h>
|
2003-03-18 09:20:20 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2003-03-08 19:58:57 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
1998-09-15 08:16:17 +00:00
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
#include <machine/atomic.h>
|
1998-09-15 08:16:17 +00:00
|
|
|
|
2013-10-24 02:39:07 +00:00
|
|
|
SDT_PROVIDER_DEFINE(io);
|
|
|
|
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE2(io, , , start, "struct bio *", "struct devstat *");
|
|
|
|
SDT_PROBE_DEFINE2(io, , , done, "struct bio *", "struct devstat *");
|
|
|
|
SDT_PROBE_DEFINE2(io, , , wait__start, "struct bio *",
|
2013-10-24 02:39:07 +00:00
|
|
|
"struct devstat *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE2(io, , , wait__done, "struct bio *",
|
2013-10-24 02:39:07 +00:00
|
|
|
"struct devstat *");
|
|
|
|
|
|
|
|
#define DTRACE_DEVSTAT_START() SDT_PROBE2(io, , , start, NULL, ds)
|
|
|
|
#define DTRACE_DEVSTAT_BIO_START() SDT_PROBE2(io, , , start, bp, ds)
|
|
|
|
#define DTRACE_DEVSTAT_DONE() SDT_PROBE2(io, , , done, NULL, ds)
|
|
|
|
#define DTRACE_DEVSTAT_BIO_DONE() SDT_PROBE2(io, , , done, bp, ds)
|
2013-11-26 08:46:27 +00:00
|
|
|
#define DTRACE_DEVSTAT_WAIT_START() SDT_PROBE2(io, , , wait__start, NULL, ds)
|
|
|
|
#define DTRACE_DEVSTAT_WAIT_DONE() SDT_PROBE2(io, , , wait__done, NULL, ds)
|
2012-07-11 16:27:02 +00:00
|
|
|
|
1998-09-15 08:16:17 +00:00
|
|
|
static int devstat_num_devs;
|
2003-08-17 12:06:19 +00:00
|
|
|
static long devstat_generation = 1;
|
1998-09-15 08:16:17 +00:00
|
|
|
static int devstat_version = DEVSTAT_VERSION;
|
|
|
|
static int devstat_current_devnumber;
|
2003-03-18 09:20:20 +00:00
|
|
|
static struct mtx devstat_mutex;
|
2011-06-13 21:21:02 +00:00
|
|
|
MTX_SYSINIT(devstat_mutex, &devstat_mutex, "devstat", MTX_DEF);
|
1998-09-15 08:16:17 +00:00
|
|
|
|
2011-06-13 21:21:02 +00:00
|
|
|
static struct devstatlist device_statq = STAILQ_HEAD_INITIALIZER(device_statq);
|
2003-03-08 19:58:57 +00:00
|
|
|
static struct devstat *devstat_alloc(void);
|
|
|
|
static void devstat_free(struct devstat *);
|
2003-03-18 07:52:59 +00:00
|
|
|
static void devstat_add_entry(struct devstat *ds, const void *dev_name,
|
2010-06-21 09:55:56 +00:00
|
|
|
int unit_number, uint32_t block_size,
|
2003-03-08 21:46:43 +00:00
|
|
|
devstat_support_flags flags,
|
|
|
|
devstat_type_flags device_type,
|
|
|
|
devstat_priority priority);
|
2003-03-08 19:58:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a devstat and initialize it
|
|
|
|
*/
|
|
|
|
struct devstat *
|
2003-03-18 07:52:59 +00:00
|
|
|
devstat_new_entry(const void *dev_name,
|
2010-06-21 09:55:56 +00:00
|
|
|
int unit_number, uint32_t block_size,
|
2003-03-08 19:58:57 +00:00
|
|
|
devstat_support_flags flags,
|
|
|
|
devstat_type_flags device_type,
|
|
|
|
devstat_priority priority)
|
|
|
|
{
|
|
|
|
struct devstat *ds;
|
2003-03-18 09:20:20 +00:00
|
|
|
|
|
|
|
mtx_assert(&devstat_mutex, MA_NOTOWNED);
|
2003-03-08 19:58:57 +00:00
|
|
|
|
|
|
|
ds = devstat_alloc();
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_lock(&devstat_mutex);
|
2003-03-18 09:30:31 +00:00
|
|
|
if (unit_number == -1) {
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
ds->unit_number = unit_number;
|
2003-03-18 09:30:31 +00:00
|
|
|
ds->id = dev_name;
|
|
|
|
binuptime(&ds->creation_time);
|
|
|
|
devstat_generation++;
|
|
|
|
} else {
|
|
|
|
devstat_add_entry(ds, dev_name, unit_number, block_size,
|
|
|
|
flags, device_type, priority);
|
|
|
|
}
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_unlock(&devstat_mutex);
|
2003-03-08 19:58:57 +00:00
|
|
|
return (ds);
|
|
|
|
}
|
1998-09-15 08:16:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a malloced and zeroed devstat structure given to us, fill it in
|
|
|
|
* and add it to the queue of devices.
|
|
|
|
*/
|
2003-03-08 21:46:43 +00:00
|
|
|
static void
|
2003-03-18 07:52:59 +00:00
|
|
|
devstat_add_entry(struct devstat *ds, const void *dev_name,
|
2010-06-21 09:55:56 +00:00
|
|
|
int unit_number, uint32_t block_size,
|
1998-09-15 08:16:17 +00:00
|
|
|
devstat_support_flags flags,
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
devstat_type_flags device_type,
|
|
|
|
devstat_priority priority)
|
1998-09-15 08:16:17 +00:00
|
|
|
{
|
|
|
|
struct devstatlist *devstat_head;
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
struct devstat *ds_tmp;
|
1998-09-15 08:16:17 +00:00
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_assert(&devstat_mutex, MA_OWNED);
|
1998-09-15 08:16:17 +00:00
|
|
|
devstat_num_devs++;
|
|
|
|
|
|
|
|
devstat_head = &device_statq;
|
|
|
|
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
/*
|
|
|
|
* Priority sort. Each driver passes in its priority when it adds
|
|
|
|
* its devstat entry. Drivers are sorted first by priority, and
|
|
|
|
* then by probe order.
|
|
|
|
*
|
|
|
|
* For the first device, we just insert it, since the priority
|
|
|
|
* doesn't really matter yet. Subsequent devices are inserted into
|
|
|
|
* the list using the order outlined above.
|
|
|
|
*/
|
|
|
|
if (devstat_num_devs == 1)
|
|
|
|
STAILQ_INSERT_TAIL(devstat_head, ds, dev_links);
|
|
|
|
else {
|
2001-02-04 16:08:18 +00:00
|
|
|
STAILQ_FOREACH(ds_tmp, devstat_head, dev_links) {
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
struct devstat *ds_next;
|
|
|
|
|
|
|
|
ds_next = STAILQ_NEXT(ds_tmp, dev_links);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we find a break between higher and lower
|
|
|
|
* priority items, and if this item fits in the
|
|
|
|
* break, insert it. This also applies if the
|
|
|
|
* "lower priority item" is the end of the list.
|
|
|
|
*/
|
|
|
|
if ((priority <= ds_tmp->priority)
|
|
|
|
&& ((ds_next == NULL)
|
|
|
|
|| (priority > ds_next->priority))) {
|
|
|
|
STAILQ_INSERT_AFTER(devstat_head, ds_tmp, ds,
|
|
|
|
dev_links);
|
|
|
|
break;
|
|
|
|
} else if (priority > ds_tmp->priority) {
|
|
|
|
/*
|
|
|
|
* If this is the case, we should be able
|
|
|
|
* to insert ourselves at the head of the
|
|
|
|
* list. If we can't, something is wrong.
|
|
|
|
*/
|
|
|
|
if (ds_tmp == STAILQ_FIRST(devstat_head)) {
|
|
|
|
STAILQ_INSERT_HEAD(devstat_head,
|
|
|
|
ds, dev_links);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
STAILQ_INSERT_TAIL(devstat_head,
|
|
|
|
ds, dev_links);
|
|
|
|
printf("devstat_add_entry: HELP! "
|
|
|
|
"sorting problem detected "
|
2003-03-18 07:52:59 +00:00
|
|
|
"for name %p unit %d\n",
|
|
|
|
dev_name, unit_number);
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-15 08:16:17 +00:00
|
|
|
|
|
|
|
ds->device_number = devstat_current_devnumber++;
|
|
|
|
ds->unit_number = unit_number;
|
2002-10-17 20:03:38 +00:00
|
|
|
strlcpy(ds->device_name, dev_name, DEVSTAT_NAME_LEN);
|
1998-09-15 08:16:17 +00:00
|
|
|
ds->block_size = block_size;
|
|
|
|
ds->flags = flags;
|
|
|
|
ds->device_type = device_type;
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
ds->priority = priority;
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
binuptime(&ds->creation_time);
|
2003-03-18 09:20:20 +00:00
|
|
|
devstat_generation++;
|
1998-09-15 08:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a devstat structure from the list of devices.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
devstat_remove_entry(struct devstat *ds)
|
|
|
|
{
|
|
|
|
struct devstatlist *devstat_head;
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_assert(&devstat_mutex, MA_NOTOWNED);
|
1998-09-15 08:16:17 +00:00
|
|
|
if (ds == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_lock(&devstat_mutex);
|
1998-09-15 08:16:17 +00:00
|
|
|
|
|
|
|
devstat_head = &device_statq;
|
|
|
|
|
|
|
|
/* Remove this entry from the devstat queue */
|
2003-03-18 09:20:20 +00:00
|
|
|
atomic_add_acq_int(&ds->sequence1, 1);
|
Merge GEOM direct dispatch changes from the projects/camlock branch.
When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.
The defined now safety requirements are:
- caller should not hold any locks and should be reenterable;
- callee should not depend on GEOM dual-threaded concurency semantics;
- on the way down, if request is unmapped while callee doesn't support it,
the context should be sleepable;
- kernel thread stack usage should be below 50%.
To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
- G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
- G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
- G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
- G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe. If any of requirements are not met, request is queued to
g_up or g_down thread same as before.
Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).
To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION. da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.
This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).
Sponsored by: iXsystems, Inc.
MFC after: 2 months
2013-10-22 08:22:19 +00:00
|
|
|
if (ds->unit_number != -1) {
|
2003-03-18 09:30:31 +00:00
|
|
|
devstat_num_devs--;
|
|
|
|
STAILQ_REMOVE(devstat_head, ds, devstat, dev_links);
|
|
|
|
}
|
2003-03-18 09:20:20 +00:00
|
|
|
devstat_free(ds);
|
|
|
|
devstat_generation++;
|
|
|
|
mtx_unlock(&devstat_mutex);
|
1998-09-15 08:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record a transaction start.
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
*
|
|
|
|
* See comments for devstat_end_transaction(). Ordering is very important
|
|
|
|
* here.
|
1998-09-15 08:16:17 +00:00
|
|
|
*/
|
|
|
|
void
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
devstat_start_transaction(struct devstat *ds, struct bintime *now)
|
1998-09-15 08:16:17 +00:00
|
|
|
{
|
2003-03-18 09:20:20 +00:00
|
|
|
|
|
|
|
mtx_assert(&devstat_mutex, MA_NOTOWNED);
|
|
|
|
|
1998-09-15 08:16:17 +00:00
|
|
|
/* sanity check */
|
|
|
|
if (ds == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
atomic_add_acq_int(&ds->sequence1, 1);
|
1998-09-15 08:16:17 +00:00
|
|
|
/*
|
|
|
|
* We only want to set the start time when we are going from idle
|
|
|
|
* to busy. The start time is really the start of the latest busy
|
|
|
|
* period.
|
|
|
|
*/
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
if (ds->start_count == ds->end_count) {
|
|
|
|
if (now != NULL)
|
|
|
|
ds->busy_from = *now;
|
|
|
|
else
|
|
|
|
binuptime(&ds->busy_from);
|
|
|
|
}
|
|
|
|
ds->start_count++;
|
2003-03-18 09:20:20 +00:00
|
|
|
atomic_add_rel_int(&ds->sequence0, 1);
|
2012-07-11 16:27:02 +00:00
|
|
|
DTRACE_DEVSTAT_START();
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
devstat_start_transaction_bio(struct devstat *ds, struct bio *bp)
|
|
|
|
{
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_assert(&devstat_mutex, MA_NOTOWNED);
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (ds == NULL)
|
|
|
|
return;
|
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
binuptime(&bp->bio_t0);
|
|
|
|
devstat_start_transaction(ds, &bp->bio_t0);
|
2012-07-11 16:27:02 +00:00
|
|
|
DTRACE_DEVSTAT_BIO_START();
|
1998-09-15 08:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record the ending of a transaction, and incrment the various counters.
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
*
|
|
|
|
* Ordering in this function, and in devstat_start_transaction() is VERY
|
|
|
|
* important. The idea here is to run without locks, so we are very
|
|
|
|
* careful to only modify some fields on the way "down" (i.e. at
|
|
|
|
* transaction start) and some fields on the way "up" (i.e. at transaction
|
|
|
|
* completion). One exception is busy_from, which we only modify in
|
|
|
|
* devstat_start_transaction() when there are no outstanding transactions,
|
|
|
|
* and thus it can't be modified in devstat_end_transaction()
|
|
|
|
* simultaneously.
|
2003-03-18 09:20:20 +00:00
|
|
|
*
|
|
|
|
* The sequence0 and sequence1 fields are provided to enable an application
|
|
|
|
* spying on the structures with mmap(2) to tell when a structure is in a
|
|
|
|
* consistent state or not.
|
|
|
|
*
|
|
|
|
* For this to work 100% reliably, it is important that the two fields
|
|
|
|
* are at opposite ends of the structure and that they are incremented
|
|
|
|
* in the opposite order of how a memcpy(3) in userland would copy them.
|
|
|
|
* We assume that the copying happens front to back, but there is actually
|
|
|
|
* no way short of writing your own memcpy(3) replacement to guarantee
|
|
|
|
* this will be the case.
|
|
|
|
*
|
|
|
|
* In addition to this, being a kind of locks, they must be updated with
|
|
|
|
* atomic instructions using appropriate memory barriers.
|
1998-09-15 08:16:17 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-06-21 09:55:56 +00:00
|
|
|
devstat_end_transaction(struct devstat *ds, uint32_t bytes,
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
devstat_tag_type tag_type, devstat_trans_flags flags,
|
|
|
|
struct bintime *now, struct bintime *then)
|
1998-09-15 08:16:17 +00:00
|
|
|
{
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
struct bintime dt, lnow;
|
1998-09-15 08:16:17 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (ds == NULL)
|
|
|
|
return;
|
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
if (now == NULL) {
|
|
|
|
now = &lnow;
|
|
|
|
binuptime(now);
|
|
|
|
}
|
1998-09-15 08:16:17 +00:00
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
atomic_add_acq_int(&ds->sequence1, 1);
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
/* Update byte and operations counts */
|
|
|
|
ds->bytes[flags] += bytes;
|
|
|
|
ds->operations[flags]++;
|
1998-09-15 08:16:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep a count of the various tag types sent.
|
|
|
|
*/
|
1999-09-19 08:28:49 +00:00
|
|
|
if ((ds->flags & DEVSTAT_NO_ORDERED_TAGS) == 0 &&
|
1999-09-18 21:28:09 +00:00
|
|
|
tag_type != DEVSTAT_TAG_NONE)
|
1998-09-15 08:16:17 +00:00
|
|
|
ds->tag_types[tag_type]++;
|
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
if (then != NULL) {
|
|
|
|
/* Update duration of operations */
|
|
|
|
dt = *now;
|
|
|
|
bintime_sub(&dt, then);
|
|
|
|
bintime_add(&ds->duration[flags], &dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Accumulate busy time */
|
|
|
|
dt = *now;
|
|
|
|
bintime_sub(&dt, &ds->busy_from);
|
|
|
|
bintime_add(&ds->busy_time, &dt);
|
|
|
|
ds->busy_from = *now;
|
|
|
|
|
|
|
|
ds->end_count++;
|
2003-03-18 09:20:20 +00:00
|
|
|
atomic_add_rel_int(&ds->sequence0, 1);
|
2012-07-11 16:27:02 +00:00
|
|
|
DTRACE_DEVSTAT_DONE();
|
1998-09-15 08:16:17 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 19:08:05 +00:00
|
|
|
void
|
|
|
|
devstat_end_transaction_bio(struct devstat *ds, struct bio *bp)
|
2013-10-16 09:12:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
devstat_end_transaction_bio_bt(ds, bp, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
devstat_end_transaction_bio_bt(struct devstat *ds, struct bio *bp,
|
|
|
|
struct bintime *now)
|
2000-04-02 19:08:05 +00:00
|
|
|
{
|
|
|
|
devstat_trans_flags flg;
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
/* sanity check */
|
|
|
|
if (ds == NULL)
|
|
|
|
return;
|
|
|
|
|
2000-04-02 19:08:05 +00:00
|
|
|
if (bp->bio_cmd == BIO_DELETE)
|
|
|
|
flg = DEVSTAT_FREE;
|
Add support for managing Shingled Magnetic Recording (SMR) drives.
This change includes support for SCSI SMR drives (which conform to the
Zoned Block Commands or ZBC spec) and ATA SMR drives (which conform to
the Zoned ATA Command Set or ZAC spec) behind SAS expanders.
This includes full management support through the GEOM BIO interface, and
through a new userland utility, zonectl(8), and through camcontrol(8).
This is now ready for filesystems to use to detect and manage zoned drives.
(There is no work in progress that I know of to use this for ZFS or UFS, if
anyone is interested, let me know and I may have some suggestions.)
Also, improve ATA command passthrough and dispatch support, both via ATA
and ATA passthrough over SCSI.
Also, add support to camcontrol(8) for the ATA Extended Power Conditions
feature set. You can now manage ATA device power states, and set various
idle time thresholds for a drive to enter lower power states.
Note that this change cannot be MFCed in full, because it depends on
changes to the struct bio API that break compatilibity. In order to
avoid breaking the stable API, only changes that don't touch or depend on
the struct bio changes can be merged. For example, the camcontrol(8)
changes don't depend on the new bio API, but zonectl(8) and the probe
changes to the da(4) and ada(4) drivers do depend on it.
Also note that the SMR changes have not yet been tested with an actual
SCSI ZBC device, or a SCSI to ATA translation layer (SAT) that supports
ZBC to ZAC translation. I have not yet gotten a suitable drive or SAT
layer, so any testing help would be appreciated. These changes have been
tested with Seagate Host Aware SATA drives attached to both SAS and SATA
controllers. Also, I do not have any SATA Host Managed devices, and I
suspect that it may take additional (hopefully minor) changes to support
them.
Thanks to Seagate for supplying the test hardware and answering questions.
sbin/camcontrol/Makefile:
Add epc.c and zone.c.
sbin/camcontrol/camcontrol.8:
Document the zone and epc subcommands.
sbin/camcontrol/camcontrol.c:
Add the zone and epc subcommands.
Add auxiliary register support to build_ata_cmd(). Make sure to
set the CAM_ATAIO_NEEDRESULT, CAM_ATAIO_DMA, and CAM_ATAIO_FPDMA
flags as appropriate for ATA commands.
Add a new get_ata_status() function to parse ATA result from SCSI
sense descriptors (for ATA passthrough over SCSI) and ATA I/O
requests.
sbin/camcontrol/camcontrol.h:
Update the build_ata_cmd() prototype
Add get_ata_status(), zone(), and epc().
sbin/camcontrol/epc.c:
Support for ATA Extended Power Conditions features. This includes
support for all features documented in the ACS-4 Revision 12
specification from t13.org (dated February 18, 2016).
The EPC feature set allows putting a drive into a power power mode
immediately, or setting timeouts so that the drive will
automatically enter progressively lower power states after various
idle times.
sbin/camcontrol/fwdownload.c:
Update the firmware download code for the new build_ata_cmd()
arguments.
sbin/camcontrol/zone.c:
Implement support for Shingled Magnetic Recording (SMR) drives
via SCSI Zoned Block Commands (ZBC) and ATA Zoned Device ATA
Command Set (ZAC).
These specs were developed in concert, and are functionally
identical. The primary differences are due to SCSI and ATA
differences. (SCSI is big endian, ATA is little endian, for
example.)
This includes support for all commands defined in the ZBC and
ZAC specs.
sys/cam/ata/ata_all.c:
Decode a number of additional ATA command names in ata_op_string().
Add a new CCB building function, ata_read_log().
Add ata_zac_mgmt_in() and ata_zac_mgmt_out() CCB building
functions. These support both DMA and NCQ encapsulation.
sys/cam/ata/ata_all.h:
Add prototypes for ata_read_log(), ata_zac_mgmt_out(), and
ata_zac_mgmt_in().
sys/cam/ata/ata_da.c:
Revamp the ada(4) driver to support zoned devices.
Add four new probe states to gather information needed for zone
support.
Add a new adasetflags() function to avoid duplication of large
blocks of flag setting between the async handler and register
functions.
Add new sysctl variables that describe zone support and paramters.
Add support for the new BIO_ZONE bio, and all of its subcommands:
DISK_ZONE_OPEN, DISK_ZONE_CLOSE, DISK_ZONE_FINISH, DISK_ZONE_RWP,
DISK_ZONE_REPORT_ZONES, and DISK_ZONE_GET_PARAMS.
sys/cam/scsi/scsi_all.c:
Add command descriptions for the ZBC IN/OUT commands.
Add descriptions for ZBC Host Managed devices.
Add a new function, scsi_ata_pass() to do ATA passthrough over
SCSI. This will eventually replace scsi_ata_pass_16() -- it
can create the 12, 16, and 32-byte variants of the ATA
PASS-THROUGH command, and supports setting all of the
registers defined as of SAT-4, Revision 5 (March 11, 2016).
Change scsi_ata_identify() to use scsi_ata_pass() instead of
scsi_ata_pass_16().
Add a new scsi_ata_read_log() function to facilitate reading
ATA logs via SCSI.
sys/cam/scsi/scsi_all.h:
Add the new ATA PASS-THROUGH(32) command CDB. Add extended and
variable CDB opcodes.
Add Zoned Block Device Characteristics VPD page.
Add ATA Return SCSI sense descriptor.
Add prototypes for scsi_ata_read_log() and scsi_ata_pass().
sys/cam/scsi/scsi_da.c:
Revamp the da(4) driver to support zoned devices.
Add five new probe states, four of which are needed for ATA
devices.
Add five new sysctl variables that describe zone support and
parameters.
The da(4) driver supports SCSI ZBC devices, as well as ATA ZAC
devices when they are attached via a SCSI to ATA Translation (SAT)
layer. Since ZBC -> ZAC translation is a new feature in the T10
SAT-4 spec, most SATA drives will be supported via ATA commands
sent via the SCSI ATA PASS-THROUGH command. The da(4) driver will
prefer the ZBC interface, if it is available, for performance
reasons, but will use the ATA PASS-THROUGH interface to the ZAC
command set if the SAT layer doesn't support translation yet.
As I mentioned above, ZBC command support is untested.
Add support for the new BIO_ZONE bio, and all of its subcommands:
DISK_ZONE_OPEN, DISK_ZONE_CLOSE, DISK_ZONE_FINISH, DISK_ZONE_RWP,
DISK_ZONE_REPORT_ZONES, and DISK_ZONE_GET_PARAMS.
Add scsi_zbc_in() and scsi_zbc_out() CCB building functions.
Add scsi_ata_zac_mgmt_out() and scsi_ata_zac_mgmt_in() CCB/CDB
building functions. Note that these have return values, unlike
almost all other CCB building functions in CAM. The reason is
that they can fail, depending upon the particular combination
of input parameters. The primary failure case is if the user
wants NCQ, but fails to specify additional CDB storage. NCQ
requires using the 32-byte version of the SCSI ATA PASS-THROUGH
command, and the current CAM CDB size is 16 bytes.
sys/cam/scsi/scsi_da.h:
Add ZBC IN and ZBC OUT CDBs and opcodes.
Add SCSI Report Zones data structures.
Add scsi_zbc_in(), scsi_zbc_out(), scsi_ata_zac_mgmt_out(), and
scsi_ata_zac_mgmt_in() prototypes.
sys/dev/ahci/ahci.c:
Fix SEND / RECEIVE FPDMA QUEUED in the ahci(4) driver.
ahci_setup_fis() previously set the top bits of the sector count
register in the FIS to 0 for FPDMA commands. This is okay for
read and write, because the PRIO field is in the only thing in
those bits, and we don't implement that further up the stack.
But, for SEND and RECEIVE FPDMA QUEUED, the subcommand is in that
byte, so it needs to be transmitted to the drive.
In ahci_setup_fis(), always set the the top 8 bits of the
sector count register. We need it in both the standard
and NCQ / FPDMA cases.
sys/geom/eli/g_eli.c:
Pass BIO_ZONE commands through the GELI class.
sys/geom/geom.h:
Add g_io_zonecmd() prototype.
sys/geom/geom_dev.c:
Add new DIOCZONECMD ioctl, which allows sending zone commands to
disks.
sys/geom/geom_disk.c:
Add support for BIO_ZONE commands.
sys/geom/geom_disk.h:
Add a new flag, DISKFLAG_CANZONE, that indicates that a given
GEOM disk client can handle BIO_ZONE commands.
sys/geom/geom_io.c:
Add a new function, g_io_zonecmd(), that handles execution of
BIO_ZONE commands.
Add permissions check for BIO_ZONE commands.
Add command decoding for BIO_ZONE commands.
sys/geom/geom_subr.c:
Add DDB command decoding for BIO_ZONE commands.
sys/kern/subr_devstat.c:
Record statistics for REPORT ZONES commands. Note that the
number of bytes transferred for REPORT ZONES won't quite match
what is received from the harware. This is because we're
necessarily counting bytes coming from the da(4) / ada(4) drivers,
which are using the disk_zone.h interface to communicate up
the stack. The structure sizes it uses are slightly different
than the SCSI and ATA structure sizes.
sys/sys/ata.h:
Add many bit and structure definitions for ZAC, NCQ, and EPC
command support.
sys/sys/bio.h:
Convert the bio_cmd field to a straight enumeration. This will
yield more space for additional commands in the future. After
change r297955 and other related changes, this is now possible.
Converting to an enumeration will also prevent use as a bitmask
in the future.
sys/sys/disk.h:
Define the DIOCZONECMD ioctl.
sys/sys/disk_zone.h:
Add a new API for managing zoned disks. This is very close to
the SCSI ZBC and ATA ZAC standards, but uses integers in native
byte order instead of big endian (SCSI) or little endian (ATA)
byte arrays.
This is intended to offer to the complete feature set of the ZBC
and ZAC disk management without requiring the application developer
to include SCSI or ATA headers. We also use one set of headers
for ioctl consumers and kernel bio-level consumers.
sys/sys/param.h:
Bump __FreeBSD_version for sys/bio.h command changes, and inclusion
of SMR support.
usr.sbin/Makefile:
Add the zonectl utility.
usr.sbin/diskinfo/diskinfo.c
Add disk zoning capability to the 'diskinfo -v' output.
usr.sbin/zonectl/Makefile:
Add zonectl makefile.
usr.sbin/zonectl/zonectl.8
zonectl(8) man page.
usr.sbin/zonectl/zonectl.c
The zonectl(8) utility. This allows managing SCSI or ATA zoned
disks via the disk_zone.h API. You can report zones, reset write
pointers, get parameters, etc.
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D6147
Reviewed by: wblock (documentation)
2016-05-19 14:08:36 +00:00
|
|
|
else if ((bp->bio_cmd == BIO_READ)
|
|
|
|
|| ((bp->bio_cmd == BIO_ZONE)
|
|
|
|
&& (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)))
|
2000-04-02 19:08:05 +00:00
|
|
|
flg = DEVSTAT_READ;
|
2003-03-18 09:20:20 +00:00
|
|
|
else if (bp->bio_cmd == BIO_WRITE)
|
2000-04-02 19:08:05 +00:00
|
|
|
flg = DEVSTAT_WRITE;
|
2003-03-18 09:20:20 +00:00
|
|
|
else
|
|
|
|
flg = DEVSTAT_NO_DATA;
|
2000-04-02 19:08:05 +00:00
|
|
|
|
|
|
|
devstat_end_transaction(ds, bp->bio_bcount - bp->bio_resid,
|
2013-10-16 09:12:40 +00:00
|
|
|
DEVSTAT_TAG_SIMPLE, flg, now, &bp->bio_t0);
|
2012-07-11 16:27:02 +00:00
|
|
|
DTRACE_DEVSTAT_BIO_DONE();
|
2000-04-02 19:08:05 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 08:16:17 +00:00
|
|
|
/*
|
|
|
|
* This is the sysctl handler for the devstat package. The data pushed out
|
|
|
|
* on the kern.devstat.all sysctl variable consists of the current devstat
|
|
|
|
* generation number, and then an array of devstat structures, one for each
|
|
|
|
* device in the system.
|
|
|
|
*
|
2003-03-18 09:20:20 +00:00
|
|
|
* This is more cryptic that obvious, but basically we neither can nor
|
|
|
|
* want to hold the devstat_mutex for any amount of time, so we grab it
|
|
|
|
* only when we need to and keep an eye on devstat_generation all the time.
|
1998-09-15 08:16:17 +00:00
|
|
|
*/
|
|
|
|
static int
|
2000-07-04 11:25:35 +00:00
|
|
|
sysctl_devstat(SYSCTL_HANDLER_ARGS)
|
1998-09-15 08:16:17 +00:00
|
|
|
{
|
2003-03-18 09:20:20 +00:00
|
|
|
int error;
|
2003-04-17 15:06:28 +00:00
|
|
|
long mygen;
|
1998-09-15 08:16:17 +00:00
|
|
|
struct devstat *nds;
|
2003-03-18 09:20:20 +00:00
|
|
|
|
|
|
|
mtx_assert(&devstat_mutex, MA_NOTOWNED);
|
1998-09-15 08:16:17 +00:00
|
|
|
|
|
|
|
/*
|
2003-03-18 09:20:20 +00:00
|
|
|
* XXX devstat_generation should really be "volatile" but that
|
|
|
|
* XXX freaks out the sysctl macro below. The places where we
|
|
|
|
* XXX change it and inspect it are bracketed in the mutex which
|
2016-04-29 22:15:33 +00:00
|
|
|
* XXX guarantees us proper write barriers. I don't believe the
|
2003-03-18 09:20:20 +00:00
|
|
|
* XXX compiler is allowed to optimize mygen away across calls
|
|
|
|
* XXX to other functions, so the following is belived to be safe.
|
1998-09-15 08:16:17 +00:00
|
|
|
*/
|
2003-03-18 09:20:20 +00:00
|
|
|
mygen = devstat_generation;
|
1998-09-15 08:16:17 +00:00
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
error = SYSCTL_OUT(req, &mygen, sizeof(mygen));
|
|
|
|
|
2003-08-17 12:06:19 +00:00
|
|
|
if (devstat_num_devs == 0)
|
|
|
|
return(0);
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
1998-09-15 08:16:17 +00:00
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_lock(&devstat_mutex);
|
|
|
|
nds = STAILQ_FIRST(&device_statq);
|
|
|
|
if (mygen != devstat_generation)
|
|
|
|
error = EBUSY;
|
|
|
|
mtx_unlock(&devstat_mutex);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
for (;nds != NULL;) {
|
|
|
|
error = SYSCTL_OUT(req, nds, sizeof(struct devstat));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
mtx_lock(&devstat_mutex);
|
|
|
|
if (mygen != devstat_generation)
|
|
|
|
error = EBUSY;
|
|
|
|
else
|
|
|
|
nds = STAILQ_NEXT(nds, dev_links);
|
|
|
|
mtx_unlock(&devstat_mutex);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
}
|
1998-09-15 08:16:17 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sysctl entries for devstat. The first one is a node that all the rest
|
|
|
|
* hang off of.
|
|
|
|
*/
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_kern, OID_AUTO, devstat, CTLFLAG_RD, NULL,
|
|
|
|
"Device Statistics");
|
1998-09-15 08:16:17 +00:00
|
|
|
|
|
|
|
SYSCTL_PROC(_kern_devstat, OID_AUTO, all, CTLFLAG_RD|CTLTYPE_OPAQUE,
|
2009-02-03 07:54:42 +00:00
|
|
|
NULL, 0, sysctl_devstat, "S,devstat", "All devices in the devstat list");
|
1998-09-15 08:16:17 +00:00
|
|
|
/*
|
|
|
|
* Export the number of devices in the system so that userland utilities
|
|
|
|
* can determine how much memory to allocate to hold all the devices.
|
|
|
|
*/
|
1999-05-03 23:57:32 +00:00
|
|
|
SYSCTL_INT(_kern_devstat, OID_AUTO, numdevs, CTLFLAG_RD,
|
|
|
|
&devstat_num_devs, 0, "Number of devices in the devstat list");
|
2003-04-17 15:06:28 +00:00
|
|
|
SYSCTL_LONG(_kern_devstat, OID_AUTO, generation, CTLFLAG_RD,
|
2000-07-05 07:46:41 +00:00
|
|
|
&devstat_generation, 0, "Devstat list generation");
|
1999-05-03 23:57:32 +00:00
|
|
|
SYSCTL_INT(_kern_devstat, OID_AUTO, version, CTLFLAG_RD,
|
|
|
|
&devstat_version, 0, "Devstat list version number");
|
2003-03-08 19:58:57 +00:00
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
/*
|
|
|
|
* Allocator for struct devstat structures. We sub-allocate these from pages
|
|
|
|
* which we get from malloc. These pages are exported for mmap(2)'ing through
|
|
|
|
* a miniature device driver
|
|
|
|
*/
|
|
|
|
|
2003-03-08 19:58:57 +00:00
|
|
|
#define statsperpage (PAGE_SIZE / sizeof(struct devstat))
|
|
|
|
|
|
|
|
static d_mmap_t devstat_mmap;
|
|
|
|
|
|
|
|
static struct cdevsw devstat_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-03-08 19:58:57 +00:00
|
|
|
.d_mmap = devstat_mmap,
|
|
|
|
.d_name = "devstat",
|
|
|
|
};
|
|
|
|
|
|
|
|
struct statspage {
|
|
|
|
TAILQ_ENTRY(statspage) list;
|
|
|
|
struct devstat *stat;
|
|
|
|
u_int nfree;
|
|
|
|
};
|
|
|
|
|
|
|
|
static TAILQ_HEAD(, statspage) pagelist = TAILQ_HEAD_INITIALIZER(pagelist);
|
|
|
|
static MALLOC_DEFINE(M_DEVSTAT, "devstat", "Device statistics");
|
|
|
|
|
|
|
|
static int
|
2009-12-29 21:51:28 +00:00
|
|
|
devstat_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
|
|
|
|
int nprot, vm_memattr_t *memattr)
|
2003-03-08 19:58:57 +00:00
|
|
|
{
|
|
|
|
struct statspage *spp;
|
|
|
|
|
|
|
|
if (nprot != VM_PROT_READ)
|
|
|
|
return (-1);
|
2014-03-24 18:13:41 +00:00
|
|
|
mtx_lock(&devstat_mutex);
|
2003-03-08 19:58:57 +00:00
|
|
|
TAILQ_FOREACH(spp, &pagelist, list) {
|
|
|
|
if (offset == 0) {
|
|
|
|
*paddr = vtophys(spp->stat);
|
2014-03-24 18:13:41 +00:00
|
|
|
mtx_unlock(&devstat_mutex);
|
2003-03-08 19:58:57 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
offset -= PAGE_SIZE;
|
|
|
|
}
|
2014-03-24 18:13:41 +00:00
|
|
|
mtx_unlock(&devstat_mutex);
|
2003-03-08 19:58:57 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct devstat *
|
|
|
|
devstat_alloc(void)
|
|
|
|
{
|
|
|
|
struct devstat *dsp;
|
2009-09-18 13:48:38 +00:00
|
|
|
struct statspage *spp, *spp2;
|
2003-03-08 19:58:57 +00:00
|
|
|
u_int u;
|
|
|
|
static int once;
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_assert(&devstat_mutex, MA_NOTOWNED);
|
2011-06-13 22:08:24 +00:00
|
|
|
if (!once) {
|
|
|
|
make_dev_credf(MAKEDEV_ETERNAL | MAKEDEV_CHECKNAME,
|
2014-03-24 18:13:41 +00:00
|
|
|
&devstat_cdevsw, 0, NULL, UID_ROOT, GID_WHEEL, 0444,
|
2011-06-13 22:08:24 +00:00
|
|
|
DEVSTAT_DEVICE_NAME);
|
|
|
|
once = 1;
|
2003-03-08 19:58:57 +00:00
|
|
|
}
|
2009-09-18 13:48:38 +00:00
|
|
|
spp2 = NULL;
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_lock(&devstat_mutex);
|
|
|
|
for (;;) {
|
|
|
|
TAILQ_FOREACH(spp, &pagelist, list) {
|
|
|
|
if (spp->nfree > 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (spp != NULL)
|
2003-03-08 19:58:57 +00:00
|
|
|
break;
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_unlock(&devstat_mutex);
|
2009-09-18 13:48:38 +00:00
|
|
|
spp2 = malloc(sizeof *spp, M_DEVSTAT, M_ZERO | M_WAITOK);
|
|
|
|
spp2->stat = malloc(PAGE_SIZE, M_DEVSTAT, M_ZERO | M_WAITOK);
|
|
|
|
spp2->nfree = statsperpage;
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
/*
|
2009-09-18 13:48:38 +00:00
|
|
|
* If free statspages were added while the lock was released
|
|
|
|
* just reuse them.
|
2003-03-18 09:20:20 +00:00
|
|
|
*/
|
2009-09-18 13:48:38 +00:00
|
|
|
mtx_lock(&devstat_mutex);
|
|
|
|
TAILQ_FOREACH(spp, &pagelist, list)
|
|
|
|
if (spp->nfree > 0)
|
|
|
|
break;
|
|
|
|
if (spp == NULL) {
|
|
|
|
spp = spp2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It would make more sense to add the new page at the
|
|
|
|
* head but the order on the list determine the
|
|
|
|
* sequence of the mapping so we can't do that.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_TAIL(&pagelist, spp, list);
|
|
|
|
} else
|
|
|
|
break;
|
2003-03-08 19:58:57 +00:00
|
|
|
}
|
|
|
|
dsp = spp->stat;
|
|
|
|
for (u = 0; u < statsperpage; u++) {
|
|
|
|
if (dsp->allocated == 0)
|
|
|
|
break;
|
|
|
|
dsp++;
|
|
|
|
}
|
|
|
|
spp->nfree--;
|
|
|
|
dsp->allocated = 1;
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_unlock(&devstat_mutex);
|
2009-09-18 13:48:38 +00:00
|
|
|
if (spp2 != NULL && spp2 != spp) {
|
|
|
|
free(spp2->stat, M_DEVSTAT);
|
|
|
|
free(spp2, M_DEVSTAT);
|
|
|
|
}
|
2003-03-08 19:58:57 +00:00
|
|
|
return (dsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
devstat_free(struct devstat *dsp)
|
|
|
|
{
|
|
|
|
struct statspage *spp;
|
|
|
|
|
2003-03-18 09:20:20 +00:00
|
|
|
mtx_assert(&devstat_mutex, MA_OWNED);
|
2003-03-08 19:58:57 +00:00
|
|
|
bzero(dsp, sizeof *dsp);
|
|
|
|
TAILQ_FOREACH(spp, &pagelist, list) {
|
|
|
|
if (dsp >= spp->stat && dsp < (spp->stat + statsperpage)) {
|
|
|
|
spp->nfree++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
|
|
|
|
SYSCTL_INT(_debug_sizeof, OID_AUTO, devstat, CTLFLAG_RD,
|
2014-10-21 07:31:21 +00:00
|
|
|
SYSCTL_NULL_INT_PTR, sizeof(struct devstat), "sizeof(struct devstat)");
|