@@ -2999,60 +2999,6 @@ void i915_oa_init_reg_state(const struct intel_context *ce,
29992999 gen8_update_reg_state_unlocked (ce , stream );
30003000}
30013001
3002- /**
3003- * i915_perf_read_locked - &i915_perf_stream_ops->read with error normalisation
3004- * @stream: An i915 perf stream
3005- * @file: An i915 perf stream file
3006- * @buf: destination buffer given by userspace
3007- * @count: the number of bytes userspace wants to read
3008- * @ppos: (inout) file seek position (unused)
3009- *
3010- * Besides wrapping &i915_perf_stream_ops->read this provides a common place to
3011- * ensure that if we've successfully copied any data then reporting that takes
3012- * precedence over any internal error status, so the data isn't lost.
3013- *
3014- * For example ret will be -ENOSPC whenever there is more buffered data than
3015- * can be copied to userspace, but that's only interesting if we weren't able
3016- * to copy some data because it implies the userspace buffer is too small to
3017- * receive a single record (and we never split records).
3018- *
3019- * Another case with ret == -EFAULT is more of a grey area since it would seem
3020- * like bad form for userspace to ask us to overrun its buffer, but the user
3021- * knows best:
3022- *
3023- * http://yarchive.net/comp/linux/partial_reads_writes.html
3024- *
3025- * Returns: The number of bytes copied or a negative error code on failure.
3026- */
3027- #ifdef __NetBSD__
3028- static int i915_perf_read_locked (struct i915_perf_stream * stream ,
3029- struct file * file ,
3030- struct uio * buf ,
3031- kauth_cred_t count , /* XXX dummy */
3032- int ppos ) /* XXX dummy */
3033- {
3034- return stream -> ops -> read (stream , buf , count , ppos );
3035- }
3036- #else
3037- static ssize_t i915_perf_read_locked (struct i915_perf_stream * stream ,
3038- struct file * file ,
3039- char __user * buf ,
3040- size_t count ,
3041- loff_t * ppos )
3042- {
3043- /* Note we keep the offset (aka bytes read) separate from any
3044- * error status so that the final check for whether we return
3045- * the bytes read with a higher precedence than any error (see
3046- * comment below) doesn't need to be handled/duplicated in
3047- * stream->ops->read() implementations.
3048- */
3049- size_t offset = 0 ;
3050- int ret = stream -> ops -> read (stream , buf , count , & offset );
3051-
3052- return offset ?: (ret ?: - EAGAIN );
3053- }
3054- #endif
3055-
30563002/**
30573003 * i915_perf_read - handles read() FOP for i915 perf stream FDs
30583004 * @file: An i915 perf stream file
@@ -3090,7 +3036,7 @@ static ssize_t i915_perf_read(struct file *file,
30903036 struct i915_perf_stream * stream = file -> private_data ;
30913037#endif
30923038 struct i915_perf * perf = stream -> perf ;
3093- ssize_t ret ;
3039+ size_t offset = 0 ;
30943040
30953041 /* To ensure it's handled consistently we simply treat all reads of a
30963042 * disabled stream as an error. In particular it might otherwise lead
@@ -3119,13 +3065,12 @@ static ssize_t i915_perf_read(struct file *file,
31193065 return ret ;
31203066
31213067 mutex_lock (& perf -> lock );
3122- ret = i915_perf_read_locked (stream , file ,
3123- buf , count , ppos );
3068+ ret = stream -> ops -> read (stream , buf , count , & offset );
31243069 mutex_unlock (& perf -> lock );
3125- } while (ret == - EAGAIN );
3070+ } while (! offset && ! ret );
31263071 } else {
31273072 mutex_lock (& perf -> lock );
3128- ret = i915_perf_read_locked (stream , file , buf , count , ppos );
3073+ ret = stream -> ops -> read (stream , buf , count , & offset );
31293074 mutex_unlock (& perf -> lock );
31303075 }
31313076
@@ -3136,15 +3081,15 @@ static ssize_t i915_perf_read(struct file *file,
31363081 * and read() returning -EAGAIN. Clearing the oa.pollin state here
31373082 * effectively ensures we back off until the next hrtimer callback
31383083 * before reporting another EPOLLIN event.
3084+ * The exception to this is if ops->read() returned -ENOSPC which means
3085+ * that more OA data is available than could fit in the user provided
3086+ * buffer. In this case we want the next poll() call to not block.
31393087 */
3140- if (ret >= 0 || ret == - EAGAIN ) {
3141- /* Maybe make ->pollin per-stream state if we support multiple
3142- * concurrent streams in the future.
3143- */
3088+ if (ret != - ENOSPC )
31443089 stream -> pollin = false;
3145- }
31463090
3147- return ret ;
3091+ /* Possible values for ret are 0, -EFAULT, -ENOSPC, -EIO, ... */
3092+ return offset ?: (ret ?: - EAGAIN );
31483093}
31493094
31503095static enum hrtimer_restart oa_poll_check_timer_cb (struct hrtimer * hrtimer )
0 commit comments