MLK-21307: ASoC: fsl_rpmsg_i2s: optimize the message sent to m4
authorShengjiu Wang <shengjiu.wang@nxp.com>
Mon, 1 Apr 2019 08:40:57 +0000 (16:40 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
M4 complain that there are two much period done message sent to m4, that
M4 don't have enough time to handle these messages.

The solution for this issue is to reduce the number of period done message.
We allocate a specific memory for period done message, every time there is
period done coming, it will be writed to this memory, not write it directly
to the work queue, that queue will not be overflow, and the old period done
message will be overwrited.

In the rpmsg_i2s_work, we first check if there is period done message, then
send it first, after that, send the command in queue.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
(cherry picked from commit caabdfa176453cc7c8d6521f7865a670a7265a18)

sound/soc/fsl/fsl_rpmsg_i2s.c
sound/soc/fsl/fsl_rpmsg_i2s.h
sound/soc/fsl/imx-pcm-rpmsg.c

index 1aa46e4..f43890a 100644 (file)
@@ -148,6 +148,16 @@ static void rpmsg_i2s_work(struct work_struct *work)
        work_of_rpmsg = container_of(work, struct work_of_rpmsg, work);
        i2s_info = work_of_rpmsg->i2s_info;
 
+       if (i2s_info->period_done_msg_enabled[0]) {
+               i2s_send_message(&i2s_info->period_done_msg[0], i2s_info);
+               i2s_info->period_done_msg_enabled[0] = false;
+       }
+
+       if (i2s_info->period_done_msg_enabled[1]) {
+               i2s_send_message(&i2s_info->period_done_msg[1], i2s_info);
+               i2s_info->period_done_msg_enabled[1] = false;
+       }
+
        i2s_send_message(&work_of_rpmsg->msg, i2s_info);
 
        i2s_info->work_read_index++;
index 14922f1..cd0badb 100644 (file)
@@ -394,6 +394,8 @@ struct i2s_info {
        struct i2s_rpmsg_r       recv_msg;
 
        struct i2s_rpmsg         rpmsg[I2S_CMD_MAX_NUM];
+       struct i2s_rpmsg         period_done_msg[2];
+       bool                     period_done_msg_enabled[2];
 
        struct workqueue_struct  *rpmsg_wq;
        struct work_of_rpmsg     work_list[WORK_MAX_NUM];
index f5ef269..1e3962d 100644 (file)
@@ -579,7 +579,6 @@ int imx_rpmsg_pcm_ack(struct snd_pcm_substream *substream)
        struct fsl_rpmsg_i2s       *rpmsg_i2s = dev_get_drvdata(cpu_dai->dev);
        struct i2s_info            *i2s_info =  &rpmsg_i2s->i2s_info;
        struct i2s_rpmsg           *rpmsg;
-       int index = i2s_info->work_write_index;
        int buffer_tail = 0;
 
        if (!rpmsg_i2s->force_lpa)
@@ -603,15 +602,9 @@ int imx_rpmsg_pcm_ack(struct snd_pcm_substream *substream)
 
        if (buffer_tail != rpmsg->send_msg.param.buffer_tail) {
                rpmsg->send_msg.param.buffer_tail = buffer_tail;
-               if (i2s_info->work_write_index != i2s_info->work_read_index) {
-                       memcpy(&i2s_info->work_list[index].msg, rpmsg,
-                                       sizeof(struct i2s_rpmsg_s));
-                       queue_work(i2s_info->rpmsg_wq,
-                                       &i2s_info->work_list[index].work);
-                       i2s_info->work_write_index++;
-                       i2s_info->work_write_index %= WORK_MAX_NUM;
-               } else
-                       i2s_info->msg_drop_count[substream->stream]++;
+               memcpy(&i2s_info->period_done_msg[substream->stream], rpmsg,
+                               sizeof(struct i2s_rpmsg_s));
+               i2s_info->period_done_msg_enabled[substream->stream] = true;
        }
 
        return 0;