Deleted Added
full compact
subr_devstat.c (227309) subr_devstat.c (238366)
1/*-
2 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/kern/subr_devstat.c 227309 2011-11-07 15:43:11Z ed $");
30__FBSDID("$FreeBSD: head/sys/kern/subr_devstat.c 238366 2012-07-11 16:27:02Z gnn $");
31
31
32#include "opt_kdtrace.h"
33
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/systm.h>
35#include <sys/bio.h>
36#include <sys/devicestat.h>
37#include <sys/sysctl.h>
38#include <sys/malloc.h>
39#include <sys/lock.h>
40#include <sys/mutex.h>
41#include <sys/conf.h>
42#include <vm/vm.h>
43#include <vm/pmap.h>
44
45#include <machine/atomic.h>
46
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/systm.h>
37#include <sys/bio.h>
38#include <sys/devicestat.h>
39#include <sys/sysctl.h>
40#include <sys/malloc.h>
41#include <sys/lock.h>
42#include <sys/mutex.h>
43#include <sys/conf.h>
44#include <vm/vm.h>
45#include <vm/pmap.h>
46
47#include <machine/atomic.h>
48
49#ifdef KDTRACE_HOOKS
50#include <sys/dtrace_bsd.h>
51
52dtrace_io_start_probe_func_t dtrace_io_start_probe;
53dtrace_io_done_probe_func_t dtrace_io_done_probe;
54dtrace_io_wait_start_probe_func_t dtrace_io_wait_start_probe;
55dtrace_io_wait_done_probe_func_t dtrace_io_wait_done_probe;
56
57uint32_t dtio_start_id;
58uint32_t dtio_done_id;
59uint32_t dtio_wait_start_id;
60uint32_t dtio_wait_done_id;
61
62#define DTRACE_DEVSTAT_START() \
63 if (dtrace_io_start_probe != NULL) \
64 (*dtrace_io_start_probe)(dtio_start_id, NULL, ds);
65
66#define DTRACE_DEVSTAT_BIO_START() \
67 if (dtrace_io_start_probe != NULL) \
68 (*dtrace_io_start_probe)(dtio_start_id, bp, ds);
69
70#define DTRACE_DEVSTAT_DONE() \
71 if (dtrace_io_done_probe != NULL) \
72 (*dtrace_io_done_probe)(dtio_done_id, NULL, ds);
73
74#define DTRACE_DEVSTAT_BIO_DONE() \
75 if (dtrace_io_done_probe != NULL) \
76 (*dtrace_io_done_probe)(dtio_done_id, bp, ds);
77
78#define DTRACE_DEVSTAT_WAIT_START() \
79 if (dtrace_io_wait_start_probe != NULL) \
80 (*dtrace_io_wait_start_probe)(dtio_wait_start_id, NULL, ds);
81
82#define DTRACE_DEVSTAT_WAIT_DONE() \
83 if (dtrace_io_wait_done_probe != NULL) \
84 (*dtrace_io_wait_done_probe)(dtio_wait_done_id, NULL, ds);
85
86#else /* ! KDTRACE_HOOKS */
87
88#define DTRACE_DEVSTAT_START()
89
90#define DTRACE_DEVSTAT_DONE()
91
92#define DTRACE_DEVSTAT_WAIT_START()
93
94#define DTRACE_DEVSTAT_WAIT_DONE()
95#endif /* KDTRACE_HOOKS */
96
47static int devstat_num_devs;
48static long devstat_generation = 1;
49static int devstat_version = DEVSTAT_VERSION;
50static int devstat_current_devnumber;
51static struct mtx devstat_mutex;
52MTX_SYSINIT(devstat_mutex, &devstat_mutex, "devstat", MTX_DEF);
53
54static struct devstatlist device_statq = STAILQ_HEAD_INITIALIZER(device_statq);

--- 167 unchanged lines hidden (view full) ---

222 if (ds->start_count == ds->end_count) {
223 if (now != NULL)
224 ds->busy_from = *now;
225 else
226 binuptime(&ds->busy_from);
227 }
228 ds->start_count++;
229 atomic_add_rel_int(&ds->sequence0, 1);
97static int devstat_num_devs;
98static long devstat_generation = 1;
99static int devstat_version = DEVSTAT_VERSION;
100static int devstat_current_devnumber;
101static struct mtx devstat_mutex;
102MTX_SYSINIT(devstat_mutex, &devstat_mutex, "devstat", MTX_DEF);
103
104static struct devstatlist device_statq = STAILQ_HEAD_INITIALIZER(device_statq);

--- 167 unchanged lines hidden (view full) ---

272 if (ds->start_count == ds->end_count) {
273 if (now != NULL)
274 ds->busy_from = *now;
275 else
276 binuptime(&ds->busy_from);
277 }
278 ds->start_count++;
279 atomic_add_rel_int(&ds->sequence0, 1);
280 DTRACE_DEVSTAT_START();
230}
231
232void
233devstat_start_transaction_bio(struct devstat *ds, struct bio *bp)
234{
235
236 mtx_assert(&devstat_mutex, MA_NOTOWNED);
237
238 /* sanity check */
239 if (ds == NULL)
240 return;
241
242 binuptime(&bp->bio_t0);
243 devstat_start_transaction(ds, &bp->bio_t0);
281}
282
283void
284devstat_start_transaction_bio(struct devstat *ds, struct bio *bp)
285{
286
287 mtx_assert(&devstat_mutex, MA_NOTOWNED);
288
289 /* sanity check */
290 if (ds == NULL)
291 return;
292
293 binuptime(&bp->bio_t0);
294 devstat_start_transaction(ds, &bp->bio_t0);
295 DTRACE_DEVSTAT_BIO_START();
244}
245
246/*
247 * Record the ending of a transaction, and incrment the various counters.
248 *
249 * Ordering in this function, and in devstat_start_transaction() is VERY
250 * important. The idea here is to run without locks, so we are very
251 * careful to only modify some fields on the way "down" (i.e. at

--- 55 unchanged lines hidden (view full) ---

307 /* Accumulate busy time */
308 dt = *now;
309 bintime_sub(&dt, &ds->busy_from);
310 bintime_add(&ds->busy_time, &dt);
311 ds->busy_from = *now;
312
313 ds->end_count++;
314 atomic_add_rel_int(&ds->sequence0, 1);
296}
297
298/*
299 * Record the ending of a transaction, and incrment the various counters.
300 *
301 * Ordering in this function, and in devstat_start_transaction() is VERY
302 * important. The idea here is to run without locks, so we are very
303 * careful to only modify some fields on the way "down" (i.e. at

--- 55 unchanged lines hidden (view full) ---

359 /* Accumulate busy time */
360 dt = *now;
361 bintime_sub(&dt, &ds->busy_from);
362 bintime_add(&ds->busy_time, &dt);
363 ds->busy_from = *now;
364
365 ds->end_count++;
366 atomic_add_rel_int(&ds->sequence0, 1);
367 DTRACE_DEVSTAT_DONE();
315}
316
317void
318devstat_end_transaction_bio(struct devstat *ds, struct bio *bp)
319{
320 devstat_trans_flags flg;
321
322 /* sanity check */

--- 6 unchanged lines hidden (view full) ---

329 flg = DEVSTAT_READ;
330 else if (bp->bio_cmd == BIO_WRITE)
331 flg = DEVSTAT_WRITE;
332 else
333 flg = DEVSTAT_NO_DATA;
334
335 devstat_end_transaction(ds, bp->bio_bcount - bp->bio_resid,
336 DEVSTAT_TAG_SIMPLE, flg, NULL, &bp->bio_t0);
368}
369
370void
371devstat_end_transaction_bio(struct devstat *ds, struct bio *bp)
372{
373 devstat_trans_flags flg;
374
375 /* sanity check */

--- 6 unchanged lines hidden (view full) ---

382 flg = DEVSTAT_READ;
383 else if (bp->bio_cmd == BIO_WRITE)
384 flg = DEVSTAT_WRITE;
385 else
386 flg = DEVSTAT_NO_DATA;
387
388 devstat_end_transaction(ds, bp->bio_bcount - bp->bio_resid,
389 DEVSTAT_TAG_SIMPLE, flg, NULL, &bp->bio_t0);
390 DTRACE_DEVSTAT_BIO_DONE();
337}
338
339/*
340 * This is the sysctl handler for the devstat package. The data pushed out
341 * on the kern.devstat.all sysctl variable consists of the current devstat
342 * generation number, and then an array of devstat structures, one for each
343 * device in the system.
344 *

--- 202 unchanged lines hidden ---
391}
392
393/*
394 * This is the sysctl handler for the devstat package. The data pushed out
395 * on the kern.devstat.all sysctl variable consists of the current devstat
396 * generation number, and then an array of devstat structures, one for each
397 * device in the system.
398 *

--- 202 unchanged lines hidden ---