casaroli commented on code in PR #21424:
URL: https://github.com/apache/nuttx/pull/21424#discussion_r4535481903


##########
sched/timer/timer_gettime.c:
##########
@@ -38,6 +38,41 @@
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: timer_cpuremaining
+ *
+ * Description:
+ *   Return the CPU time until a CPU-time timer expires, or zero if the
+ *   timer is disarmed.
+ *
+ ****************************************************************************/
+
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
+void timer_cpuremaining(FAR struct posix_timer_s *timer,

Review Comment:
   Done.



##########
sched/timer/timer_create.c:
##########
@@ -107,6 +107,38 @@ static FAR struct posix_timer_s *timer_allocate(void)
   return ret;
 }
 
+/****************************************************************************
+ * Name: timer_cpuclock
+ *
+ * Description:
+ *   Check a CPU-time clock of a new timer.  Give a clock of the calling
+ *   thread its thread ID: the timer reads the clock in interrupt handlers.
+ *
+ ****************************************************************************/
+
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
+static bool timer_cpuclock(FAR clockid_t *clockid)

Review Comment:
   Done.



##########
sched/timer/timer.h:
##########
@@ -45,6 +46,14 @@
 
 #define PT_FLAGS_PREALLOCATED 0x01u /* Timer comes from a pool of preallocated 
timers */
 
+/* Timers on the CPU-time clocks need the run time of the threads */
+
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
+#  define timer_iscputime(t) \

Review Comment:
   Done.



##########
sched/timer/timer_settime.c:
##########
@@ -74,6 +74,97 @@ static inline void timer_overrun(FAR struct posix_timer_s 
*timer, clock_t n)
     }
 }
 
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
+/****************************************************************************
+ * Name: timer_cputicks
+ *
+ * Description:
+ *   Read the CPU-time clock of the timer, in ticks rounded down.
+ *
+ ****************************************************************************/
+
+static int timer_cputicks(FAR struct posix_timer_s *timer,

Review Comment:
   Done.



##########
sched/timer/timer_settime.c:
##########
@@ -74,6 +74,97 @@ static inline void timer_overrun(FAR struct posix_timer_s 
*timer, clock_t n)
     }
 }
 
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
+/****************************************************************************
+ * Name: timer_cputicks
+ *
+ * Description:
+ *   Read the CPU-time clock of the timer, in ticks rounded down.
+ *
+ ****************************************************************************/
+
+static int timer_cputicks(FAR struct posix_timer_s *timer,
+                          FAR clock_t *ticks)
+{
+  struct timespec ts;
+  int ret;
+
+  ret = nxclock_gettime(timer->pt_clock, &ts);
+  if (ret >= 0)
+    {
+      *ticks = clock_time2ticks_floor(&ts);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: timer_cpustart
+ *
+ * Description:
+ *   Start the watchdog of a CPU-time timer.  The CPU time cannot reach
+ *   pt_expected before the watchdog expires.  timer_timeout() then reads
+ *   the clock again and starts the watchdog again if that is necessary.
+ *
+ ****************************************************************************/
+
+static int timer_cpustart(FAR struct posix_timer_s *timer, clock_t ticks)
+{
+  clock_t delay = timer->pt_expected - ticks;
+
+  if (delay < 0)
+    {
+      delay = 0;
+    }
+
+#ifdef CONFIG_SMP
+  /* The threads of a process can run on all CPUs at the same time */
+
+  if ((timer->pt_clock & CLOCK_MASK) == CLOCK_PROCESS_CPUTIME_ID)
+    {
+      delay = div_round_up(delay, CONFIG_SMP_NCPUS);
+    }
+#endif
+
+  return wd_start(&timer->pt_wdog, delay, timer_timeout, (wdparm_t)timer);
+}
+
+/****************************************************************************
+ * Name: timer_cpusettime
+ *
+ * Description:
+ *   Arm a CPU-time timer.  pt_expected is a time on the CPU-time clock.
+ *
+ ****************************************************************************/
+
+static int timer_cpusettime(FAR struct posix_timer_s *timer, int flags,

Review Comment:
   Done.



##########
sched/timer/timer_settime.c:
##########
@@ -74,6 +74,97 @@ static inline void timer_overrun(FAR struct posix_timer_s 
*timer, clock_t n)
     }
 }
 
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
+/****************************************************************************
+ * Name: timer_cputicks
+ *
+ * Description:
+ *   Read the CPU-time clock of the timer, in ticks rounded down.
+ *
+ ****************************************************************************/
+
+static int timer_cputicks(FAR struct posix_timer_s *timer,
+                          FAR clock_t *ticks)
+{
+  struct timespec ts;
+  int ret;
+
+  ret = nxclock_gettime(timer->pt_clock, &ts);
+  if (ret >= 0)
+    {
+      *ticks = clock_time2ticks_floor(&ts);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: timer_cpustart
+ *
+ * Description:
+ *   Start the watchdog of a CPU-time timer.  The CPU time cannot reach
+ *   pt_expected before the watchdog expires.  timer_timeout() then reads
+ *   the clock again and starts the watchdog again if that is necessary.
+ *
+ ****************************************************************************/
+
+static int timer_cpustart(FAR struct posix_timer_s *timer, clock_t ticks)

Review Comment:
   Done.



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