Skip to content

samples: Add task statistics and semaphore samples - #43

Open
Aditya-abs397 wants to merge 2 commits into
vedantmalkar:mainfrom
Aditya-abs397:samples/samples_sem_stats
Open

samples: Add task statistics and semaphore samples#43
Aditya-abs397 wants to merge 2 commits into
vedantmalkar:mainfrom
Aditya-abs397:samples/samples_sem_stats

Conversation

@Aditya-abs397

@Aditya-abs397 Aditya-abs397 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds two new samples (samples/stats and samples/sem) demonstrating AstraRTOS's task statistics and the counting semaphore implementation for a resource with limited concurrent access.

What it does

Task statistics sample (samples/stats)

  • Defines two tasks: stats_task (telemetry) and addition_task (a simple counter, included to give the stats output a second user task to report on).
  • stats_task calls os_task_get_stats() once per second for every active task in the scheduler.
  • Reports run count, stack high-water mark, and allocated stack size.
  • Output includes both user-created tasks and the scheduler's auto-created idle task.
  • Uses polled UART (uart_send_string) for printing.

Semaphore sample (samples/sem)

  • Defines four tasks (task_a - task_d) across three priority levels.
  • Shared resource protected by a counting semaphore initialized with capacity = 2.
  • Each task waits, acquires, holds the resource for 300 ms, then releases in a loop.
  • Demonstrates that os_sem_give() wakes the highest-priority waiting task first when a slot frees up.
  • UART output is protected, so logs are clean and non-interleaved.

Testing

Verified both samples on QEMU

Semaphore sample output:
Sem sample output

Task statistics sample output:

Task statistics output

Related

Part of #15

Adds new sample for implementation of task statistics,
os_task_get_stats is used to pull live scheduler data, and polled
UART transmission is used to print it without depending on
interrupts.

Part of vedantmalkar#15

Signed-off-by: Aditya Salunke <adisalunke07@gmail.com>
Adds a sample for semaphore, with 4 priority-tiered tasks sharing a
resource capped at 2 concurrent users, proving priority-based access
ordering with mutex protected logging.

Signed-off-by: Aditya Salunke <adisalunke07@gmail.com>
@Aditya-abs397
Aditya-abs397 force-pushed the samples/samples_sem_stats branch from 86f47ae to 885fd40 Compare July 27, 2026 20:40
@Aditya-abs397

Copy link
Copy Markdown
Contributor Author

Worked on suggested changes.

@vedantmalkar

Copy link
Copy Markdown
Owner

pinging @mt-tass

@mt-tass

mt-tass commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@Aditya-abs397 did you test this on board ?

@Aditya-abs397

Copy link
Copy Markdown
Contributor Author

@mt-tass I haven't tested it on board yet, will make sure to do it before tomorrow

@mt-tass

mt-tass commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@Aditya-abs397 updates ?

@Aditya-abs397

Copy link
Copy Markdown
Contributor Author

@mt-tass Tested both samples on stm32 discovery board, its working

sem_basic testing
hardware testing sem_basic

sem.implementation.mp4

stats_basic testing
stats sample testing

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