Skip to content

Conversation

@jserv
Copy link
Contributor

@jserv jserv commented Nov 19, 2025

This implements an asynchronous I/O pattern for printf/puts, eliminating race conditions in preemptive multitasking.

  • Ring buffer: 8 entries × 128 bytes (1KB total)
  • Logger task at IDLE priority: drains queue to UART
  • Mutex-protected enqueue/dequeue with short critical sections
  • UART output outside lock: prevents blocking other tasks during writes
  • Graceful degradation: falls back to direct output on queue full

Close #34


Summary by cubic

Makes printf/puts thread-safe under preemptive scheduling by deferring UART writes to a low-priority logger task. This avoids race conditions and prevents other tasks from blocking during output; falls back to direct output when the queue is full.

  • New Features
    • Logger subsystem with a ring buffer (8 entries × 128 bytes = 1KB).
    • IDLE-priority logger task drains the queue; UART writes happen outside the mutex.
    • printf/puts now enqueue messages; direct output is used during early boot or on overflow.
    • New APIs: mo_logger_init, mo_logger_enqueue, mo_logger_queue_depth, mo_logger_dropped_count.
    • Kernel wiring: logger.o added; main initializes the logger; _putchar declared for low-level output.

Written for commit 3359f53. Summary will update automatically on new commits.

cubic-dev-ai[bot]

This comment was marked as resolved.

This implements an asynchronous I/O pattern for printf/puts, eliminating
race conditions in preemptive multitasking.
- Ring buffer: 8 entries × 128 bytes (1KB total)
- Logger task at IDLE priority: drains queue to UART
- Mutex-protected enqueue/dequeue with short critical sections
- UART output outside lock: prevents blocking other tasks during writes
- Graceful degradation: falls back to direct output on queue full

Benefits:
- Lower interrupt latency
- ISRs remain responsive during logging
- No nested critical section issues
@jserv jserv force-pushed the thread-safe-printf branch from 64d2a47 to 3359f53 Compare November 19, 2025 18:40
@github-actions
Copy link

Linmo CI Test Results

Overall Status: ✅ passed
Timestamp: 2025-11-19T18:44:02+00:00

Toolchain Results

Toolchain Build Crash Test Functional
GNU ✅ passed ✅ passed ✅ passed
LLVM ✅ passed ⏭️ skipped ⏭️ skipped

Application Tests

App GNU LLVM
cond ✅ passed ⏭️ skipped
coop ✅ passed ⏭️ skipped
cpubench ✅ passed ⏭️ skipped
echo ✅ passed ⏭️ skipped
hello ✅ passed ⏭️ skipped
mqueues ✅ passed ⏭️ skipped
mutex ✅ passed ⏭️ skipped
pipes ✅ passed ⏭️ skipped
pipes_small ✅ passed ⏭️ skipped
pipes_struct ✅ passed ⏭️ skipped
prodcons ✅ passed ⏭️ skipped
progress ✅ passed ⏭️ skipped
rtsched ✅ passed ⏭️ skipped
semaphore ✅ passed ⏭️ skipped
suspend ✅ passed ⏭️ skipped
test64 ✅ passed ⏭️ skipped
test_libc ✅ passed ⏭️ skipped
timer ✅ passed ⏭️ skipped
timer_kill ✅ passed ⏭️ skipped

Functional Test Details

Test GNU LLVM
mutex:data_consistency ✅ passed ⏭️ skipped
mutex:fairness ✅ passed ⏭️ skipped
mutex:mutual_exclusion ✅ passed ⏭️ skipped
mutex:overall ✅ passed ⏭️ skipped
semaphore:all_tests_passed! ✅ passed ⏭️ skipped

Report generated from test-summary.toml

@sysprog21 sysprog21 deleted a comment from github-actions bot Nov 19, 2025
@jserv jserv merged commit 36e82af into main Nov 19, 2025
3 checks passed
@jserv jserv deleted the thread-safe-printf branch November 19, 2025 18:46
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.

mutex and semaphore tests timeout or fail to build

2 participants