[PATCH] Separate libbsd and RTEMS clock ticks

Sebastian Huber sebastian.huber at embedded-brains.de
Mon May 13 09:20:59 UTC 2019


---
 freebsd/sys/kern/kern_timeout.c    |  5 ++++-
 freebsd/sys/sys/kernel.h           |  9 ---------
 rtemsbsd/rtems/rtems-kernel-init.c | 25 +++++++++++++++----------
 3 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/freebsd/sys/kern/kern_timeout.c b/freebsd/sys/kern/kern_timeout.c
index 8ef42c9a9..2f478afc5 100644
--- a/freebsd/sys/kern/kern_timeout.c
+++ b/freebsd/sys/kern/kern_timeout.c
@@ -317,6 +317,7 @@ rtems_bsd_callout_timer(rtems_id id, void *arg)
 	sc = rtems_timer_reset(id);
 	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 
+	++ticks;
 	callout_process(sbinuptime());
 }
 
@@ -339,7 +340,9 @@ rtems_bsd_timeout_init_late(void *unused)
 	sc = rtems_timer_create(rtems_build_name('_', 'C', 'L', 'O'), &id);
 	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 
-	sc = rtems_timer_server_fire_after(id, 1, rtems_bsd_callout_timer, NULL);
+	sc = rtems_timer_server_fire_after(id,
+	    rtems_clock_get_ticks_per_second() / (rtems_interval)hz,
+	    rtems_bsd_callout_timer, NULL);
 	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 }
 
diff --git a/freebsd/sys/sys/kernel.h b/freebsd/sys/sys/kernel.h
index 42a376049..41a5233ab 100644
--- a/freebsd/sys/sys/kernel.h
+++ b/freebsd/sys/sys/kernel.h
@@ -70,16 +70,7 @@ extern int psratio;			/* ratio: prof / stat */
 extern int stathz;			/* statistics clock's frequency */
 extern int profhz;			/* profiling clock's frequency */
 extern int profprocs;			/* number of process's profiling */
-#ifndef __rtems__
 extern volatile int ticks;
-#else /* __rtems__ */
-/*
- * This must be a singed integer type, otherwise expressions like
- * (x - ticks) > 0 would yield unexpected results.
- */
-extern volatile int32_t _bsd_ticks;
-#define ticks _bsd_ticks
-#endif /* __rtems__ */
 
 #endif /* _KERNEL */
 
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c b/rtemsbsd/rtems/rtems-kernel-init.c
index 846ca1f12..42d495d58 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -85,6 +85,7 @@ void mi_startup(void);
 
 int hz;
 int tick;
+volatile int ticks;
 sbintime_t tick_sbt;
 struct bintime bt_timethreshold;
 struct bintime bt_tickthreshold;
@@ -105,22 +106,26 @@ SYSCTL_INT(_kern_smp, OID_AUTO, maxid, CTLFLAG_RD|CTLFLAG_CAPRD,
 SYSCTL_INT(_kern_smp, OID_AUTO, maxcpus, CTLFLAG_RD|CTLFLAG_CAPRD,
     &maxid_maxcpus, 0, "Max number of CPUs that the system was compiled for.");
 
-#undef _bsd_ticks
-
-RTEMS_STATIC_ASSERT(sizeof(int) == sizeof(int32_t), ticks);
-
-volatile uint32_t _Watchdog_Ticks_since_boot;
-
-extern volatile int32_t _bsd_ticks
-    __attribute__ ((__alias__("_Watchdog_Ticks_since_boot")));
-
 rtems_status_code
 rtems_bsd_initialize(void)
 {
 	static const char name[] = "TIME";
 	rtems_status_code sc;
+	int tps;
+
+	tps = (int)rtems_clock_get_ticks_per_second();
+
+	/*
+	 * Limit the libbsd ticks per second to 100Hz.  This helps to reduce
+	 * the processor load on low end targets which use 1000Hz for the RTEMS
+	 * clock tick.
+	 */
+	if (tps > 100) {
+		hz = tps / (tps / 100);
+	} else {
+		hz = tps;
+	}
 
-	hz = (int) rtems_clock_get_ticks_per_second();
 	tick = 1000000 / hz;
 	tick_sbt = SBT_1S / hz;
 	FREQ2BT(hz, &tc_tick_bt);
-- 
2.16.4



More information about the devel mailing list