wangchdo commented on code in PR #17489:
URL: https://github.com/apache/nuttx/pull/17489#discussion_r2617274354


##########
drivers/timers/arch_alarm.c:
##########


Review Comment:
   Please take a look at  nsched_processhrtimer implementation.
   
   ```
   /* Global high-resolution timer instance used by the scheduler */
   
   hrtimer_t g_nxsched_hrtimer;
   
   /* Whether the scheduler high-resolution timer has been initialized */
   
   static bool g_sched_hrtimer_inited = false;
   
   /****************************************************************************
    * Private Functions
    
****************************************************************************/
   
   /****************************************************************************
    * Name: nxsched_hrtimer_callback
    *
    * Description:
    *   High-resolution timer callback used for scheduler tick processing.
    *
    *   This callback updates the scheduler state and arms the next timer
    *   event. The behavior differs depending on whether tickless mode is
    *   enabled:
    *
    *   - In tickless mode, nxsched_tick_expiration() determines the next
    *     expiration point.
    *   - In non-tickless mode, a tick is generated unconditionally at
    *     every timer interval.
    *
    * Input Parameters:
    *   hrtimer - Pointer to the high-resolution timer instance that expired.
    *
    * Returned Value:
    *   None.
    *
    
****************************************************************************/
   
   static void nxsched_hrtimer_callback(FAR hrtimer_t *hrtimer)
   {
   #ifdef CONFIG_SCHED_TICKLESS
     uint64_t now = hrtimer_gettime();
     nxsched_tick_expiration(NSEC2TICK(now));
   #else
   
     /* Process a single scheduler tick */
   
     nxsched_process_timer();
   
     /* Schedule the next tick relative to now */
   
     hrtimer_start(hrtimer, hrtimer->expired + NSEC_PER_TICK, HRTIMER_MODE_ABS);
   #endif
   }
   
   /****************************************************************************
    * Public Functions
    
****************************************************************************/
   
   /****************************************************************************
    * Name: nxsched_process_hrtimer
    *
    * Description:
    *   Process pending high-resolution timer events for the scheduler.
    *
    *   This function performs lazy initialization of the scheduler's
    *   high-resolution timer and processes expired timer events. It is intended
    *   to be invoked periodically from architecture-specific high-resolution
    *   timer handling code.
    *
    * Input Parameters:
    *   None.
    *
    * Returned Value:
    *   None.
    *
    
****************************************************************************/
   
   void nxsched_process_hrtimer(void)
   {
     uint64_t now = hrtimer_gettime();
   
     /* Perform one-time initialization */
   
     if (g_sched_hrtimer_inited == false)
       {
         g_sched_hrtimer_inited = true;
   
         /* Initialize the scheduler hrtimer */
   
         hrtimer_init(&g_nxsched_hrtimer,
                      nxsched_hrtimer_callback,
                      NULL);
   
         /* Start the first timer event */
   
         hrtimer_start(&g_nxsched_hrtimer,
                       now + NSEC_PER_TICK,
                       HRTIMER_MODE_ABS);
       }
   
     /* Process any expired high-resolution timer events */
   
     hrtimer_process(now);
   }
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to