Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Jun 2018 11:33:14 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r334482 - in head/sys/compat/linuxkpi/common: include/linux src
Message-ID:  <201806011133.w51BXEHH061458@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Fri Jun  1 11:33:14 2018
New Revision: 334482
URL: https://svnweb.freebsd.org/changeset/base/334482

Log:
  Improve high resolution timer support in the LinuxKPI.
  
  Submitted by:	Johannes Lundberg <johalun0@gmail.com>
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies
  Sponsored by:	Limelight Networks

Modified:
  head/sys/compat/linuxkpi/common/include/linux/hrtimer.h
  head/sys/compat/linuxkpi/common/src/linux_hrtimer.c

Modified: head/sys/compat/linuxkpi/common/include/linux/hrtimer.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/hrtimer.h	Fri Jun  1 11:14:59 2018	(r334481)
+++ head/sys/compat/linuxkpi/common/include/linux/hrtimer.h	Fri Jun  1 11:33:14 2018	(r334482)
@@ -36,6 +36,7 @@
 
 enum hrtimer_mode {
 	HRTIMER_MODE_REL,
+	HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL,
 };
 
 enum hrtimer_restart {
@@ -47,31 +48,42 @@ struct hrtimer {
 	enum hrtimer_restart (*function)(struct hrtimer *);
 	struct mtx mtx;
 	struct callout callout;
+	s64 expires;	/* relative time in nanoseconds */
+	s64 precision;	/* in nanoseconds */
 };
 
 #define	hrtimer_active(hrtimer)	linux_hrtimer_active(hrtimer)
 #define	hrtimer_cancel(hrtimer)	linux_hrtimer_cancel(hrtimer)
+
 #define	hrtimer_init(hrtimer, clock, mode) do {			\
 	CTASSERT((clock) == CLOCK_MONOTONIC);			\
 	CTASSERT((mode) == HRTIMER_MODE_REL);			\
 	linux_hrtimer_init(hrtimer);				\
 } while (0)
+
 #define	hrtimer_set_expires(hrtimer, time)			\
 	linux_hrtimer_set_expires(hrtimer, time)
+
 #define	hrtimer_start(hrtimer, time, mode) do {			\
 	CTASSERT((mode) == HRTIMER_MODE_REL);			\
 	linux_hrtimer_start(hrtimer, time);			\
 } while (0)
+
 #define	hrtimer_start_range_ns(hrtimer, time, prec, mode) do {	\
 	CTASSERT((mode) == HRTIMER_MODE_REL);			\
 	linux_hrtimer_start_range_ns(hrtimer, time, prec);	\
 } while (0)
 
+#define	hrtimer_forward_now(hrtimer, interval) do {		\
+	linux_hrtimer_forward_now(hrtimer, interval);		\
+} while (0)
+
 bool	linux_hrtimer_active(struct hrtimer *);
 int	linux_hrtimer_cancel(struct hrtimer *);
 void	linux_hrtimer_init(struct hrtimer *);
 void	linux_hrtimer_set_expires(struct hrtimer *, ktime_t);
 void	linux_hrtimer_start(struct hrtimer *, ktime_t);
 void	linux_hrtimer_start_range_ns(struct hrtimer *, ktime_t, int64_t);
+void	linux_hrtimer_forward_now(struct hrtimer *, ktime_t);
 
 #endif /* _LINUX_HRTIMER_H_ */

Modified: head/sys/compat/linuxkpi/common/src/linux_hrtimer.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_hrtimer.c	Fri Jun  1 11:14:59 2018	(r334481)
+++ head/sys/compat/linuxkpi/common/src/linux_hrtimer.c	Fri Jun  1 11:33:14 2018	(r334482)
@@ -44,8 +44,13 @@ hrtimer_call_handler(void *arg)
 
 	hrtimer = arg;
 	ret = hrtimer->function(hrtimer);
-	MPASS(ret == HRTIMER_NORESTART);
-	callout_deactivate(&hrtimer->callout);
+
+	if (ret == HRTIMER_RESTART) {
+		callout_schedule_sbt(&hrtimer->callout,
+		    nstosbt(hrtimer->expires), nstosbt(hrtimer->precision), 0);
+	} else {
+		callout_deactivate(&hrtimer->callout);
+	}
 }
 
 bool
@@ -56,6 +61,7 @@ linux_hrtimer_active(struct hrtimer *hrtimer)
 	mtx_lock(&hrtimer->mtx);
 	ret = callout_active(&hrtimer->callout);
 	mtx_unlock(&hrtimer->mtx);
+
 	return (ret);
 }
 
@@ -74,15 +80,16 @@ void
 linux_hrtimer_init(struct hrtimer *hrtimer)
 {
 
-	hrtimer->function = NULL;
-	mtx_init(&hrtimer->mtx, "hrtimer", NULL, MTX_DEF | MTX_RECURSE);
+	memset(hrtimer, 0, sizeof(*hrtimer));
+	mtx_init(&hrtimer->mtx, "hrtimer", NULL,
+	    MTX_DEF | MTX_RECURSE | MTX_NOWITNESS);
 	callout_init_mtx(&hrtimer->callout, &hrtimer->mtx, 0);
 }
 
 void
-linux_hrtimer_set_expires(struct hrtimer *hrtimer __unused,
-    ktime_t time __unused)
+linux_hrtimer_set_expires(struct hrtimer *hrtimer, ktime_t time)
 {
+	hrtimer->expires = ktime_to_ns(time);
 }
 
 void
@@ -93,11 +100,24 @@ linux_hrtimer_start(struct hrtimer *hrtimer, ktime_t t
 }
 
 void
-linux_hrtimer_start_range_ns(struct hrtimer *hrtimer, ktime_t time, int64_t nsec)
+linux_hrtimer_start_range_ns(struct hrtimer *hrtimer, ktime_t time,
+    int64_t nsec)
 {
 
 	mtx_lock(&hrtimer->mtx);
-	callout_reset_sbt(&hrtimer->callout, nstosbt(time), nstosbt(nsec),
-	    hrtimer_call_handler, hrtimer, 0);
+	hrtimer->precision = nsec;
+	callout_reset_sbt(&hrtimer->callout, nstosbt(ktime_to_ns(time)),
+	    nstosbt(nsec), hrtimer_call_handler, hrtimer, 0);
 	mtx_unlock(&hrtimer->mtx);
 }
+
+void
+linux_hrtimer_forward_now(struct hrtimer *hrtimer, ktime_t interval)
+{
+
+	mtx_lock(&hrtimer->mtx);
+	callout_reset_sbt(&hrtimer->callout, nstosbt(ktime_to_ns(interval)),
+	    nstosbt(hrtimer->precision), hrtimer_call_handler, hrtimer, 0);
+	mtx_unlock(&hrtimer->mtx);
+}
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806011133.w51BXEHH061458>