[rtems-libbsd commit] Separate libbsd and RTEMS clock ticks

Sebastian Huber sebh at rtems.org
Wed May 15 10:43:54 UTC 2019


Module:    rtems-libbsd
Branch:    master
Commit:    c727e4a22e6046b69329a13c1560680cec61be92
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=c727e4a22e6046b69329a13c1560680cec61be92

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon May 13 11:19:05 2019 +0200

Separate libbsd and RTEMS clock ticks

---

 freebsd/sys/kern/kern_intr.c                         |  1 -
 freebsd/sys/kern/kern_timeout.c                      |  5 ++++-
 freebsd/sys/kern/subr_sleepqueue.c                   |  1 -
 freebsd/sys/kern/sys_generic.c                       |  2 --
 freebsd/sys/sys/kernel.h                             |  9 ---------
 .../include/machine/rtems-bsd-kernel-namespace.h     |  1 +
 rtemsbsd/rtems/rtems-kernel-init.c                   | 20 ++++++++++----------
 rtemsbsd/rtems/rtems-kernel-thread.c                 |  2 --
 8 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/freebsd/sys/kern/kern_intr.c b/freebsd/sys/kern/kern_intr.c
index 4e311cb..647c7f9 100644
--- a/freebsd/sys/kern/kern_intr.c
+++ b/freebsd/sys/kern/kern_intr.c
@@ -65,7 +65,6 @@ __FBSDID("$FreeBSD$");
 #else /* __rtems__ */
   #include <machine/rtems-bsd-thread.h>
   #define RTEMSBSD_SWI_WAKEUP_EVENT RTEMS_EVENT_31
-  #undef ticks
   #include <rtems/score/threadimpl.h>
 #endif /* __rtems__ */
 #include <machine/stdarg.h>
diff --git a/freebsd/sys/kern/kern_timeout.c b/freebsd/sys/kern/kern_timeout.c
index 8ef42c9..2f478af 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/kern/subr_sleepqueue.c b/freebsd/sys/kern/subr_sleepqueue.c
index 9aa9d7f..e8e221c 100644
--- a/freebsd/sys/kern/subr_sleepqueue.c
+++ b/freebsd/sys/kern/subr_sleepqueue.c
@@ -94,7 +94,6 @@ __FBSDID("$FreeBSD$");
 #endif
 #ifdef __rtems__
 #include <machine/rtems-bsd-thread.h>
-#undef ticks
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/watchdogimpl.h>
 #endif /* __rtems__ */
diff --git a/freebsd/sys/kern/sys_generic.c b/freebsd/sys/kern/sys_generic.c
index 70638ad..24da393 100644
--- a/freebsd/sys/kern/sys_generic.c
+++ b/freebsd/sys/kern/sys_generic.c
@@ -1999,8 +1999,6 @@ kern_posix_error(struct thread *td, int error)
 #ifdef __rtems__
 #include <machine/rtems-bsd-thread.h>
 
-#undef ticks
-
 #include <rtems/score/objectimpl.h>
 #include <rtems/score/threadimpl.h>
 
diff --git a/freebsd/sys/sys/kernel.h b/freebsd/sys/sys/kernel.h
index 42a3760..41a5233 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/include/machine/rtems-bsd-kernel-namespace.h b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index d1b0d71..d7967c6 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -4939,6 +4939,7 @@
 #define	ticket_altqs_active _bsd_ticket_altqs_active
 #define	ticket_altqs_inactive _bsd_ticket_altqs_inactive
 #define	ticket_pabuf _bsd_ticket_pabuf
+#define	ticks _bsd_ticks
 #define	tick_sbt _bsd_tick_sbt
 #define	ti_hwmods _bsd_ti_hwmods
 #define	ti_hwmods_contains _bsd_ti_hwmods_contains
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c b/rtemsbsd/rtems/rtems-kernel-init.c
index 846ca1f..ac03fed 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,21 @@ 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;
+
+	/*
+	 * 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.
+	 */
+	tps = (int)rtems_clock_get_ticks_per_second();
+	hz = MIN(100, tps);
 
-	hz = (int) rtems_clock_get_ticks_per_second();
 	tick = 1000000 / hz;
 	tick_sbt = SBT_1S / hz;
 	FREQ2BT(hz, &tc_tick_bt);
diff --git a/rtemsbsd/rtems/rtems-kernel-thread.c b/rtemsbsd/rtems/rtems-kernel-thread.c
index 8d8f30a..8e3344e 100644
--- a/rtemsbsd/rtems/rtems-kernel-thread.c
+++ b/rtemsbsd/rtems/rtems-kernel-thread.c
@@ -53,8 +53,6 @@
 
 #include <rtems/bsd/bsd.h>
 
-#undef ticks
-
 #include <rtems/score/objectimpl.h>
 #include <rtems/score/statesimpl.h>
 #include <rtems/score/threaddispatch.h>



More information about the vc mailing list