diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-06-28 09:32:29 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-06-28 09:32:29 +0000 |
commit | f469e1ef26e454d2f6c35b94b977c4ee07795b13 (patch) | |
tree | b2dbb5e5525c950662e68da1f393cb80953ec734 /sys/dev/dt | |
parent | 61eef5c03ddb57b2047cfb9deae0f649210dd256 (diff) |
Use btrace(8) to debug reference counting. dt(4) provides a static
tracepoint for each type of refcnt we have. As a start, add inpcb
and tdb refcnt. When the counter changes, btrace may print the
actual object, the current counter, the change value and optionally
the stack trace.
discussed with visa@; OK mpi@
Diffstat (limited to 'sys/dev/dt')
-rw-r--r-- | sys/dev/dt/dt_prov_static.c | 19 | ||||
-rw-r--r-- | sys/dev/dt/dtvar.h | 25 |
2 files changed, 39 insertions, 5 deletions
diff --git a/sys/dev/dt/dt_prov_static.c b/sys/dev/dt/dt_prov_static.c index 144b3545ff4..d608373df56 100644 --- a/sys/dev/dt/dt_prov_static.c +++ b/sys/dev/dt/dt_prov_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_prov_static.c,v 1.13 2022/03/17 14:53:59 bluhm Exp $ */ +/* $OpenBSD: dt_prov_static.c,v 1.14 2022/06/28 09:32:27 bluhm Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org> @@ -87,6 +87,12 @@ DT_STATIC_PROBE1(smr, barrier_exit, "int"); DT_STATIC_PROBE0(smr, wakeup); DT_STATIC_PROBE2(smr, thread, "uint64_t", "uint64_t"); +/* + * reference counting + */ +DT_STATIC_PROBE0(refcnt, none); +DT_STATIC_PROBE3(refcnt, inpcb, "void *", "int", "int"); +DT_STATIC_PROBE3(refcnt, tdb, "void *", "int", "int"); /* * List of all static probes @@ -127,15 +133,24 @@ struct dt_probe *const dtps_static[] = { &_DT_STATIC_P(smr, barrier_exit), &_DT_STATIC_P(smr, wakeup), &_DT_STATIC_P(smr, thread), + /* refcnt */ + &_DT_STATIC_P(refcnt, none), + &_DT_STATIC_P(refcnt, inpcb), + &_DT_STATIC_P(refcnt, tdb), }; +struct dt_probe *const *dtps_index_refcnt; + int dt_prov_static_init(void) { int i; - for (i = 0; i < nitems(dtps_static); i++) + for (i = 0; i < nitems(dtps_static); i++) { + if (dtps_static[i] == &_DT_STATIC_P(refcnt, none)) + dtps_index_refcnt = &dtps_static[i]; dt_dev_register_probe(dtps_static[i]); + } return i; } diff --git a/sys/dev/dt/dtvar.h b/sys/dev/dt/dtvar.h index 5d5a38bf23d..9f425dfe0c6 100644 --- a/sys/dev/dt/dtvar.h +++ b/sys/dev/dt/dtvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dtvar.h,v 1.13 2022/02/27 10:14:01 bluhm Exp $ */ +/* $OpenBSD: dtvar.h,v 1.14 2022/06/28 09:32:27 bluhm Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org> @@ -310,16 +310,35 @@ extern volatile uint32_t dt_tracing; /* currently tracing? */ #define DT_STATIC_PROBE5(func, name, arg0, arg1, arg2, arg3, arg4) \ _DT_STATIC_PROBEN(func, name, arg0, arg1, arg2, arg3, arg4, 5) -#define DT_STATIC_ENTER(func, name, args...) do { \ +#define DT_STATIC_ENTER(func, name, args...) do { \ extern struct dt_probe _DT_STATIC_P(func, name); \ struct dt_probe *dtp = &_DT_STATIC_P(func, name); \ - struct dt_provider *dtpv = dtp->dtp_prov; \ \ if (__predict_false(dt_tracing) && \ __predict_false(dtp->dtp_recording)) { \ + struct dt_provider *dtpv = dtp->dtp_prov; \ + \ dtpv->dtpv_enter(dtpv, dtp, args); \ } \ } while (0) +#define _DT_INDEX_P(func) (dtps_index_##func) + +#define DT_INDEX_ENTER(func, index, args...) do { \ + extern struct dt_probe **_DT_INDEX_P(func); \ + \ + if (__predict_false(dt_tracing) && \ + __predict_false(index > 0) && \ + __predict_true(_DT_INDEX_P(func) != NULL)) { \ + struct dt_probe *dtp = _DT_INDEX_P(func)[index]; \ + \ + if(__predict_false(dtp->dtp_recording)) { \ + struct dt_provider *dtpv = dtp->dtp_prov; \ + \ + dtpv->dtpv_enter(dtpv, dtp, args); \ + } \ + } \ +} while (0) + #endif /* !_KERNEL */ #endif /* !_DT_H_ */ |