configUSE_TICKLESS_IDLE

l4n4 wrote on Friday, April 04, 2014:

If we enable the configUSE_TICKLESS_IDLE, it will go to ‘idle’ only when the xExpectedIdleTime >= 2. Do you think , it’s worthwhile to call the __WFI (wait for interrupt) even if the xExpectedIdleTime is < 2 (in term of power saving)? I’m running a 180Mhz cortex M3.

if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )
{
portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );
}
else{
__WFI(); //add wait for interrupt here
}

rtel wrote on Friday, April 04, 2014:

It may be that, in your particular application, you get some benefit from doing that, but if so I would not recommend changing the source code in that way but instead define an idle hook function that just calls wfi.

Regards.

l4n4 wrote on Friday, April 04, 2014:

The idle hook will be called all the time and before portSUPPRESS_TICKS_AND_SLEEP, so it will always sleep for 1 tick time first before do any further checks. This means :

  • if xExpectedIdleTime < 2 : this is ok
  • if xExpectedIdleTime == 2 : Idle hook will sleep for 1 tick and portSUPPRESS_TICKS_AND_SLEEP will not be called. I would like the portSUPPRESS_TICKS_AND_SLEEP to be called in this condition.
  • xExpectedIdleTime > 2 : this is ok

Thanks!

rtel wrote on Friday, April 04, 2014:

How about setting configEXPECTED_IDLE_TIME_BEFORE_SLEEP to 0 (may cause a compiler warning where the >= check is performed) then use the configPRE_SLEEP_PROCESSING to check the expected idle time and if the expected idle time is below a threshold set by yourself it can just call wfi and cancel the tickless entry (the macros parameter can be used for cancelling the tickless entry).

Regards.

mplmht wrote on Tuesday, January 10, 2017:

I have the same concern here but I would like to keep usage of configEXPECTED_IDLE_TIME_BEFORE_SLEEP functionnality which is interesting I beleive.

I would like to get your advice on following code change proposal:

  • when tickless idle feature is enabled, call to the idle hook
    when xExpectedIdleTime is below configEXPECTED_IDLE_TIME_BEFORE_SLEEP
  • when tickless idle feature is not enabled, keep calling the idle hook the same way as now.

The code change could look like below in portTASK_FUNCTION function of tasks.c (line 3177 of v9.0.0)?

#if ( configUSE_TICKLESS_IDLE == 0 )
    #if ( configUSE_IDLE_HOOK == 1 )
    {
        extern void vApplicationIdleHook( void );

        /* Call the user defined function from within the idle task.  This
        allows the application designer to add background functionality
        without the overhead of a separate task.
        NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,
        CALL A FUNCTION THAT MIGHT BLOCK. */
        vApplicationIdleHook();
    }
    #endif /* ( configUSE_IDLE_HOOK == 1 ) */

/* This conditional compilation should use inequality to 0, not equality
to 1.  This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when
user defined low power mode	implementations require
configUSE_TICKLESS_IDLE to be set to a value other than 1. */
#else /* configUSE_TICKLESS_IDLE != 0 */
{
TickType_t xExpectedIdleTime;

    /* It is not desirable to suspend then resume the scheduler on
    each iteration of the idle task.  Therefore, a preliminary
    test of the expected idle time is performed without the
    scheduler suspended.  The result here is not necessarily
    valid. */
    xExpectedIdleTime = prvGetExpectedIdleTime();

    if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )
    {
        vTaskSuspendAll();
        {
            /* Now the scheduler is suspended, the expected idle
            time can be sampled again, and this time its value can
            be used. */
            configASSERT( xNextTaskUnblockTime >= xTickCount );
            xExpectedIdleTime = prvGetExpectedIdleTime();

            if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )
            {
                traceLOW_POWER_IDLE_BEGIN();
                portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );
                traceLOW_POWER_IDLE_END();
            }
            else
            {
                mtCOVERAGE_TEST_MARKER();
                #if ( configUSE_IDLE_HOOK == 1 )
                {
                    extern void vApplicationIdleHook( void );

                    /* Call the user defined function from within the idle task.  This
                    allows the application designer to add background functionality
                    without the overhead of a separate task.
                    NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,
                    CALL A FUNCTION THAT MIGHT BLOCK. */
                    vApplicationIdleHook();
                }
                #endif /* configUSE_IDLE_HOOK */
            }
        }
        ( void ) xTaskResumeAll();
    }
    else
    {
        mtCOVERAGE_TEST_MARKER();
    }
}
#endif /* configUSE_TICKLESS_IDLE */

Regards.

rtel wrote on Tuesday, January 10, 2017:

Hi - thanks for your input, although I doubt this would be adopted
because it would change the existing behaviour, which could cause issues
for users that update the version of FreeRTOS they are using in existing
applications.