Date: Mon, 12 Feb 2018 17:33:15 +0000 (UTC) From: Ian Lepore <ian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329172 - in head/sys: kern sys Message-ID: <201802121733.w1CHXF9N068957@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ian Date: Mon Feb 12 17:33:14 2018 New Revision: 329172 URL: https://svnweb.freebsd.org/changeset/base/329172 Log: Add a set of convenience routines for RTC drivers to use for debug output, and a debug.clock_show_io sysctl to control debugging output. Modified: head/sys/kern/subr_rtc.c head/sys/sys/clock.h Modified: head/sys/kern/subr_rtc.c ============================================================================== --- head/sys/kern/subr_rtc.c Mon Feb 12 17:27:50 2018 (r329171) +++ head/sys/kern/subr_rtc.c Mon Feb 12 17:33:14 2018 (r329172) @@ -76,6 +76,10 @@ __FBSDID("$FreeBSD$"); #include "clock_if.h" +static int show_io; +SYSCTL_INT(_debug, OID_AUTO, clock_show_io, CTLFLAG_RWTUN, &show_io, 0, + "Enable debug printing of RTC clock I/O; 1=reads, 2=writes, 3=both."); + /* XXX: should be kern. now, it's no longer machdep. */ static int disable_rtc_set; SYSCTL_INT(_machdep, OID_AUTO, disable_rtc_set, CTLFLAG_RW, &disable_rtc_set, @@ -142,6 +146,60 @@ settime_task_func(void *arg, int pending) ts.tv_nsec = 0; } CLOCK_SETTIME(rtc->clockdev, &ts); +} + +static void +clock_dbgprint_hdr(device_t dev, int rw) +{ + struct timespec now; + + getnanotime(&now); + device_printf(dev, "%s at ", (rw & CLOCK_DBG_READ) ? "read " : "write"); + clock_print_ts(&now, 9); + printf(": "); +} + +void +clock_dbgprint_bcd(device_t dev, int rw, const struct bcd_clocktime *bct) +{ + + if (show_io & rw) { + clock_dbgprint_hdr(dev, rw); + clock_print_bcd(bct, 9); + printf("\n"); + } +} + +void +clock_dbgprint_ct(device_t dev, int rw, const struct clocktime *ct) +{ + + if (show_io & rw) { + clock_dbgprint_hdr(dev, rw); + clock_print_ct(ct, 9); + printf("\n"); + } +} + +void +clock_dbgprint_err(device_t dev, int rw, int err) +{ + + if (show_io & rw) { + clock_dbgprint_hdr(dev, rw); + printf("error = %d\n", err); + } +} + +void +clock_dbgprint_ts(device_t dev, int rw, const struct timespec *ts) +{ + + if (show_io & rw) { + clock_dbgprint_hdr(dev, rw); + clock_print_ts(ts, 9); + printf("\n"); + } } void Modified: head/sys/sys/clock.h ============================================================================== --- head/sys/sys/clock.h Mon Feb 12 17:27:50 2018 (r329171) +++ head/sys/sys/clock.h Mon Feb 12 17:33:14 2018 (r329172) @@ -191,6 +191,18 @@ void clock_print_bcd(const struct bcd_clocktime *bct, void clock_print_ct(const struct clocktime *ct, int nsdig); void clock_print_ts(const struct timespec *ts, int nsdig); +/* + * Debugging helpers for RTC clock drivers. Print a [bcd_]clocktime or + * timespec, only if rtc clock debugging has been enabled. The rw argument is + * one of CLOCK_DBG_READ or CLOCK_DBG_WRITE. + */ +#define CLOCK_DBG_READ 0x01 +#define CLOCK_DBG_WRITE 0x02 +void clock_dbgprint_bcd(device_t dev, int rw, const struct bcd_clocktime *bct); +void clock_dbgprint_ct(device_t dev, int rw, const struct clocktime *ct); +void clock_dbgprint_err(device_t dev, int rw, int err); +void clock_dbgprint_ts(device_t dev, int rw, const struct timespec *ts); + #endif /* _KERNEL */ #endif /* !_SYS_CLOCK_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802121733.w1CHXF9N068957>