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.
This commit is contained in:
Ian Lepore 2018-02-12 17:33:14 +00:00
parent 48fca66157
commit 45eee6db6f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329172
2 changed files with 70 additions and 0 deletions

View File

@ -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,
@ -144,6 +148,60 @@ settime_task_func(void *arg, int pending)
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
clock_register_flags(device_t clockdev, long resolution, int flags)
{

View File

@ -191,6 +191,18 @@ void clock_print_bcd(const struct bcd_clocktime *bct, int nsdig);
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_ */