Page 1 of 1

posix simulator hal_lld changes

Posted: Wed Jan 17, 2018 9:44 pm
by faisal
If interrupts are too frequent, then the system tick will never happen due to the call to chSchDoReschedule(). Below is a patch to _sim_check_for_interrupts() which will ensure that the systick is always evaluated, and chSchDoReschedule() is called at the end. Originally I had included a call to nanosleep() for a short duration so that the process doesn't run at 100% CPU utilization. However, that is probably best done in CH_CFG_IDLE_LOOP_HOOK() .


Code: Select all

--- 
+++
@@ -1,31 +1,32 @@
 void _sim_check_for_interrupts(void) {
   struct timeval tv;
-
+  bool int_occurred = false;
 #if HAL_USE_SERIAL
   if (sd_lld_interrupt_pending()) {
-    _dbg_check_lock();
-    if (chSchIsPreemptionRequired())
-      chSchDoReschedule();
-    _dbg_check_unlock();
-    return;
+    int_occured = true;
   }
 #endif
 
   gettimeofday(&tv, NULL);
   if (timercmp(&tv, &nextcnt, >=)) {
+    int_occurred = true;
     timeradd(&nextcnt, &tick, &nextcnt);
 
     CH_IRQ_PROLOGUE();
 
     chSysLockFromISR();
     chSysTimerHandlerI();
     chSysUnlockFromISR();
 
     CH_IRQ_EPILOGUE();
 
-    _dbg_check_lock();
-    if (chSchIsPreemptionRequired())
-      chSchDoReschedule();
-    _dbg_check_unlock();
   }
+ 
+  if (int_occurred)
+  {
+    _dbg_check_lock();
+    if (chSchIsPreemptionRequired())
+      chSchDoReschedule();
+    _dbg_check_unlock();
+  }
 }

Re: posix simulator hal_lld changes

Posted: Fri Mar 16, 2018 6:25 am
by faisal
Any appetite to include this change in 18.2.x?

Re: posix simulator hal_lld changes

Posted: Sat Mar 17, 2018 11:33 am
by Giovanni
Hi,

I committed it in both trunk and 18.2.x.

Giovanni