Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Dixit, Ashutosh" <ashutosh.dixit@intel.com>
To: Harish Chegondi <harish.chegondi@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v9 4/8] drm/xe/eustall: Add support to read() and poll() EU stall data
Date: Mon, 17 Feb 2025 20:02:57 -0800	[thread overview]
Message-ID: <85wmdn293i.wl-ashutosh.dixit@intel.com> (raw)
In-Reply-To: <Z7PV1xrxwHeMnBnk@intel.com>

On Mon, 17 Feb 2025 16:35:35 -0800, Harish Chegondi wrote:
>
> > > > > > > +	if (!(file->f_flags & O_NONBLOCK)) {
> > > > > > > +		do {
> > > > > > > +			ret = wait_event_interruptible(stream->poll_wq, stream->pollin);
> > > > > > > +			if (ret)
> > > > > > > +				return -EINTR;
> > > > > > > +
> > > > > > > +			mutex_lock(&gt->eu_stall->stream_lock);
> > > > > > > +			ret = xe_eu_stall_stream_read_locked(stream, file, buf, count);
> > > > > > > +			mutex_unlock(&gt->eu_stall->stream_lock);
> > > > > > > +		} while (ret == -EAGAIN);
> > > > > > > +	} else {
> > > > > > > +		mutex_lock(&gt->eu_stall->stream_lock);
> > > > > > > +		ret = xe_eu_stall_stream_read_locked(stream, file, buf, count);
> > > > > > > +		mutex_unlock(&gt->eu_stall->stream_lock);
> > > > > > > +	}
> > > > > > > +
> > > > > > > +	stream->pollin = false;
> > > > > >
> > > > > > Carry over comment from previous rev: this breaks if user buffer is smaller
> > > > > > than available data. But this is a corner case so let's fix this after the
> > > > > > initial merge.
> > > > > I will check your fix in OA to better understand the problem here. If
> > > > > the user buffer is smaller than data record size, it just returns
> > > > > without copying any data.
> > > >
> > > > No, it is the issue when user buffer is larger than record_size, but still
> > > > smaller than the size of total data available. In that case, basically we
> > > > should let stream->pollin set to true, so that the user thread does not get
> > > > blocked, enabling it to rapidly consume data, even with a small buffer.
> > > >
> > > > Otherwise the thread is getting blocked every 10 ms, even when data is
> > > > available. And because new data keeps arriving, the user thread constantly
> > > > falls behind and soon HW will start dropping data (because the kernel is
> > > > blocking the user thread, it's a kernel not a user thread issue)
> > > >
> > > > To handle this OA does:
> > > >
> > > >	if (ret != -ENOSPC && ret != -EIO)
> > > EU stall read() never returns -ENOSPC. Even if the user buffer is
> > > smaller then the size of total data in the buffer, only the data that
> > > can fit into the user buffer will be copied through read().
> >
> > OA read() also doesn't return -ENOSPC to userland. That is the expected
> > read() behavior (return number of bytes if you are returning any data). The
> > full code is this:
> >
> >         if (ret != -ENOSPC && ret != -EIO)
> >                 stream->pollin = false;
> >
> >         return offset ?: (ret ?: -EAGAIN);
> >
> > > As long as there are atleast wait_num_reports data rows in the buffer,
> > > stream->pollin is set to true. It sounds to me that this issue is
> > > specific to OA code only. Is there something that I missed?
> >
> > No this issue is there in EU stall code. You should not block reads till
> > the next time the polling thread runs, if we could not copy all data in the
> > previous read (because there already is data, don't block the user thread).
> The polling thread runs approximately once every 10ms. The question here
> is what would be time duration between two successive reads from the
> user space with no additional delay between them. If the duration is
> more than 10ms, the polling thread would set pollin to true. If not,
> the issue you have mentioned would occur.

If we don't block the user thread in the kernel, ideally it would call into
the kernel continuously to read data, let's say every few us. Say a memcpy
in userspace and then back into the kernel to read more data.

> However, I am changing the code here to this:
>
>         if (!eu_stall_data_buf_poll(stream))
>                 stream->pollin = false;
>
> Wouldn't this fix the issue?

No, this is not correct. There are two requirements:

1. Don't wake up the user thread too frequently, that is why we have the 10
   ms timer, so ordinarily, with a large buffer, the user thread only wakes
   up only every 10 ms.

2. Only when the user buffer is small, that is we have data which we could
   not copy in the user buffer, we shouldn't block the user thread.

In the above code, you are checking for data after completing the memcpy
into the user buffer. This would solve 2., but might break 1. Because the
code does not take into account that we should not block the user thread
only if the user buffer is small.

Let's not introduce this into the existing patches, this small user buffer
handling would need a new patch. As I said, let's do this after we merge
what we currently have. I don't want to review this stuff now.

Thanks.
--
Ashutosh

  reply	other threads:[~2025-02-18  4:02 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10 13:46 [PATCH v9 0/8] Add support for EU stall sampling Harish Chegondi
2025-02-10 13:46 ` [PATCH v9 1/8] drm/xe/topology: Add a function to find the index of the last enabled DSS in a mask Harish Chegondi
2025-02-10 17:31   ` Dixit, Ashutosh
2025-02-10 13:46 ` [PATCH v9 2/8] drm/xe/uapi: Introduce API for EU stall sampling Harish Chegondi
2025-02-10 23:07   ` Dixit, Ashutosh
2025-02-10 23:53     ` Dixit, Ashutosh
2025-02-11 19:50     ` Dixit, Ashutosh
2025-02-12 23:54     ` Harish Chegondi
2025-02-13  2:39       ` Dixit, Ashutosh
2025-02-16  1:49         ` Harish Chegondi
2025-02-16  5:49           ` Dixit, Ashutosh
2025-02-18 11:54             ` Jani Nikula
2025-02-10 13:46 ` [PATCH v9 3/8] drm/xe/eustall: Add support to init, enable and disable " Harish Chegondi
2025-02-11 17:33   ` Dixit, Ashutosh
2025-02-11 22:02     ` Harish Chegondi
2025-02-12  2:44       ` Dixit, Ashutosh
2025-02-10 13:46 ` [PATCH v9 4/8] drm/xe/eustall: Add support to read() and poll() EU stall data Harish Chegondi
2025-02-12 19:02   ` Dixit, Ashutosh
2025-02-14  7:51     ` Harish Chegondi
2025-02-14 20:34       ` Dixit, Ashutosh
2025-02-15  0:44         ` Harish Chegondi
2025-02-15  2:22           ` Dixit, Ashutosh
2025-02-18  0:35             ` Harish Chegondi
2025-02-18  4:02               ` Dixit, Ashutosh [this message]
2025-02-10 13:46 ` [PATCH v9 5/8] drm/xe/eustall: Add support to handle dropped " Harish Chegondi
2025-02-13  6:31   ` Dixit, Ashutosh
2025-02-13 21:55     ` Harish Chegondi
2025-02-13 23:45       ` Dixit, Ashutosh
2025-02-14  0:11         ` Dixit, Ashutosh
2025-02-14  2:05           ` Dixit, Ashutosh
2025-02-14  2:23             ` Dixit, Ashutosh
2025-02-10 13:46 ` [PATCH v9 6/8] drm/xe/eustall: Add EU stall sampling support for Xe2 Harish Chegondi
2025-02-12 19:46   ` Dixit, Ashutosh
2025-02-10 13:46 ` [PATCH v9 7/8] drm/xe/uapi: Add a device query to get EU stall sampling information Harish Chegondi
2025-02-12 21:13   ` Dixit, Ashutosh
2025-02-10 13:46 ` [PATCH v9 8/8] drm/xe/eustall: Add workaround 22016596838 which applies to PVC Harish Chegondi
2025-02-12 20:01   ` Dixit, Ashutosh
2025-02-10 14:32 ` ✓ CI.Patch_applied: success for Add support for EU stall sampling Patchwork
2025-02-10 14:33 ` ✗ CI.checkpatch: warning " Patchwork
2025-02-10 14:34 ` ✓ CI.KUnit: success " Patchwork
2025-02-10 14:50 ` ✓ CI.Build: " Patchwork
2025-02-10 14:53 ` ✓ CI.Hooks: " Patchwork
2025-02-10 14:54 ` ✓ CI.checksparse: " Patchwork
2025-02-11  7:24 ` ✓ CI.Patch_applied: success for Add support for EU stall sampling (rev2) Patchwork
2025-02-11  7:24 ` ✗ CI.checkpatch: warning " Patchwork
2025-02-11  7:25 ` ✓ CI.KUnit: success " Patchwork
2025-02-11  7:42 ` ✓ CI.Build: " Patchwork
2025-02-11  7:43 ` ✗ CI.Hooks: failure " Patchwork
2025-02-11  7:44 ` ✗ CI.checksparse: warning " Patchwork
2025-02-11  8:04 ` ✓ Xe.CI.BAT: success " Patchwork
2025-02-11 16:11 ` ✗ Xe.CI.Full: failure " Patchwork
2025-02-11 19:23 ` [PATCH v9 0/8] Add support for EU stall sampling Dixit, Ashutosh
2025-02-12  9:42 ` ✗ Xe.CI.Full: failure for " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85wmdn293i.wl-ashutosh.dixit@intel.com \
    --to=ashutosh.dixit@intel.com \
    --cc=harish.chegondi@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox