From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pierre-Louis Bossart Subject: Re: [Sound-open-firmware] [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support Date: Thu, 14 Feb 2019 09:13:04 -0600 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 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Content-Language: en-US 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: Takashi Iwai Cc: Daniel Baluta , andriy.shevchenko@intel.com, Pan Xiuli , alsa-devel@alsa-project.org, liam.r.girdwood@linux.intel.com, vkoul@kernel.org, broonie@kernel.org, sound-open-firmware@alsa-project.org, Alan Cox List-Id: alsa-devel@alsa-project.org On 2/14/19 7:19 AM, Takashi Iwai wrote: > 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. Yes. This was cleaned-up to remove a goto but we missed the common code. will fix > >> + >> + /* 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. It's my understanding that there is a single trace stream and a single consumer (via a debugfs file), but will double check.