All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: "Tangudu, Tilak" <tilak.tangudu@intel.com>,
	"Vivi, Rodrigo" <rodrigo.vivi@intel.com>
Cc: "intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"Wilson, Chris P" <chris.p.wilson@intel.com>,
	"Gupta, saurabhg" <saurabhg.gupta@intel.com>
Subject: Re: [Intel-gfx] [PATCH 04/11] drm/i915: Added is_intel_rpm_allowed helper
Date: Thu, 23 Jun 2022 20:49:04 +0300	[thread overview]
Message-ID: <87v8srmfsf.fsf@intel.com> (raw)
In-Reply-To: <DM4PR11MB5248CEEF733FACCE6543C5AFE2B59@DM4PR11MB5248.namprd11.prod.outlook.com>

On Thu, 23 Jun 2022, "Tangudu, Tilak" <tilak.tangudu@intel.com> wrote:
>> -----Original Message-----
>> From: Vivi, Rodrigo <rodrigo.vivi@intel.com>
>> Sent: Thursday, June 23, 2022 2:11 AM
>> To: Jani Nikula <jani.nikula@linux.intel.com>
>> Cc: Tangudu, Tilak <tilak.tangudu@intel.com>; Gupta, Anshuman
>> <anshuman.gupta@intel.com>; intel-gfx@lists.freedesktop.org; Ewins, Jon
>> <jon.ewins@intel.com>; Belgaumkar, Vinay <vinay.belgaumkar@intel.com>;
>> Wilson, Chris P <chris.p.wilson@intel.com>; Dixit, Ashutosh
>> <ashutosh.dixit@intel.com>; Nilawar, Badal <badal.nilawar@intel.com>;
>> Roper, Matthew D <matthew.d.roper@intel.com>; Gupta, saurabhg
>> <saurabhg.gupta@intel.com>; Iddamsetty, Aravind
>> <aravind.iddamsetty@intel.com>; Sundaresan, Sujaritha
>> <sujaritha.sundaresan@intel.com>; Deak, Imre <imre.deak@intel.com>
>> Subject: Re: [Intel-gfx] [PATCH 04/11] drm/i915: Added is_intel_rpm_allowed
>> helper
>> 
>> On Wed, Jun 22, 2022 at 03:55:03PM +0300, Jani Nikula wrote:
>> > On Tue, 21 Jun 2022, "Tangudu, Tilak" <tilak.tangudu@intel.com> wrote:
>> > >> -----Original Message-----
>> > >> From: Gupta, Anshuman <anshuman.gupta@intel.com>
>> > >> Sent: Tuesday, June 21, 2022 7:47 PM
>> > >> To: Tangudu, Tilak <tilak.tangudu@intel.com>;
>> > >> intel-gfx@lists.freedesktop.org; Ewins, Jon <jon.ewins@intel.com>;
>> > >> Vivi, Rodrigo <rodrigo.vivi@intel.com>; Belgaumkar, Vinay
>> > >> <vinay.belgaumkar@intel.com>; Wilson, Chris P
>> > >> <chris.p.wilson@intel.com>; Dixit, Ashutosh
>> > >> <ashutosh.dixit@intel.com>; Nilawar, Badal
>> > >> <badal.nilawar@intel.com>; Roper, Matthew D
>> > >> <matthew.d.roper@intel.com>; Gupta, saurabhg
>> > >> <saurabhg.gupta@intel.com>; Iddamsetty, Aravind
>> > >> <aravind.iddamsetty@intel.com>; Sundaresan, Sujaritha
>> > >> <sujaritha.sundaresan@intel.com>
>> > >> Subject: RE: [PATCH 04/11] drm/i915: Added is_intel_rpm_allowed
>> > >> helper
>> > >>
>> > >>
>> > >>
>> > >> > -----Original Message-----
>> > >> > From: Tangudu, Tilak <tilak.tangudu@intel.com>
>> > >> > Sent: Tuesday, June 21, 2022 6:05 PM
>> > >> > To: intel-gfx@lists.freedesktop.org; Ewins, Jon
>> > >> > <jon.ewins@intel.com>; Vivi, Rodrigo <rodrigo.vivi@intel.com>;
>> > >> > Belgaumkar, Vinay <vinay.belgaumkar@intel.com>; Wilson, Chris P
>> > >> > <chris.p.wilson@intel.com>; Dixit, Ashutosh
>> > >> > <ashutosh.dixit@intel.com>; Nilawar, Badal
>> > >> > <badal.nilawar@intel.com>; Gupta, Anshuman
>> > >> > <anshuman.gupta@intel.com>; Tangudu, Tilak
>> > >> > <tilak.tangudu@intel.com>; Roper, Matthew D
>> > >> > <matthew.d.roper@intel.com>; Gupta, saurabhg
>> > >> > <saurabhg.gupta@intel.com>; Iddamsetty, Aravind
>> > >> > <aravind.iddamsetty@intel.com>; Sundaresan, Sujaritha
>> > >> > <sujaritha.sundaresan@intel.com>
>> > >> > Subject: [PATCH 04/11] drm/i915: Added is_intel_rpm_allowed
>> > >> > helper
>> > >> >
>> > >> > Added is_intel_rpm_allowed function to query the runtime_pm
>> > >> > status and disllow during suspending and resuming.
>> > >> This seems a hack,
>> > >> Not sure if we have better way to handle it.
>> > >> May be check this in intel_pm_runtime_{get,put} to keep entire code
>> simple ?
>> > > Yes, that would be simple without code refactoring.
>> > > Checked the same with Chris, he suggested unbalancing of wakeref
>> > > might popup If used at intel_pm_runtime_{get,put}  . So used like
>> > > this,  @Wilson, Chris P , Please comment .
>> > > @Vivi, Rodrigo , Any suggestion ?
>> >
>> > One option would be to track this in intel_wakeref_t, i.e. _get flags
>> > the case in the returned wakeref and _put skips in that case.
>
> @Jani Nikula 
>
> I did not understand the suggestion, Can you please elaborate ?
> Did you mean below or something more ? please help clarify.

The code below will lead to get/put inbalance if is_intel_rpm_allowed()
status changes between the get/put calls. I don't know how likely that
is, but if it happens it's nasty.

intel_wakeref_t is depot_stack_handle_t, which is actually just u32. We
already abuse -1 value to not track wakeref (when
CONFIG_DRM_I915_DEBUG_RUNTIME_PM=n or track_intel_runtime_pm_wakeref()
fails.

It's a bit of a hack, but we could have __intel_runtime_pm_get() early
return -2 as the wakeref when !is_intel_rpm_allowed(), and
intel_runtime_pm_put() (both versions for both kconfig option values!)
ignore the put when the passed in wakeref == -2.

This requires no changes in the calling code anywhere, even though the
implementation is a hack. A pedantically correct implementation would
turn intel_wakeref_t into a struct that wraps depot_stack_handle_t
inside, and has a separate field for validity, but that probably has a
non-trivial code size penalty.


BR,
Jani.


>
> 8< ------------------------------
> linux-desk:~/Code/drm-tip$ git diff
> diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
> index 3759a8596084..ce272c569a89 100644
> --- a/drivers/gpu/drm/i915/intel_runtime_pm.c
> +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
> @@ -369,12 +369,16 @@ static intel_wakeref_t __intel_runtime_pm_get(struct intel_runtime_pm *rpm,
>                                                      runtime_pm);
>         int ret;
>
> +       if (!is_intel_rpm_allowed(rpm))
> +               goto out:
> +
>         ret = pm_runtime_get_sync(rpm->kdev);
>         drm_WARN_ONCE(&i915->drm, ret < 0,
>                       "pm_runtime_get_sync() failed: %d\n", ret);
>
>         intel_runtime_pm_acquire(rpm, wakelock);
>
> +out:
>         return track_intel_runtime_pm_wakeref(rpm);
>  }
>
> @@ -505,6 +509,9 @@ static void __intel_runtime_pm_put(struct intel_runtime_pm *rpm,
>
>         untrack_intel_runtime_pm_wakeref(rpm, wref);
>
> +       if (!is_intel_rpm_allowed(rpm))
> +               return;
> +
>         intel_runtime_pm_release(rpm, wakelock);
>
>         pm_runtime_mark_last_busy(kdev);
> ----------------------------------------------------------  >8
>
> Thanks
> Tilak
>> 
>> yeap, this seems to be the quick path at this moment...
>> 
>> Imre, do you see any other quick option?
>> 
>> In general I don't like much the big wakeref infra we end up creating here
>> because all of the historical unbalanced cases we got.
>> We should be able to get something cleaner and use the rpm infra as other
>> drivers are using, or improve in the rpm side itself whatever we feel that we
>> are missing to deal with these cases.
>> 
>> But back to this specific case/usage here we might need to duplicate some
>> functions to be called just from the inside the resuming/suspending path...
>> and/or moving the gets & puts upper on the stack...
>> 
>> The quick hacks will solve our short term problems and continue bloating our
>> rpm infra.
>> 
>> >
>> > BR,
>> > Jani.
>> >
>> >
>> > >
>> > >> >
>> > >> > Signed-off-by: Tilak Tangudu <tilak.tangudu@intel.com>
>> > >> > ---
>> > >> >  drivers/gpu/drm/i915/intel_runtime_pm.c | 15 +++++++++++++++
>> > >> > drivers/gpu/drm/i915/intel_runtime_pm.h |  1 +
>> > >> >  2 files changed, 16 insertions(+)
>> > >> >
>> > >> > diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c
>> > >> > b/drivers/gpu/drm/i915/intel_runtime_pm.c
>> > >> > index 6ed5786bcd29..3759a8596084 100644
>> > >> > --- a/drivers/gpu/drm/i915/intel_runtime_pm.c
>> > >> > +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
>> > >> > @@ -320,6 +320,21 @@ untrack_all_intel_runtime_pm_wakerefs(struct
>> > >> > intel_runtime_pm *rpm)  }
>> > >> >
>> > >> >  #endif
>> > >> > +static int intel_runtime_pm_status(struct intel_runtime_pm *rpm)
>> > >> > +{ return rpm->kdev->power.runtime_status; }
>> > >> This is racy in principal, we need a kdev->power lock here.
>> > >> Regards,
>> > >> Anshuman Gupta.
>> > >> > +
>> > >> > +bool is_intel_rpm_allowed(struct intel_runtime_pm *rpm) { int
>> > >> > +rpm_status;
>> > >> > +
>> > >> > +rpm_status = intel_runtime_pm_status(rpm); if (rpm_status ==
>> > >> > +RPM_RESUMING || rpm_status ==
>> > >> > RPM_SUSPENDING)
>> > >> > +return false;
>> > >> > +else
>> > >> > +return true;
>> > >> > +}
>> > >> >
>> > >> >  static void
>> > >> >  intel_runtime_pm_acquire(struct intel_runtime_pm *rpm, bool
>> > >> > wakelock) diff -- git a/drivers/gpu/drm/i915/intel_runtime_pm.h
>> > >> > b/drivers/gpu/drm/i915/intel_runtime_pm.h
>> > >> > index d9160e3ff4af..99418c3a934a 100644
>> > >> > --- a/drivers/gpu/drm/i915/intel_runtime_pm.h
>> > >> > +++ b/drivers/gpu/drm/i915/intel_runtime_pm.h
>> > >> > @@ -173,6 +173,7 @@ void intel_runtime_pm_init_early(struct
>> > >> > intel_runtime_pm *rpm);  void intel_runtime_pm_enable(struct
>> > >> > intel_runtime_pm *rpm);  void intel_runtime_pm_disable(struct
>> > >> > intel_runtime_pm *rpm);  void
>> > >> > intel_runtime_pm_driver_release(struct
>> > >> > intel_runtime_pm *rpm);
>> > >> > +bool is_intel_rpm_allowed(struct intel_runtime_pm *rpm);
>> > >> >
>> > >> >  intel_wakeref_t intel_runtime_pm_get(struct intel_runtime_pm
>> > >> > *rpm); intel_wakeref_t intel_runtime_pm_get_if_in_use(struct
>> > >> > intel_runtime_pm *rpm);
>> > >> > --
>> > >> > 2.25.1
>> > >>
>> > >
>> >
>> > --
>> > Jani Nikula, Intel Open Source Graphics Center

-- 
Jani Nikula, Intel Open Source Graphics Center

  reply	other threads:[~2022-06-23 17:49 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21 12:35 [Intel-gfx] [PATCH 00/11] drm/i915: Add D3Cold-Off support for runtime-pm Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 01/11] drm/i915: Avoid rpm helpers in intel_guc_global_policies_update Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 02/11] drm/i915: Avoid rpm helpers in intel_guc_slpc_set_media_ratio_mode Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 03/11] drm/i915: Avoid rpm helpers in intel_gt_suspend_late Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 04/11] drm/i915: Added is_intel_rpm_allowed helper Tilak Tangudu
2022-06-21 14:16   ` Gupta, Anshuman
2022-06-21 14:22     ` Tangudu, Tilak
2022-06-22 12:55       ` Jani Nikula
2022-06-22 20:40         ` Rodrigo Vivi
2022-06-23 17:21           ` Tangudu, Tilak
2022-06-23 17:49             ` Jani Nikula [this message]
2022-06-21 12:35 ` [Intel-gfx] [PATCH 05/11] drm/i915: Guard rpm helpers in gt helpers functions Tilak Tangudu
2022-06-22 12:52   ` Jani Nikula
2022-06-21 12:35 ` [Intel-gfx] [PATCH 06/11] drm/i915: Avoid rpm helpers in try_context_registration Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 07/11] drm/i915: Guard rc6 helpers with is_intel_rpm_allowed Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 08/11] drm/i915: Guard rpm helpers in rpm_get/put Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 09/11] drm/i915: Add i915_save/load_pci_state helpers Tilak Tangudu
2022-06-21 16:30   ` kernel test robot
2022-06-21 19:44   ` kernel test robot
2022-06-21 22:57   ` kernel test robot
2022-06-22  8:35   ` kernel test robot
2022-06-21 12:35 ` [Intel-gfx] [PATCH 10/11] drm/i915: Guard rpm helpers at gt_park/unpark Tilak Tangudu
2022-06-21 12:35 ` [Intel-gfx] [PATCH 11/11] drm/i915 : Add D3COLD OFF support Tilak Tangudu
2022-06-21 13:15   ` Gupta, Anshuman
2022-06-21 13:24 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for drm/i915: Add D3Cold-Off support for runtime-pm Patchwork
2022-06-23 17:35 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for drm/i915: Add D3Cold-Off support for runtime-pm (rev2) 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=87v8srmfsf.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=chris.p.wilson@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=saurabhg.gupta@intel.com \
    --cc=tilak.tangudu@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.