[PATCH v2 2/2] drm/xe: Use new force-wake guard class in xe_mocs.c

Michal Wajdeczko michal.wajdeczko at intel.com
Tue Nov 19 21:05:46 UTC 2024



On 19.11.2024 21:03, Lucas De Marchi wrote:
> On Mon, Nov 18, 2024 at 07:45:11PM +0100, Michal Wajdeczko wrote:
>> Start using new xe_fw class to minimize risk of leaking force-wake
>> references.
>>
>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
>> ---
>> v2: rebased
>> ---
>> drivers/gpu/drm/xe/xe_mocs.c | 10 +++-------
>> 1 file changed, 3 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_mocs.c b/drivers/gpu/drm/xe/xe_mocs.c
>> index 54d199b5cfb2..f18aaa6595c7 100644
>> --- a/drivers/gpu/drm/xe/xe_mocs.c
>> +++ b/drivers/gpu/drm/xe/xe_mocs.c
>> @@ -776,19 +776,15 @@ void xe_mocs_dump(struct xe_gt *gt, struct
>> drm_printer *p)
>> {
>>     struct xe_device *xe = gt_to_xe(gt);
>>     struct xe_mocs_info table;
>> -    unsigned int fw_ref, flags;
>> +    unsigned int flags;
>>
>>     flags = get_mocs_settings(xe, &table);
>>
>>     xe_pm_runtime_get_noresume(xe);
>> -    fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
>> -    if (!fw_ref)
>> -        goto err_fw;
>>
>> -    table.ops->dump(&table, flags, gt, p);
>> +    scoped_guard(xe_fw, gt_to_fw(gt), XE_FW_GT)
>> +        table.ops->dump(&table, flags, gt, p);
> 
> 
> afair one caveat is that you can't have a goto that jumps over guard
> because of the usage of the cleanup attribute. Is that still the case or
> do we have some magic convincing the compiler to do the right thing?

not sure if I get the problem right, but in the perfect world, we will
not need to use goto's any more (as we need them mostly for the cleanup)

so code like this:

int legacy(gt)
{
	unsigned int fw_ref;
	int res;

	xe_pm_runtime_get(gt_to_xe(gt));
	fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_GT);
	if (!fw_ref) {
		res = -ETIMEDOUT;
		goto out_pm;
	}

	res = foo();

	xe_force_wake_put(gt_to_fw(gt), fw_ref);
out_pm:
	xe_pm_runtime_put(gt_to_xe(gt));
	return res;
}

we could likely replace with:

int future(gt)
{
	guard(xe_pm)(gt_to_xe(gt));
	scoped_guard(xe_fw, gt_to_fw(gt), XE_FORCEWAKE_GT)
		return foo();

	return -ETIMEDOUT;
}

> 
> once we get agreement on the approach, please let's convert everything
> that can be converted to scoped guard so we don't have to keep both
> approaches for a long time.
> 
> Lucas De Marchi
> 
>>
>> -    xe_force_wake_put(gt_to_fw(gt), fw_ref);
>> -err_fw:
>>     xe_pm_runtime_put(xe);
>> }
>>
>> -- 
>> 2.43.0
>>



More information about the Intel-xe mailing list