Skip to content

Conversation

@tact1m4n3
Copy link
Collaborator

@tact1m4n3 tact1m4n3 commented Feb 8, 2026

Some numbers with 200 concurrent tasks:

  • Plain cooperative rescheduling of a task until the switch to a different task: 140-150 cycles
  • If the task suspends itself (eg: waiting on a mutex without timeout): 126-137 cycles (this only measures the yielding time, not the overhead induced by the mutex)
  • If the task sleeps: 268-1700 cycles (1700 is for the 200th task that must be inserted at the end of the sleep_queue since it wakes up last). This is O(n). Also there is an overhead in the tick interrupt when all these tasks are woken up: the max tick interrupt time is close to 4000cycles (O(n) with the number of tasks waking up on the same tick) (otherwise being ~250cycles if no tasks wake).

I also added support for time slicing (switch between tasks of the same priority on the tick interval). This is by default off.

Tasks can now be awaited and the memory freed. I used this to implement cleanup for radio/timer.zig, but for the tasks spawned by the wifi driver it is more complicated so I will leave this for a later PR.

Unit tests for the esp port now run on CI.

@tact1m4n3 tact1m4n3 merged commit 82c7d8d into main Feb 10, 2026
59 of 60 checks passed
@tact1m4n3 tact1m4n3 deleted the esp_rtos_upgrade branch February 10, 2026 08:30
@github-actions
Copy link

⚠️ Unused Imports Found

examples/espressif/esp/src/rtos.zig:7:0: gpio is unused
examples/espressif/esp/src/rtos.zig:5:0: peripherals is unused
examples/espressif/esp/src/rtos.zig:2:0: log is unused
examples/espressif/esp/src/rtos.zig:8:0: systimer is unused
examples/espressif/esp/src/tcp_server.zig:5:0: interrupt is unused
examples/espressif/esp/src/tcp_server.zig:2:0: assert is unused
port/espressif/esp/src/hal/radio/osi.zig:8:0: time is unused
port/espressif/esp/src/hal/radio/osi.zig:16:0: systimer is unused
port/espressif/esp/src/hal/rtos.zig:3:0: Allocator is unused
port/espressif/esp/src/hal/rtos.zig:15:0: get_time_since_boot is unused
port/espressif/esp/src/hal/rtos.zig:11:0: SYSTEM is unused
port/espressif/esp/src/hal/rtos.zig:8:0: CriticalSection is unused
port/espressif/esp/src/hal/rtos.zig:12:0: time is unused
port/espressif/esp/src/hal/rtos.zig:5:0: builtin is unused

Run zigimports --fix <file> locally to automatically remove unused imports.

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

Successfully merging this pull request may close these issues.

3 participants