anchao commented on code in PR #13293:
URL: https://github.com/apache/nuttx/pull/13293#discussion_r1753064836
##########
sched/clock/clock_systime_ticks.c:
##########
@@ -76,86 +76,51 @@
clock_t clock_systime_ticks(void)
{
#ifdef CONFIG_RTC_HIRES
- /* Do we have a high-resolution RTC that can provide us with the time? */
-
- if (g_rtc_enabled)
+ struct timespec ts =
{
- struct timespec ts;
-
- /* Get the time from the platform specific hardware */
-
- if (clock_systime_timespec(&ts) == OK)
- {
- /* Convert to a 64-bit value in microseconds,
- * then in clock tick units.
- */
-
- return timespec_to_tick(&ts);
- }
- else
- {
- return 0;
- }
- }
- else
-#endif
- {
- /* In tickless mode, all timing is controlled by platform-specific
- * code. Let the platform timer do the work.
- */
-
-#if defined(CONFIG_SCHED_TICKLESS_TICK_ARGUMENT)
- clock_t ticks;
- if (up_timer_gettick(&ticks) == OK)
- {
- return ticks;
- }
- else
- {
- return 0;
- }
-#elif defined(CONFIG_SCHED_TICKLESS)
- struct timespec ts;
- if (up_timer_gettime(&ts) == OK)
- {
- return timespec_to_tick(&ts);
- }
- else
- {
- return 0;
- }
-#elif defined(CONFIG_SYSTEM_TIME64)
-
- clock_t sample;
- clock_t verify;
-
- /* 64-bit accesses are not atomic on most architectures. The following
- * loop samples the 64-bit timer twice and loops in the rare event that
- * there was 32-bit rollover between samples.
- *
- * If there is no 32-bit rollover, then:
- *
- * - The MS 32-bits of each sample will be the same, and
- * - The LS 32-bits of the second sample will be greater than or equal
- * to the LS 32-bits for the first sample.
- */
-
- do
- {
- verify = g_system_ticks;
- sample = g_system_ticks;
- }
- while ((sample & TIMER_MASK32) < (verify & TIMER_MASK32) ||
- (sample & ~TIMER_MASK32) != (verify & ~TIMER_MASK32));
+ 0
+ };
- return sample;
+ clock_systime_timespec(&ts);
+ return clock_time2ticks(&ts);
+#elif defined(CONFIG_SCHED_TICKLESS_TICK_ARGUMENT)
+ clock_t ticks = 0;
-#else /* CONFIG_SYSTEM_TIME64 */
-
- /* Return the current system time */
-
- return g_system_ticks;
+ up_timer_gettick(&ticks);
+ return ticks;
+#elif defined(CONFIG_SCHED_TICKLESS)
+ struct timespec ts =
+ {
+ 0
+ };
-#endif /* CONFIG_SYSTEM_TIME64 */
+ up_timer_gettime(&ts);
+ return clock_time2ticks(&ts);
+#elif defined(CONFIG_SYSTEM_TIME64)
+ clock_t sample;
+ clock_t verify;
+
+ /* 64-bit accesses are not atomic on most architectures. The following
+ * loop samples the 64-bit timer twice and loops in the rare event that
+ * there was 32-bit rollover between samples.
+ *
+ * If there is no 32-bit rollover, then:
+ *
+ * - The MS 32-bits of each sample will be the same, and
+ * - The LS 32-bits of the second sample will be greater than or equal
+ * to the LS 32-bits for the first sample.
+ */
+
+ do
+ {
+ verify = g_system_ticks;
+ sample = g_system_ticks;
}
+ while ((sample & TIMER_MASK32) < (verify & TIMER_MASK32) ||
+ (sample & ~TIMER_MASK32) != (verify & ~TIMER_MASK32));
Review Comment:
could we simplify the process here on architectures that support 64-bit
atomicity
##########
sched/clock/clock_gettime.c:
##########
@@ -34,198 +34,150 @@
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include <nuttx/spinlock.h>
-#include <nuttx/queue.h>
#include "clock/clock.h"
#include "sched/sched.h"
#ifdef CONFIG_CLOCK_TIMEKEEPING
# include "clock/clock_timekeeping.h"
#endif
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_CRITMONITOR
+static clock_t clock_process_runtime(FAR struct tcb_s *tcb)
+{
+# ifdef HAVE_GROUP_MEMBERS
+ FAR struct task_group_s *group;
+ FAR sq_entry_t *curr;
+ FAR sq_entry_t *next;
+ clock_t runtime = 0;
+ irqstate_t flags;
+
+ group = tcb->group;
+
+ flags = spin_lock_irqsave(NULL);
+ sq_for_every_safe(&group->tg_members, curr, next)
Review Comment:
```suggestion
sq_for_every(&group->tg_members, curr)
```
--
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]