Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Francois Dugast <francois.dugast@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v8 08/11] drm/xe/hw_engine_group: Ensure safe transition between execution modes
Date: Fri, 9 Aug 2024 03:40:22 +0000	[thread overview]
Message-ID: <ZrWPpm08mjwVayK+@DUT025-TGLU.fm.intel.com> (raw)
In-Reply-To: <20240808184220.1715625-9-francois.dugast@intel.com>

On Thu, Aug 08, 2024 at 08:40:26PM +0200, Francois Dugast wrote:
> Provide a way to safely transition execution modes of the hw engine group
> ahead of the actual execution. When necessary, either wait for running
> jobs to complete or preempt them, thus ensuring mutual exclusion between
> execution modes.
> 
> Unlike a mutex, the rw_semaphore used in this context allows multiple
> submissions in the same mode.
> 
> v2: Use lockdep_assert_held_write, add annotations (Matt Brost)
> 
> v3: Fix kernel doc, remove redundant code (Matt Brost)
> 
> v4: Now that xe_hw_engine_group_suspend_faulting_lr_jobs can fail,
>     propagate the error to the caller (Matt Brost)
> 
> Signed-off-by: Francois Dugast <francois.dugast@intel.com>

Reviewed-by: Matthew Brost <matthew.brost@intel.com>

> ---
>  drivers/gpu/drm/xe/xe_hw_engine_group.c | 75 +++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_hw_engine_group.h |  5 ++
>  2 files changed, 80 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_hw_engine_group.c b/drivers/gpu/drm/xe/xe_hw_engine_group.c
> index 8d3ddfc4ee82..e6c235119351 100644
> --- a/drivers/gpu/drm/xe/xe_hw_engine_group.c
> +++ b/drivers/gpu/drm/xe/xe_hw_engine_group.c
> @@ -235,3 +235,78 @@ static int xe_hw_engine_group_wait_for_dma_fence_jobs(struct xe_hw_engine_group
>  
>  	return 0;
>  }
> +
> +static int switch_mode(struct xe_hw_engine_group *group)
> +{
> +	int err = 0;
> +	enum xe_hw_engine_group_execution_mode new_mode;
> +
> +	lockdep_assert_held_write(&group->mode_sem);
> +
> +	switch (group->cur_mode) {
> +	case EXEC_MODE_LR:
> +		new_mode = EXEC_MODE_DMA_FENCE;
> +		err = xe_hw_engine_group_suspend_faulting_lr_jobs(group);
> +		break;
> +	case EXEC_MODE_DMA_FENCE:
> +		new_mode = EXEC_MODE_LR;
> +		err = xe_hw_engine_group_wait_for_dma_fence_jobs(group);
> +		break;
> +	}
> +
> +	if (err)
> +		return err;
> +
> +	group->cur_mode = new_mode;
> +
> +	return 0;
> +}
> +
> +/**
> + * xe_hw_engine_group_get_mode() - Get the group to execute in the new mode
> + * @group: The hw engine group
> + * @new_mode: The new execution mode
> + * @previous_mode: Pointer to the previous mode provided for use by caller
> + *
> + * Return: 0 if successful, -EINTR if locking failed.
> + */
> +int xe_hw_engine_group_get_mode(struct xe_hw_engine_group *group,
> +				enum xe_hw_engine_group_execution_mode new_mode,
> +				enum xe_hw_engine_group_execution_mode *previous_mode)
> +__acquires(&group->mode_sem)
> +{
> +	int err = down_read_interruptible(&group->mode_sem);
> +
> +	if (err)
> +		return err;
> +
> +	*previous_mode = group->cur_mode;
> +
> +	if (new_mode != group->cur_mode) {
> +		up_read(&group->mode_sem);
> +		err = down_write_killable(&group->mode_sem);
> +		if (err)
> +			return err;
> +
> +		if (new_mode != group->cur_mode) {
> +			err = switch_mode(group);
> +			if (err) {
> +				up_write(&group->mode_sem);
> +				return err;
> +			}
> +		}
> +		downgrade_write(&group->mode_sem);
> +	}
> +
> +	return err;
> +}
> +
> +/**
> + * xe_hw_engine_group_put() - Put the group
> + * @group: The hw engine group
> + */
> +void xe_hw_engine_group_put(struct xe_hw_engine_group *group)
> +__releases(&group->mode_sem)
> +{
> +	up_read(&group->mode_sem);
> +}
> diff --git a/drivers/gpu/drm/xe/xe_hw_engine_group.h b/drivers/gpu/drm/xe/xe_hw_engine_group.h
> index 857a83787504..e0deb7c7bb5b 100644
> --- a/drivers/gpu/drm/xe/xe_hw_engine_group.h
> +++ b/drivers/gpu/drm/xe/xe_hw_engine_group.h
> @@ -17,4 +17,9 @@ int xe_hw_engine_setup_groups(struct xe_gt *gt);
>  int xe_hw_engine_group_add_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q);
>  void xe_hw_engine_group_del_exec_queue(struct xe_hw_engine_group *group, struct xe_exec_queue *q);
>  
> +int xe_hw_engine_group_get_mode(struct xe_hw_engine_group *group,
> +				enum xe_hw_engine_group_execution_mode new_mode,
> +				enum xe_hw_engine_group_execution_mode *previous_mode);
> +void xe_hw_engine_group_put(struct xe_hw_engine_group *group);
> +
>  #endif
> -- 
> 2.43.0
> 

  reply	other threads:[~2024-08-09  3:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08 18:40 [PATCH v8 00/11] Parallel submission of dma fence jobs and LR jobs with shared hardware resources Francois Dugast
2024-08-08 18:40 ` [PATCH v8 01/11] drm/xe/hw_engine_group: Introduce xe_hw_engine_group Francois Dugast
2024-08-08 18:40 ` [PATCH v8 02/11] drm/xe/guc_submit: Make suspend_wait interruptible Francois Dugast
2024-08-08 23:51   ` Matthew Brost
2024-08-08 18:40 ` [PATCH v8 03/11] 'drm/xe/hw_engine_group: Register hw engine group's exec queues Francois Dugast
2024-08-09  3:36   ` Matthew Brost
2024-08-08 18:40 ` [PATCH v8 04/11] drm/xe/hw_engine_group: Add helper to suspend faulting LR jobs Francois Dugast
2024-08-09  3:19   ` Matthew Brost
2024-08-08 18:40 ` [PATCH v8 05/11] drm/xe/exec_queue: Remove duplicated code Francois Dugast
2024-08-08 18:40 ` [PATCH v8 06/11] drm/xe/exec_queue: Prepare last fence for hw engine group resume context Francois Dugast
2024-08-09  3:37   ` Matthew Brost
2024-08-08 18:40 ` [PATCH v8 07/11] drm/xe/hw_engine_group: Add helper to wait for dma fence jobs Francois Dugast
2024-08-09  3:39   ` Matthew Brost
2024-08-08 18:40 ` [PATCH v8 08/11] drm/xe/hw_engine_group: Ensure safe transition between execution modes Francois Dugast
2024-08-09  3:40   ` Matthew Brost [this message]
2024-08-08 18:40 ` [PATCH v8 09/11] drm/xe/exec: Switch hw engine group execution mode upon job submission Francois Dugast
2024-08-09  3:57   ` Matthew Brost
2024-08-08 18:40 ` [PATCH v8 10/11] drm/xe/vm: Remove restriction that all VMs must be faulting if one is Francois Dugast
2024-08-08 18:40 ` [PATCH v8 11/11] drm/xe/device: Remove unused xe_device::usm::num_vm_in_* Francois Dugast
2024-08-08 20:57 ` ✓ CI.Patch_applied: success for Parallel submission of dma fence jobs and LR jobs with shared hardware resources (rev8) Patchwork
2024-08-08 20:58 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-08 20:59 ` ✓ CI.KUnit: success " Patchwork
2024-08-08 21:11 ` ✓ CI.Build: " Patchwork
2024-08-08 21:13 ` ✓ CI.Hooks: " Patchwork
2024-08-08 21:14 ` ✓ CI.checksparse: " Patchwork
2024-08-08 21:35 ` ✗ CI.BAT: failure " Patchwork
2024-08-09  1:29 ` ✗ CI.FULL: " 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=ZrWPpm08mjwVayK+@DUT025-TGLU.fm.intel.com \
    --to=matthew.brost@intel.com \
    --cc=francois.dugast@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /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