From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E629C43331 for ; Fri, 27 Mar 2020 03:39:19 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FD2B206DB for ; Fri, 27 Mar 2020 03:39:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FD2B206DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8BD946E231; Fri, 27 Mar 2020 03:39:18 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 520B76E231 for ; Fri, 27 Mar 2020 03:39:17 +0000 (UTC) IronPort-SDR: tIcOUtLVXMnQg6ZSYPFhzeZEjRnosYzhd63B/fqrCv+HvJ+n7ShTWtrz8yEiyUztA/Ekh9pohV ffq/25QtZOag== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2020 20:39:15 -0700 IronPort-SDR: lCA9Qt6ZP0VSCFNpAlulXpYYJZq/dV330Mzx93tc4pwMpPbaObuMHqa0CcLUGqFT43ziiipK6k PWOcfNPucW5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,310,1580803200"; d="scan'208";a="447269229" Received: from adixit-mobl.amr.corp.intel.com (HELO adixit-arch.intel.com) ([10.134.77.53]) by fmsmga005.fm.intel.com with ESMTP; 26 Mar 2020 20:39:15 -0700 Date: Thu, 26 Mar 2020 20:39:15 -0700 Message-ID: <87zhc2sbz0.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: Lionel Landwerlin In-Reply-To: <60dd3f4f-7728-89eb-d582-19232967a8bb@intel.com> References: <6ec4772094094bb6967f0bd68e68c5e9e5613557.1585197556.git.ashutosh.dixit@intel.com> <60dd3f4f-7728-89eb-d582-19232967a8bb@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 EasyPG/1.0.0 Emacs/26 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Subject: Re: [Intel-gfx] [PATCH] drm/i915/perf: Do not clear pollin for small user read buffers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Thu, 26 Mar 2020 02:09:34 -0700, Lionel Landwerlin wrote: > > On 26/03/2020 06:43, Ashutosh Dixit wrote: > > It is wrong to block the user thread in the next poll when OA data is > > already available which could not fit in the user buffer provided in > > the previous read. In several cases the exact user buffer size is not > > known. Blocking user space in poll can lead to data loss when the > > buffer size used is smaller than the available data. > > > > This change fixes this issue and allows user space to read all OA data > > even when using a buffer size smaller than the available data using > > multiple non-blocking reads rather than staying blocked in poll till > > the next timer interrupt. > > > > v2: Fix ret value for blocking reads (Umesh) > > > > Cc: Umesh Nerlige Ramappa > > Cc: Lionel Landwerlin > > Signed-off-by: Ashutosh Dixit > > --- > > drivers/gpu/drm/i915/i915_perf.c | 63 ++++++-------------------------- > > 1 file changed, 12 insertions(+), 51 deletions(-) > > > > diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c > > index 3222f6cd8255..e2d083efba6d 100644 > > --- a/drivers/gpu/drm/i915/i915_perf.c > > +++ b/drivers/gpu/drm/i915/i915_perf.c > > @@ -2957,49 +2957,6 @@ void i915_oa_init_reg_state(const struct intel_context *ce, > > gen8_update_reg_state_unlocked(ce, stream); > > } > > -/** > > - * i915_perf_read_locked - &i915_perf_stream_ops->read with error normalisation > > - * @stream: An i915 perf stream > > - * @file: An i915 perf stream file > > - * @buf: destination buffer given by userspace > > - * @count: the number of bytes userspace wants to read > > - * @ppos: (inout) file seek position (unused) > > - * > > - * Besides wrapping &i915_perf_stream_ops->read this provides a common place to > > - * ensure that if we've successfully copied any data then reporting that takes > > - * precedence over any internal error status, so the data isn't lost. > > - * > > - * For example ret will be -ENOSPC whenever there is more buffered data than > > - * can be copied to userspace, but that's only interesting if we weren't able > > - * to copy some data because it implies the userspace buffer is too small to > > - * receive a single record (and we never split records). > > - * > > - * Another case with ret == -EFAULT is more of a grey area since it would seem > > - * like bad form for userspace to ask us to overrun its buffer, but the user > > - * knows best: > > - * > > - * http://yarchive.net/comp/linux/partial_reads_writes.html > > - * > > - * Returns: The number of bytes copied or a negative error code on failure. > > - */ > > -static ssize_t i915_perf_read_locked(struct i915_perf_stream *stream, > > - struct file *file, > > - char __user *buf, > > - size_t count, > > - loff_t *ppos) > > -{ > > - /* Note we keep the offset (aka bytes read) separate from any > > - * error status so that the final check for whether we return > > - * the bytes read with a higher precedence than any error (see > > - * comment below) doesn't need to be handled/duplicated in > > - * stream->ops->read() implementations. > > - */ > > - size_t offset = 0; > > - int ret = stream->ops->read(stream, buf, count, &offset); > > - > > - return offset ?: (ret ?: -EAGAIN); > > -} > > - > > /** > > * i915_perf_read - handles read() FOP for i915 perf stream FDs > > * @file: An i915 perf stream file > > @@ -3025,6 +2982,8 @@ static ssize_t i915_perf_read(struct file *file, > > { > > struct i915_perf_stream *stream = file->private_data; > > struct i915_perf *perf = stream->perf; > > + size_t offset = 0; > > + int __ret; > > ssize_t ret; > > /* To ensure it's handled consistently we simply treat all reads of > > a > > @@ -3048,16 +3007,19 @@ static ssize_t i915_perf_read(struct file *file, > > return ret; > > mutex_lock(&perf->lock); > > - ret = i915_perf_read_locked(stream, file, > > - buf, count, ppos); > > + __ret = stream->ops->read(stream, buf, count, &offset); > > + ret = offset ?: (__ret ?: -EAGAIN); > > mutex_unlock(&perf->lock); > > } while (ret == -EAGAIN); > > } else { > > mutex_lock(&perf->lock); > > - ret = i915_perf_read_locked(stream, file, buf, count, ppos); > > + __ret = stream->ops->read(stream, buf, count, &offset); > > + ret = offset ?: (__ret ?: -EAGAIN); > > mutex_unlock(&perf->lock); > > } > > + /* Possible values for __ret are 0, -EFAULT, -ENOSPC, -EAGAIN, > > ... */ > > + > > /* We allow the poll checking to sometimes report false positive EPOLLIN > > * events where we might actually report EAGAIN on read() if there's > > * not really any data available. In this situation though we don't > > @@ -3065,13 +3027,12 @@ static ssize_t i915_perf_read(struct file *file, > > * and read() returning -EAGAIN. Clearing the oa.pollin state here > > * effectively ensures we back off until the next hrtimer callback > > * before reporting another EPOLLIN event. > > + * The exception to this is if ops->read() returned -ENOSPC which means > > + * that more OA data is available than could fit in the user provided > > + * buffer. In this case we want the next poll() call to not block. > > */ > > - if (ret >= 0 || ret == -EAGAIN) { > > - /* Maybe make ->pollin per-stream state if we support multiple > > - * concurrent streams in the future. > > - */ > > + if ((ret > 0 || ret == -EAGAIN) && __ret != -ENOSPC) > > stream->pollin = false; > > - } > > return ret; > > } > > I think this reset of the pollin field is in the wrong place in the driver. > > The decision of whether pollin is true/false should be based off the > difference between head/tail pointers. > > In my opinion the best place to do this in at the end of > gen7/8_append_oa_reports functions, under the stream->oa_buffer.ptr_lock. > > If everything has been read up to the tail pointer, then there is nothing > to wake up userspace for, otherwise leave pollin untouched. Hi Lionel, Are you seeing any problems of correctness in the code? My intention was to use previously existing mechanisms (viz. -ENOSPC). Afais when stream->ops->read() returns -ENOSPC it has already looked at head/tail pointers and determined that there is data to be returned which it is unable to because the provided buffer was too small. Also, -ENOSPC can also be returned from append_oa_status(), though that can probably be ignored. Following your reasoning we should probably also say that pollin should be set in oa_buffer_check_unlocked()? About, stream->oa_buffer.ptr_lock, as I said previously, imo it is a lock between a ring buffer producer (oa_buffer_check_unlocked()) and consumer (i915_perf_read) which should not be needed, that ring buffer operation should be lockless. Though we will need to check before removing it, maybe I am wrong. So unless you say there are real correctness problems in the patch or previously existing code I am leaning towards leaving as it as is. Thanks! -- Ashutosh _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx