Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Belgaumkar, Vinay" <vinay.belgaumkar@intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-xe@lists.freedesktop.org,
	"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"Jani Nikula" <jani.nikula@intel.com>,
	"John Harrison" <John.C.Harrison@intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Maarten Lankhorst" <dev@lankhorst.se>
Subject: Re: [PATCH v3 2/5] drm/xe/guc_pc: Use poll_timeout_us() for waiting
Date: Fri, 12 Sep 2025 16:55:28 -0700	[thread overview]
Message-ID: <dad2bb7c-892a-42d7-82ba-869ffaddc036@intel.com> (raw)
In-Reply-To: <6pt5o6cgres5n3argefbocisccmfbjpawk5s6cts2k5fm3ropr@xmbnve5zwltu>


On 9/11/2025 9:56 PM, Lucas De Marchi wrote:
> On Thu, Sep 11, 2025 at 02:21:28PM -0700, Belgaumkar, Vinay wrote:
>>
>> On 9/11/2025 10:25 AM, Lucas De Marchi wrote:
>>> Convert wait_for_pc_state() and wait_for_act_freq_limit() to
>>> poll_timeout_us(). This brings 2 changes in behavior: Drop the
>>> exponential wait and fix a potential much longer sleep.
>>>
>>> usleep_range() will wait anywhere between `wait` and `wait << 1`, so
>>> it's not correct to assume `slept += wait`.  This code is not really
>>> accurate. Pairing this with the exponential wait increase, it could be
>>> waiting much longer than intended.
>>>
>>> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
>>> ---
>>> v2: Simplify functions by removing helper variables and changing break
>>>     condition on poll_timeout_us() call (Maarten)
>>> v3: dial a little bit back from v2: better to have some helper vars
>>>     and avoid the weird syntax (Jani)
>>> ---
>>>  drivers/gpu/drm/xe/xe_guc_pc.c | 42 
>>> ++++++++++++------------------------------
>>>  1 file changed, 12 insertions(+), 30 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/xe/xe_guc_pc.c 
>>> b/drivers/gpu/drm/xe/xe_guc_pc.c
>>> index 68a5bf8e39462..ecfe37836692f 100644
>>> --- a/drivers/gpu/drm/xe/xe_guc_pc.c
>>> +++ b/drivers/gpu/drm/xe/xe_guc_pc.c
>>> @@ -7,6 +7,7 @@
>>>  #include <linux/cleanup.h>
>>>  #include <linux/delay.h>
>>> +#include <linux/iopoll.h>
>>>  #include <linux/jiffies.h>
>>>  #include <linux/ktime.h>
>>>  #include <linux/wait_bit.h>
>>> @@ -130,26 +131,16 @@ static struct iosys_map *pc_to_maps(struct 
>>> xe_guc_pc *pc)
>>>       FIELD_PREP(HOST2GUC_PC_SLPC_REQUEST_MSG_1_EVENT_ARGC, count))
>>>  static int wait_for_pc_state(struct xe_guc_pc *pc,
>>> -                 enum slpc_global_state state,
>>> +                 enum slpc_global_state target_state,
>>>                   int timeout_ms)
>>>  {
>>> -    int timeout_us = 1000 * timeout_ms;
>>> -    int slept, wait = 10;
>>> +    enum slpc_global_state state;
>>>      xe_device_assert_mem_access(pc_to_xe(pc));
>>> -    for (slept = 0; slept < timeout_us;) {
>>> -        if (slpc_shared_data_read(pc, header.global_state) == state)
>>> -            return 0;
>>> -
>>> -        usleep_range(wait, wait << 1);
>>> -        slept += wait;
>>> -        wait <<= 1;
>>> -        if (slept + wait > timeout_us)
>>> -            wait = timeout_us - slept;
>>> -    }
>>> -
>>> -    return -ETIMEDOUT;
>>> +    return poll_timeout_us(state = slpc_shared_data_read(pc, 
>>> header.global_state),
>>> +                   state == target_state,
>>> +                   20, timeout_ms * USEC_PER_MSEC, false);
>>>  }
>>>  static int wait_for_flush_complete(struct xe_guc_pc *pc)
>>> @@ -164,24 +155,15 @@ static int wait_for_flush_complete(struct 
>>> xe_guc_pc *pc)
>>>      return 0;
>>>  }
>>> -static int wait_for_act_freq_limit(struct xe_guc_pc *pc, u32 freq)
>>> +static int wait_for_act_freq_limit(struct xe_guc_pc *pc, u32 max_freq)
>>
>> Nit: rename to limit_freq or something instead of max_freq in order 
>> to avoid linking this to gt max freq.
>
> problem with "limit" is that it gives no clue if it's limiting down or
> up. wait_for_act_freq_up_to() or s/max_freq/max_limit/ ?

true. Either one should clarify it a little.

Thanks,

Vinay.

>
>>
>> with that,
>>
>> Reviewed-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
>
> thanks
> Lucas De Marchi
>
>
>>
>>>  {
>>> -    int timeout_us = SLPC_ACT_FREQ_TIMEOUT_MS * USEC_PER_MSEC;
>>> -    int slept, wait = 10;
>>> -
>>> -    for (slept = 0; slept < timeout_us;) {
>>> -        if (xe_guc_pc_get_act_freq(pc) <= freq)
>>> -            return 0;
>>> -
>>> -        usleep_range(wait, wait << 1);
>>> -        slept += wait;
>>> -        wait <<= 1;
>>> -        if (slept + wait > timeout_us)
>>> -            wait = timeout_us - slept;
>>> -    }
>>> +    u32 freq;
>>> -    return -ETIMEDOUT;
>>> +    return poll_timeout_us(freq = xe_guc_pc_get_act_freq(pc),
>>> +                   freq <= max_freq,
>>> +                   20, SLPC_ACT_FREQ_TIMEOUT_MS * USEC_PER_MSEC, 
>>> false);
>>>  }
>>> +
>>>  static int pc_action_reset(struct xe_guc_pc *pc)
>>>  {
>>>      struct xe_guc_ct *ct = pc_to_ct(pc);
>>>

  reply	other threads:[~2025-09-12 23:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 17:25 [PATCH v3 0/5] drm/xe: Use poll_timeout_us() Lucas De Marchi
2025-09-11 17:25 ` [PATCH v3 1/5] drm/xe/device: Use poll_timeout_us() to wait for lmem Lucas De Marchi
2025-09-11 17:25 ` [PATCH v3 2/5] drm/xe/guc_pc: Use poll_timeout_us() for waiting Lucas De Marchi
2025-09-11 21:21   ` Belgaumkar, Vinay
2025-09-12  4:56     ` Lucas De Marchi
2025-09-12 23:55       ` Belgaumkar, Vinay [this message]
2025-09-11 17:25 ` [PATCH v3 3/5] drm/xe/guc: Drop helper to read freq Lucas De Marchi
2025-09-11 17:25 ` [PATCH v3 4/5] drm/xe/guc: Extract function to print load error Lucas De Marchi
2025-09-16 20:06   ` John Harrison
2025-09-11 17:25 ` [PATCH v3 5/5] drm/xe/guc: Refactor GuC load to use poll_timeout_us() Lucas De Marchi
2025-09-16 20:03   ` John Harrison
2025-09-11 17:32 ` ✗ CI.checkpatch: warning for drm/xe: Use poll_timeout_us() (rev4) Patchwork
2025-09-11 17:33 ` ✓ CI.KUnit: success " Patchwork
2025-09-11 18:08 ` ✓ Xe.CI.BAT: " Patchwork
2025-09-11 23:37 ` ✗ Xe.CI.Full: failure " 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=dad2bb7c-892a-42d7-82ba-869ffaddc036@intel.com \
    --to=vinay.belgaumkar@intel.com \
    --cc=John.C.Harrison@intel.com \
    --cc=dev@lankhorst.se \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=lucas.demarchi@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=ville.syrjala@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox