svn commit: r302251 - head/sys/kern
Konstantin Belousov
kib at FreeBSD.org
Tue Jun 28 16:42:41 UTC 2016
Author: kib
Date: Tue Jun 28 16:42:40 2016
New Revision: 302251
URL: https://svnweb.freebsd.org/changeset/base/302251
Log:
Do not use Giant to prevent parallel calls to CLOCK_SETTIME(). Use
private mtx in resettodr(), no implementation of CLOCK_SETTIME() is
allowed to sleep.
Reviewed by: imp, jhb
Sponsored by: The FreeBSD Foundation
Approved by: re (gjb)
X-Differential revision: https://reviews.freebsd.org/D6825
Modified:
head/sys/kern/subr_clock.c
head/sys/kern/subr_rtc.c
Modified: head/sys/kern/subr_clock.c
==============================================================================
--- head/sys/kern/subr_clock.c Tue Jun 28 16:41:50 2016 (r302250)
+++ head/sys/kern/subr_clock.c Tue Jun 28 16:42:40 2016 (r302251)
@@ -67,8 +67,8 @@ sysctl_machdep_adjkerntz(SYSCTL_HANDLER_
resettodr();
return (error);
}
-SYSCTL_PROC(_machdep, OID_AUTO, adjkerntz, CTLTYPE_INT|CTLFLAG_RW,
- &adjkerntz, 0, sysctl_machdep_adjkerntz, "I",
+SYSCTL_PROC(_machdep, OID_AUTO, adjkerntz, CTLTYPE_INT | CTLFLAG_RW |
+ CTLFLAG_MPSAFE, &adjkerntz, 0, sysctl_machdep_adjkerntz, "I",
"Local offset from UTC in seconds");
static int ct_debug;
Modified: head/sys/kern/subr_rtc.c
==============================================================================
--- head/sys/kern/subr_rtc.c Tue Jun 28 16:41:50 2016 (r302250)
+++ head/sys/kern/subr_rtc.c Tue Jun 28 16:42:40 2016 (r302251)
@@ -62,6 +62,8 @@ __FBSDID("$FreeBSD$");
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/clock.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
#include <sys/sysctl.h>
#ifdef FFCLOCK
#include <sys/timeffc.h>
@@ -73,6 +75,8 @@ __FBSDID("$FreeBSD$");
static device_t clock_dev = NULL;
static long clock_res;
static struct timespec clock_adj;
+static struct mtx resettodr_lock;
+MTX_SYSINIT(resettodr_init, &resettodr_lock, "tod2rl", MTX_DEF);
/* XXX: should be kern. now, it's no longer machdep. */
static int disable_rtc_set;
@@ -168,11 +172,14 @@ resettodr(void)
if (disable_rtc_set || clock_dev == NULL)
return;
+ mtx_lock(&resettodr_lock);
getnanotime(&ts);
timespecadd(&ts, &clock_adj);
ts.tv_sec -= utc_offset();
/* XXX: We should really set all registered RTCs */
- if ((error = CLOCK_SETTIME(clock_dev, &ts)) != 0)
+ error = CLOCK_SETTIME(clock_dev, &ts);
+ mtx_unlock(&resettodr_lock);
+ if (error != 0)
printf("warning: clock_settime failed (%d), time-of-day clock "
"not adjusted to system time\n", error);
}
More information about the svn-src-head
mailing list