posix simulator hal_lld changes Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

posix simulator hal_lld changes

Post 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();
+  }
 }
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: posix simulator hal_lld changes

Post by faisal »

Any appetite to include this change in 18.2.x?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: posix simulator hal_lld changes

Post by Giovanni »

Hi,

I committed it in both trunk and 18.2.x.

Giovanni
Post Reply