xiaoxiang781216 commented on code in PR #18002:
URL: https://github.com/apache/nuttx/pull/18002#discussion_r2703262691


##########
sched/sched/sched_timer.c:
##########
@@ -31,6 +31,104 @@
 #include <errno.h>
 
 #include "sched/sched.h"
+#include "hrtimer/hrtimer.h"
+
+#ifdef CONFIG_HRTIMER
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* High-resolution timer used to drive the scheduler tick.
+ *
+ * In non-tickless mode, this timer periodically generates a scheduler
+ * tick with interval NSEC_PER_TICK.
+ *
+ * In tickless mode, the timer is still used, but the callback does not
+ * request automatic re-arming.
+ */
+
+static hrtimer_t g_sched_hrtimer;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_hrtimer_callback
+ *
+ * Description:
+ *   High-resolution timer callback used to drive the scheduler.
+ *
+ *   This callback is invoked when the scheduler hrtimer expires.
+ *   It advances the scheduler time base by calling
+ *   nxsched_process_tick().
+ *
+ * Input Parameters:
+ *   hrtimer - Pointer to the expired hrtimer instance
+ *   expired - Expiration time in nanoseconds
+ *
+ * Returned Value:
+ *   In non-tickless mode:
+ *     Returns the next expiration interval (NSEC_PER_TICK),
+ *     causing the hrtimer to be re-armed periodically.
+ *
+ *   In tickless mode:
+ *     Returns 0 to indicate that the timer should not be
+ *     automatically restarted.
+ *
+ ****************************************************************************/
+
+static uint64_t
+nxsched_hrtimer_callback(FAR const struct hrtimer_s *hrtimer,
+                         uint64_t expired)
+{
+  UNUSED(hrtimer);
+  UNUSED(expired);
+
+  /* Advance scheduler time and process time slice expiration */
+
+  nxsched_process_tick();
+
+#ifndef CONFIG_SCHED_TICKLESS
+  /* Periodic tick mode: re-arm timer with fixed tick interval */
+
+  return NSEC_PER_TICK;
+#else
+  /* Tickless mode controls the next wakeup explicitly */
+
+  return 0;
+#endif
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_hrtimer_init
+ *
+ * Description:
+ *   Initialize and start the scheduler high-resolution timer.
+ *
+ *   This function sets up a periodic hrtimer that drives the scheduler
+ *   tick using nanosecond resolution.
+ *
+ ****************************************************************************/
+
+void nxsched_hrtimer_init(void)
+{
+  /* Initialize scheduler hrtimer structure */
+
+  hrtimer_init(&g_sched_hrtimer);
+
+  /* Start the hrtimer in relative mode with one tick interval */
+
+  hrtimer_start(&g_sched_hrtimer,

Review Comment:
   can we start g_sched_hrtimer internally and remove nxsched_hrtimer_init



##########
sched/sched/sched_timer.c:
##########
@@ -31,6 +31,104 @@
 #include <errno.h>
 
 #include "sched/sched.h"
+#include "hrtimer/hrtimer.h"
+
+#ifdef CONFIG_HRTIMER
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* High-resolution timer used to drive the scheduler tick.
+ *
+ * In non-tickless mode, this timer periodically generates a scheduler
+ * tick with interval NSEC_PER_TICK.
+ *
+ * In tickless mode, the timer is still used, but the callback does not
+ * request automatic re-arming.
+ */
+
+static hrtimer_t g_sched_hrtimer;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_hrtimer_callback
+ *
+ * Description:
+ *   High-resolution timer callback used to drive the scheduler.
+ *
+ *   This callback is invoked when the scheduler hrtimer expires.
+ *   It advances the scheduler time base by calling
+ *   nxsched_process_tick().
+ *
+ * Input Parameters:
+ *   hrtimer - Pointer to the expired hrtimer instance
+ *   expired - Expiration time in nanoseconds
+ *
+ * Returned Value:
+ *   In non-tickless mode:
+ *     Returns the next expiration interval (NSEC_PER_TICK),
+ *     causing the hrtimer to be re-armed periodically.
+ *
+ *   In tickless mode:
+ *     Returns 0 to indicate that the timer should not be
+ *     automatically restarted.
+ *
+ ****************************************************************************/
+
+static uint64_t
+nxsched_hrtimer_callback(FAR const struct hrtimer_s *hrtimer,
+                         uint64_t expired)
+{
+  UNUSED(hrtimer);
+  UNUSED(expired);
+
+  /* Advance scheduler time and process time slice expiration */
+
+  nxsched_process_tick();
+
+#ifndef CONFIG_SCHED_TICKLESS
+  /* Periodic tick mode: re-arm timer with fixed tick interval */
+
+  return NSEC_PER_TICK;
+#else
+  /* Tickless mode controls the next wakeup explicitly */
+
+  return 0;
+#endif
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_hrtimer_init
+ *
+ * Description:
+ *   Initialize and start the scheduler high-resolution timer.
+ *
+ *   This function sets up a periodic hrtimer that drives the scheduler
+ *   tick using nanosecond resolution.
+ *
+ ****************************************************************************/
+
+void nxsched_hrtimer_init(void)
+{
+  /* Initialize scheduler hrtimer structure */
+
+  hrtimer_init(&g_sched_hrtimer);

Review Comment:
   don't need



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