Skip to content

Commit

Permalink
critmonitor: add caller support
Browse files Browse the repository at this point in the history
Signed-off-by: ligd <[email protected]>
  • Loading branch information
GUIDINGLI authored and xiaoxiang781216 committed Sep 18, 2024
1 parent e28b311 commit 90dcd5e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
10 changes: 6 additions & 4 deletions fs/procfs/fs_procfsproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,10 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,

/* Generate output for maximum time pre-emption disabled */

linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%lu.%09lu,",
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%lu.%09lu %p,",
(unsigned long)maxtime.tv_sec,
(unsigned long)maxtime.tv_nsec);
(unsigned long)maxtime.tv_nsec,
tcb->premp_max_caller);
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
&offset);

Expand Down Expand Up @@ -827,9 +828,10 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,

/* Generate output for maximum time in a critical section */

linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%lu.%09lu,",
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%lu.%09lu %p,",
(unsigned long)maxtime.tv_sec,
(unsigned long)maxtime.tv_nsec);
(unsigned long)maxtime.tv_nsec,
tcb->crit_max_caller);
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
&offset);

Expand Down
4 changes: 4 additions & 0 deletions include/nuttx/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,15 @@ struct tcb_s
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
clock_t premp_start; /* Time when preemption disabled */
clock_t premp_max; /* Max time preemption disabled */
void *premp_caller; /* Caller of preemption disabled */
void *premp_max_caller; /* Caller of max preemption */
#endif

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
clock_t crit_start; /* Time critical section entered */
clock_t crit_max; /* Max time in critical section */
void *crit_caller; /* Caller of critical section */
void *crit_max_caller; /* Caller of max critical section */
#endif

/* State save areas *******************************************************/
Expand Down
8 changes: 4 additions & 4 deletions sched/irq/irq_csection.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ irqstate_t enter_critical_section(void)
/* Note that we have entered the critical section */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, true);
nxsched_critmon_csection(rtcb, true, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, true);
Expand Down Expand Up @@ -423,7 +423,7 @@ irqstate_t enter_critical_section(void)
/* Note that we have entered the critical section */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, true);
nxsched_critmon_csection(rtcb, true, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, true);
Expand Down Expand Up @@ -524,7 +524,7 @@ void leave_critical_section(irqstate_t flags)
/* No.. Note that we have left the critical section */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, false);
nxsched_critmon_csection(rtcb, false, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, false);
Expand Down Expand Up @@ -578,7 +578,7 @@ void leave_critical_section(irqstate_t flags)
/* Note that we have left the critical section */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
nxsched_critmon_csection(rtcb, false);
nxsched_critmon_csection(rtcb, false, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
sched_note_csection(rtcb, false);
Expand Down
6 changes: 4 additions & 2 deletions sched/sched/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,13 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb);
#endif

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state);
void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state,
FAR void *caller);
#endif

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state);
void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state,
FAR void *caller);
#endif

/* TCB operations */
Expand Down
22 changes: 16 additions & 6 deletions sched/sched/sched_critmonitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ static void nxsched_critmon_cpuload(FAR struct tcb_s *tcb, clock_t current,
* Assumptions:
* - Called within a critical section.
* - Never called from an interrupt handler
* - Caller is the address of the function that is changing the pre-emption
*
****************************************************************************/

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state)
void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state,
FAR void *caller)
{
int cpu = this_cpu();

Expand All @@ -195,6 +197,7 @@ void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state)
/* Disabling.. Save the thread start time */

tcb->premp_start = perf_gettime();
tcb->premp_caller = caller;
g_premp_start[cpu] = tcb->premp_start;
}
else
Expand All @@ -206,7 +209,8 @@ void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state)

if (elapsed > tcb->premp_max)
{
tcb->premp_max = elapsed;
tcb->premp_max = elapsed;
tcb->premp_max_caller = tcb->premp_caller;
CHECK_PREEMPTION(tcb->pid, elapsed);
}

Expand All @@ -230,11 +234,13 @@ void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state)
* Assumptions:
* - Called within a critical section.
* - Never called from an interrupt handler
* - Caller is the address of the function that is entering the critical
*
****************************************************************************/

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state)
void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state,
FAR void *caller)
{
int cpu = this_cpu();

Expand All @@ -245,6 +251,7 @@ void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state)
/* Entering... Save the start time. */

tcb->crit_start = perf_gettime();
tcb->crit_caller = caller;
g_crit_start[cpu] = tcb->crit_start;
}
else
Expand All @@ -256,7 +263,8 @@ void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state)

if (elapsed > tcb->crit_max)
{
tcb->crit_max = elapsed;
tcb->crit_max = elapsed;
tcb->crit_max_caller = tcb->crit_caller;
CHECK_CSECTION(tcb->pid, elapsed);
}

Expand Down Expand Up @@ -386,7 +394,8 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb)
elapsed = current - tcb->premp_start;
if (elapsed > tcb->premp_max)
{
tcb->premp_max = elapsed;
tcb->premp_max = elapsed;
tcb->premp_max_caller = tcb->premp_caller;
CHECK_PREEMPTION(tcb->pid, elapsed);
}
}
Expand All @@ -401,7 +410,8 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb)
elapsed = current - tcb->crit_start;
if (elapsed > tcb->crit_max)
{
tcb->crit_max = elapsed;
tcb->crit_max = elapsed;
tcb->crit_max_caller = tcb->crit_caller;
CHECK_CSECTION(tcb->pid, elapsed);
}
}
Expand Down
6 changes: 3 additions & 3 deletions sched/sched/sched_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ int sched_lock(void)
/* Note that we have pre-emption locked */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
nxsched_critmon_preemption(rtcb, true);
nxsched_critmon_preemption(rtcb, true, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
sched_note_premption(rtcb, true);
sched_note_premption(rtcb, true);
#endif
}

Expand Down Expand Up @@ -213,7 +213,7 @@ int sched_lock(void)
/* Note that we have pre-emption locked */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
nxsched_critmon_preemption(rtcb, true);
nxsched_critmon_preemption(rtcb, true, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
sched_note_premption(rtcb, true);
Expand Down
4 changes: 2 additions & 2 deletions sched/sched/sched_unlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int sched_unlock(void)
/* Note that we no longer have pre-emption disabled. */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
nxsched_critmon_preemption(rtcb, false);
nxsched_critmon_preemption(rtcb, false, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
sched_note_premption(rtcb, false);
Expand Down Expand Up @@ -250,7 +250,7 @@ int sched_unlock(void)
/* Note that we no longer have pre-emption disabled. */

#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
nxsched_critmon_preemption(rtcb, false);
nxsched_critmon_preemption(rtcb, false, return_address(0));
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
sched_note_premption(rtcb, false);
Expand Down

0 comments on commit 90dcd5e

Please sign in to comment.