Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33e3820d authored by Bjorn Andersson's avatar Bjorn Andersson
Browse files

rpmsg: smd: Use spinlock in tx path



By switching the tx_lock to a spinlock we allow clients to use
rpmsg_trysend() from atomic context.

The mutex was interruptable as it was previously held for the duration
of some client waiting for available space in the FIFO, but this was
recently changed to only be held temporarily - allowing us to replace it
with a spinlock.

Tested-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent be5acd24
Loading
Loading
Loading
Loading
+11 −10
Original line number Original line Diff line number Diff line
@@ -205,7 +205,7 @@ struct qcom_smd_channel {
	struct smd_channel_info_pair *info;
	struct smd_channel_info_pair *info;
	struct smd_channel_info_word_pair *info_word;
	struct smd_channel_info_word_pair *info_word;


	struct mutex tx_lock;
	spinlock_t tx_lock;
	wait_queue_head_t fblockread_event;
	wait_queue_head_t fblockread_event;


	void *tx_fifo;
	void *tx_fifo;
@@ -729,6 +729,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
{
{
	__le32 hdr[5] = { cpu_to_le32(len), };
	__le32 hdr[5] = { cpu_to_le32(len), };
	int tlen = sizeof(hdr) + len;
	int tlen = sizeof(hdr) + len;
	unsigned long flags;
	int ret;
	int ret;


	/* Word aligned channels only accept word size aligned data */
	/* Word aligned channels only accept word size aligned data */
@@ -739,9 +740,11 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
	if (tlen >= channel->fifo_size)
	if (tlen >= channel->fifo_size)
		return -EINVAL;
		return -EINVAL;


	ret = mutex_lock_interruptible(&channel->tx_lock);
	/* Highlight the fact that if we enter the loop below we might sleep */
	if (ret)
	if (wait)
		return ret;
		might_sleep();

	spin_lock_irqsave(&channel->tx_lock, flags);


	while (qcom_smd_get_tx_avail(channel) < tlen &&
	while (qcom_smd_get_tx_avail(channel) < tlen &&
	       channel->state == SMD_CHANNEL_OPENED) {
	       channel->state == SMD_CHANNEL_OPENED) {
@@ -753,7 +756,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 0);
		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 0);


		/* Wait without holding the tx_lock */
		/* Wait without holding the tx_lock */
		mutex_unlock(&channel->tx_lock);
		spin_unlock_irqrestore(&channel->tx_lock, flags);


		ret = wait_event_interruptible(channel->fblockread_event,
		ret = wait_event_interruptible(channel->fblockread_event,
				       qcom_smd_get_tx_avail(channel) >= tlen ||
				       qcom_smd_get_tx_avail(channel) >= tlen ||
@@ -761,9 +764,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
		if (ret)
		if (ret)
			return ret;
			return ret;


		ret = mutex_lock_interruptible(&channel->tx_lock);
		spin_lock_irqsave(&channel->tx_lock, flags);
		if (ret)
			return ret;


		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 1);
		SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 1);
	}
	}
@@ -787,7 +788,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
	qcom_smd_signal_channel(channel);
	qcom_smd_signal_channel(channel);


out_unlock:
out_unlock:
	mutex_unlock(&channel->tx_lock);
	spin_unlock_irqrestore(&channel->tx_lock, flags);


	return ret;
	return ret;
}
}
@@ -1090,7 +1091,7 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
	if (!channel->name)
	if (!channel->name)
		return ERR_PTR(-ENOMEM);
		return ERR_PTR(-ENOMEM);


	mutex_init(&channel->tx_lock);
	spin_lock_init(&channel->tx_lock);
	spin_lock_init(&channel->recv_lock);
	spin_lock_init(&channel->recv_lock);
	init_waitqueue_head(&channel->fblockread_event);
	init_waitqueue_head(&channel->fblockread_event);
	init_waitqueue_head(&channel->state_change_event);
	init_waitqueue_head(&channel->state_change_event);