kernel: Remove legacy mem block from mailbox

Memory blocks are a legacy feature and are to be removed from
mailboxes.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
Peter Mitsis 2023-09-30 11:28:31 -04:00 committed by Johan Hedberg
commit e9987aabbc
4 changed files with 8 additions and 143 deletions

View file

@ -248,7 +248,6 @@ portion of the message isn't used.
send_msg.info = random_value;
send_msg.size = 0;
send_msg.tx_data = NULL;
send_msg.tx_block.data = NULL;
send_msg.tx_target_thread = K_ANY;
/* send message and wait until a consumer receives it */
@ -284,7 +283,6 @@ the maximum size message buffer that each thread can handle.
send_msg.info = buffer_bytes_used;
send_msg.size = buffer_bytes_used;
send_msg.tx_data = buffer;
send_msg.tx_block.data = NULL;
send_msg.tx_target_thread = K_ANY;
/* send message and wait until a consumer receives it */

View file

@ -4700,8 +4700,6 @@ struct k_mbox_msg {
uint32_t info;
/** sender's message data buffer */
void *tx_data;
/** message data block descriptor */
struct k_mem_block tx_block;
/** source thread id */
k_tid_t rx_source_thread;
/** target thread id */
@ -4770,8 +4768,8 @@ extern void k_mbox_init(struct k_mbox *mbox);
* @brief Send a mailbox message in a synchronous manner.
*
* This routine sends a message to @a mbox and waits for a receiver to both
* receive and process it. The message data may be in a buffer, in a memory
* pool block, or non-existent (i.e. an empty message).
* receive and process it. The message data may be in a buffer or non-existent
* (i.e. an empty message).
*
* @param mbox Address of the mailbox.
* @param tx_msg Address of the transmit message descriptor.
@ -4792,10 +4790,10 @@ extern int k_mbox_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
* @brief Send a mailbox message in an asynchronous manner.
*
* This routine sends a message to @a mbox without waiting for a receiver
* to process it. The message data may be in a buffer, in a memory pool block,
* or non-existent (i.e. an empty message). Optionally, the semaphore @a sem
* will be given when the message has been both received and completely
* processed by the receiver.
* to process it. The message data may be in a buffer or non-existent
* (i.e. an empty message). Optionally, the semaphore @a sem will be given
* when the message has been both received and completely processed by
* the receiver.
*
* @param mbox Address of the mailbox.
* @param tx_msg Address of the transmit message descriptor.

View file

@ -140,14 +140,6 @@ static int mbox_message_match(struct k_mbox_msg *tx_msg,
/* update data location fields for receiver only */
rx_msg->tx_data = tx_msg->tx_data;
rx_msg->tx_block = tx_msg->tx_block;
if (rx_msg->tx_data != NULL) {
rx_msg->tx_block.data = NULL;
} else if (rx_msg->tx_block.data != NULL) {
rx_msg->tx_data = rx_msg->tx_block.data;
} else {
/* no data */
}
/* update syncing thread field for receiver only */
rx_msg->_syncing_thread = tx_msg->_syncing_thread;
@ -161,8 +153,7 @@ static int mbox_message_match(struct k_mbox_msg *tx_msg,
/**
* @brief Dispose of received message.
*
* Releases any memory pool block still associated with the message,
* then notifies the sender that message processing is complete.
* Notifies the sender that message processing is complete.
*
* @param rx_msg Pointer to receive message descriptor.
*/
@ -176,10 +167,6 @@ static void mbox_message_dispose(struct k_mbox_msg *rx_msg)
return;
}
if (rx_msg->tx_block.data != NULL) {
rx_msg->tx_block.data = NULL;
}
/* recover sender info */
sending_thread = rx_msg->_syncing_thread;
rx_msg->_syncing_thread = NULL;

View file

@ -30,10 +30,9 @@ static struct k_mbox mbox;
static k_tid_t sender_tid, receiver_tid, random_tid;
static K_THREAD_STACK_DEFINE(tstack, STACK_SIZE);
static K_THREAD_STACK_DEFINE(rtstack, STACK_SIZE);
static K_THREAD_STACK_DEFINE(tstack_1, STACK_SIZE);
static K_THREAD_STACK_ARRAY_DEFINE(waiting_get_stack, 5, STACK_SIZE);
static struct k_thread tdata, rtdata, async_tid, waiting_get_tid[5];
static struct k_thread tdata, async_tid, waiting_get_tid[5];
static struct k_sem end_sema, sync_sema;
@ -164,7 +163,6 @@ static void tmbox_put(struct k_mbox *pmbox)
/* Get a msg and dispose it by making the size = 0 */
mmsg.size = 0;
mmsg.tx_data = data[1];
mmsg.tx_block.data = NULL;
mmsg.tx_target_thread = K_ANY;
zassert_true(k_mbox_put(pmbox, &mmsg, K_FOREVER) == 0);
break;
@ -432,122 +430,6 @@ ZTEST(mbox_api, test_mbox_kdefine)
tmbox(&kmbox);
}
static void thread_mbox_data_get_null(void *p1, void *p2, void *p3)
{
struct k_mbox_msg get_msg = {0};
char str_data[] = "it string for get msg test";
get_msg.size = 16;
get_msg.rx_source_thread = K_ANY;
get_msg.tx_block.data = str_data;
get_msg._syncing_thread = NULL;
k_mbox_data_get(&get_msg, NULL);
k_sem_give(&end_sema);
}
/**
*
* @brief Test k_mbox_data_get() API
*
* @details
* - Init a mbox and just invoke k_mbox_data_get() with different
* input to check robust of API.
*
* @see k_mbox_data_get()
*
* @ingroup kernel_mbox_api
*/
ZTEST(mbox_api, test_mbox_data_get_null)
{
k_sem_reset(&end_sema);
receiver_tid = k_thread_create(&tdata, tstack, STACK_SIZE,
thread_mbox_data_get_null,
NULL, NULL, NULL,
K_PRIO_PREEMPT(0), 0,
K_NO_WAIT);
k_sem_take(&end_sema, K_FOREVER);
/*test case teardown*/
k_thread_abort(receiver_tid);
}
static void thread_mbox_get_block_data(void *p1, void *p2, void *p3)
{
k_sem_take(&sync_sema, K_FOREVER);
struct k_mbox_msg bdmsg = {0};
bdmsg.size = MAIL_LEN;
bdmsg.rx_source_thread = sender_tid;
bdmsg.tx_target_thread = receiver_tid;
bdmsg.tx_data = NULL;
bdmsg.tx_block.data = data;
bdmsg.tx_data = data;
zassert_equal(k_mbox_get((struct k_mbox *)p1, &bdmsg, p2, K_FOREVER),
0, NULL);
k_sem_give(&end_sema);
}
/* give a block data to API k_mbox_async_put */
static void thread_mbox_put_block_data(void *p1, void *p2, void *p3)
{
struct k_mbox_msg put_msg = {0};
put_msg.size = MAIL_LEN;
put_msg.tx_data = NULL;
put_msg.tx_block.data = p2;
put_msg.tx_target_thread = receiver_tid;
put_msg.rx_source_thread = sender_tid;
k_mbox_async_put((struct k_mbox *)p1, &put_msg, NULL);
}
/**
*
* @brief Test put and get mailbox with block data
*
* @details
* - Create two threads to put and get block data with
* specify thread ID and K_FOREVER for each other.
* - Check the result after finished exchange.
*
* @see k_mbox_init() k_mbox_async_put() k_mbox_get()
*
* @ingroup kernel_mbox_api
*/
ZTEST(mbox_api, test_mbox_get_put_block_data)
{
struct k_mbox bdmbox;
/*test case setup*/
k_sem_reset(&end_sema);
k_sem_reset(&sync_sema);
k_mbox_init(&bdmbox);
char buff[MAIL_LEN];
char data_put[] = "mbox put data";
/**TESTPOINT: thread-thread data passing via mbox*/
sender_tid = k_current_get();
receiver_tid = k_thread_create(&rtdata, rtstack, STACK_SIZE,
thread_mbox_get_block_data,
&bdmbox, buff, NULL,
K_PRIO_PREEMPT(0), 0, K_NO_WAIT);
sender_tid = k_thread_create(&tdata, tstack, STACK_SIZE,
thread_mbox_put_block_data,
&bdmbox, data_put, NULL,
K_PRIO_PREEMPT(0), 0, K_NO_WAIT);
k_sem_give(&sync_sema);
k_sem_take(&end_sema, K_FOREVER);
/*abort receiver thread*/
k_thread_abort(receiver_tid);
k_thread_abort(sender_tid);
zassert_equal(memcmp(buff, data_put, sizeof(data_put)), 0,
NULL);
}
static ZTEST_BMEM char __aligned(4) buffer[8];
/**