mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lukas Zapolskas <lukas.zapolskas@arm.com>
To: "Adrián Larumbe" <adrian.larumbe@collabora.com>
Cc: Boris Brezillon <boris.brezillon@collabora.com>,
	Steven Price <steven.price@arm.com>,
	Liviu Dudau <liviu.dudau@arm.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 6/7] drm/panthor: Add suspend, resume and reset handling
Date: Fri, 25 Jul 2025 10:26:46 +0100	[thread overview]
Message-ID: <8a65cc81-92cf-48e9-90b7-645a1fc94ef8@arm.com> (raw)
In-Reply-To: <2vdubr5ieiuwmy7j6bogyzhpz27hsvaaeaktuqtuhm3nvgsnkv@jhy2f2pb3hyz>



On 18/07/2025 16:01, Adrián Larumbe wrote:
> On 16.05.2025 16:49, Lukas Zapolskas wrote:
>> The sampler must disable and re-enable counter sampling around suspends,
>> and must re-program the FW interface after a reset to avoid losing
>> data.
>>
>> Signed-off-by: Lukas Zapolskas <lukas.zapolskas@arm.com>
>> ---
>>  drivers/gpu/drm/panthor/panthor_device.c |   7 +-
>>  drivers/gpu/drm/panthor/panthor_perf.c   | 102 +++++++++++++++++++++++
>>  drivers/gpu/drm/panthor/panthor_perf.h   |   6 ++
>>  3 files changed, 114 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
>> index 7ac985d44655..92624a8717c5 100644
>> --- a/drivers/gpu/drm/panthor/panthor_device.c
>> +++ b/drivers/gpu/drm/panthor/panthor_device.c
>> @@ -139,6 +139,7 @@ static void panthor_device_reset_work(struct work_struct *work)
>>  	if (!drm_dev_enter(&ptdev->base, &cookie))
>>  		return;
>>
>> +	panthor_perf_pre_reset(ptdev);
>>  	panthor_sched_pre_reset(ptdev);
>>  	panthor_fw_pre_reset(ptdev, true);
>>  	panthor_mmu_pre_reset(ptdev);
>> @@ -148,6 +149,7 @@ static void panthor_device_reset_work(struct work_struct *work)
>>  	ret = panthor_fw_post_reset(ptdev);
>>  	atomic_set(&ptdev->reset.pending, 0);
>>  	panthor_sched_post_reset(ptdev, ret != 0);
>> +	panthor_perf_post_reset(ptdev);
>>  	drm_dev_exit(cookie);
>>
>>  	if (ret) {
>> @@ -496,8 +498,10 @@ int panthor_device_resume(struct device *dev)
>>  			ret = panthor_device_resume_hw_components(ptdev);
>>  		}
>>
>> -		if (!ret)
>> +		if (!ret) {
>>  			panthor_sched_resume(ptdev);
>> +			panthor_perf_resume(ptdev);
>> +		}
>>
>>  		drm_dev_exit(cookie);
>>
>> @@ -561,6 +565,7 @@ int panthor_device_suspend(struct device *dev)
>>  		/* We prepare everything as if we were resetting the GPU.
>>  		 * The end of the reset will happen in the resume path though.
>>  		 */
>> +		panthor_perf_suspend(ptdev);
>>  		panthor_sched_suspend(ptdev);
>>  		panthor_fw_suspend(ptdev);
>>  		panthor_mmu_suspend(ptdev);
>> diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c
>> index 97603b168d2d..438319cf71ab 100644
>> --- a/drivers/gpu/drm/panthor/panthor_perf.c
>> +++ b/drivers/gpu/drm/panthor/panthor_perf.c
>> @@ -1845,6 +1845,76 @@ void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_per
>>  	}
>>  }
>>
>> +static int panthor_perf_sampler_resume(struct panthor_perf_sampler *sampler)
>> +{
>> +	int ret;
>> +
>> +	if (!atomic_read(&sampler->enabled_clients))
>> +		return 0;
>> +
>> +	ret = panthor_perf_fw_start_sampling(sampler->ptdev);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return 0;
>> +}
>> +
>> +static int panthor_perf_sampler_suspend(struct panthor_perf_sampler *sampler)
>> +{
>> +	int ret;
>> +
>> +	if (!atomic_read(&sampler->enabled_clients))
>> +		return 0;
>> +
>> +	ret = panthor_perf_fw_stop_sampling(sampler->ptdev);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return 0;
>> +}
>> +
>> +/**
>> + * panthor_perf_suspend - Prepare the performance counter subsystem for system suspend.
>> + * @ptdev: Panthor device.
>> + *
>> + * Indicate to the performance counters that the system is suspending.
>> + *
>> + * This function must not be used to handle MCU power state transitions: just before MCU goes
>> + * from on to any inactive state, an automatic sample will be performed by the firmware, and
>> + * the performance counter firmware state will be restored on warm boot.
>> + *
>> + * Return: 0 on success, negative error code on failure.
>> + */
>> +int panthor_perf_suspend(struct panthor_device *ptdev)
>> +{
>> +	struct panthor_perf *perf = ptdev->perf;
>> +
>> +	if (!perf)
>> +		return 0;
>> +
>> +	return panthor_perf_sampler_suspend(&perf->sampler);
>> +}
>> +
>> +/**
>> + * panthor_perf_resume - Resume the performance counter subsystem after system resumption.
>> + * @ptdev: Panthor device.
>> + *
>> + * Indicate to the performance counters that the system has resumed. This must not be used
>> + * to handle MCU state transitions, for the same reasons as detailed in the kerneldoc for
>> + * @panthor_perf_suspend.
>> + *
>> + * Return: 0 on success, negative error code on failure.
>> + */
>> +int panthor_perf_resume(struct panthor_device *ptdev)
>> +{
>> +	struct panthor_perf *perf = ptdev->perf;
>> +
>> +	if (!perf)
>> +		return 0;
>> +
>> +	return panthor_perf_sampler_resume(&perf->sampler);
>> +}
> 
> In the two previous functions, you return an int, but you never used it
> from where they're called. 

Thanks, will drop the return values from the perf_{suspend,resume} functions.

> Also, in both of them, for the sake of
> coherence, I'd get rid of the *sampler* subcalls because later in
> 'panthor_perf_pre_reset' and 'panthor_perf_post_reset' you manipulate the
> sampler directly without referring it to another function. The functions
> are short enough for us to be able to inline the content of
> 'panthor_perf_sampler_resume' into 'panthor_perf_resume'.
> 

Will do.

>> +
>>  /**
>>   * panthor_perf_unplug - Terminate the performance counter subsystem.
>>   * @ptdev: Panthor device.
>> @@ -1878,3 +1948,35 @@ void panthor_perf_unplug(struct panthor_device *ptdev)
>>
>>  	ptdev->perf = NULL;
>>  }
>> +
>> +void panthor_perf_pre_reset(struct panthor_device *ptdev)
>> +{
>> +	struct panthor_perf_sampler *sampler;
>> +
>> +	if (!ptdev || !ptdev->perf)
>> +		return;
>> +
>> +	sampler = &ptdev->perf->sampler;
>> +
>> +	if (!atomic_read(&sampler->enabled_clients))
>> +		return;
>> +
>> +	panthor_perf_fw_stop_sampling(sampler->ptdev);
>> +}
>> +
>> +void panthor_perf_post_reset(struct panthor_device *ptdev)
>> +{
>> +	struct panthor_perf_sampler *sampler;
>> +
>> +	if (!ptdev || !ptdev->perf)
>> +		return;
> 
> In both this function and the preceding one, ptdev is meant to be
> available by the time they're called, so I'd turn the check of ptdev not
> being null into a drm_WARN().
>

I'll drop the check for the ptdev entirely, since it looks like there will 
be other issues before these functions are even called if it's null, and 
add the drm_WARN_ON_ONCE for the perf pointer, since that should also be 
initialized by this point. 

>> +
>> +	sampler = &ptdev->perf->sampler;
>> +
>> +	if (!atomic_read(&sampler->enabled_clients))
>> +		return;
>> +
>> +	panthor_perf_fw_write_sampler_config(sampler);
>> +
>> +	panthor_perf_fw_start_sampling(sampler->ptdev);
>> +}
>> diff --git a/drivers/gpu/drm/panthor/panthor_perf.h b/drivers/gpu/drm/panthor/panthor_perf.h
>> index c482198b6fbd..fc08a5440a35 100644
>> --- a/drivers/gpu/drm/panthor/panthor_perf.h
>> +++ b/drivers/gpu/drm/panthor/panthor_perf.h
>> @@ -13,6 +13,8 @@ struct panthor_file;
>>  struct panthor_perf;
>>
>>  int panthor_perf_init(struct panthor_device *ptdev);
>> +int panthor_perf_suspend(struct panthor_device *ptdev);
>> +int panthor_perf_resume(struct panthor_device *ptdev);
>>  void panthor_perf_unplug(struct panthor_device *ptdev);
>>
>>  int panthor_perf_session_setup(struct panthor_device *ptdev, struct panthor_perf *perf,
>> @@ -30,5 +32,9 @@ void panthor_perf_session_destroy(struct panthor_file *pfile, struct panthor_per
>>
>>  void panthor_perf_report_irq(struct panthor_device *ptdev, u32 status);
>>
>> +void panthor_perf_pre_reset(struct panthor_device *ptdev);
>> +
>> +void panthor_perf_post_reset(struct panthor_device *ptdev);
>> +
>>  #endif /* __PANTHOR_PERF_H__ */
>>
>> --
>> 2.33.0.dirty
> 
> 
> Adrian Larumbe


  reply	other threads:[~2025-07-25  9:27 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-16 15:49 [PATCH v4 0/7] Performance counter implementation with single manual client support Lukas Zapolskas
2025-05-16 15:49 ` [PATCH v4 1/7] drm/panthor: Add performance counter uAPI Lukas Zapolskas
2025-07-18  2:43   ` Adrián Larumbe
2025-07-21  8:46     ` Lukas Zapolskas
2025-05-16 15:49 ` [PATCH v4 2/7] drm/panthor: Add DEV_QUERY.PERF_INFO handling for Gx10 Lukas Zapolskas
2025-07-18  2:52   ` Adrián Larumbe
2025-07-21  9:04     ` Lukas Zapolskas
2025-07-18 15:11   ` Adrián Larumbe
2025-07-21  9:06     ` Lukas Zapolskas
2025-05-16 15:49 ` [PATCH v4 3/7] drm/panthor: Add panthor perf initialization and termination Lukas Zapolskas
2025-07-18  3:10   ` Adrián Larumbe
2025-07-21  9:10     ` Lukas Zapolskas
2025-05-16 15:49 ` [PATCH v4 4/7] drm/panthor: Introduce sampling sessions to handle userspace clients Lukas Zapolskas
2025-05-17  7:53   ` kernel test robot
2025-06-20 15:28   ` Steven Price
2025-07-21  9:58     ` Lukas Zapolskas
2025-07-18  3:34   ` Adrián Larumbe
2025-07-21  9:53     ` Lukas Zapolskas
2025-05-16 15:49 ` [PATCH v4 5/7] drm/panthor: Implement the counter sampler and sample handling Lukas Zapolskas
2025-05-17  8:56   ` kernel test robot
2025-07-18 14:49   ` Adrián Larumbe
2025-07-25 10:29     ` Lukas Zapolskas
2025-05-16 15:49 ` [PATCH v4 6/7] drm/panthor: Add suspend, resume and reset handling Lukas Zapolskas
2025-07-18 15:01   ` Adrián Larumbe
2025-07-25  9:26     ` Lukas Zapolskas [this message]
2025-05-16 15:49 ` [PATCH v4 7/7] drm/panthor: Expose the panthor perf ioctls Lukas Zapolskas
2025-07-18 15:05   ` Adrián Larumbe
2025-07-18 15:19   ` Adrián Larumbe
2025-07-25  9:09     ` Lukas Zapolskas

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=8a65cc81-92cf-48e9-90b7-645a1fc94ef8@arm.com \
    --to=lukas.zapolskas@arm.com \
    --cc=adrian.larumbe@collabora.com \
    --cc=airlied@gmail.com \
    --cc=boris.brezillon@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    /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

all inboxes | Powered by JetHome®