Skip to contentSkip to conversation

drm/i915/perf: Do not clear pollin for small user read buffers

PATCH In review Ashutosh Dixit 3 participants 5 messages Mar 27, 2020 – Mar 31, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/perf: Do not clear pollin for small user read buffers

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)
v3: Mistake during patch send (Ashutosh)
v4: Remove -EAGAIN from comment (Umesh)

Cc Umesh Nerlige Ramappa <[email protected]>
Cc Lionel Landwerlin <[email protected]>
---
 drivers/gpu/drm/i915/i915_perf.c | 59 +++++++-------------------------
 1 file changed, 12 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +12 -47
index c74ebac50015..5f6d9bff99c8 100644
@@ -2914,49 +2914,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
@@ -2982,6 +2939,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
@@ -3005,16 +2964,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, -EIO, ... */
+
 	/* 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
@@ -3022,8 +2984,11 @@ 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)
+	if ((ret > 0 || ret == -EAGAIN) && __ret != -ENOSPC)
 		stream->pollin = false;
 
 	return ret;
Signature · 6 lines
2.25.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915/perf: Do not clear pollin for small user read buffers (rev4)

== Series Details ==

== Series Details ==

Series: drm/i915/perf: Do not clear pollin for small user read buffers (rev4)
URL : https://patchwork.freedesktop.org/series/75085/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_8206 -> Patchwork_17121
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/index.html

Known issues
------------

Here are the changes found in Patchwork_17121 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live@gt_heartbeat:
- fi-apl-guc: [PASS][1] -> [DMESG-FAIL][2] ([fdo#112406])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/fi-apl-guc/igt@i915_selftest@live@gt_heartbeat.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/fi-apl-guc/igt@i915_selftest@live@gt_heartbeat.html

* igt@i915_selftest@live@requests:
- fi-icl-u2: [PASS][3] -> [INCOMPLETE][4] ([fdo#109644] / [fdo#110464])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/fi-icl-u2/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/fi-icl-u2/igt@i915_selftest@[email protected]

#### Possible fixes ####

* igt@debugfs_test@read_all_entries:
- fi-icl-u2: [DMESG-WARN][5] ([i915#289]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/fi-icl-u2/igt@debugfs_test@read_all_entries.html
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/fi-icl-u2/igt@debugfs_test@read_all_entries.html

* igt@gem_exec_parallel@contexts:
- fi-icl-dsi: [INCOMPLETE][7] -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/fi-icl-dsi/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/fi-icl-dsi/igt@[email protected]

[fdo#109644]: https://bugs.freedesktop.org/show_bug.cgi?id=109644
[fdo#110464]: https://bugs.freedesktop.org/show_bug.cgi?id=110464
[fdo#112406]: https://bugs.freedesktop.org/show_bug.cgi?id=112406
[i915#289]: https://gitlab.freedesktop.org/drm/intel/issues/289

Participating hosts (49 -> 34)
------------------------------

Missing (15): fi-ilk-m540 fi-bdw-samus fi-hsw-4200u fi-byt-j1900 fi-hsw-peppy fi-byt-squawks fi-bsw-cyan fi-bwr-2160 fi-kbl-7500u fi-ctg-p8600 fi-skl-lmem fi-blb-e6850 fi-byt-clapper fi-skl-6600u fi-snb-2600

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_8206 -> Patchwork_17121

CI-20190529: 20190529
CI_DRM_8206: 584fcbd287863a6ba897f1b671acd7115d611362 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5543: 779d43cda49c230afd32c37730ad853f02e9d749 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_17121: 629368ea252e2101ef3c1b5deb7bd0554f4a4ad9 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

629368ea252e drm/i915/perf: Do not clear pollin for small user read buffers

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

[Intel-gfx] ✓ Fi.CI.IGT: success for drm/i915/perf: Do not clear pollin for small user read buffers (rev4)

In reply to Ashutosh Dixit
== Series Details ==

== Series Details ==

Series: drm/i915/perf: Do not clear pollin for small user read buffers (rev4)
URL : https://patchwork.freedesktop.org/series/75085/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_8206_full -> Patchwork_17121_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_17121_full:

### IGT changes ###

#### Suppressed ####

The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.

* {igt@gem_ctx_shared@q-independent@vcs0}:
- shard-tglb: [PASS][1] -> [FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-tglb6/igt@gem_ctx_shared@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-tglb8/igt@gem_ctx_shared@[email protected]

* {igt@perf@blocking-parameterized}:
- shard-hsw: [PASS][3] -> [FAIL][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-hsw2/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-hsw8/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_17121_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_schedule@implicit-both-bsd2:
- shard-iclb: [PASS][5] -> [SKIP][6] ([fdo#109276] / [i915#677]) +1 similar issue
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb1/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb3/igt@[email protected]

* igt@gem_exec_schedule@independent-bsd2:
- shard-iclb: [PASS][7] -> [SKIP][8] ([fdo#109276]) +7 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb4/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb3/igt@[email protected]

* igt@gem_exec_schedule@pi-distinct-iova-bsd:
- shard-iclb: [PASS][9] -> [SKIP][10] ([i915#677]) +2 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb3/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb4/igt@[email protected]

* igt@gem_exec_schedule@preempt-bsd:
- shard-iclb: [PASS][11] -> [SKIP][12] ([fdo#112146]) +3 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb7/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb2/igt@[email protected]

* igt@gem_exec_store@pages-vcs1:
- shard-iclb: [PASS][13] -> [SKIP][14] ([fdo#112080]) +6 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb1/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb3/igt@[email protected]

* igt@gem_reg_read@timestamp-monotonic:
- shard-hsw: [PASS][15] -> [INCOMPLETE][16] ([i915#61])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-hsw4/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-hsw4/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-suspend:
- shard-kbl: [PASS][17] -> [DMESG-WARN][18] ([i915#180]) +4 similar issues
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-kbl3/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-kbl4/igt@[email protected]

* igt@kms_cursor_legacy@2x-long-flip-vs-cursor-legacy:
- shard-glk: [PASS][19] -> [FAIL][20] ([i915#72])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-glk7/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-glk5/igt@[email protected]

* igt@kms_dp_dsc@basic-dsc-enable-edp:
- shard-iclb: [PASS][21] -> [SKIP][22] ([fdo#109349])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb2/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-suspend:
- shard-kbl: [PASS][23] -> [DMESG-WARN][24] ([i915#180] / [i915#93] / [i915#95])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-kbl7/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-kbl6/igt@[email protected]

* igt@kms_hdr@bpc-switch-dpms:
- shard-skl: [PASS][25] -> [FAIL][26] ([i915#1188]) +1 similar issue
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-skl6/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-skl7/igt@[email protected]

* igt@kms_plane@plane-panning-bottom-right-suspend-pipe-b-planes:
- shard-apl: [PASS][27] -> [DMESG-WARN][28] ([i915#180]) +1 similar issue
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-apl2/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-apl1/igt@[email protected]

* igt@kms_plane_lowres@pipe-a-tiling-x:
- shard-glk: [PASS][29] -> [FAIL][30] ([i915#899])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-glk5/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-glk8/igt@[email protected]

* igt@kms_psr@psr2_primary_page_flip:
- shard-iclb: [PASS][31] -> [SKIP][32] ([fdo#109441]) +1 similar issue
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb2/igt@kms_psr@psr2_primary_page_flip.html
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb1/igt@kms_psr@psr2_primary_page_flip.html

#### Possible fixes ####

* {igt@gem_ctx_isolation@preservation-s3@rcs0}:
- shard-apl: [DMESG-WARN][33] ([i915#180]) -> [PASS][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-apl4/igt@gem_ctx_isolation@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-apl3/igt@gem_ctx_isolation@[email protected]

* igt@gem_exec_schedule@pi-shared-iova-bsd:
- shard-iclb: [SKIP][35] ([i915#677]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb2/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb7/igt@[email protected]

* igt@gem_exec_schedule@preemptive-hang-bsd:
- shard-iclb: [SKIP][37] ([fdo#112146]) -> [PASS][38] +4 similar issues
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb4/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb3/igt@[email protected]

* igt@gen9_exec_parse@allowed-all:
- shard-glk: [DMESG-WARN][39] ([i915#716]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-glk8/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-glk1/igt@[email protected]

* igt@i915_pm_rps@min-max-config-loaded:
- shard-glk: [FAIL][41] ([i915#39]) -> [PASS][42]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-glk9/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-glk2/igt@[email protected]

* igt@i915_suspend@sysfs-reader:
- shard-kbl: [DMESG-WARN][43] ([i915#180]) -> [PASS][44] +1 similar issue
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-kbl7/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-kbl3/igt@[email protected]

* igt@kms_draw_crc@draw-method-xrgb2101010-render-untiled:
- shard-skl: [FAIL][45] ([i915#52] / [i915#54]) -> [PASS][46]
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-skl7/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-skl3/igt@[email protected]

* igt@kms_flip@flip-vs-expired-vblank-interruptible:
- shard-glk: [FAIL][47] ([i915#79]) -> [PASS][48]
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-glk2/igt@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-glk2/igt@[email protected]

* igt@kms_flip@plain-flip-fb-recreate-interruptible:
- shard-skl: [FAIL][49] ([i915#34]) -> [PASS][50]
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-skl4/igt@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-skl9/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-rte:
- shard-tglb: [SKIP][51] ([i915#668]) -> [PASS][52] +8 similar issues
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-tglb6/igt@[email protected]
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-tglb3/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-c:
- shard-iclb: [INCOMPLETE][53] ([i915#1185]) -> [PASS][54]
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb3/igt@[email protected]
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb3/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-constant-alpha-min:
- shard-skl: [FAIL][55] ([fdo#108145]) -> [PASS][56]
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-skl1/igt@[email protected]
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-skl1/igt@[email protected]

* igt@kms_psr@psr2_primary_mmap_cpu:
- shard-iclb: [SKIP][57] ([fdo#109441]) -> [PASS][58] +2 similar issues
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb7/igt@kms_psr@psr2_primary_mmap_cpu.html
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb2/igt@kms_psr@psr2_primary_mmap_cpu.html

* igt@perf_pmu@busy-double-start-vcs1:
- shard-iclb: [SKIP][59] ([fdo#112080]) -> [PASS][60] +2 similar issues
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb8/igt@[email protected]
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb1/igt@[email protected]

* igt@prime_busy@hang-bsd2:
- shard-iclb: [SKIP][61] ([fdo#109276]) -> [PASS][62] +8 similar issues
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-iclb7/igt@[email protected]
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-iclb2/igt@[email protected]

#### Warnings ####

* igt@i915_pm_dc@dc6-psr:
- shard-tglb: [FAIL][63] ([i915#454]) -> [SKIP][64] ([i915#468])
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-tglb7/igt@[email protected]
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-tglb2/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-alpha-7efc:
- shard-apl: [FAIL][65] ([fdo#108145]) -> [FAIL][66] ([fdo#108145] / [i915#95])
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8206/shard-apl3/igt@[email protected]
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/shard-apl1/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
[fdo#109349]: https://bugs.freedesktop.org/show_bug.cgi?id=109349
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#112080]: https://bugs.freedesktop.org/show_bug.cgi?id=112080
[fdo#112146]: https://bugs.freedesktop.org/show_bug.cgi?id=112146
[i915#1185]: https://gitlab.freedesktop.org/drm/intel/issues/1185
[i915#1188]: https://gitlab.freedesktop.org/drm/intel/issues/1188
[i915#180]: https://gitlab.freedesktop.org/drm/intel/issues/180
[i915#34]: https://gitlab.freedesktop.org/drm/intel/issues/34
[i915#39]: https://gitlab.freedesktop.org/drm/intel/issues/39
[i915#454]: https://gitlab.freedesktop.org/drm/intel/issues/454
[i915#468]: https://gitlab.freedesktop.org/drm/intel/issues/468
[i915#52]: https://gitlab.freedesktop.org/drm/intel/issues/52
[i915#54]: https://gitlab.freedesktop.org/drm/intel/issues/54
[i915#61]: https://gitlab.freedesktop.org/drm/intel/issues/61
[i915#668]: https://gitlab.freedesktop.org/drm/intel/issues/668
[i915#677]: https://gitlab.freedesktop.org/drm/intel/issues/677
[i915#716]: https://gitlab.freedesktop.org/drm/intel/issues/716
[i915#72]: https://gitlab.freedesktop.org/drm/intel/issues/72
[i915#79]: https://gitlab.freedesktop.org/drm/intel/issues/79
[i915#899]: https://gitlab.freedesktop.org/drm/intel/issues/899
[i915#93]: https://gitlab.freedesktop.org/drm/intel/issues/93
[i915#95]: https://gitlab.freedesktop.org/drm/intel/issues/95

Participating hosts (10 -> 10)
------------------------------

No changes in participating hosts

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_8206 -> Patchwork_17121

CI-20190529: 20190529
CI_DRM_8206: 584fcbd287863a6ba897f1b671acd7115d611362 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5543: 779d43cda49c230afd32c37730ad853f02e9d749 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_17121: 629368ea252e2101ef3c1b5deb7bd0554f4a4ad9 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_17121/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Ashutosh Dixit
Quoted 11 lines · Ashutosh Dixit

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.

Quoted 7 lines

v2: Fix ret value for blocking reads (Umesh)
v3: Mistake during patch send (Ashutosh)
v4: Remove -EAGAIN from comment (Umesh)

Cc Umesh Nerlige Ramappa <[email protected]>
Cc Lionel Landwerlin <[email protected]>

Looks like you change makes more sense than what I suggested.

I have a few nits below.

Thanks,

-Lionel

Quoted 68 lines
---
  drivers/gpu/drm/i915/i915_perf.c | 59 +++++++-------------------------
  1 file changed, 12 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +2 -43
index c74ebac50015..5f6d9bff99c8 100644
@@ -2914,49 +2914,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
@@ -2982,6 +2939,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

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2968

Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c +2 -2
@@ -3005,16 +2964,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);

I would drop this line above and move it to the end of the function.

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2974

Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c +2 -1
  			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);

I would drop this line above and move it to the end of the function.

Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +2 -0
  		mutex_unlock(&perf->lock);
  	}
 
+	/* Possible values for __ret are 0, -EFAULT, -ENOSPC, -EIO, ... */
+
  	/* 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

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2991

Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +4 -1
@@ -3022,8 +2984,11 @@ 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)
+	if ((ret > 0 || ret == -EAGAIN) && __ret != -ENOSPC)

I guess this could be simplified with

if (__ret != -ENOSPC)

As far as I can see in all other cases (failure of some kind, all data read), we should clear pollin.

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2994

Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +0 -0
  		stream->pollin = false;
 
  	return ret;

return offset ?: (__ret ?: -EAGAIN);

You could probably just retain a single ret variable.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
Quoted 17 lines · Lionel Landwerlin
Quoted 15 lines · Ashutosh Dixit

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)
v3: Mistake during patch send (Ashutosh)
v4: Remove -EAGAIN from comment (Umesh)

Quoted 7 lines
Quoted 3 lines
Cc Umesh Nerlige Ramappa <[email protected]>
Cc Lionel Landwerlin <[email protected]>

Looks like you change makes more sense than what I suggested.

I have a few nits below.

Thanks Lionel, most of what you suggested made sense so I have made those changes and submitted a v5. Please take a look. More comments below.

Quoted 73 lines

Thanks,

-Lionel

Quoted 67 lines
---
  drivers/gpu/drm/i915/i915_perf.c | 59 +++++++-------------------------
  1 file changed, 12 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +2 -42
index c74ebac50015..5f6d9bff99c8 100644
@@ -2914,49 +2914,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
@@ -2982,6 +2939,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

drivers/gpu/drm/i915/i915_perf.c +0 -0
@@ -3005,16 +2964,19 @@ static ssize_t i915_perf_read(struct file *file,
Quoted 8 lines

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2968

Quoted 6 lines
drivers/gpu/drm/i915/i915_perf.c +2 -2
 				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);

I would drop this line above and move it to the end of the function.

Unfortunately, Umesh pointed this out, that can't be done because ret is used in the loop (do { } while (ret == -EAGAIN); ).

Quoted 9 lines

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2974

Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c +2 -1
 			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);

I would drop this line above and move it to the end of the function.

Done.

Quoted 20 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c +1 -0
 		mutex_unlock(&perf->lock);
 	}
  +	/* Possible values for __ret are 0, -EFAULT, -ENOSPC, -EIO, ... */
+
 	/* 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

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2991

Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +4 -1
@@ -3022,8 +2984,11 @@ 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)
+	if ((ret > 0 || ret == -EAGAIN) && __ret != -ENOSPC)

I guess this could be simplified with

Quoted 4 lines

if (__ret != -ENOSPC)

As far as I can see in all other cases (failure of some kind, all data read), we should clear pollin.

Done.

Quoted 7 lines

drivers/gpu/drm/i915/i915_perf.c static ssize_t i915_perf_read(struct file *file, · line 2994

Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +0 -0
 		stream->pollin = false;
 		return ret;

return offset ?: (__ret ?: -EAGAIN);

You could probably just retain a single ret variable.

Done, mostly. There is a second ret in a restricted scope due to the reason mentioned above (ret in the loop).
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx