All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Paulo Zanoni <przanoni@gmail.com>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	Paulo Zanoni <paulo.r.zanoni@intel.com>
Subject: Re: [PATCH 04/19] drm/i915: get/put PC8 when we get/put a CRTC
Date: Wed, 4 Dec 2013 15:07:13 +0100	[thread overview]
Message-ID: <CAKMK7uGdTzPnPm3DPB3p+QnmKiox9q1TF+uqmqtcs-xapRKzZw@mail.gmail.com> (raw)
In-Reply-To: <CA+gsUGQL9+8aiq477hivE2uO3HMN3_DopD3w5M0H=i6um-jYSg@mail.gmail.com>

On Wed, Dec 4, 2013 at 2:44 PM, Paulo Zanoni <przanoni@gmail.com> wrote:
> 2013/12/4 Daniel Vetter <daniel@ffwll.ch>:
>> On Thu, Nov 21, 2013 at 01:47:18PM -0200, Paulo Zanoni wrote:
>>> From: Paulo Zanoni <paulo.r.zanoni@intel.com>
>>>
>>> Currently, PC8 is enabled at modeset_global_resources, which is called
>>> after intel_modeset_update_state. Due to this, there's a small race
>>> condition on the case where we start enabling PC8, then do a modeset
>>> while PC8 is still being enabled. The racing condition triggers a WARN
>>> because intel_modeset_update_state will mark the CRTC as enabled, then
>>> the thread that's still enabling PC8 might look at the data structure
>>> and think that PC8 is being enabled while a pipe is enabled. Despite
>>> the WARN, this is not really a bug since we'll wait for the
>>> PC8-enabling thread to finish when we call modeset_global_resources.
>>>
>>> So this patch makes sure we get/put PC8 before we update
>>> drm_crtc->enabled, because if a get() call triggers a PC8 disable,
>>> we'll call cancel_delayed_work_sync(), which will wait for the thread
>>> that's enabling PC8, then, after this, we'll disable PC8.
>>>
>>> The side-effect benefit of this patch is that we have a nice place to
>>> track enabled/disabled CRTCs, so we may want to move some code from
>>> modeset_global_resources to intel_crtc_set_state in the future.
>>>
>>> The problem fixed by this patch can be reproduced by the
>>> modeset-lpsp-stress-no-wait subtest from the pc8 test of
>>> intel-gpu-tools.
>>>
>>> v2: - No need for pc8.lock since we already have
>>>       cancel_delayed_work_sync().
>>>
>>> Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
>>
>> Now that Imre's big rework has landed this looks a bit strange. We now
>> have the display power wells (properly refcounted) and the hsw pc8 stuff
>> here. Which imo doesn't make much sense since to have a working display
>> power well we can't go into pc8.
>
> This patch has nothing to do with power wells. We're checking
> enabled/disabled CRTCs here, not power wells. The problem this patch
> solves also happens on LPSP mode, where the power well is disabled.
> I'm confused, please clarify.

With Imre's power well rework we now have two pieces that manage the
power state of the display hw: modeset_update_power_wells and
modeset_update_power_wells. The later is redundant since you can't
ever enable a crtc power well without disabling pc8.

Note that I'm talking about the generic display power wells Imre
added, which means we also track the power domain usage for crtc A.

My idea is to completely ditch the call to hsw_update_package_c8 and
shovel the respective pc8 get/put calls into the right power domains
in the haswell display power domain implementation in intel_pm.c. That
means that we need to adjust the always-on power well code a bit for
hsw.

In a way power domains should nest, and code should always only care
about the innermost power domain. If it needs to grab explicit
references for power domains outside of that the structure isn't quite
right.

>> So the right thing to do is to only grab the topmost power well/domain
>> reference. Those in turn then need to grab the lower-level domains. I.e.
>> on hsw the crtc get/put should also do a pc8 get/put and then that in turn
>> should do a D3 get/put (if we keep them split up).
>>
>
> Same as above.
>
>
>> With that change it'd also make tons of sense to move all the hsw pc8
>> stuff into intel_pm.c together with the other power well stuff. Imo the
>> approach with use_count in Imre's code is easier to understand.
>>
>> Now for the actual issue you're trying to fix here: That's just a race in
>> the check in assert_can_disable_lcpll - you access crtc->base.enabled
>> without taking the right locks.
>
> Which ones are the "right locks"?

crtc->mutex. It'll deadlock though due to the synchronous work
cancelling. If you go with lockless you'd need some barriers since the
implicit barriers in schedule_work and cancel_work aren't good enough
any more.

>> And if the work runs concurrently to
>> re-enabling the display power then it'll get confused.
>
> What exactly do you mean when you say "re-enabling the display power"?
> Power wells?

power domains in general, whether this is what bspec calls "display
ower well" or pc8 mode or something else. Specifically here the race
seems to happen with the pc8 domain though.

>> The other issue
>> with this check is that crtc->base.enabled is the wrong thing to check: It
>> only tracks sw state, e.g. it's still set when we're in dpms off mode. The
>> right thing to check would be crtc->active, and for that one we have the
>> correct ordering between get/put calls and updating the field already.
>
> No, we only set crtc->active to true after we call
> ironlake_crtc_enable, and that's too late for this specific bug. Also,
> we don't enable PC8 nor disable power wells while in DPMS off, there's
> a lot of work to do if we want to enable that, and this patch here is
> just a bug fix.

I mean the WARN check in assert_can_disable_lcpll, not the checks
you're touching in your patch. For actually deciding whether we can
allow pc8 or not we should imo piggy-pack on top of Imre's rework of
the display power domain handling.

Maybe we should go over the code and replace all mentions of
power_well with power_domain in the generic code to make this clearer.
Imo Imre's work isn't just about what Bspec calls "power wells" but
about managing display power domains in general. Which includes pc8.

>> Plan B would be to just ditch this check.
>
> The "crtc->base.enabled == enabled" check? That's not possible, it
> would result in unbalanced get/put calls.

I mean the check in assert_can_disable_lcpll for crtc->base.enabled,
not the ones you're touching in your patch here. Sorry for the unclear
"this" reference.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

  reply	other threads:[~2013-12-04 14:07 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-21 15:47 [PATCH 00/19] Haswell runtime PM support + D3 Paulo Zanoni
2013-11-21 15:47 ` [PATCH 01/19] drm/i915: WARN if !HAS_PC8 when enabling/disabling PC8 Paulo Zanoni
2013-11-29 11:11   ` Rodrigo Vivi
2013-11-29 12:55     ` Paulo Zanoni
2013-11-29 13:31       ` Rodrigo Vivi
2013-11-21 15:47 ` [PATCH 02/19] drm/i915: use the correct force_wake function at the PC8 code Paulo Zanoni
2013-11-27 19:57   ` Paulo Zanoni
2013-11-29 11:14     ` [Intel-gfx] " Rodrigo Vivi
2013-11-29 13:23       ` Daniel Vetter
2013-11-21 15:47 ` [PATCH 03/19] drm/i915: get a PC8 reference when enabling the power well Paulo Zanoni
2013-11-27 19:59   ` Paulo Zanoni
2013-11-29 12:35     ` Rodrigo Vivi
2013-11-29 13:34       ` Rodrigo Vivi
2013-12-10 21:29     ` Daniel Vetter
2013-11-21 15:47 ` [PATCH 04/19] drm/i915: get/put PC8 when we get/put a CRTC Paulo Zanoni
2013-11-21 16:12   ` Chris Wilson
2013-11-27 20:01     ` Paulo Zanoni
2013-11-29 12:38       ` Rodrigo Vivi
2013-11-29 13:34         ` Rodrigo Vivi
2013-12-04  9:01   ` Daniel Vetter
2013-12-04 13:44     ` Paulo Zanoni
2013-12-04 14:07       ` Daniel Vetter [this message]
2013-12-05 13:43         ` Paulo Zanoni
2013-12-05 14:40           ` Daniel Vetter
2013-12-06 22:29             ` [PATCH] drm/i915: change CRTC assertion on LCPLL disable Paulo Zanoni
2013-12-06 22:37               ` Daniel Vetter
2013-11-21 15:47 ` [PATCH 05/19] drm/i915: add initial Runtime PM functions Paulo Zanoni
2013-11-27 20:10   ` Paulo Zanoni
2013-11-29 12:54     ` Rodrigo Vivi
2013-11-29 13:33       ` Rodrigo Vivi
2013-11-29 14:05     ` Takashi Iwai
2013-12-06 22:31       ` Paulo Zanoni
2013-12-06 22:32         ` Paulo Zanoni
2013-12-08  9:06         ` Takashi Iwai
2013-12-02 12:23   ` Imre Deak
2013-11-21 15:47 ` [PATCH 06/19] drm/i915: do adapter power state notification at runtime PM Paulo Zanoni
2013-11-21 16:14   ` Chris Wilson
2013-11-27 20:13     ` Paulo Zanoni
2013-11-29 12:56       ` Rodrigo Vivi
2013-11-29 13:33         ` Rodrigo Vivi
2013-12-06 22:34         ` Paulo Zanoni
2013-11-21 15:47 ` [PATCH 07/19] drm/i915: add runtime put/get calls at the basic places Paulo Zanoni
2013-11-21 16:07   ` Chris Wilson
2013-11-25 20:55     ` Paulo Zanoni
2013-11-25 21:21       ` Chris Wilson
2013-11-27 20:20         ` Paulo Zanoni
2013-11-29 13:03           ` Rodrigo Vivi
2013-11-29 13:32             ` Rodrigo Vivi
2013-12-10 21:49             ` Daniel Vetter
2013-12-12 20:07               ` Paulo Zanoni
2013-12-12 20:54                 ` Daniel Vetter
2013-11-21 15:47 ` [PATCH 08/19] drm/i915: add some runtime PM get/put calls Paulo Zanoni
2013-11-27 20:21   ` Paulo Zanoni
2013-11-29 13:05     ` Rodrigo Vivi
2013-11-29 13:31       ` Rodrigo Vivi
2013-11-29 13:42       ` Daniel Vetter
2013-11-29 13:56         ` Paulo Zanoni
2013-11-21 15:47 ` [PATCH 09/19] drm/i915: get a runtime PM reference when the panel VDD is on Paulo Zanoni
2013-11-29 13:50   ` Rodrigo Vivi
2013-11-29 13:59     ` Paulo Zanoni
2013-11-29 14:37       ` Rodrigo Vivi
2013-12-06 22:23         ` Paulo Zanoni
2013-11-21 15:47 ` [PATCH 10/19] drm/i915: do not assert DE_PCH_EVENT_IVB enabled Paulo Zanoni
2013-11-29 14:30   ` Rodrigo Vivi
2013-12-10 21:54   ` Daniel Vetter
2013-11-21 15:47 ` [PATCH 11/19] drm/i915: disable interrupts when enabling PC8 Paulo Zanoni
2013-12-02 13:33   ` Rodrigo Vivi
2013-12-10 21:59   ` Daniel Vetter
2013-12-11 21:33     ` Paulo Zanoni
2013-11-21 15:47 ` [PATCH 12/19] drm/i915: release the GTT mmaps when going into D3 Paulo Zanoni
2013-11-21 16:02   ` Chris Wilson
2013-11-21 16:27     ` Paulo Zanoni
2013-12-10 22:03   ` Daniel Vetter
2013-11-21 15:47 ` [PATCH 13/19] drm: do not steal the display if we have a master Paulo Zanoni
2013-11-21 16:04   ` Chris Wilson
2013-11-27 20:24     ` Paulo Zanoni
2013-11-29 13:37       ` Daniel Vetter
2013-11-30 11:19       ` David Herrmann
2013-11-21 15:47 ` [PATCH 14/19] drm/i915: add runtime PM support on Haswell Paulo Zanoni
2013-12-02 13:37   ` Rodrigo Vivi
2013-12-10 22:10     ` Daniel Vetter
2013-12-10 22:06   ` Daniel Vetter
2013-11-21 15:47 ` [PATCH 15/19] drm/i915: don't enable VDD just to enable the panel Paulo Zanoni
2013-11-29 14:40   ` Rodrigo Vivi
2013-11-21 15:47 ` [PATCH 16/19] drm/i915: don't touch the VDD when disabling " Paulo Zanoni
2013-11-29 14:41   ` Rodrigo Vivi
2013-11-21 15:47 ` [PATCH 17/19] drm/i915: fix VDD override off wait Paulo Zanoni
2013-11-21 15:47 ` [PATCH 18/19] drm/i915: save some time when waiting the eDP timings Paulo Zanoni
2013-11-21 16:00   ` Chris Wilson
2013-11-25 22:17     ` Ben Widawsky
2013-11-25 23:25       ` Chris Wilson
2013-11-26  2:38         ` Ben Widawsky
2013-11-26  9:14           ` Chris Wilson
2013-11-26 15:53             ` Paulo Zanoni
2013-11-21 15:47 ` [PATCH 19/19] drm/i915: init the DP panel power seq regs earlier Paulo Zanoni
2013-12-05 15:00   ` Jani Nikula
2013-12-06 18:39     ` Paulo Zanoni

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=CAKMK7uGdTzPnPm3DPB3p+QnmKiox9q1TF+uqmqtcs-xapRKzZw@mail.gmail.com \
    --to=daniel@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=paulo.r.zanoni@intel.com \
    --cc=przanoni@gmail.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.