summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/geom/geom.h4
-rw-r--r--sys/geom/geom_int.h5
-rw-r--r--sys/geom/geom_io.c68
-rw-r--r--sys/geom/geom_kern.c4
-rw-r--r--sys/geom/geom_stats.c137
-rw-r--r--sys/geom/geom_stats.h87
-rw-r--r--sys/geom/geom_subr.c11
7 files changed, 16 insertions, 300 deletions
diff --git a/sys/geom/geom.h b/sys/geom/geom.h
index 6aba180..169da26 100644
--- a/sys/geom/geom.h
+++ b/sys/geom/geom.h
@@ -151,7 +151,7 @@ struct g_consumer {
int acr, acw, ace;
struct g_event *event;
int spoiled;
- struct g_stat *stat;
+ struct devstat *stat;
u_int nstart, nend;
};
@@ -173,7 +173,7 @@ struct g_provider {
u_int sectorsize;
u_int stripesize;
u_int stripeoffset;
- struct g_stat *stat;
+ struct devstat *stat;
u_int nstart, nend;
u_int flags;
#define G_PF_CANDELETE 0x1
diff --git a/sys/geom/geom_int.h b/sys/geom/geom_int.h
index cd67d19..81f8069 100644
--- a/sys/geom/geom_int.h
+++ b/sys/geom/geom_int.h
@@ -103,8 +103,3 @@ void g_io_schedule_up(struct thread *tp);
/* geom_kern.c / geom_kernsim.c */
void g_init(void);
-
-/* geom_stats.c */
-void g_stat_init(void);
-struct g_stat *g_stat_new(void *id);
-void g_stat_delete(struct g_stat *);
diff --git a/sys/geom/geom_io.c b/sys/geom/geom_io.c
index e67738a..d631670 100644
--- a/sys/geom/geom_io.c
+++ b/sys/geom/geom_io.c
@@ -54,7 +54,7 @@
#include <sys/errno.h>
#include <geom/geom.h>
#include <geom/geom_int.h>
-#include <geom/geom_stats.h>
+#include <sys/devicestat.h>
static struct g_bioq g_bio_run_down;
static struct g_bioq g_bio_run_up;
@@ -264,7 +264,6 @@ void
g_io_request(struct bio *bp, struct g_consumer *cp)
{
struct g_provider *pp;
- struct bintime bt;
pp = cp->provider;
KASSERT(cp != NULL, ("NULL cp in g_io_request"));
@@ -278,14 +277,8 @@ g_io_request(struct bio *bp, struct g_consumer *cp)
bp->bio_completed = 0;
if (g_collectstats) {
- binuptime(&bt);
- bp->bio_t0 = bt;
- if (cp->nstart == cp->nend)
- cp->stat->wentbusy = bt; /* Consumer is idle */
- if (pp->nstart == pp->nend)
- pp->stat->wentbusy = bt; /* Provider is idle */
- cp->stat->nop++;
- pp->stat->nop++;
+ devstat_start_transaction_bio(cp->stat, bp);
+ devstat_start_transaction_bio(pp->stat, bp);
}
cp->nstart++;
pp->nstart++;
@@ -302,8 +295,6 @@ g_io_deliver(struct bio *bp, int error)
{
struct g_consumer *cp;
struct g_provider *pp;
- struct bintime t1, dt;
- int idx;
cp = bp->bio_from;
pp = bp->bio_to;
@@ -317,56 +308,11 @@ g_io_deliver(struct bio *bp, int error)
bp, cp, cp->geom->name, pp, pp->name, bp->bio_cmd, error,
(intmax_t)bp->bio_offset, (intmax_t)bp->bio_length);
+ bp->bio_bcount = bp->bio_length;
if (g_collectstats) {
- switch (bp->bio_cmd) {
- case BIO_READ: idx = G_STAT_IDX_READ; break;
- case BIO_WRITE: idx = G_STAT_IDX_WRITE; break;
- case BIO_DELETE: idx = G_STAT_IDX_DELETE; break;
- case BIO_GETATTR: idx = -1; break;
- case BIO_SETATTR: idx = -1; break;
- default:
- panic("unknown bio_cmd in g_io_deliver");
- break;
- }
- binuptime(&t1);
- /* Raise the "inconsistent" flag for userland */
- atomic_add_acq_int(&cp->stat->seq0, 1);
- atomic_add_acq_int(&pp->stat->seq0, 1);
- if (idx >= 0) {
- /* Account the service time */
- dt = t1;
- bintime_sub(&dt, &bp->bio_t0);
- bintime_add(&cp->stat->ops[idx].dt, &dt);
- bintime_add(&pp->stat->ops[idx].dt, &dt);
- /* ... and the metrics */
- pp->stat->ops[idx].nbyte += bp->bio_completed;
- cp->stat->ops[idx].nbyte += bp->bio_completed;
- pp->stat->ops[idx].nop++;
- cp->stat->ops[idx].nop++;
- /* ... and any errors */
- if (error == ENOMEM) {
- cp->stat->ops[idx].nmem++;
- pp->stat->ops[idx].nmem++;
- } else if (error != 0) {
- cp->stat->ops[idx].nerr++;
- pp->stat->ops[idx].nerr++;
- }
- }
- /* Account for busy time on the consumer */
- dt = t1;
- bintime_sub(&dt, &cp->stat->wentbusy);
- bintime_add(&cp->stat->bt, &dt);
- cp->stat->wentbusy = t1;
- /* Account for busy time on the provider */
- dt = t1;
- bintime_sub(&dt, &pp->stat->wentbusy);
- bintime_add(&pp->stat->bt, &dt);
- pp->stat->wentbusy = t1;
- /* Mark the structures as consistent again */
- atomic_add_acq_int(&cp->stat->seq1, 1);
- atomic_add_acq_int(&pp->stat->seq1, 1);
- cp->stat->nend++;
- pp->stat->nend++;
+ bp->bio_resid = bp->bio_bcount - bp->bio_completed;
+ devstat_end_transaction_bio(cp->stat, bp);
+ devstat_end_transaction_bio(pp->stat, bp);
}
cp->nend++;
pp->nend++;
diff --git a/sys/geom/geom_kern.c b/sys/geom/geom_kern.c
index 6f2dc65..d8ab014 100644
--- a/sys/geom/geom_kern.c
+++ b/sys/geom/geom_kern.c
@@ -49,7 +49,6 @@
#include <sys/sbuf.h>
#include <geom/geom.h>
#include <geom/geom_int.h>
-#include <geom/geom_stats.h>
MALLOC_DEFINE(M_GEOM, "GEOM", "Geom data structures");
@@ -144,7 +143,6 @@ void
g_init(void)
{
sx_init(&topology_lock, "GEOM topology");
- g_stat_init();
g_io_init();
g_event_init();
mtx_lock(&Giant);
@@ -237,5 +235,3 @@ SYSCTL_INT(_debug_sizeof, OID_AUTO, g_bioq, CTLFLAG_RD,
0, sizeof(struct g_bioq), "");
SYSCTL_INT(_debug_sizeof, OID_AUTO, g_event, CTLFLAG_RD,
0, sizeof(struct g_event), "");
-SYSCTL_INT(_debug_sizeof, OID_AUTO, g_stat, CTLFLAG_RD,
- 0, sizeof(struct g_stat), "");
diff --git a/sys/geom/geom_stats.c b/sys/geom/geom_stats.c
deleted file mode 100644
index 03e1c75..0000000
--- a/sys/geom/geom_stats.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*-
- * Copyright (c) 2002 Poul-Henning Kamp
- * 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 names of the authors 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.
- *
- * $FreeBSD$
- */
-
-#include "opt_geom.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/bio.h>
-#include <sys/conf.h>
-#include <sys/disk.h>
-#include <sys/malloc.h>
-#include <sys/sysctl.h>
-#include <vm/vm.h>
-#include <vm/pmap.h>
-
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <geom/geom.h>
-#include <geom/geom_int.h>
-#include <geom/geom_stats.h>
-
-#define statsperpage (PAGE_SIZE / sizeof(struct g_stat))
-
-struct statspage {
- TAILQ_ENTRY(statspage) list;
- struct g_stat *stat;
- u_int nfree;
-};
-
-static TAILQ_HEAD(, statspage) pagelist = TAILQ_HEAD_INITIALIZER(pagelist);
-
-struct g_stat *
-g_stat_new(void *id)
-{
- struct g_stat *gsp;
- struct statspage *spp;
- u_int u;
-
- g_topology_assert();
- TAILQ_FOREACH(spp, &pagelist, list) {
- if (spp->nfree > 0)
- break;
- }
- if (spp == NULL) {
- spp = g_malloc(sizeof *spp, M_ZERO | M_WAITOK);
- TAILQ_INSERT_TAIL(&pagelist, spp, list);
- spp->stat = g_malloc(PAGE_SIZE, M_ZERO | M_WAITOK);
- spp->nfree = statsperpage;
- }
- gsp = spp->stat;
- for (u = 0; u < statsperpage; u++) {
- if (gsp->id == NULL)
- break;
- gsp++;
- }
- spp->nfree--;
- gsp->id = id;
- return (gsp);
-}
-
-void
-g_stat_delete(struct g_stat *gsp)
-{
- struct statspage *spp;
-
- bzero(gsp, sizeof *gsp);
- TAILQ_FOREACH(spp, &pagelist, list) {
- if (gsp >= spp->stat && gsp < (spp->stat + statsperpage)) {
- spp->nfree++;
- return;
- }
- }
-}
-
-static d_mmap_t g_stat_mmap;
-
-static struct cdevsw geom_stats_cdevsw = {
- .d_open = nullopen,
- .d_close = nullclose,
- .d_mmap = g_stat_mmap,
- .d_name = "g_stats",
- .d_maj = GEOM_MAJOR,
-};
-
-static int
-g_stat_mmap(dev_t dev, vm_offset_t offset, vm_offset_t *paddr, int nprot)
-{
- struct statspage *spp;
-
- if (nprot != VM_PROT_READ)
- return (-1);
- TAILQ_FOREACH(spp, &pagelist, list) {
- if (offset == 0) {
- *paddr = vtophys(spp->stat);
- return (0);
- }
- offset -= PAGE_SIZE;
- }
- return (-1);
-}
-
-void
-g_stat_init(void)
-{
- make_dev(&geom_stats_cdevsw, GEOM_MINOR_STATS,
- UID_ROOT, GID_WHEEL, 0400, GEOM_STATS_DEVICE);
-}
diff --git a/sys/geom/geom_stats.h b/sys/geom/geom_stats.h
deleted file mode 100644
index 1c13adf..0000000
--- a/sys/geom/geom_stats.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * Copyright (c) 2002 Poul-Henning Kamp
- *
- * 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 names of the authors 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.
- *
- * $FreeBSD$
- */
-
-#ifndef _GEOM_GEOM_STATS_H_
-#define _GEOM_GEOM_STATS_H_
-
-#define GEOM_STATS_DEVICE "geom.stats"
-
-/*
- * A g_stat contains the statistics the kernel collect on consumers and
- * providers. See libgeom(3) for how to get hold of these.
- */
-struct g_stat {
- int seq0;
- /*
- * Sequence number, used with seq1 to determine
- * if snapshot is consistent.
- */
-
- void *id;
- /* GEOM-identifier for the consumer/provider */
-
- uint64_t nop;
- /* Number of requests started */
-
- uint64_t nend;
- /* Number of requests completed */
-
- struct bintime bt;
- /* Accumulated busy time */
-
- struct bintime wentbusy;
- /* Busy time accounted for until here */
- struct {
- uint64_t nop;
- /* Number of requests completed */
-
- uint64_t nbyte;
- /* Number of bytes completed */
-
- uint64_t nmem;
- /* Number of ENOMEM request errors */
-
- uint64_t nerr;
- /* Number of other request errors */
-
- struct bintime dt;
- /* Accumulated request processing time */
-
- } ops[3];
-
-#define G_STAT_IDX_READ 0
-#define G_STAT_IDX_WRITE 1
-#define G_STAT_IDX_DELETE 2
-
- int seq1;
- /* See seq0 */
-};
-
-#endif /* _GEOM_GEOM_STATS_H_ */
diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c
index e76a71d..b5c1861 100644
--- a/sys/geom/geom_subr.c
+++ b/sys/geom/geom_subr.c
@@ -46,6 +46,7 @@
#include <err.h>
#else
#include <sys/systm.h>
+#include <sys/devicestat.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bio.h>
@@ -144,7 +145,8 @@ g_new_consumer(struct g_geom *gp)
cp = g_malloc(sizeof *cp, M_WAITOK | M_ZERO);
cp->protect = 0x020016602;
cp->geom = gp;
- cp->stat = g_stat_new(cp);
+ cp->stat = devstat_new_entry(cp, -1, 0, DEVSTAT_ALL_SUPPORTED,
+ DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
LIST_INSERT_HEAD(&gp->consumer, cp, consumer);
return(cp);
}
@@ -161,7 +163,7 @@ g_destroy_consumer(struct g_consumer *cp)
KASSERT (cp->acw == 0, ("g_destroy_consumer with acw"));
KASSERT (cp->ace == 0, ("g_destroy_consumer with ace"));
LIST_REMOVE(cp, consumer);
- g_stat_delete(cp->stat);
+ devstat_remove_entry(cp->stat);
g_free(cp);
}
@@ -185,7 +187,8 @@ g_new_providerf(struct g_geom *gp, const char *fmt, ...)
LIST_INIT(&pp->consumers);
pp->error = ENXIO;
pp->geom = gp;
- pp->stat = g_stat_new(pp);
+ pp->stat = devstat_new_entry(pp, -1, 0, DEVSTAT_ALL_SUPPORTED,
+ DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
LIST_INSERT_HEAD(&gp->provider, pp, provider);
g_nproviders++;
g_post_event(EV_NEW_PROVIDER, NULL, NULL, pp, NULL);
@@ -216,7 +219,7 @@ g_destroy_provider(struct g_provider *pp)
g_nproviders--;
LIST_REMOVE(pp, provider);
gp = pp->geom;
- g_stat_delete(pp->stat);
+ devstat_remove_entry(pp->stat);
g_free(pp);
if (!(gp->flags & G_GEOM_WITHER))
return;
OpenPOWER on IntegriCloud