hujun260 commented on code in PR #15324:
URL: https://github.com/apache/nuttx/pull/15324#discussion_r1898496814


##########
sched/clock/clock_systime_timespec.c:
##########
@@ -62,21 +62,21 @@
 int clock_systime_timespec(FAR struct timespec *ts)
 {
 #ifdef CONFIG_RTC_HIRES
+  irqstate_t flags;
+
+  flags = spin_lock_irqsave(&g_basetime_lock);
   if (g_rtc_enabled)
     {
-      irqstate_t flags;
-
       up_rtc_gettime(ts);

Review Comment:
   Many cases are not simply a matter of replacement. 
   
   There are roughly three purposes:
   1 The current c_section is used too extensively, leading many meaningless 
busywaits. Using smaller locks can avoid competition among critical sections, 
thereby improving performance.
   2 There are logical flaws in c_section, It doesn't match the apparent 
semantics. which can cause the protection provided by the c_section to fail in 
casees where wait/post is called.
   for example
   enter_critical_section
   post/wait  ->>> protection failed 
   leave_critical_section
   3 The implementation of the c_section itself is complex and time-consuming. 
Using a spinlock is better than using a critical section.
   4 Due to the auto locking and unlocking mechanism during context switching 
in c_section, we are unable to precisely control the duration of the lock, 
which leads to performance issues.



##########
sched/clock/clock_systime_timespec.c:
##########
@@ -62,21 +62,21 @@
 int clock_systime_timespec(FAR struct timespec *ts)
 {
 #ifdef CONFIG_RTC_HIRES
+  irqstate_t flags;
+
+  flags = spin_lock_irqsave(&g_basetime_lock);
   if (g_rtc_enabled)
     {
-      irqstate_t flags;
-
       up_rtc_gettime(ts);

Review Comment:
   Many cases are not simply a matter of replacement. 
   
   There are roughly 4 purposes:
   1 The current c_section is used too extensively, leading many meaningless 
busywaits. Using smaller locks can avoid competition among critical sections, 
thereby improving performance.
   2 There are logical flaws in c_section, It doesn't match the apparent 
semantics. which can cause the protection provided by the c_section to fail in 
casees where wait/post is called.
   for example
   enter_critical_section
   post/wait  ->>> protection failed 
   leave_critical_section
   3 The implementation of the c_section itself is complex and time-consuming. 
Using a spinlock is better than using a critical section.
   4 Due to the auto locking and unlocking mechanism during context switching 
in c_section, we are unable to precisely control the duration of the lock, 
which leads to performance issues.



-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to