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


##########
include/nuttx/spinlock.h:
##########
@@ -973,16 +1000,16 @@ bool rspin_trylock(FAR rspinlock_t *lock);
  ****************************************************************************/
 
 #ifdef CONFIG_SPINLOCK
-static inline_function
+static inline_function noinstrument_function
 void spin_unlock_irqrestore_notrace(FAR volatile spinlock_t *lock,
                                 irqstate_t flags)
 {
   spin_unlock_notrace(lock);
 
-  irq_restore(flags);
+  up_irq_restore(flags);

Review Comment:
   With critmon on, `spin_lock_irqsave()` starts with `irq_save()` (line 500), 
which counts `irqdis_count` up. `spin_unlock_irqrestore()` ends in 
`spin_unlock_irqrestore_notrace()`, which calls `up_irq_restore()` here, so the 
count never comes down. After the first 
`spin_lock_irqsave()`/`spin_unlock_irqrestore()` pair, every later `irq_save()` 
of the task returns early in `nxsched_critmon_irqdisable()` 
(sched_critmonitor.c:278), and the IRQ-disabled time of the task is no longer 
measured. `spin_trylock_irqsave()` (line 957) has the same imbalance.
   
   Fix: in `spin_unlock_irqrestore()`, call `spin_unlock_notrace(lock)` and 
then `irq_restore(flags)` instead of `spin_unlock_irqrestore_notrace()`, as 
`rspin_unlock_irqrestore()` does (line 1171) and as commit 2d57c1d19cf 
describes.



##########
sched/irq/irq_csection.c:
##########
@@ -310,11 +310,8 @@ irqstate_t enter_critical_section(void)
       rtcb = this_task();
       if (rtcb->irqcount == 1)

Review Comment:
   This removes the `nxsched_critmon_csection()` calls, but 
`enter_critical_section_notrace()` uses `up_irq_save()` (lines 110 and 264) and 
`leave_critical_section_notrace()` uses `up_irq_restore()` (lines 431 and 456). 
So the time in a critical section is no longer measured at all, on UP and SMP, 
although the Kconfig help of `SCHED_CRITMONITOR_MAXTIME_IRQDISABLE` says it 
covers `enter_critical_section`.
   
   Fix: use `irq_save()`/`irq_restore()` in 
`enter_critical_section_notrace()`/`leave_critical_section_notrace()`, or keep 
the critmon call here.



##########
sched/Kconfig:
##########
@@ -1101,27 +1108,28 @@ config SCHED_CRITMONITOR_MAXTIME_PREEMPTION
                SCHED_CRITMONITOR_MAXTIME_PREEMPTION, or system will give a 
warning.
                For debugging system latency, 0 means disabled.
 
-config SCHED_CRITMONITOR_MAXTIME_CSECTION
-       int "Csection (enter_critical_section) max holding time"
+config SCHED_CRITMONITOR_MAXTIME_IRQDISABLE

Review Comment:
   nuttx-apps `system/critmon/critmon.c` (lines 236 and 384) still tests 
`CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION`. On arm64, qemu-armv8a:nsh_smp with 
`CONFIG_SCHED_CRITMONITOR=y` and `CONFIG_SYSTEM_CRITMONITOR=y` now fails: 
`critmon.c:236:5: error: "CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION" is not 
defined, evaluates to 0 [-Werror=undef]`. On the other arches the name is 0, so 
critmon reads a column that the kernel does not print when the option is -1 
(the default).
   
   Fix: open the nuttx-apps PR that renames the option in 
`system/critmon/critmon.c`, and merge the two together.



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