Skip to content

sched/mqueue: Enable receiving messages on an interrupt handler#18376

Merged
linguini1 merged 1 commit intoapache:masterfrom
tmedicci:improvement/mq_receive_isr
Feb 11, 2026
Merged

sched/mqueue: Enable receiving messages on an interrupt handler#18376
linguini1 merged 1 commit intoapache:masterfrom
tmedicci:improvement/mq_receive_isr

Conversation

@tmedicci
Copy link
Contributor

Summary

  • sched/mqueue: Enable receiving messages on an interrupt handler

The internal implementation of file_mq_receive did not allow receiving a message from an interrupt handler. Although it is not possible to wait for a message in an interrupt context, it is perfectly possible to retrieve already-existing messages from the message queue. This commit modifies file_mq_timedreceive_internal to enable checking the message list and, if no messages exist, it returns immediately. This enables receiving any existing messages in an interrupt context.

Impact

Impact on user: Yes. It allows receiving existing messages in an interrupt context.

Impact on build: No.

Impact on hardware: No.

Impact on documentation: No.

Impact on security: No.

Impact on compatibility: No.

Testing

It can be tested with a simple testing application available at tmedicci's nuttx-apps (branch test/mqueue_isr) with an ESP32-S3 device. This application receives a message during an interrupt handler with a software-triggered interrupt and checks its content. Additionally, it tries to receive a nonexistent message, ensuring that it won't block the ISR (returning immediately with the proper error code).

Please note, however, that this application clearly violates kernel/userspace boundaries, so it won't be submitted upstream (it was specifically written for this implementation).

Building

After setting the alternative nuttx-apps repository, build the following firmware based on esp32s3-devkit:nsh:

make -j distclean && ./tools/configure.sh -S esp32s3-devkit:nsh && kconfig-tweak --enable CONFIG_TESTING_MQUEUE_ISR && kconfig-merge -m .config ../esp-nuttx-ci/configs/build && make olddefconfig -s -j && make -j bootloader && make flash EXTRAFLAGS="-Wno-cpp -DDISABLE_GIT_DEPTH" ESPTOOL_PORT=/dev/ttyUSB0 ESPTOOL_BINDIR=./ -s -j$(nproc) && picocom -b 115200 /dev/ttyUSB0

Running

  • It can be flashed to a ESP32-S3:
  • Or, it can run on QEMU with:
qemu-system-xtensa -nographic -machine esp32s3 -global driver=esp32s3.gpio,property=strap_mode,value=0x04 -drive file=nuttx.merged.bin,if=mtd,format=raw

Run nsh> mqueue_isr.

Results

nsh> mqueue_isr
============================================
  mqueue_isr: Message Queue ISR Test
============================================

Testing file_mq_timedreceive_internal from ISR context.
This test validates that mq_receive works correctly
when called from an interrupt handler on ESP32-S3.

[SETUP] Message queue '/mqueue_isr_test' opened (fd=3)
[SETUP] Message sent to queue: "Hello from task!" (len=17, prio=1)
[SETUP] Software interrupt configured (cpuint=2)
[SETUP] ISR attached and enabled

[ACTION] Triggering software interrupt...

============================================
  Test Results
============================================

ISR executed: YES

Test 1: mq_receive with available message
  Expected: success (ret > 0)
  Got:      ret=17, errno=0 (Unknown error 0)
  Message:  content OK
  Result:   PASS

Test 2: mq_receive on empty queue from ISR
  Expected: ret=-1, errno=EAGAIN (11)
  Got:      ret=-1, errno=11 (Unknown error 11)
  Result:   PASS

============================================
  Overall: ALL TESTS PASSED
============================================
nsh> 

The internal implementation of `file_mq_receive` did not allow
receiving a message from an interrupt handler. Although it is not
possible to wait for a message in an interrupt context, it is
perfectly possible to retrieve already-existing messages from the
message queue. This commit modifies file_mq_timedreceive_internal
to enable checking the message list and, if no messages exist, it
returns immediately. This enables receiving any existing messages
in an interrupt context.

Signed-off-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
@github-actions github-actions bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Feb 10, 2026
@linguini1 linguini1 merged commit 9cf7d80 into apache:master Feb 11, 2026
72 of 114 checks passed
@tmedicci tmedicci deleted the improvement/mq_receive_isr branch February 12, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants