Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for FreeRTOS xTaskAbortDelay() (IDF-158) #1453

Closed
ammaree opened this issue Dec 30, 2017 · 16 comments
Closed

Support for FreeRTOS xTaskAbortDelay() (IDF-158) #1453

ammaree opened this issue Dec 30, 2017 · 16 comments

Comments

@ammaree
Copy link

ammaree commented Dec 30, 2017

In order to facilitate graceful shutdown and restart of our application we require the ability to take (primarily network) tasks out of a blocked state and force them through their cleanup and termination process.

I have scanned the current FreeRTOS source and noticed that this function is only referred to through its INCLUDE_ macro but nothing implemented. Are there any plans to backport this function and if so, in what timescale.

Thanks

AMM

@FayeY FayeY changed the title Backporting implementation of xTaskAbortDelay() [TW#17307] Backporting implementation of xTaskAbortDelay() Jan 3, 2018
@ammaree
Copy link
Author

ammaree commented Jan 6, 2018

Any chance of some feedback on this request.

We are trying to implement a clean/organised shutdown process but without htis function being available have no control over blocked tasks..

Thanks

@igrr
Copy link
Member

igrr commented Jan 6, 2018

Adding this function is currently planned together with migration to FreeRTOS 10, which might take a few months. We will update this ticket once more concrete plan is available.

@ammaree
Copy link
Author

ammaree commented Jan 6, 2018

Very good news, other than the timeframe

@ammaree
Copy link
Author

ammaree commented Mar 14, 2018

Hi @igrr

Any progress on porting xTaskAbortDelay()?

Thanks,
Andre

@chanibal
Copy link
Contributor

Instead of waiting for xTaskAbortDelay, I'm using a combination of xTaskNotifyWait with a timeout for delay and xTaskNotify with a to abort the delay. It doesn't use any additional resources.

Using a flag with them allows you to know if the wait was aborted (or even allow for conditional cancelation).

@ammaree
Copy link
Author

ammaree commented Mar 14, 2018

Hi @chanibal @igrr

The whole problem revolves around FOTA and esp_restart() not working consistently, a critical functionality to make FOTA work reliably. The FOTA happens 99% reliably, new firmware is downloaded and written, problem comes with the restart.

We have already been forced (against our will) to revert to UNICORE mode to improve restart reliability and currently have about ~75-80% successful restarts across 40 test devices running the exact same UNICORE firmware. Based on a recent scan of the issues here it seems we are not the only ones with the problem.

To further improve esp_restart() reliability it seems we have to do organised shutdown and cleanup of as many user tasks as possible (all?), prior to calling esp_restart(), and that is where we are working now.

The challenge lies in telnet, http and mqtt tasks where we do blocking calls in read(), select() and accept() and would like to abort these tasks and do proper cleanup in case of events such as restarts for firmware upgrades.

Rewriting the complete task flow to be non blocking to work around the absence of xTaskAbortDelay() is not a clean solution. Right now we are forced to change the calls to be non blocking with short timeouts (basically polling) then handle EAGAIN and EWOULDBLOCK, and restart the waiting process.

We also have to add a check for a status flag to determine if a signal has been given for the task to abort, and then start the cleanup process.

If I am missing some alternative to manage blocking socket calls, please let me know.

Andre

@chanibal
Copy link
Contributor

@ammaree unfortunatelly, my hint is only applicable with simple delay calls, not moving the tasks back from the blocked state.

I have looked around the sources of the new FreeRTOS's tasks.c for a bit, and it looks like you could try to backport xTaskAbortDelay yourself. The TCB structures look like they're almost the same as in the IDF's version.

I have no idea if aborting a wait for a network call might have any additional side effects or will this be the same as a timeout.

@ammaree
Copy link
Author

ammaree commented Aug 27, 2018

@igrr any progress on this item?

@ammaree
Copy link
Author

ammaree commented Jan 5, 2019

@igrr @projectgus any update on this request?

Please ??

@projectgus
Copy link
Contributor

Hi @ammaree ,

Sorry for the extended silence. We've decided to stop backporting FreeRTOS features to our ESP-IDF fork of FreeRTOS V9, and instead we're focusing on updating to add SMP support to FreeRTOS V10.

So far we don't have an ETA for this update, I'm sorry. We will update this GitHub issue as soon as that work is done, though.

@projectgus projectgus changed the title [TW#17307] Backporting implementation of xTaskAbortDelay() Backporting implementation of xTaskAbortDelay() (IDF-158) Mar 12, 2019
@monkeytronics
Copy link

How close are you wonderful people to esp-IDF with amazon freertos. Is SMP working yet? Any hope of getting it into platformio? Keen to port existing projects using esp8266 across. I want to use Amazon's ota; jitp; and easy integration with awsiot. And bin all my messy Mqtt, password manager & not really secure enough garbage code.

@ammaree
Copy link
Author

ammaree commented Aug 25, 2020

@igrr @projectgus
Gents, we are almost 2years 8 months after the original issue was logged. Since then the proposed solution was moved towards a FreeRTOS 10 based solution.

In various other posts we have been encouraged to test the feature branch but very quickly came up against some obstacles there, see #5763

Any chance we can have some clarity on
a) the exact status of support for FreeRTOS 10?
b) the target date for full transparent FR10 support in ESP-IDF?

Thanks

@projectgus
Copy link
Contributor

Hi @ammaree,

Thanks for being patient with us as we worked through this. Maintaining an SMP-enabled FreeRTOS port is relatively complex, as I'm sure you can image, and we've been careful to try and avoid regressions when updating the FreeRTOS kernel.

FreeRTOS 10 is now in the ESP-IDF master branch and can be used now. It will be available in the ESP-IDF v4.3 stable release which is planned for late Q1 next year.

I'm afraid the configuration flag to enable xTaskAbortDelay() is still disabled in ESP-IDF, so this particular feature remains unsupported. It is a one line change to add a macro in FreeRTOSConfig.h to enable it, and in my basic tests this works fine.

However, testing it works correctly under all possible permutations of an SMP system is a relatively complex task that we haven't had time to do yet. There are also a lot of places inside ESP-IDF code that assume a delay won't be aborted - so we need to check all of these are handled cleanly. This includes the network calls that you've mentioned as your use case, LWIP isn't designed on the assumption that any blocking mutex/queue call can time out early so we need to check the implications of that carefully.

Therefore, I'm afraid we still don't have an ETA for full support of this feature.

@projectgus projectgus changed the title Backporting implementation of xTaskAbortDelay() (IDF-158) Support for FreeRTOS xTaskAbortDelay() (IDF-158) Oct 15, 2020
@AxelLin
Copy link
Contributor

AxelLin commented Oct 16, 2020

Hi @projectgus

FreeRTOS 10 is now in the ESP-IDF master branch and can be used now.

Just FYI, there is a compile error in current master tree.

/home/axel/esp/esp-idf/components/freertos/tasks.c: In function 'vTaskGetInfo':
/home/axel/esp/esp-idf/components/freertos/tasks.c:4137:15: error: 'pxTaskStatus' is a pointer; did you mean to use '->'?
   pxTaskStatus.xCoreID = pxTCB->xCoreID;
               ^
               ->
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

@projectgus
Copy link
Contributor

Thanks @AxelLin, will fix.

Everyone, to report any other issues related to FreeRTOS 10 but not related to xTaskAbortDelay() please open a new issue with the details.

espressif-bot pushed a commit that referenced this issue Nov 3, 2020
Regression when adding FreeRTOS 10 support.

As reported at #1453 (comment)
@ammaree
Copy link
Author

ammaree commented Jul 6, 2021

Have not tested yet since we reworked all our tasks.
Assume fixed/working since no warning notes found in FreeRTOS 10 source

@ammaree ammaree closed this as completed Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants