patacongo commented on a change in pull request #1380:
URL: https://github.com/apache/incubator-nuttx/pull/1380#discussion_r451204873



##########
File path: arch/arm/src/stm32f7/stm32_tickless.c
##########
@@ -988,22 +988,31 @@ int up_timer_start(FAR const struct timespec *ts)
 }
 #endif
 
+#ifdef CONFIG_SCHED_TICKLESS_ALARM
 int up_alarm_start(FAR const struct timespec *ts)
 {
   uint64_t tm = ((uint64_t)ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec) /
                 NSEC_PER_TICK;
-  uint64_t counter = ((uint64_t)g_tickless.overflow << 32) |
-                     STM32_TIM_GETCOUNTER(g_tickless.tch);
-
-  g_tickless.last_alrm = tm;
+  irqstate_t flags;
 
-  int32_t diff = tm / NSEC_PER_TICK + counter;
+  flags = enter_critical_section();
 
   STM32_TIM_SETCOMPARE(g_tickless.tch, CONFIG_STM32F7_TICKLESS_CHANNEL, tm);
 
   stm32_tickless_ackint(g_tickless.channel);
   stm32_tickless_enableint(CONFIG_STM32F7_TICKLESS_CHANNEL);
 
+  g_tickless.pending = true;
+
+  uint64_t counter = ((uint64_t)g_tickless.overflow << 32) |
+                     STM32_TIM_GETCOUNTER(g_tickless.tch);
+
+  if (counter > tm)
+    {
+      stm32_interval_handler();

Review comment:
       > So my change is trying to basically expire the timer before it even 
starts.
   
   The only way that I can see that happening is in sched/wdog/wd_start.c:
   
       232 #ifdef CONFIG_SCHED_TICKLESS
       233   /* Cancel the interval timer that drives the timing events.  This 
will
       234    * cause wd_timer to be called which update the delay value for 
the first
       235    * time at the head of the timer list (there is a possibility that 
it
       236    * could even remove it).
       237    */
       238
       239   nxsched_cancel_timer();
       240 #endif
   
   Before we set up the new interval timer, we have to cancel the current one.
   
   But this would not effect the wdog being started at line 360 where 
wd_start(0 is called; that wdog is not yet in the active wdog list.  That does 
not happen until after nxsched_cancel_timer(); is called.
   
   The symptoms are different but this is very similar to the problem of issue 
#1138.  In that case, as I call, wd_cancel() was being called and causing an 
expected timer expiration for the same reason.  But the #1138 problem caused 
and unexpected context switch.
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to