Performance improvement: Idle loop should not take MM semaphore if there is not garbage to be collected. This can cause loss of performance and thrashing in tasking

This commit is contained in:
Gregory Nutt
2016-02-16 19:33:22 -06:00
parent 6dfa72d038
commit 6aeb4a52e8
6 changed files with 103 additions and 13 deletions
+3 -2
View File
@@ -97,6 +97,7 @@ int os_idletask(int argc, FAR char *argv[])
/* Enter the IDLE loop */
sdbg("CPU%d: Beginning Idle Loop\n", this_cpu());
for (; ; )
{
/* Perform garbage collection (if it is not being done by the worker
@@ -118,9 +119,9 @@ int os_idletask(int argc, FAR char *argv[])
* queue so that is done in a safer context.
*/
if (kmm_trysemaphore() == 0)
if (sched_have_garbage() && kmm_trysemaphore() == 0)
{
sched_garbagecollection();
sched_garbage_collection();
kmm_givesemaphore();
}
#endif
+6 -4
View File
@@ -415,11 +415,13 @@ void os_start(void)
#endif
{
FAR dq_queue_t *tasklist;
int hashndx;
/* Assign the process ID(s) of ZERO to the idle task(s) */
g_pidhash[PIDHASH(g_lastpid)].tcb = &g_idletcb[cpu].cmn;
g_pidhash[PIDHASH(g_lastpid)].pid = g_lastpid;
hashndx = PIDHASH(g_lastpid);
g_pidhash[hashndx].tcb = &g_idletcb[cpu].cmn;
g_pidhash[hashndx].pid = g_lastpid;
/* Initialize a TCB for this thread of execution. NOTE: The default
* value for most components of the g_idletcb are zero. The entire
@@ -783,9 +785,9 @@ void os_start(void)
* queue so that is done in a safer context.
*/
if (kmm_trysemaphore() == 0)
if (sched_have_garbage() && kmm_trysemaphore() == 0)
{
sched_garbagecollection();
sched_garbage_collection();
kmm_givesemaphore();
}
#endif