mailbox: check mailbox queue is full or not
Subsystems (2)
PATCH 1/1 mailbox: check mailbox queue is full or not
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing MBOX_TX_QUEUE_LEN".
--- drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 + 3 files changed, 29 insertions(+)
drivers/mailbox/mailbox.c +24 -0
@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan) +{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags); + res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 )); +spin_unlock_irqrestore (&chan->lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full); +/** * mbox_send_message - For client to submit a message to be * sent to the remote.
drivers/remoteproc/xlnx_r5_remoteproc.c +4 -0
@@ -335,6 +335,10 @@ static void zynqmp_r5_rproc_kick(struct rproc *rproc, int vqid)if (!ipi)return ; +/* Do not need new kick as already many kick interrupts are pending. */ +if (mbox_queue_full (ipi->tx_chan) == true) +return ; + mb_msg = (struct zynqmp_ipi_message *)ipi->tx_mc_buf;memcpy (mb_msg->data, &vqid,sizeof (vqid)); mb_msg->len =sizeof (vqid);
include/linux/mailbox_client.h +1 -0
@@ -46,5 +46,6 @@ int mbox_flush(struct mbox_chan *chan, unsigned long timeout);void mbox_client_txdone (struct mbox_chan *chan,int r);/* atomic */ bool mbox_client_peek_data (struct mbox_chan *chan);/* atomic */ void mbox_free_channel (struct mbox_chan *chan);/* may sleep */ +int mbox_queue_full (struct mbox_chan *chan);#endif /* __MAILBOX_CLIENT_H */
base-commit: 56d030ea3330ab737fe6c05f89d52f56208b07ac
Signature · 1 line
2.34.1
Hi Tanmay,
Quoted 7 lines · Tanmay Shah
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing
MBOX_TX_QUEUE_LEN".
Quoted 5 lines
Signed-off-by Tanmay Shah <[email protected]>---
drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 +
The mailbox and remoteproc should be separated.
Quoted 17 lines
3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +7
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 236
Quoted 10 lines
drivers/mailbox/mailbox.c +10
-0+*/ +int mbox_queue_full (struct mbox_chan *chan) +{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags);
Use scoped_guard.
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 242
Quoted 6 lines
drivers/mailbox/mailbox.c +6
-0+ res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 )); +spin_unlock_irqrestore (&chan->lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full);
add_to_rbuf is able to return ENOBUFS when call mbox_send_message. Does checking mbox_send_message return value works for you?
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 246
Quoted 4 lines
drivers/mailbox/mailbox.c +1
-0+/** * mbox_send_message - For client to submit a message to be * sent to the remote.
Regards
Peng
Hi Peng,
Thanks for reviews. Please find my comments below.
Quoted 10 lines · Peng Fan
Hi Tanmay,
Quoted 7 lines · Tanmay Shah
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing
MBOX_TX_QUEUE_LEN".
Quoted 8 lines
Quoted 5 lines
Signed-off-by Tanmay Shah <[email protected]>---
drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 +The mailbox and remoteproc should be separated.
Mailbox framework is introducing new API. I wanted the use case to be in the same patch-set, otherwise we might see unused API warning.
Hence, both in the same patch makes more sense. If maintainers prefer, I will separate them.
Quoted 21 lines
Quoted 21 lines
3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +11
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan) +{ +unsigned long flags;
Quoted 8 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 236
Quoted 6 lines
drivers/mailbox/mailbox.c +6
-0+int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags);Use
scoped_guard.
Other APIs use spin_lock_irqsave. Probably scoped_guard should be introduced in a different patch for all APIs in the mailbox.
Quoted 11 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 242
Quoted 7 lines
drivers/mailbox/mailbox.c +6
-0+ res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 )); +spin_unlock_irqrestore (&chan->lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full);
add_to_rbufis able to return ENOBUFS when callmbox_send_message. Does checkingmbox_send_messagereturn value works for you?
That is the problem. mbox_send_message uses add_to_rbuf and fails. But during failure, it prints warning message:
dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n");
In some cases there are lot of such messages on terminal. Functionally nothing is wrong and everything is working but user keeps getting false positive warning about increasing mbox tx queue length. That is why we need API to check if mbox queue length is full or not before doing mbox_send_message. Not all clients need to use it, but some cane make use of it.
Quoted 7 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 246
Quoted 4 lines
drivers/mailbox/mailbox.c +1
-0+/** * mbox_send_message - For client to submit a message to be * sent to the remote. Regards
Peng
Hi,
Quoted 10 lines · Tanmay Shah
Quoted 7 lines
Quoted 4 lines
---
drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 +The mailbox and remoteproc should be separated.
Mailbox framework is introducing new API. I wanted the use case to be in the same patch-set, otherwise we might see unused API warning.
I mean two patches in one patchset.
Quoted 34 lines
Hence, both in the same patch makes more sense. If maintainers prefer, I will separate them.
Quoted 21 lines
Quoted 21 lines
3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +11
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan) +{ +unsigned long flags;Quoted 8 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 236
Quoted 6 lines
drivers/mailbox/mailbox.c +6
-0+int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags);Use
scoped_guard.
Quoted 2 lines
Other APIs use
spin_lock_irqsave. Probablyscoped_guardshould be introduced in a different patch for all APIs in the mailbox.
Your code base seems not up to date.
Quoted 16 lines
Quoted 12 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 242
Quoted 8 lines
drivers/mailbox/mailbox.c +6
-0+ res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 )); +spin_unlock_irqrestore (&chan->lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full);
add_to_rbufis able to return ENOBUFS when callmbox_send_message. Does checkingmbox_send_messagereturn value works for you?That is the problem.
mbox_send_messageusesadd_to_rbufand fails. But during failure, it prints warning message:
Quoted 8 lines
dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n");In some cases there are lot of such messages on terminal. Functionally nothing is wrong and everything is working but user keeps getting false positive warning about increasing mbox tx queue length. That is why we need API to check if mbox queue length is full or not before doing
mbox_send_message. Not all clients need to use it, but some cane make use of it.
I think check whether mbox_send_message returns -ENOBUFS or not should work for you. If the "Try increasing MBOX_TX_QUEUE_LEN" message bothers you, it could be update to dev_dbg per my understanding.
Regards,
Peng
Quoted 10 lines
Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 246
Quoted 6 lines
drivers/mailbox/mailbox.c +1
-0+/** * mbox_send_message - For client to submit a message to be * sent to the remote. Regards
Peng
Mathieu Poirier
maintainerQuoted 8 lines · Peng Fan
Hi,
Quoted 5 lines · Tanmay Shah
Quoted 5 lines
Quoted 4 lines
---
drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 +
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The mailbox and remoteproc should be separated.
Mailbox framework is introducing new API. I wanted the use case to be in the same patch-set, otherwise we might see unused API warning.
I mean two patches in one patchset.
Agreed
Quoted 34 lines
Quoted 34 lines
Hence, both in the same patch makes more sense. If maintainers prefer, I will separate them.
Quoted 29 lines
Quoted 17 lines
3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +7
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 236
Quoted 10 lines
drivers/mailbox/mailbox.c +10
-0+*/ +int mbox_queue_full (struct mbox_chan *chan) +{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags);Use
scoped_guard.
Quoted 5 lines
Quoted 2 lines
Other APIs use
spin_lock_irqsave. Probablyscoped_guardshould be introduced in a different patch for all APIs in the mailbox.Your code base seems not up to date.
Agreed
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 237
Quoted 3 lines
drivers/mailbox/mailbox.c +1
-0+ res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 ));
Please have a look at this condition again - the implementation of addr_to_rbuf() [1] is checking for space differently.
[1]. https://elixir.bootlin.com/linux/v6.17/source/drivers/mailbox/mailbox.c#L32
Quoted 22 lines
Quoted 13 lines
Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 242
Quoted 5 lines
drivers/mailbox/mailbox.c +5
-0+spin_unlock_irqrestore (&chan->lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full);
add_to_rbufis able to return ENOBUFS when callmbox_send_message. Does checkingmbox_send_messagereturn value works for you?That is the problem.
mbox_send_messageusesadd_to_rbufand fails. But during failure, it prints warning message:Quoted 8 lines
dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n");In some cases there are lot of such messages on terminal. Functionally nothing is wrong and everything is working but user keeps getting false positive warning about increasing mbox tx queue length. That is why we need API to check if mbox queue length is full or not before doing
mbox_send_message. Not all clients need to use it, but some cane make use of it.
Quoted 4 lines
I think check whether
mbox_send_messagereturns-ENOBUFSor not should work for you. If the "Try increasingMBOX_TX_QUEUE_LEN" message bothers you, it could be update todev_dbgper my understanding.
This new API is trying to avoid calling mbox_send_message(), no checking if it succeeded or not. Moving dev_err() nto dev_dbg() is also the wrong approach.
Quoted 13 lines
Regards,
PengQuoted 10 lines
Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 246
Quoted 6 lines
drivers/mailbox/mailbox.c +1
-0+/** * mbox_send_message - For client to submit a message to be * sent to the remote. Regards
Peng
Quoted 12 lines · Mathieu Poirier
Quoted 11 lines · Peng Fan
Hi,
Quoted 8 lines · Tanmay Shah
Quoted 7 lines
Quoted 4 lines
---
drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 +The mailbox and remoteproc should be separated.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Mailbox framework is introducing new API. I wanted the use case to be in the same patch-set, otherwise we might see unused API warning.
I mean two patches in one patchset.
Agreed
Okay.
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Hence, both in the same patch makes more sense. If maintainers prefer, I will separate them.
Quoted 29 lines
Quoted 17 lines
3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +7
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 236
Quoted 10 lines
drivers/mailbox/mailbox.c +10
-0+*/ +int mbox_queue_full (struct mbox_chan *chan) +{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags);Use
scoped_guard.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Other APIs use
spin_lock_irqsave. Probablyscoped_guardshould be introduced in a different patch for all APIs in the mailbox.Your code base seems not up to date.
Agreed
Okay. I was referring to different branch when I referred other API in the mailbox framework.
Sure, I will use scoped_guard.
Quoted 31 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 237
Quoted 3 lines
drivers/mailbox/mailbox.c +1
-0+ res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 ));Please have a look at this condition again - the implementation of
addr_to_rbuf()[1] is checking for space differently.[1]. https://elixir.bootlin.com/linux/v6.17/source/drivers/mailbox/mailbox.c#L32
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 242
Quoted 5 lines
drivers/mailbox/mailbox.c +5
-0+spin_unlock_irqrestore (&chan->lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full);
add_to_rbufis able to return ENOBUFS when callmbox_send_message. Does checkingmbox_send_messagereturn value works for you?That is the problem.
mbox_send_messageusesadd_to_rbufand fails. But during failure, it prints warning message:
dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n");In some cases there are lot of such messages on terminal. Functionally nothing is wrong and everything is working but user keeps getting false positive warning about increasing mbox tx queue length. That is why we need API to check if mbox queue length is full or not before doing
mbox_send_message. Not all clients need to use it, but some cane make use of it.
Quoted 8 lines
Quoted 4 lines
I think check whether
mbox_send_messagereturns-ENOBUFSor not should work for you. If the "Try increasingMBOX_TX_QUEUE_LEN" message bothers you, it could be update todev_dbgper my understanding.This new API is trying to avoid calling
mbox_send_message(), no checking if it succeeded or not. Movingdev_err()ntodev_dbg()is also the wrong approach.
Correct.
Quoted 13 lines
Quoted 13 lines
Regards,
PengQuoted 10 lines
Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 246
Quoted 6 lines
drivers/mailbox/mailbox.c +1
-0+/** * mbox_send_message - For client to submit a message to be * sent to the remote. Regards
Peng
Quoted 15 lines · Tanmay Shah
Quoted 12 lines · Mathieu Poirier
Quoted 11 lines · Peng Fan
Hi,
Quoted 8 lines · Tanmay Shah
Quoted 7 lines
Quoted 4 lines
---
drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++drivers/remoteproc/xlnx_r5_remoteproc.c| 4 ++++ include/linux/mailbox_client.h | 1 +The mailbox and remoteproc should be separated.
[...]
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ res = (
chan->msg_count== (MBOX_TX_QUEUE_LEN- 1));Please have a look at this condition again - the implementation of
addr_to_rbuf()[1] is checking for space differently.[1]. https://elixir.bootlin.com/linux/v6.17/source/drivers/mailbox/ mailbox.c#L32
Here Ack as well. I think it should be same as what's there in add_to_rbuf.
Quoted 48 lines
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 242
Quoted 5 lines
+
spin_unlock_irqrestore(&chan->lock, flags);drivers/mailbox/mailbox.c +4
-0+ + return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full);
add_to_rbufis able to return ENOBUFS when callmbox_send_message. Does checkingmbox_send_messagereturn value works for you?That is the problem.
mbox_send_messageusesadd_to_rbufand fails. But during failure, it prints warning message:
dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n");In some cases there are lot of such messages on terminal. Functionally nothing is wrong and everything is working but user keeps getting false positive warning about increasing mbox tx queue length. That is why we need API to check if mbox queue length is full or not before doing
mbox_send_message. Not all clients need to use it, but some cane make use of it.Quoted 8 lines
Quoted 4 lines
I think check whether
mbox_send_messagereturns-ENOBUFSor not should work for you. If the "Try increasingMBOX_TX_QUEUE_LEN" message bothers you, it could be update todev_dbgper my understanding.This new API is trying to avoid calling
mbox_send_message(), no checking if it succeeded or not. Movingdev_err()ntodev_dbg()is also the wrong approach.Correct.
Quoted 13 lines
Quoted 13 lines
Regards,
PengQuoted 10 lines
Quoted 9 lines
Quoted 6 lines
+
/**
*mbox_send_message- For client to submit a message to be * sent to the remote.Regards
Peng
Quoted 5 lines · Tanmay Shah
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 237
Quoted 2 lines
drivers/mailbox/mailbox.c +1
-0+ res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 ));Please have a look at this condition again - the implementation of
addr_to_rbuf()[1] is checking for space differently.
Tanmay,
May I know why you want to compare with "MBOX_TX_QUEUE_LEN - 1", not "MBOX_TX_QUEUE_LEN"?
Quoted 25 lines
Quoted 25 lines
[1]. https://elixir.bootlin.com/linux/v6.17/source/drivers/mailbox/mailbox.c#L32
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 242
Quoted 5 lines
drivers/mailbox/mailbox.c +5
-0+spin_unlock_irqrestore (&chan->lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (mbox_queue_full);
add_to_rbufis able to return ENOBUFS when callmbox_send_message. Does checkingmbox_send_messagereturn value works for you?That is the problem.
mbox_send_messageusesadd_to_rbufand fails. But during failure, it prints warning message:
dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n");In some cases there are lot of such messages on terminal. Functionally nothing is wrong and everything is working but user keeps getting false positive warning about increasing mbox tx queue length. That is why we need API to check if mbox queue length is full or not before doing
mbox_send_message. Not all clients need to use it, but some cane make use of it.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
I think check whether
mbox_send_messagereturns-ENOBUFSor not should work for you. If the "Try increasingMBOX_TX_QUEUE_LEN" message bothers you, it could be update todev_dbgper my understanding.This new API is trying to avoid calling
mbox_send_message(), no checking if it succeeded or not.
I think it may not deserve to introduce a new API. add_to_rbuf is almost the first function that mbox_send_message calls. But if Tanmay insists on adding a new API, I am fine. Jassi may comment more.
Quoted 4 lines
Quoted 2 lines
Moving
dev_err()ntodev_dbg()is also the wrong approach.Correct.
The caller of mbox_send_message detect error value and choose to add dev_err or not in caller driver, so I think dev_dbg is fine here.
I would appreciate if there is explaination on why dev_dbg is not correct :)
Thanks,
Peng
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Regards,
PengQuoted 10 lines
Quoted 9 lines
Quoted 6 lines
+
/**
*mbox_send_message- For client to submit a message to be
* sent to the remote.Regards
Peng
Jassi Brar
maintainerQuoted 32 lines · Tanmay Shah
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing
MBOX_TX_QUEUE_LEN".Signed-off-by Tanmay Shah <[email protected]>--- drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 + 3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +9
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan)
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 238
Quoted 10 lines
drivers/mailbox/mailbox.c +9
-0+{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags); + res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 ));
1) If we really need this, it should be
res = (chan->msg_count == MBOX_TX_QUEUE_LEN);
2) I am thinking instead, introduce a
struct mbox_client.msg_slots_ro;
Which is a read-only field for the client, denoting how many message
slots are currently available.
The mailbox api will always adjust it when msg_count changes...
chan->cl->msg_slots_ro = MBOX_TX_QUEUE_LEN - chan->msg_count;-jassi
Hi Jassi,
Please find my comments below.
Quoted 44 lines · Jassi Brar
Quoted 32 lines · Tanmay Shah
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing
MBOX_TX_QUEUE_LEN".Signed-off-by Tanmay Shah <[email protected]>--- drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 + 3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +9
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan)drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 238
Quoted 10 lines
drivers/mailbox/mailbox.c +9
-0+{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags); + res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 ));1) If we really need this, it should be
Quoted 2 lines
res = (chan->msg_count == MBOX_TX_QUEUE_LEN);
Ack here.
Quoted 7 lines
2) I am thinking instead, introduce a
struct mbox_client.msg_slots_ro; Which is a read-only field for the client, denoting how many message slots are currently available. The mailbox api will always adjust it when msg_count changes... chan->cl->msg_slots_ro = MBOX_TX_QUEUE_LEN - chan->msg_count;
It's not possible to make msg_slots_ro true Read-Only. Nothing prevents clients to write to that variable as far as I know. Also, we have msg_free variable that can be used to implement similar concept as msg_slots_ro. But that also has same problem, not possible to implement it in true read-only fashion.
I can instead implement API msg_queue_empty() and return msg_free variable via that API.
Quoted 1 line
-jassi
Jassi Brar
maintainerQuoted 63 lines · Tanmay Shah
Hi Jassi,
Please find my comments below.
Quoted 44 lines · Jassi Brar
Quoted 32 lines · Tanmay Shah
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing
MBOX_TX_QUEUE_LEN".Signed-off-by Tanmay Shah <[email protected]>--- drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 + 3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +9
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan)drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 238
Quoted 10 lines
drivers/mailbox/mailbox.c +9
-0+{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags); + res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 ));1) If we really need this, it should be
Quoted 2 lines
res = (chan->msg_count == MBOX_TX_QUEUE_LEN);Ack here.
Quoted 7 lines
2) I am thinking instead, introduce a
struct mbox_client.msg_slots_ro; Which is a read-only field for the client, denoting how many message slots are currently available. The mailbox api will always adjust it when msg_count changes... chan->cl->msg_slots_ro = MBOX_TX_QUEUE_LEN - chan->msg_count;
Quoted 3 lines
It's not possible to make
msg_slots_rotrue Read-Only. Nothing prevents clients to write to that variable as far as I know.
Correct, nothing prevents a client from changing 'msg_slots_ro', just like nothing
prevents it from setting tx_done or rx_callback to 0xdeadbabe. The '_ro' suffix is to tell the client developer to not mess with it. I am slightly more inclined towards this approach because it avoids adding another
convenience api and is more immediately available without needing a spinlock.
-jassi
Quoted 67 lines · Jassi Brar
Quoted 63 lines · Tanmay Shah
Hi Jassi,
Please find my comments below.
Quoted 44 lines · Jassi Brar
Quoted 32 lines · Tanmay Shah
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing
MBOX_TX_QUEUE_LEN".Signed-off-by Tanmay Shah <[email protected]>--- drivers/mailbox/mailbox.c | 24 ++++++++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 4 ++++ include/linux/mailbox_client.h | 1 + 3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +9
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) }EXPORT_SYMBOL_GPL (mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan)drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan) · line 238
Quoted 10 lines
drivers/mailbox/mailbox.c +9
-0+{ +unsigned long flags; +int res; + +if (!chan) +return -EINVAL ; + +spin_lock_irqsave (&chan->lock, flags); + res = (chan->msg_count == (MBOX_TX_QUEUE_LEN -1 ));1) If we really need this, it should be
Quoted 2 lines
res = (chan->msg_count == MBOX_TX_QUEUE_LEN);Ack here.
Quoted 7 lines
2) I am thinking instead, introduce a
struct mbox_client.msg_slots_ro;
Which is a read-only field for the client, denoting how many message
slots are currently available.
The mailbox api will always adjust it whenmsg_countchanges...
chan->cl->msg_slots_ro=MBOX_TX_QUEUE_LEN-chan->msg_count;Quoted 3 lines
It's not possible to make
msg_slots_rotrue Read-Only. Nothing prevents clients to write to that variable as far as I know.
Quoted 7 lines
Correct, nothing prevents a client from changing '
msg_slots_ro', just like nothing
prevents it from settingtx_doneorrx_callbackto0xdeadbabe. The '_ro' suffix is to tell the client developer to not mess with it. I am slightly more inclined towards this approach because it avoids adding another
convenience api and is more immediately available without needing a spinlock.
To avoid spinlock, msg_slots_ro should be atomic right?
Quoted 1 line
Then in the remoteproc driver, before using mbox_send_message, I can simply check (chan->cl->msg_slots_ro == 0) then don't use mbox_send_message.
Quoted 1 line
-jassi
Quoted 80 lines · Tanmay Shah
Quoted 69 lines · Jassi Brar
Quoted 65 lines · Tanmay Shah
Hi Jassi,
Please find my comments below.
Quoted 39 lines · Jassi Brar
Quoted 38 lines · Tanmay Shah
Sometimes clients need to know if mailbox queue is full or not before posting new message via mailbox. If mailbox queue is full clients can choose not to post new message. This doesn't mean current queue length should be increased, but clients may want to wait till previous Tx is done. This API can help avoid false positive warning from mailbox framework "Try increasing
MBOX_TX_QUEUE_LEN".Signed-off-by Tanmay Shah <[email protected]>---
drivers/mailbox/mailbox.c | 24 +++++++++++++++++++
+++++
drivers/remoteproc/xlnx_r5_remoteproc.c| 4 ++++ include/linux/mailbox_client.h | 1 +3 files changed, 29 insertions(+)drivers/mailbox/mailbox.c +13
-0@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan) } EXPORT_SYMBOL_GPL(mbox_client_peek_data); +/** +* mbox_queue_full - check if mailbox queue is full or not +* @chan: Mailbox channel assigned to this client. +* +* Clients can choose not to send new msg if mbox queue is full. +* +* Return: true if queue is full else false. < 0 for error +*/ +int mbox_queue_full (struct mbox_chan *chan) +{ + unsigned long flags; + int res; +Quoted 9 lines
drivers/mailbox/mailbox.c bool mbox_client_peek_data(struct mbox_chan *chan)
Quoted 6 lines
drivers/mailbox/mailbox.c +5
-0+ if (!chan) + return -EINVAL; + + spin_lock_irqsave(&chan->lock, flags); + res = (chan->msg_count == (MBOX_TX_QUEUE_LEN - 1));1) If we really need this, it should be
res = (chan->msg_count==MBOX_TX_QUEUE_LEN);Ack here.
Quoted 7 lines
2) I am thinking instead, introduce a
struct mbox_client.msg_slots_ro;
Which is a read-only field for the client, denoting how many message slots are currently available.
The mailbox api will always adjust it whenmsg_countchanges...chan->cl->msg_slots_ro=MBOX_TX_QUEUE_LEN-chan->msg_count;Quoted 3 lines
It's not possible to make
msg_slots_rotrue Read-Only. Nothing prevents clients to write to that variable as far as I know.Quoted 7 lines
Correct, nothing prevents a client from changing '
msg_slots_ro', just like nothing
prevents it from settingtx_doneorrx_callbackto0xdeadbabe. The '_ro' suffix is to tell the client developer to not mess with it. I am slightly more inclined towards this approach because it avoids adding another
convenience api and is more immediately available without needing a spinlock.
Quoted 1 line
To avoid spinlock,
msg_slots_roshould be atomic right?
I take it back, it doesn't have to be atomic. I will send a new revision with the design we discussed here.
Quoted 9 lines
Quoted 2 lines
Then in the remoteproc driver, before using
mbox_send_message, I can simply check (chan->cl->msg_slots_ro== 0) then don't usembox_send_message.Quoted 1 line
-jassi