From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support Date: Thu, 14 Feb 2019 14:19:08 +0100 Message-ID: References: <20190213220734.10471-1-pierre-louis.bossart@linux.intel.com> <20190213220734.10471-8-pierre-louis.bossart@linux.intel.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20190213220734.10471-8-pierre-louis.bossart@linux.intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Pierre-Louis Bossart Cc: alsa-devel@alsa-project.org, andriy.shevchenko@intel.com, Pan Xiuli , Daniel Baluta , liam.r.girdwood@linux.intel.com, vkoul@kernel.org, broonie@kernel.org, Alan Cox , sound-open-firmware@alsa-project.org List-Id: alsa-devel@alsa-project.org On Wed, 13 Feb 2019 23:07:27 +0100, Pierre-Louis Bossart wrote: > > +static size_t sof_wait_trace_avail(struct snd_sof_dev *sdev, > + loff_t pos, size_t buffer_size) > +{ > + wait_queue_entry_t wait; > + > + /* > + * If host offset is less than local pos, it means write pointer of > + * host DMA buffer has been wrapped. We should output the trace data > + * at the end of host DMA buffer at first. > + */ > + if (sdev->host_offset < pos) > + return buffer_size - pos; > + > + /* If there is available trace data now, it is unnecessary to wait. */ > + if (sdev->host_offset > pos) > + return sdev->host_offset - pos; > + > + /* wait for available trace data from FW */ > + init_waitqueue_entry(&wait, current); > + set_current_state(TASK_INTERRUPTIBLE); > + add_wait_queue(&sdev->trace_sleep, &wait); > + > + if (signal_pending(current)) { > + remove_wait_queue(&sdev->trace_sleep, &wait); > + } else { > + /* set timeout to max value, no error code */ > + schedule_timeout(MAX_SCHEDULE_TIMEOUT); > + remove_wait_queue(&sdev->trace_sleep, &wait); > + } Can be slightly optimized here, e.g. no need of two remove_wait_queue() calls. > + > + /* return bytes available for copy */ > + if (sdev->host_offset < pos) > + return buffer_size - pos; > + > + return sdev->host_offset - pos; Are these sdev->host_offset accesses race-free? If I understand correctly, snd_sof_trace_update_pos() can be called at any time, and the offset might become inconsistent during these multiple references. thanks, Takashi