-
Notifications
You must be signed in to change notification settings - Fork 1.3k
nuttx/msgq: add kernel message queue support #16226
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
base: master
Are you sure you want to change the base?
Conversation
Currently NuttX have 2 message queue implementations: 1. Posix Message Queue (mq_close/mq_getattr/mq_getsetattr/mq_notify/mq_open/mq_overview/mq_receive/mq_send/mq_setattr/mq_timedreceive/mq_timedsend/mq_unlink) 2. System V Message Queue (msgctl/msgget/msggrep/msginit/msgmerge/msgop/msgrcv/msgsnd) Posix/SysteV message queues meet the standard implementation, But there are various limitations for kernel developer: 1. Depends on the file system, and message sending and receiving require file descriptors as handles, resulting in additional resource overhead and performance degradation 2. Do not support static memory pool configuration, and use global shared memory pools, which will cause more uncertainty in some use case. 3. Cannot support additional capabilities(such as "message peek") So in this PR, we are planing to introduce the "nxmsgq" implementation to simplify the development in kernel space: (Compare with of Zephyr and FreeRTOS interfaces) ------------------------------------------------------------------------------ | NuttX | Zephyr | FreeRTOS | |---------------------|-------------------------|----------------------------| | nxmsgq_init | k_msgq_init | xQueueCreateStatic | |---------------------|-------------------------|----------------------------| | nxmsgq_create | k_msgq_alloc_init | xQueueCreate | |---------------------|-------------------------|----------------------------| | nxmsgq_destroy | k_msgq_cleanup | vQueueDelete | |---------------------|-------------------------|----------------------------| | nxmsgq_used | k_msgq_num_used_get | uxQueueMessagesWaiting | |---------------------|-------------------------|----------------------------| | nxmsgq_space | k_msgq_num_free_get | uxQueueSpacesAvailable | |---------------------|-------------------------|----------------------------| | nxmsgq_purge | k_msgq_purge | | |---------------------|-------------------------|----------------------------| | nxmsgq_ticksend | k_msgq_put | xQueueSend | | nxmsgq_trysend | | xQueueSendFromISR | | nxmsgq_send | | xQueueSend | |---------------------|-------------------------|----------------------------| | nxmsgq_tickrecv | k_msgq_get | xQueueReceive | | nxmsgq_tryrecv | | xQueueReceiveFromISR | | nxmsgq_recv | | xQueueReceive | |---------------------|-------------------------|----------------------------| | nxmsgq_tickpeek | k_msgq_peek | xQueuePeek | | nxmsgq_trypeek | | xQueuePeekFromISR | | nxmsgq_peek | | xQueuePeek | |---------------------|-------------------------|----------------------------| | nxmsgq_is_empty | | | | nxmsgq_is_full | | | ------------------------------------------------------------------------------ Posix Open Test(mq) : loop: 1001:spending 0.13305000s Kernel Open Test(nxmsgq) : loop: 1001:spending 0.6345000s (-52%) Posix Recv Test(mq) : loop: 1001:spending 0.7884000s Kernel Recv Test(nxmsgq) : loop: 1001:spending 0.6837000s (-13%) Signed-off-by: chao an <[email protected]>
[Experimental Bot, please feedback here] This PR does not fully meet the NuttX requirements. Here's why:
To fully meet the requirements, the PR author needs to:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include Documentation/, the commit Summary could be used as a starting point
|
||
typedef struct nxmsgq | ||
{ | ||
struct circbuf_s cbuf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would using a linked list (sq or dq) be an option here? The messages themselves would obviously need a bit more space, but it would remove the "max_msgs" limit from this implementation ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, list
is a good suggestion. I will improve it if we want to implement a priority queue in the future, However in this stage, if we only compare the API with freertos/zephyr, the current data type already meets the requirements.
max_msgs
is the behavior expected by users. Most kernel developers expect that the queue is within a controllable range, which will help them find problems in advance.
* nxmsgq_destroy() | ||
* | ||
* Input Parameters: | ||
* msg_size - Message size (in bytes). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that a nxmsgq can only handle messages of a certain size ? Isn't this limitation a bit too harsh ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is just aligned with other operating systems
FreeRTOS:
https://freertos.org/Documentation/02-Kernel/04-API-references/06-Queues/02-xQueueCreateStatic
ThreadX:
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/threadx/chapter4.md#tx_queue_create
int nxmsgq_used(FAR nxmsgq_t *msgq); | ||
|
||
/**************************************************************************** | ||
* Name: nxmsgq_used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nxmsgq_space
I like the idea a lot, I was always wondering how NuttX did not already have this kernel internal message system (which does not depend on a file system). Like stated in the summary field, many RTOSes provide this and I think it is an extremely useful and powerful synchronization mechanism. |
let me mark this PR as a draft first . I want to support the priority queue and zero-copy in this pull request. |
Summary
nuttx/msgq: add kernel message queue support
Currently NuttX have 2 message queue implementations:
Posix/SysteV message queues meet the standard implementation, But there are various limitations for kernel developer:
So in this PR, we are planing to introduce the "nxmsgq" implementation to simplify the development in kernel space:
(Compare with of Zephyr and FreeRTOS interfaces)
Signed-off-by: chao an [email protected]
Impact
N/A
Testing
sim/nsh, Cortex-M55, test code as below