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

feat(task): Allow run_on_core callers to ensure a separate task is created #358

Merged
merged 3 commits into from
Jan 7, 2025

Conversation

finger563
Copy link
Contributor

Description

  • Update espp::task::run_on_core (blocking) APIs to have a bool ensure_task = false parameter which (if true) will ensure that the function is run in a separate task, regardless of the requested core and current core id.
  • Update espp::task::run_on_core (blocking) APIs so that core_id = -1 (do not care) parameter will still spawn a separate task, instead of running in the same context as the calling function.

Motivation and Context

The espp::task::run_on_core provides a convenient API for ensuring a function is run in a separate task (with its own stack) in a way that cleans up the memory and provides easy to read code. However, it was not great for guaranteeing that the requested stack is provided to the function, since there were conditions when it would run in the calling context (which may not have enough stack space).

This PR addresses that by providing a new optional argument ensure_task = false which (if true) will force the function to run in a separate task, ensuring that the function is provided the requested stack in that case.

This also makes the change that a don't-care core_id (-1) now no longer means that the function should run in the same thread-context as the caller. There's no benefit to that behavior since it doesn't guarantee anything about the execution core or the stack space available, so now a don't care (-1) core_id will ensure a task is spawned and the scheduler can decide the core to put it on.

How has this been tested?

Building and running task/example on a QtPy ESP32s3.

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

Hardware

  • I have updated the design files (schematic, board, libraries).
  • I have attached the PDFs of the SCH / BRD to this PR
  • I have updated the design output (GERBER, BOM) files.

…created

* Update `espp::task::run_on_core` (blocking) APIs to have a `bool ensure_task = false` parameter which (if true) will ensure that the function is run in a separate task, regardless of the requested core and current core id.
* Update `espp::task::run_on_core` (blocking) APIs so that `core_id = -1` (do not care) parameter will still spawn a separate task, instead of running in the same context as the calling function.
@finger563 finger563 self-assigned this Jan 6, 2025
@finger563 finger563 added enhancement New feature or request tasks labels Jan 6, 2025
Copy link

github-actions bot commented Jan 6, 2025

✅Static analysis result - no issues found! ✅

@finger563 finger563 merged commit 4ee42c8 into main Jan 7, 2025
69 checks passed
@finger563 finger563 deleted the feat/task-run-on-core branch January 7, 2025 04:20
SquaredPotato pushed a commit to smartknob-ha/espp that referenced this pull request Jan 27, 2025
…created (esp-cpp#358)

* feat(task): Allow `run_on_core` callers to ensure a separate task is created
* Update `espp::task::run_on_core` (blocking) APIs to have a `bool ensure_task = false` parameter which (if true) will ensure that the function is run in a separate task, regardless of the requested core and current core id.
* Update `espp::task::run_on_core` (blocking) APIs so that `core_id = -1` (do not care) parameter will still spawn a separate task, instead of running in the same context as the calling function.

* minor update to commnet

* consistency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant