mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	drm/xe: Allow userspace to configure CCS mode
Allow user to configure the CCS mode setting through a
'ccs_mode' sysfs interface. Also report the current
CCS mode configuration and number of compute slices
available through this interface.
v2: Rebase, make it platform agnostic
v3: Separte out num_cslices sysfs interface and make
    xe_gt_ccs_mode_sysfs_init() return void
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
			
			
This commit is contained in:
		
							parent
							
								
									0d97ecce16
								
							
						
					
					
						commit
						f3bc5bb4d5
					
				
					 3 changed files with 107 additions and 0 deletions
				
			
		| 
						 | 
					@ -378,6 +378,9 @@ static int gt_fw_domain_init(struct xe_gt *gt)
 | 
				
			||||||
			 "failed to register engines sysfs directory, err: %d\n",
 | 
								 "failed to register engines sysfs directory, err: %d\n",
 | 
				
			||||||
			 err);
 | 
								 err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Initialize CCS mode sysfs after early initialization of HW engines */
 | 
				
			||||||
 | 
						xe_gt_ccs_mode_sysfs_init(gt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
 | 
						err = xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
 | 
				
			||||||
	XE_WARN_ON(err);
 | 
						XE_WARN_ON(err);
 | 
				
			||||||
	xe_device_mem_access_put(gt_to_xe(gt));
 | 
						xe_device_mem_access_put(gt_to_xe(gt));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,10 +3,13 @@
 | 
				
			||||||
 * Copyright © 2023 Intel Corporation
 | 
					 * Copyright © 2023 Intel Corporation
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <drm/drm_managed.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "regs/xe_gt_regs.h"
 | 
					#include "regs/xe_gt_regs.h"
 | 
				
			||||||
#include "xe_assert.h"
 | 
					#include "xe_assert.h"
 | 
				
			||||||
#include "xe_gt.h"
 | 
					#include "xe_gt.h"
 | 
				
			||||||
#include "xe_gt_ccs_mode.h"
 | 
					#include "xe_gt_ccs_mode.h"
 | 
				
			||||||
 | 
					#include "xe_gt_sysfs.h"
 | 
				
			||||||
#include "xe_mmio.h"
 | 
					#include "xe_mmio.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void __xe_gt_apply_ccs_mode(struct xe_gt *gt, u32 num_engines)
 | 
					static void __xe_gt_apply_ccs_mode(struct xe_gt *gt, u32 num_engines)
 | 
				
			||||||
| 
						 | 
					@ -76,3 +79,103 @@ void xe_gt_apply_ccs_mode(struct xe_gt *gt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	__xe_gt_apply_ccs_mode(gt, gt->ccs_mode);
 | 
						__xe_gt_apply_ccs_mode(gt, gt->ccs_mode);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static ssize_t
 | 
				
			||||||
 | 
					num_cslices_show(struct device *kdev,
 | 
				
			||||||
 | 
							 struct device_attribute *attr, char *buf)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct xe_gt *gt = kobj_to_gt(&kdev->kobj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return sysfs_emit(buf, "%u\n", hweight32(CCS_MASK(gt)));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static DEVICE_ATTR_RO(num_cslices);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static ssize_t
 | 
				
			||||||
 | 
					ccs_mode_show(struct device *kdev,
 | 
				
			||||||
 | 
						      struct device_attribute *attr, char *buf)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct xe_gt *gt = kobj_to_gt(&kdev->kobj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return sysfs_emit(buf, "%u\n", gt->ccs_mode);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static ssize_t
 | 
				
			||||||
 | 
					ccs_mode_store(struct device *kdev, struct device_attribute *attr,
 | 
				
			||||||
 | 
						       const char *buff, size_t count)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct xe_gt *gt = kobj_to_gt(&kdev->kobj);
 | 
				
			||||||
 | 
						u32 num_engines, num_slices;
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = kstrtou32(buff, 0, &num_engines);
 | 
				
			||||||
 | 
						if (ret)
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Ensure number of engines specified is valid and there is an
 | 
				
			||||||
 | 
						 * exact multiple of engines for slices.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						num_slices = hweight32(CCS_MASK(gt));
 | 
				
			||||||
 | 
						if (!num_engines || num_engines > num_slices || num_slices % num_engines) {
 | 
				
			||||||
 | 
							xe_gt_dbg(gt, "Invalid compute config, %d engines %d slices\n",
 | 
				
			||||||
 | 
								  num_engines, num_slices);
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (gt->ccs_mode != num_engines) {
 | 
				
			||||||
 | 
							xe_gt_info(gt, "Setting compute mode to %d\n", num_engines);
 | 
				
			||||||
 | 
							gt->ccs_mode = num_engines;
 | 
				
			||||||
 | 
							xe_gt_reset_async(gt);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return count;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static DEVICE_ATTR_RW(ccs_mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct attribute *gt_ccs_mode_attrs[] = {
 | 
				
			||||||
 | 
						&dev_attr_ccs_mode.attr,
 | 
				
			||||||
 | 
						&dev_attr_num_cslices.attr,
 | 
				
			||||||
 | 
						NULL,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void xe_gt_ccs_mode_sysfs_fini(struct drm_device *drm, void *arg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct xe_gt *gt = arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sysfs_remove_files(gt->sysfs, gt_ccs_mode_attrs);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * xe_gt_ccs_mode_sysfs_init - Initialize CCS mode sysfs interfaces
 | 
				
			||||||
 | 
					 * @gt: GT structure
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Through a per-gt 'ccs_mode' sysfs interface, the user can enable a fixed
 | 
				
			||||||
 | 
					 * number of compute hardware engines to which the available compute slices
 | 
				
			||||||
 | 
					 * are to be allocated. This user configuration change triggers a gt reset
 | 
				
			||||||
 | 
					 * and it is expected that there are no open drm clients while doing so.
 | 
				
			||||||
 | 
					 * The number of available compute slices is exposed to user through a per-gt
 | 
				
			||||||
 | 
					 * 'num_cslices' sysfs interface.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void xe_gt_ccs_mode_sysfs_init(struct xe_gt *gt)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct xe_device *xe = gt_to_xe(gt);
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!xe_gt_ccs_mode_enabled(gt))
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = sysfs_create_files(gt->sysfs, gt_ccs_mode_attrs);
 | 
				
			||||||
 | 
						if (err) {
 | 
				
			||||||
 | 
							drm_warn(&xe->drm, "Sysfs creation for ccs_mode failed err: %d\n", err);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = drmm_add_action_or_reset(&xe->drm, xe_gt_ccs_mode_sysfs_fini, gt);
 | 
				
			||||||
 | 
						if (err) {
 | 
				
			||||||
 | 
							sysfs_remove_files(gt->sysfs, gt_ccs_mode_attrs);
 | 
				
			||||||
 | 
							drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
 | 
				
			||||||
 | 
								 __func__, err);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@
 | 
				
			||||||
#include "xe_platform_types.h"
 | 
					#include "xe_platform_types.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void xe_gt_apply_ccs_mode(struct xe_gt *gt);
 | 
					void xe_gt_apply_ccs_mode(struct xe_gt *gt);
 | 
				
			||||||
 | 
					void xe_gt_ccs_mode_sysfs_init(struct xe_gt *gt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline bool xe_gt_ccs_mode_enabled(const struct xe_gt *gt)
 | 
					static inline bool xe_gt_ccs_mode_enabled(const struct xe_gt *gt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue