drm/xe: Add job timeout engine property to sysfs
authorTejas Upadhyay <tejas.upadhyay@intel.com>
Fri, 4 Aug 2023 12:38:25 +0000 (18:08 +0530)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 21 Dec 2023 16:39:23 +0000 (11:39 -0500)
The time after which a job is removed from the scheduler.
Add sysfs entry to provide user defined job timeout to
scheduler.

The job timeout can be adjusted per-engine class using,

/sys/class/drm/cardX/device/tileN/gtN/engines/ccs/job_timeout_ms

V8:
  - Rebase
V7:
  - Rebase to use s/xe_engine/xe_hw_engine/ - Matt
V6:
  - Remove timeout validation, not relevant - Niranjana
  - Rebase to use common error path
V5:
  - Rebase to use engine class interface instead of hw engine
V4:
  - Rebase to per class engine props interface
V3:
  - Rebase
  - Update commit message to reflect tile update
V2:
  - Use sysfs_create_files as part of this patch

Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_hw_engine_class_sysfs.c

index 99a8197765bda8cc190cb4965f8c2a2077f3bacc..03e0c29445b7aee5a267876dfcef7718965b9200 100644 (file)
@@ -24,38 +24,34 @@ static const struct kobj_type kobj_xe_hw_engine_type = {
        .sysfs_ops = &kobj_sysfs_ops
 };
 
-static void kobj_xe_hw_engine_class_fini(struct drm_device *drm, void *arg)
+static ssize_t job_timeout_store(struct kobject *kobj,
+                                struct kobj_attribute *attr,
+                                const char *buf, size_t count)
 {
-       struct kobject *kobj = arg;
+       struct xe_hw_engine_class_intf *eclass = kobj_to_eclass(kobj);
+       u32 timeout;
+       int err;
 
-       kobject_put(kobj);
-}
+       err = kstrtou32(buf, 0, &timeout);
+       if (err)
+               return err;
 
-       static struct kobj_eclass *
-kobj_xe_hw_engine_class(struct xe_device *xe, struct kobject *parent, char *name)
-{
-       struct kobj_eclass *keclass;
-       int err = 0;
+       WRITE_ONCE(eclass->sched_props.job_timeout_ms, timeout);
 
-       keclass = kzalloc(sizeof(*keclass), GFP_KERNEL);
-       if (!keclass)
-               return NULL;
+       return count;
+}
 
-       kobject_init(&keclass->base, &kobj_xe_hw_engine_type);
-       if (kobject_add(&keclass->base, parent, "%s", name)) {
-               kobject_put(&keclass->base);
-               return NULL;
-       }
+static ssize_t job_timeout_show(struct kobject *kobj,
+                               struct kobj_attribute *attr, char *buf)
+{
+       struct xe_hw_engine_class_intf *eclass = kobj_to_eclass(kobj);
 
-       err = drmm_add_action_or_reset(&xe->drm, kobj_xe_hw_engine_class_fini,
-                                      &keclass->base);
-       if (err)
-               drm_warn(&xe->drm,
-                        "%s: drmm_add_action_or_reset failed, err: %d\n",
-                        __func__, err);
-       return keclass;
+       return sprintf(buf, "%u\n", eclass->sched_props.job_timeout_ms);
 }
 
+static struct kobj_attribute job_timeout_attr =
+__ATTR(job_timeout_ms, 0644, job_timeout_show, job_timeout_store);
+
 static ssize_t job_timeout_default(struct kobject *kobj,
                                   struct kobj_attribute *attr, char *buf)
 {
@@ -97,6 +93,44 @@ static const struct attribute *defaults[] = {
        NULL
 };
 
+static const struct attribute *files[] = {
+       &job_timeout_attr.attr,
+       NULL
+};
+
+static void kobj_xe_hw_engine_class_fini(struct drm_device *drm, void *arg)
+{
+       struct kobject *kobj = arg;
+
+       sysfs_remove_files(kobj, files);
+       kobject_put(kobj);
+}
+
+       static struct kobj_eclass *
+kobj_xe_hw_engine_class(struct xe_device *xe, struct kobject *parent, char *name)
+{
+       struct kobj_eclass *keclass;
+       int err = 0;
+
+       keclass = kzalloc(sizeof(*keclass), GFP_KERNEL);
+       if (!keclass)
+               return NULL;
+
+       kobject_init(&keclass->base, &kobj_xe_hw_engine_type);
+       if (kobject_add(&keclass->base, parent, "%s", name)) {
+               kobject_put(&keclass->base);
+               return NULL;
+       }
+
+       err = drmm_add_action_or_reset(&xe->drm, kobj_xe_hw_engine_class_fini,
+                                      &keclass->base);
+       if (err)
+               drm_warn(&xe->drm,
+                        "%s: drmm_add_action_or_reset failed, err: %d\n",
+                        __func__, err);
+       return keclass;
+}
+
 static void hw_engine_class_defaults_fini(struct drm_device *drm, void *arg)
 {
        struct kobject *kobj = arg;
@@ -229,6 +263,10 @@ int xe_hw_engine_class_sysfs_init(struct xe_gt *gt)
                                 err);
                        goto err_object;
                }
+
+               err = sysfs_create_files(&keclass->base, files);
+               if (err)
+                       goto err_object;
        }
 
        err = drmm_add_action_or_reset(&xe->drm, hw_engine_class_sysfs_fini,