From: "Goel, Akash" <akash.goel@intel.com>
To: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
intel-gfx@lists.freedesktop.org
Cc: akash.goel@intel.com
Subject: Re: [PATCH 05/20] drm/i915: Support for GuC interrupts
Date: Fri, 12 Aug 2016 21:02:38 +0530 [thread overview]
Message-ID: <31cfa60f-52c0-1e2d-e71c-1de68ec5e2ec@intel.com> (raw)
In-Reply-To: <57ADE5A5.7090505@linux.intel.com>
On 8/12/2016 8:35 PM, Tvrtko Ursulin wrote:
>
> On 12/08/16 15:31, Goel, Akash wrote:
>> On 8/12/2016 7:01 PM, Tvrtko Ursulin wrote:
>>>>>> +static void gen9_guc2host_events_work(struct work_struct *work)
>>>>>> +{
>>>>>> + struct drm_i915_private *dev_priv =
>>>>>> + container_of(work, struct drm_i915_private,
>>>>>> guc.events_work);
>>>>>> +
>>>>>> + spin_lock_irq(&dev_priv->irq_lock);
>>>>>> + /* Speed up work cancellation during disabling guc
>>>>>> interrupts. */
>>>>>> + if (!dev_priv->guc.interrupts_enabled) {
>>>>>> + spin_unlock_irq(&dev_priv->irq_lock);
>>>>>> + return;
>>>>>
>>>>> I suppose locking for early exit is something about ensuring the
>>>>> worker
>>>>> sees the update to dev_priv->guc.interrupts_enabled done on another
>>>>> CPU?
>>>>
>>>> Yes locking (providing implicit barrier) will ensure that update made
>>>> from another CPU is immediately visible to the worker.
>>>
>>> What if the disable happens after the unlock above? It would wait in
>>> disable until the irq handler exits.
>> Most probably it will not have to wait, as irq handler would have
>> completed if work item began the execution.
>> Irq handler just queues the work item, which gets scheduled later on.
>>
>> Using the lock is beneficial for the case where the execution of work
>> item and interrupt disabling is done around the same time.
>
> Ok maybe I am missing something.
>
> When can the interrupt disabling happen? Will it be controlled by the
> debugfs file or is it driver load/unload and suspend/resume?
>
yes disabling will happen for all the above 3 scenarios.
>>>>>> +static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv,
>>>>>> u32 gt_iir)
>>>>>> +{
>>>>>> + bool interrupts_enabled;
>>>>>> +
>>>>>> + if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) {
>>>>>> + spin_lock(&dev_priv->irq_lock);
>>>>>> + interrupts_enabled = dev_priv->guc.interrupts_enabled;
>>>>>> + spin_unlock(&dev_priv->irq_lock);
>>>>>
>>>>> Not sure that taking a lock around only this read is needed.
>>>>>
>>>> Again same reason as above, to make sure an update made on another CPU
>>>> is immediately visible to the irq handler.
>>>
>>> I don't get it, see above. :)
>>
>> Here also If interrupt disabling & ISR execution happens around the same
>> time then ISR might miss the reset of 'interrupts_enabled' flag and
>> queue the new work.
>
> What if reset of interrupts_enabled happens just as the ISR releases the
> lock?
>
Then ISR will proceed ahead and queue the work item.
Lock is useful if reset of interrupts_enabled flag just happens before
the ISR inspects the value of that flag.
Also lock will help when interrupts_enabled flag is set again, next ISR
will definitely see it as set.
>> And same applies to the case when interrupt is re-enabled, ISR might
>> still see the 'interrupts_enabled' flag as false.
>> It will eventually see the update though.
>>
>>>
>>>>>> + if (interrupts_enabled) {
>>>>>> + /* Sample the log buffer flush related bits & clear them
>>>>>> + * out now itself from the message identity register to
>>>>>> + * minimize the probability of losing a flush interrupt,
>>>>>> + * when there are back to back flush interrupts.
>>>>>> + * There can be a new flush interrupt, for different log
>>>>>> + * buffer type (like for ISR), whilst Host is handling
>>>>>> + * one (for DPC). Since same bit is used in message
>>>>>> + * register for ISR & DPC, it could happen that GuC
>>>>>> + * sets the bit for 2nd interrupt but Host clears out
>>>>>> + * the bit on handling the 1st interrupt.
>>>>>> + */
>>>>>> + u32 msg = I915_READ(SOFT_SCRATCH(15)) &
>>>>>> + (GUC2HOST_MSG_CRASH_DUMP_POSTED |
>>>>>> + GUC2HOST_MSG_FLUSH_LOG_BUFFER);
>>>>>> + if (msg) {
>>>>>> + /* Clear the message bits that are handled */
>>>>>> + I915_WRITE(SOFT_SCRATCH(15),
>>>>>> + I915_READ(SOFT_SCRATCH(15)) & ~msg);
>>>>>
>>>>> Cache full value of SOFT_SCRATCH(15) so you don't have to mmio read it
>>>>> twice?
>>>>>
>>>> Thought reading it again (just before the update) is bit safer compared
>>>> to reading it once, as there is a potential race problem here.
>>>> GuC could also write to the SOFT_SCRATCH(15) register, set new events
>>>> bit, while Host clears off the bit of handled events.
>>>
>>> Don't get it. If there is a race between read and write there still is,
>>> don't see how a second read makes it safer.
>>>
>> Yes can't avoid the race completely by double reads, but can reduce the
>> race window size.
>
> There was only one thing between the two reads, and that was "if (msg)":
>
> + u32 msg = I915_READ(SOFT_SCRATCH(15)) &
> + (GUC2HOST_MSG_CRASH_DUMP_POSTED |
> + GUC2HOST_MSG_FLUSH_LOG_BUFFER);
>
> + if (msg) {
>
> + /* Clear the message bits that are handled */
> + I915_WRITE(SOFT_SCRATCH(15),
> + I915_READ(SOFT_SCRATCH(15)) & ~msg);
>
>>
>> Also I felt code looked better in current form, as macros
>> GUC2HOST_MSG_CRASH_DUMP_POSTED & GUC2HOST_MSG_FLUSH_LOG_BUFFER were used
>> only once.
>>
>> Will change as per the initial implementation.
>>
>> u32 msg = I915_READ(SOFT_SCRATCH(15));
>> if (msg & (GUC2HOST_MSG_CRASH_DUMP_POSTED |
>> GUC2HOST_MSG_FLUSH_LOG_BUFFER) {
>> msg &= ~(GUC2HOST_MSG_CRASH_DUMP_POSTED |
>> GUC2HOST_MSG_FLUSH_LOG_BUFFER);
>> I915_WRITE(SOFT_SCRATCH(15), msg);
>> }
>
> Or:
> u32 msg, flush;
>
> msg = I915_READ(SOFT_SCRATCH(15));
> flush = msg & (GUC2HOST_MSG_CRASH_DUMP_POSTED |
> GUC2HOST_MSG_FLUSH_LOG_BUFFER);
> if (flush) {
> I915_WRITE(SOFT_SCRATCH(15), ~flush);
> ... queue woker ...
>
> ?
Thanks much, will change as per the above.
>
>>
>>>>> Also, is the RMW outside any locks safe?
>>>>>
>>>>
>>>> Ideally need a way to atomically do the RMW, i.e. read the register
>>>> value, clear off the handled events bit and update the register with
>>>> the
>>>> modified value.
>>>>
>>>> Please kindly suggest how to address the above.
>>>> Or can this be left as a TODO, when we do start handling other events
>>>> also.
>>>
>>> From the comment in code above it sounds like a GuC fw interface
>>> shortcoming - that there is a single bit for two different interrupt
>>> sources, is that right?
>> Yes that shortcoming is there, GUC2HOST_MSG_FLUSH_LOG_BUFFER bit is used
>> for conveying the flush for ISR & DPC log buffers.
>>
>>> Is there any other register or something that
>>> you can read to detect that the interrupt has been re-asserted while in
>>> the irq handler?
>>
>>
>>> Although I thought you said before that the GuC will
>>> not do that - that it won't re-assert the interrupt before we send the
>>> flush command.
>> Yes that is the case, but with respect to one type of a log buffer, like
>> for example unless GuC firmware receives the ack for DPC log
>> buffer it won't send a new flush for DPC buffer, but if meanwhile ISR
>> buffer becomes half full it will send a flush interrupt.
>
> So the potential for losing interrupts is unavoidable it seems. :( If I
> am understanding this correctly.
>
Yes unavoidable, but that's a very small window.
Have apprised GuC folks about this.
Best Regards
Akash
> Regards,
>
> Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2016-08-12 15:32 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-12 6:25 [PATCH v5 00/20] Support for sustained capturing of GuC firmware logs akash.goel
2016-08-12 6:25 ` [PATCH 01/20] drm/i915: Decouple GuC log setup from verbosity parameter akash.goel
2016-08-12 6:25 ` [PATCH 02/20] drm/i915: Add GuC ukernel logging related fields to fw interface file akash.goel
2016-08-12 6:25 ` [PATCH 03/20] drm/i915: New structure to contain GuC logging related fields akash.goel
2016-08-12 6:25 ` [PATCH 04/20] drm/i915: Add low level set of routines for programming PM IER/IIR/IMR register set akash.goel
2016-08-12 11:15 ` Tvrtko Ursulin
2016-08-12 6:25 ` [PATCH 05/20] drm/i915: Support for GuC interrupts akash.goel
2016-08-12 11:54 ` Tvrtko Ursulin
2016-08-12 13:10 ` Goel, Akash
2016-08-12 13:31 ` Tvrtko Ursulin
2016-08-12 14:31 ` Goel, Akash
2016-08-12 15:05 ` Tvrtko Ursulin
2016-08-12 15:32 ` Goel, Akash [this message]
2016-08-12 6:25 ` [PATCH 06/20] drm/i915: Handle log buffer flush interrupt event from GuC akash.goel
2016-08-12 6:28 ` Chris Wilson
2016-08-12 6:44 ` Goel, Akash
2016-08-12 6:51 ` Chris Wilson
2016-08-12 7:00 ` Goel, Akash
2016-08-12 13:17 ` Tvrtko Ursulin
2016-08-12 13:45 ` Goel, Akash
2016-08-12 14:07 ` Tvrtko Ursulin
2016-08-12 16:17 ` Goel, Akash
2016-08-12 6:25 ` [PATCH 07/20] relay: Use per CPU constructs for the relay channel buffer pointers akash.goel
2016-08-12 6:25 ` [PATCH 08/20] drm/i915: Add a relay backed debugfs interface for capturing GuC logs akash.goel
2016-08-12 13:53 ` Tvrtko Ursulin
2016-08-12 16:10 ` Goel, Akash
2016-08-12 6:25 ` [PATCH 09/20] drm/i915: New lock to serialize the Host2GuC actions akash.goel
2016-08-12 13:55 ` Tvrtko Ursulin
2016-08-12 15:01 ` Goel, Akash
2016-08-12 6:25 ` [PATCH 10/20] drm/i915: Add stats for GuC log buffer flush interrupts akash.goel
2016-08-12 14:26 ` Tvrtko Ursulin
2016-08-12 14:56 ` Goel, Akash
2016-08-12 6:25 ` [PATCH 11/20] drm/i915: Optimization to reduce the sampling time of GuC log buffer akash.goel
2016-08-12 14:42 ` Tvrtko Ursulin
2016-08-12 14:48 ` Goel, Akash
2016-08-12 15:06 ` Tvrtko Ursulin
2016-08-12 6:25 ` [PATCH 12/20] drm/i915: Increase GuC log buffer size to reduce flush interrupts akash.goel
2016-08-12 6:25 ` [PATCH 13/20] drm/i915: Augment i915 error state to include the dump of GuC log buffer akash.goel
2016-08-12 15:20 ` Tvrtko Ursulin
2016-08-12 15:32 ` Chris Wilson
2016-08-12 15:46 ` Goel, Akash
2016-08-12 15:52 ` Chris Wilson
2016-08-12 16:04 ` Goel, Akash
2016-08-12 16:09 ` Chris Wilson
2016-08-12 6:25 ` [PATCH 14/20] drm/i915: Forcefully flush GuC log buffer on reset akash.goel
2016-08-12 6:33 ` Chris Wilson
2016-08-12 7:02 ` Goel, Akash
2016-08-12 6:25 ` [PATCH 15/20] drm/i915: Debugfs support for GuC logging control akash.goel
2016-08-12 15:57 ` Tvrtko Ursulin
2016-08-12 17:08 ` Goel, Akash
2016-08-12 6:25 ` [PATCH 16/20] drm/i915: Support to create write combined type vmaps akash.goel
2016-08-12 10:49 ` Tvrtko Ursulin
2016-08-12 15:13 ` Goel, Akash
2016-08-12 15:16 ` Chris Wilson
2016-08-12 16:46 ` Goel, Akash
2016-08-12 6:25 ` [PATCH 17/20] drm/i915: Use uncached(WC) mapping for acessing the GuC log buffer akash.goel
2016-08-12 16:05 ` Tvrtko Ursulin
2016-08-12 6:25 ` [PATCH 18/20] drm/i915: Use SSE4.1 movntdqa to accelerate reads from WC memory akash.goel
2016-08-12 10:54 ` Tvrtko Ursulin
2016-08-12 12:22 ` Chris Wilson
2016-08-12 6:25 ` [PATCH 19/20] drm/i915: Use SSE4.1 movntdqa based memcpy for sampling GuC log buffer akash.goel
2016-08-12 16:06 ` Tvrtko Ursulin
2016-08-12 6:25 ` [PATCH 20/20] drm/i915: Early creation of relay channel for capturing boot time logs akash.goel
2016-08-12 16:22 ` Tvrtko Ursulin
2016-08-12 16:31 ` Goel, Akash
2016-08-15 9:20 ` Tvrtko Ursulin
2016-08-15 10:20 ` Goel, Akash
2016-08-12 6:58 ` ✗ Ro.CI.BAT: warning for Support for sustained capturing of GuC firmware logs (rev6) 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=31cfa60f-52c0-1e2d-e71c-1de68ec5e2ec@intel.com \
--to=akash.goel@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=tvrtko.ursulin@linux.intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.