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


##########
include/nuttx/arch.h:
##########
@@ -2101,8 +2102,8 @@ int up_timer_tick_cancel(FAR clock_t *ticks);
  *   non-reentrancy.
  *
  ****************************************************************************/
-
-#if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM)
+#if (defined(CONFIG_HRTIMER) && defined(CONFIG_TIMER_ARCH)) || \

Review Comment:
   why change up_timer_start



##########
sched/sched/sched_processtimer.c:
##########
@@ -44,11 +44,145 @@
 #include "sched/sched.h"
 #include "wdog/wdog.h"
 #include "clock/clock.h"
+#include "hrtimer/hrtimer.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_HRTIMER
+
+/* Scheduler-owned high-resolution timer instance.
+ *
+ * This timer acts as the time source for scheduler-related events:
+ *
+ *  - Periodic scheduler ticks in non-tickless mode
+ *  - Dynamic expiration points in tickless mode
+ *
+ * The timer is initialized lazily to avoid unnecessary setup when
+ * CONFIG_HRTIMER is enabled but not used immediately.
+ */
+
+static hrtimer_t g_nxsched_hrtimer;
+
+/* Indicates whether the scheduler hrtimer has been initialized.
+ *
+ * Initialization is performed on first invocation of
+ * nxsched_process_hrtimer().
+ */
+
+static bool g_sched_hrtimer_inited = false;
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+static void nxsched_process_tick(void);
+
+/****************************************************************************
+ * Name: nxsched_hrtimer_callback
+ *
+ * Description:
+ *   Callback invoked by the high-resolution timer framework when the
+ *   scheduler timer expires.
+ *
+ *   Behavior depends on scheduler configuration:
+ *
+ *   CONFIG_SCHED_TICKLESS:
+ *     - Query current high-resolution time
+ *     - Convert time to scheduler ticks
+ *     - Notify scheduler via nxsched_tick_expiration()
+ *
+ *   !CONFIG_SCHED_TICKLESS:
+ *     - Re-arm the next periodic tick
+ *     - Process a single scheduler tick
+ *
+ * Input Parameters:
+ *   hrtimer - Pointer to the expired high-resolution timer
+ *
+ * Returned Value:
+ *   In non-tickless mode, returns the interval until the next expiration.
+ *   In tickless mode, the return value is ignored.
+ *
+ ****************************************************************************/
+
+static uint64_t
+nxsched_hrtimer_callback(FAR hrtimer_t *hrtimer, uint64_t expired)
+{
+  UNUSED(hrtimer);
+  UNUSED(expired);
+
+#ifdef CONFIG_SCHED_TICKLESS
+  uint64_t now = hrtimer_gettime();
+
+  /* Notify scheduler of the current time (converted to ticks) */
+
+  nxsched_tick_expiration(NSEC2TICK(now));

Review Comment:
   why not use expired directly



##########
include/nuttx/arch.h:
##########


Review Comment:
   move to private header file



##########
sched/sched/sched_processtimer.c:
##########
@@ -44,11 +44,145 @@
 #include "sched/sched.h"
 #include "wdog/wdog.h"
 #include "clock/clock.h"
+#include "hrtimer/hrtimer.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_HRTIMER
+
+/* Scheduler-owned high-resolution timer instance.
+ *
+ * This timer acts as the time source for scheduler-related events:
+ *
+ *  - Periodic scheduler ticks in non-tickless mode
+ *  - Dynamic expiration points in tickless mode
+ *
+ * The timer is initialized lazily to avoid unnecessary setup when
+ * CONFIG_HRTIMER is enabled but not used immediately.
+ */
+
+static hrtimer_t g_nxsched_hrtimer;
+
+/* Indicates whether the scheduler hrtimer has been initialized.
+ *
+ * Initialization is performed on first invocation of
+ * nxsched_process_hrtimer().
+ */
+
+static bool g_sched_hrtimer_inited = false;
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+static void nxsched_process_tick(void);
+
+/****************************************************************************
+ * Name: nxsched_hrtimer_callback
+ *
+ * Description:
+ *   Callback invoked by the high-resolution timer framework when the
+ *   scheduler timer expires.
+ *
+ *   Behavior depends on scheduler configuration:
+ *
+ *   CONFIG_SCHED_TICKLESS:
+ *     - Query current high-resolution time
+ *     - Convert time to scheduler ticks
+ *     - Notify scheduler via nxsched_tick_expiration()
+ *
+ *   !CONFIG_SCHED_TICKLESS:
+ *     - Re-arm the next periodic tick
+ *     - Process a single scheduler tick
+ *
+ * Input Parameters:
+ *   hrtimer - Pointer to the expired high-resolution timer
+ *
+ * Returned Value:
+ *   In non-tickless mode, returns the interval until the next expiration.
+ *   In tickless mode, the return value is ignored.
+ *
+ ****************************************************************************/
+
+static uint64_t
+nxsched_hrtimer_callback(FAR hrtimer_t *hrtimer, uint64_t expired)
+{
+  UNUSED(hrtimer);
+  UNUSED(expired);
+
+#ifdef CONFIG_SCHED_TICKLESS
+  uint64_t now = hrtimer_gettime();
+
+  /* Notify scheduler of the current time (converted to ticks) */
+
+  nxsched_tick_expiration(NSEC2TICK(now));
+

Review Comment:
   not return value



##########
include/nuttx/arch.h:
##########
@@ -2031,7 +2031,8 @@ int up_alarm_tick_cancel(FAR clock_t *ticks);
  *
  ****************************************************************************/
 
-#if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
+#if (defined(CONFIG_HRTIMER) && defined(CONFIG_ALARM_ARCH)) || \

Review Comment:
   remove CONFIG_ALARM_ARCH



##########
include/nuttx/arch.h:
##########


Review Comment:
   do you need change this line



##########
sched/sched/sched_processtimer.c:
##########
@@ -44,11 +44,145 @@
 #include "sched/sched.h"
 #include "wdog/wdog.h"
 #include "clock/clock.h"
+#include "hrtimer/hrtimer.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_HRTIMER
+
+/* Scheduler-owned high-resolution timer instance.
+ *
+ * This timer acts as the time source for scheduler-related events:
+ *
+ *  - Periodic scheduler ticks in non-tickless mode
+ *  - Dynamic expiration points in tickless mode
+ *
+ * The timer is initialized lazily to avoid unnecessary setup when
+ * CONFIG_HRTIMER is enabled but not used immediately.
+ */
+
+static hrtimer_t g_nxsched_hrtimer;

Review Comment:
   let's init to func directly and remove g_sched_hrtimer_inited 



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