diff --git a/sched/sched/sched_critmonitor.c b/sched/sched/sched_critmonitor.c index e54678356b9..db504fb53c4 100644 --- a/sched/sched/sched_critmonitor.c +++ b/sched/sched/sched_critmonitor.c @@ -138,31 +138,18 @@ void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state) if (state) { - DEBUGASSERT(tcb->premp_start == 0); - /* Disabling.. Save the thread start time */ - tcb->premp_start = up_perf_gettime(); - - /* Zero means that the timer is not ready */ - - if (tcb->premp_start != 0 && g_premp_start[cpu] == 0) - { - /* Save the global start time */ - - g_premp_start[cpu] = tcb->premp_start; - } + tcb->premp_start = up_perf_gettime(); + g_premp_start[cpu] = tcb->premp_start; } - else if (tcb->premp_start != 0) + else { /* Re-enabling.. Check for the max elapsed time */ uint32_t now = up_perf_gettime(); uint32_t elapsed = now - tcb->premp_start; - DEBUGASSERT(now != 0); - - tcb->premp_start = 0; if (elapsed > tcb->premp_max) { tcb->premp_max = elapsed; @@ -171,15 +158,10 @@ void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state) /* Check for the global max elapsed time */ - if (g_premp_start[cpu] != 0) + elapsed = now - g_premp_start[cpu]; + if (elapsed > g_premp_max[cpu]) { - elapsed = now - g_premp_start[cpu]; - g_premp_start[cpu] = 0; - - if (elapsed > g_premp_max[cpu]) - { - g_premp_max[cpu] = elapsed; - } + g_premp_max[cpu] = elapsed; } } } @@ -206,28 +188,16 @@ void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state) { /* Entering... Save the start time. */ - DEBUGASSERT(tcb->crit_start == 0); - tcb->crit_start = up_perf_gettime(); - - /* Zero means that the timer is not ready */ - - if (tcb->crit_start != 0 && g_crit_start[cpu] == 0) - { - /* Set the global start time */ - - g_crit_start[cpu] = tcb->crit_start; - } + tcb->crit_start = up_perf_gettime(); + g_crit_start[cpu] = tcb->crit_start; } - else if (tcb->crit_start != 0) + else { /* Leaving .. Check for the max elapsed time */ uint32_t now = up_perf_gettime(); uint32_t elapsed = now - tcb->crit_start; - DEBUGASSERT(now != 0); - - tcb->crit_start = 0; if (elapsed > tcb->crit_max) { tcb->crit_max = elapsed; @@ -236,15 +206,10 @@ void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state) /* Check for the global max elapsed time */ - if (g_crit_start[cpu] != 0) + elapsed = now - g_crit_start[cpu]; + if (elapsed > g_crit_max[cpu]) { - elapsed = now - g_crit_start[cpu]; - g_crit_start[cpu] = 0; - - if (elapsed > g_crit_max[cpu]) - { - g_crit_max[cpu] = elapsed; - } + g_crit_max[cpu] = elapsed; } } } @@ -268,9 +233,6 @@ void nxsched_resume_critmon(FAR struct tcb_s *tcb) int cpu = this_cpu(); uint32_t elapsed; - DEBUGASSERT(tcb->premp_start == 0 && tcb->crit_start == 0 && - tcb->run_start == 0); - tcb->run_start = current; /* Did this task disable pre-emption? */ @@ -279,22 +241,14 @@ void nxsched_resume_critmon(FAR struct tcb_s *tcb) { /* Yes.. Save the start time */ - tcb->premp_start = current; - - /* Zero means that the timer is not ready */ - - if (g_premp_start[cpu] == 0) - { - g_premp_start[cpu] = tcb->premp_start; - } + tcb->premp_start = current; + g_premp_start[cpu] = current; } - else if (g_premp_start[cpu] != 0) + else { /* Check for the global max elapsed time */ - elapsed = current - g_premp_start[cpu]; - g_premp_start[cpu] = 0; - + elapsed = current - g_premp_start[cpu]; if (elapsed > g_premp_max[cpu]) { g_premp_max[cpu] = elapsed; @@ -308,20 +262,14 @@ void nxsched_resume_critmon(FAR struct tcb_s *tcb) { /* Yes.. Save the start time */ - tcb->crit_start = current; - - if (g_crit_start[cpu] == 0) - { - g_crit_start[cpu] = tcb->crit_start; - } + tcb->crit_start = current; + g_crit_start[cpu] = current; } - else if (g_crit_start[cpu] != 0) + else { /* Check for the global max elapsed time */ - elapsed = current - g_crit_start[cpu]; - g_crit_start[cpu] = 0; - + elapsed = current - g_crit_start[cpu]; if (elapsed > g_crit_max[cpu]) { g_crit_max[cpu] = elapsed; @@ -348,7 +296,6 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb) uint32_t current = up_perf_gettime(); uint32_t elapsed = current - tcb->run_start; - tcb->run_start = 0; if (elapsed > tcb->run_max) { tcb->run_max = elapsed; @@ -362,8 +309,6 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb) /* Possibly re-enabling.. Check for the max elapsed time */ elapsed = current - tcb->premp_start; - - tcb->premp_start = 0; if (elapsed > tcb->premp_max) { tcb->premp_max = elapsed; @@ -378,8 +323,6 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb) /* Possibly leaving .. Check for the max elapsed time */ elapsed = current - tcb->crit_start; - - tcb->crit_start = 0; if (elapsed > tcb->crit_max) { tcb->crit_max = elapsed;