drm/xe: Add vram frequency sysfs attributes
Subsystems (2)
PATCH v6 1/1 drm/xe: Add vram frequency sysfs attributes
Add vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq |-min_freq
v2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix from XEHP_PCODE_FREQUENCY_CONFIG (Riana)
v4: Create sysfs under tile#/freq0 after removal of
physical_memsize attrbute
v5: Revert back to creating sysfs under tile#/memory/freq0
Remove definition of GT_FREQUENCY_MULTIPLIER (Rodrigo)
v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)
--- drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++ drivers/gpu/drm/xe/xe_tile_sysfs.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)
drivers/gpu/drm/xe/xe_pcode_api.h +7 -0
@@ -42,6 +42,13 @@#define POWER_SETUP_I1_SHIFT 6/* 10.6 fixed point format */ #define POWER_SETUP_I1_DATA_MASK REG_GENMASK(15, 0) +#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct pcode_err_decode {int errno;const char *str;
drivers/gpu/drm/xe/xe_tile_sysfs.c +86 -0
113 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 80 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq |-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0
Remove definition ofGT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by Sujaritha Sundaresan <[email protected]>--- drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++ drivers/gpu/drm/xe/xe_tile_sysfs.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@#define POWER_SETUP_I1_SHIFT 6/* 10.6 fixed point format */
#define POWER_SETUP_I1_DATA_MASK REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct pcode_err_decode {int errno;const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +9
-0@@ -7,9 +7,21 @@#include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h" +/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a
Quoted 1 line
configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a configuration.
Quoted 41 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */drivers/gpu/drm/xe/xe_tile_sysfs.c +12
-0+static void xe_tile_sysfs_kobj_release (struct kobject *kobj) {kfree (kobj);@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct device_attribute *attr, +char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent); +struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox =REG_FIELD_PREP (PCODE_MB_COMMAND ,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); +} +static DEVICE_ATTR_RO (max_freq); + +static ssize_t min_freq_show(struct device *kdev, struct device_attribute*attr,
drivers/gpu/drm/xe/xe_tile_sysfs.c static const struct kobj_type xe_tile_sysfs_kobj_type = { · line 39
Quoted 4 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +4
-0+ char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent);
If you are missing to create a kobject for freq0 , then this should be kobj->parent->parent.
Quoted 45 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +5
-0+struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,
PCODE_FREQUENCY_CONFIG)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_PN)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +24
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); +} +static DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, +NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name ="freq0" , + .attrs = freq_attrs, +}; +static void tile_sysfs_fini (struct drm_device *drm,void *arg) {struct xe_tile *tile = arg;@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile)struct xe_device *xe =tile_to_xe (tile);struct device *dev = xe->drm.dev;struct kobj_tile *kt; +struct kobject *kobj;int err; kt = kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ void
xe_tile_sysfs_init(struct xe_tile *tile)
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 126
Quoted 4 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0tile->sysfs = &kt->base; +if (xe->info.platform ==XE_PVC ) { + kobj =kobject_create_and_add ("memory" , tile->sysfs);
How freq0 is getting added, I am unable to see the freq0 kobject as per the path "device/tile#/memory/freq0/"
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 137
Quoted 13 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (!kobj) + drm_warn(&xe->drm, "failed to add memorydirectory, err: %d\n",
-ENOMEM);drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+ } + +if (kobj && xe->info.platform ==XE_PVC ) { + err =sysfs_create_group (kobj, &freq_group_attrs); +if (err) { + drm_warn(&xe->drm, "failed to register vram freqsysfs, err: %d\n", err);
drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0+return ; + } + }
Don't we need sysfs cleanup and kobject_put in tile_sysfs_fini() ? Have you made sure kmemleak won't complain here on memory leak ?
Thanks,
Anshuman Gupta.
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ err =drmm_add_action_or_reset (&xe->drm, tile_sysfs_fini, tile);if (err) drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed,err: %d\n",
--
2.25.1
Quoted 73 lines · Anshuman
Quoted 73 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq |-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0
Remove definition ofGT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by Sujaritha Sundaresan <[email protected]>--- drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++ drivers/gpu/drm/xe/xe_tile_sysfs.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@#define POWER_SETUP_I1_SHIFT 6/* 10.6 fixed point format */
#define POWER_SETUP_I1_DATA_MASK REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct pcode_err_decode {int errno;const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0@@ -7,9 +7,21 @@#include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h"
Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a configuration.
Sure
Quoted 39 lines
Quoted 39 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */drivers/gpu/drm/xe/xe_tile_sysfs.c +12
-0+static void xe_tile_sysfs_kobj_release (struct kobject *kobj) {kfree (kobj);@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct device_attribute *attr, +char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent); +struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox =REG_FIELD_PREP (PCODE_MB_COMMAND ,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +12
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); +} +static DEVICE_ATTR_RO (max_freq); +
Quoted 8 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c static const struct kobj_type xe_tile_sysfs_kobj_type = { · line 39
Quoted 6 lines
+static
ssize_tmin_freq_show(struct device *kdev, structdevice_attribute*attr,drivers/gpu/drm/xe/xe_tile_sysfs.c +4
-0+ char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent);If you are missing to create a kobject for freq0 , then this should be
kobj->parent->parent.
I don't think a kobject is needed for freq0, since it we are only using attribute_group for it.
Similar to throttle_reasons.
Quoted 42 lines
Quoted 42 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +5
-0+struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,
PCODE_FREQUENCY_CONFIG)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_PN)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +24
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); +} +static DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, +NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name ="freq0" , + .attrs = freq_attrs, +}; +static void tile_sysfs_fini (struct drm_device *drm,void *arg) {struct xe_tile *tile = arg;@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile)struct xe_device *xe =tile_to_xe (tile);struct device *dev = xe->drm.dev;struct kobj_tile *kt; +struct kobject *kobj;int err;
Quoted 8 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 126
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +0
-0kt = kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ void
xe_tile_sysfs_init(struct xe_tile *tile)tile->sysfs = &kt->base;drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (xe->info.platform ==XE_PVC ) { + kobj =kobject_create_and_add ("memory" , tile->sysfs);How freq0 is getting added, I am unable to see the freq0 kobject as per the path "device/tile#/memory/freq0/"
freq0 is being added as an attribute group. It is similar to the throttle_reasons implementation.
Quoted 16 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 137
Quoted 13 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (!kobj) + drm_warn(&xe->drm, "failed to add memorydirectory, err: %d\n",
-ENOMEM);drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+ } + +if (kobj && xe->info.platform ==XE_PVC ) { + err =sysfs_create_group (kobj, &freq_group_attrs); +if (err) { + drm_warn(&xe->drm, "failed to register vram freqsysfs, err: %d\n", err);
drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0+return ; + } + }Don't we need sysfs cleanup and
kobject_putintile_sysfs_fini()? Have you made sure kmemleak won't complain here on memory leak ?
Quoted 2 lines
Thanks,
Anshuman Gupta.
I have already checked for mem leaks during the cleanup. The kobject_put is not needed.
Thanks,
Suja
Quoted 7 lines
Quoted 7 lines
+
err =drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); if (err)
drm_warn(&xe->drm, "%s:drmm_add_action_or_resetfailed,
err: %d\n",
--
2.25.1
Quoted 144 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Tuesday, December 26, 2023 10:02 AM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 73 lines · Anshuman
Quoted 73 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq |-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0
Remove definition ofGT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by Sujaritha Sundaresan <[email protected]>--- drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++ drivers/gpu/drm/xe/xe_tile_sysfs.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@#define POWER_SETUP_I1_SHIFT 6/* 10.6 fixed point format */
#define POWER_SETUP_I1_DATA_MASK REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct pcode_err_decode {int errno;const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0@@ -7,9 +7,21 @@#include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h" Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a
configuration.
SureQuoted 40 lines
Quoted 40 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+static void xe_tile_sysfs_kobj_release (struct kobject *kobj) {kfree (kobj);@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct +device_attribute *attr, +char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent); +struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox =REG_FIELD_PREP (PCODE_MB_COMMAND ,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +12
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (max_freq); + +static ssize_t min_freq_show(struct device *kdev, structQuoted 8 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c static const struct kobj_type xe_tile_sysfs_kobj_type = { · line 39
Quoted 6 lines
+device_attribute
*attr,drivers/gpu/drm/xe/xe_tile_sysfs.c +4
-0+ char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent);If you are missing to create a kobject for freq0 , then this should be
kobj->parent->parent.
Quoted 4 lines
I don't think a kobject is needed for freq0, since it we are only using
attribute_groupfor it.Similar to
throttle_reasons.
Sure, thanks for explanation.
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +5
-0+struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,
PCODE_FREQUENCY_CONFIG)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_PN)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +23
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, +NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name ="freq0" , + .attrs = freq_attrs, +}; +static void tile_sysfs_fini (struct drm_device *drm,void *arg) {struct xe_tile *tile = arg;@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile)struct xe_device *xe =tile_to_xe (tile);struct device *dev = xe->drm.dev;struct kobj_tile *kt; +struct kobject *kobj;int err; kt = kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ void
xe_tile_sysfs_init(struct xe_tile *tile)
Quoted 23 lines
Quoted 5 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 126
Quoted 4 lines
tile->sysfs = &kt->base;drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (xe->info.platform ==XE_PVC ) { + kobj =kobject_create_and_add ("memory" , tile->sysfs);How freq0 is getting added, I am unable to see the freq0 kobject as per the path
"device/tile#/memory/freq0/"
freq0 is being added as an attribute group. It is similar to thethrottle_reasonsimplementation.Quoted 15 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 137
Quoted 13 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (!kobj) + drm_warn(&xe->drm, "failed to add memorydirectory, err: %d\n",
-ENOMEM);drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+ } + +if (kobj && xe->info.platform ==XE_PVC ) { + err =sysfs_create_group (kobj, &freq_group_attrs); +if (err) { + drm_warn(&xe->drm, "failed to register vram freqsysfs, err: %d\n", err);
drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0+return ; + } + }Don't we need sysfs cleanup and
kobject_putintile_sysfs_fini()? Have you made sure kmemleak won't complain here on memory leak ?
Check the kobject_release() , this will only get call , when all ref count of that kobj is being put. Here you are creating a object and it will never be released.
Also we need to call the sysfs_remove_group() as well in fini function ?
Thanks,
Anshuman.
Quoted 18 lines
Quoted 3 lines
Thanks,
Anshuman Gupta.I have already checked for mem leaks during the cleanup. The
kobject_putis not needed.Thanks,
Suja
Quoted 7 lines
Quoted 7 lines
+
err =drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); if (err)
drm_warn(&xe->drm, "%s:drmm_add_action_or_resetfailed,
err: %d\n",
--
2.25.1
Quoted 213 lines · Anshuman
Quoted 141 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Tuesday, December 26, 2023 10:02 AM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 72 lines · Anshuman
Quoted 72 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq |-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0
Remove definition ofGT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by Sujaritha Sundaresan <[email protected]>--- drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++ drivers/gpu/drm/xe/xe_tile_sysfs.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@#define POWER_SETUP_I1_SHIFT 6/* 10.6 fixed point format */
#define POWER_SETUP_I1_DATA_MASK REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct pcode_err_decode {int errno;const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0@@ -7,9 +7,21 @@#include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h" Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a
configuration.
SureQuoted 40 lines
Quoted 40 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+static void xe_tile_sysfs_kobj_release (struct kobject *kobj) {kfree (kobj);@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct +device_attribute *attr, +char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent); +struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox =REG_FIELD_PREP (PCODE_MB_COMMAND ,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +12
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (max_freq); + +static ssize_t min_freq_show(struct device *kdev, structQuoted 8 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c static const struct kobj_type xe_tile_sysfs_kobj_type = { · line 39
Quoted 6 lines
+device_attribute
*attr,drivers/gpu/drm/xe/xe_tile_sysfs.c +4
-0+ char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent);If you are missing to create a kobject for freq0 , then this should be
kobj->parent->parent.Quoted 4 lines
I don't think a kobject is needed for freq0, since it we are only using
attribute_groupfor it.Similar to
throttle_reasons.Sure, thanks for explanation.
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +5
-0+struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,
PCODE_FREQUENCY_CONFIG)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_PN)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +23
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, +NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name ="freq0" , + .attrs = freq_attrs, +}; +static void tile_sysfs_fini (struct drm_device *drm,void *arg) {struct xe_tile *tile = arg;@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile)struct xe_device *xe =tile_to_xe (tile);struct device *dev = xe->drm.dev;struct kobj_tile *kt; +struct kobject *kobj;int err; kt = kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ void
xe_tile_sysfs_init(struct xe_tile *tile)Quoted 23 lines
Quoted 5 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 126
Quoted 4 lines
tile->sysfs = &kt->base;drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (xe->info.platform ==XE_PVC ) { + kobj =kobject_create_and_add ("memory" , tile->sysfs);How freq0 is getting added, I am unable to see the freq0 kobject as per the path
"device/tile#/memory/freq0/"
freq0 is being added as an attribute group. It is similar to thethrottle_reasonsimplementation.Quoted 15 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 137
Quoted 13 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (!kobj) + drm_warn(&xe->drm, "failed to add memorydirectory, err: %d\n",
-ENOMEM);drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+ } + +if (kobj && xe->info.platform ==XE_PVC ) { + err =sysfs_create_group (kobj, &freq_group_attrs); +if (err) { + drm_warn(&xe->drm, "failed to register vram freqsysfs, err: %d\n", err);
drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0+return ; + } + }Don't we need sysfs cleanup and
kobject_putintile_sysfs_fini()? Have you made sure kmemleak won't complain here on memory leak ?
Quoted 6 lines
Check the
kobject_release(), this will only get call , when all ref count of that kobj is being put. Here you are creating a object and it will never be released.
Also we need to call thesysfs_remove_group()as well in fini function ?Thanks,
Anshuman.
This is a bit of unique case. In this file we have two issues that keeps us from cleaning up like others.
One, we need to cleanup the base tile directory here. And second, we are creating the kobject only for PVC. If we add the "memory" kobject cleanup to fini, we will be defining tile using kobj. This is causing an error on unload, despite adding platform conditions on fini.
After testing multiple iterations of the fini function, this was the cleanest way with no errors that worked across platforms.
If needed, the only way to accommodate the kobject_put(kobj) and the sysfs_remove_group is to move the vram sysfs creation to a separate file, similar to throttle_reasons and gt_freq.
Thanks,
Suja
Quoted 17 lines
Quoted 17 lines
Quoted 3 lines
Thanks,
Anshuman Gupta.I have already checked for mem leaks during the cleanup. The
kobject_putis not needed.Thanks,
Suja
Quoted 7 lines
Quoted 7 lines
+
err = drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); if (err) drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed,err: %d\n",
--
2.25.1
Quoted 231 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Wednesday, December 27, 2023 3:01 PM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 217 lines · Anshuman
Quoted 144 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Tuesday, December 26, 2023 10:02 AM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 73 lines · Anshuman
Quoted 73 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq |-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0
Remove definition ofGT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by: Sujaritha Sundaresan
<[email protected]>--- drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++ drivers/gpu/drm/xe/xe_tile_sysfs.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@#define POWER_SETUP_I1_SHIFT 6/* 10.6 fixed point format */
#define POWER_SETUP_I1_DATA_MASK REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct pcode_err_decode {int errno;const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0@@ -7,9 +7,21 @@#include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h" Quoted 9 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a
configuration.
SureQuoted 41 lines
Quoted 41 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+static void xe_tile_sysfs_kobj_release (struct kobject *kobj) {kfree (kobj);@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct +device_attribute *attr, +char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent); +struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox =REG_FIELD_PREP (PCODE_MB_COMMAND ,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (max_freq); + +static ssize_t min_freq_show (struct device *kdev,struct +device_attributeQuoted 8 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c static const struct kobj_type xe_tile_sysfs_kobj_type = { · line 39
Quoted 5 lines
*attr,
drivers/gpu/drm/xe/xe_tile_sysfs.c +4
-0+ char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent);If you are missing to create a kobject for freq0 , then this should be
kobj->parent->parent.Quoted 4 lines
I don't think a kobject is needed for freq0, since it we are only using
attribute_groupfor it.Similar to
throttle_reasons.Sure, thanks for explanation.
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +5
-0+struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,
PCODE_FREQUENCY_CONFIG)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_PN)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +23
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, +NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name ="freq0" , + .attrs = freq_attrs, +}; +static void tile_sysfs_fini (struct drm_device *drm,void *arg) {struct xe_tile *tile = arg;@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile)struct xe_device *xe =tile_to_xe (tile);struct device *dev = xe->drm.dev;struct kobj_tile *kt; +struct kobject *kobj;int err; kt = kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ void
xe_tile_sysfs_init(struct xe_tile *tile)tile->sysfs = &kt->base;Quoted 22 lines
Quoted 4 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 126
Quoted 2 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (xe->info.platform ==XE_PVC ) { + kobj =kobject_create_and_add ("memory" , tile->sysfs);How freq0 is getting added, I am unable to see the freq0 kobject as per the path
"device/tile#/memory/freq0/"
freq0 is being added as an attribute group. It is similar to thethrottle_reasonsimplementation.Quoted 15 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 137
Quoted 13 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (!kobj) + drm_warn(&xe->drm, "failed to add memorydirectory, err: %d\n",
-ENOMEM);drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+ } + +if (kobj && xe->info.platform ==XE_PVC ) { + err =sysfs_create_group (kobj, &freq_group_attrs); +if (err) { + drm_warn(&xe->drm, "failed to register vram freqsysfs, err: %d\n", err);
drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0+return ; + } + }Don't we need sysfs cleanup and
kobject_putintile_sysfs_fini()? Have you made sure kmemleak won't complain here on memory leak ?Quoted 1 line
Check the
kobject_release(), this will only get call , when all ref count of thatkobj is being put.
Quoted 8 lines
Quoted 5 lines
Here you are creating a object and it will never be released. Also we need to call the
sysfs_remove_group()as well in fini function ?Thanks,
Anshuman.This is a bit of unique case. In this file we have two issues that keeps us from cleaning up like others.
Current patch looks broken to me, this will leak the kobject on module unload. Please check kmemleak after module unload.
Quoted 5 lines
One, we need to cleanup the base tile directory here. And second, we are creating the kobject only for PVC. If we add the "memory" kobject cleanup to fini, we will be defining tile using kobj. This is causing an error on unload, despite adding platform conditions on fini.
You may try by changing the type of void *arg to "memory" kob to fini function ?
Quoted 7 lines
After testing multiple iterations of the fini function, this was the cleanest way with no errors that worked across platforms.
If needed, the only way to accommodate the kobject_put(kobj) and the
sysfs_remove_groupis to move the vram sysfs creation to a separate file, similar tothrottle_reasonsandgt_freq.
I think it is needed for a functional working patch, if it can not be handled by using "void *arg" in fini function.
Thanks,
Anshuman Gupta.
Quoted 22 lines
Thanks,
Suja
Quoted 17 lines
Quoted 17 lines
Quoted 3 lines
Thanks,
Anshuman Gupta.I have already checked for mem leaks during the cleanup. The
kobject_putis not needed.Thanks,
Suja
Quoted 7 lines
Quoted 7 lines
+
err = drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); if (err) drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed,err: %d\n",
--
2.25.1
Quoted 246 lines · Anshuman
Quoted 228 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Wednesday, December 27, 2023 3:01 PM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 216 lines · Anshuman
Quoted 143 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Tuesday, December 26, 2023 10:02 AM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 73 lines · Anshuman
Quoted 73 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq |-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0
Remove definition ofGT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by: Sujaritha Sundaresan
<[email protected]>--- drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++ drivers/gpu/drm/xe/xe_tile_sysfs.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@#define POWER_SETUP_I1_SHIFT 6/* 10.6 fixed point format */
#define POWER_SETUP_I1_DATA_MASK REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct pcode_err_decode {int errno;const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0@@ -7,9 +7,21 @@#include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h" Quoted 9 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a
configuration.
SureQuoted 41 lines
Quoted 41 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+static void xe_tile_sysfs_kobj_release (struct kobject *kobj) {kfree (kobj);@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct +device_attribute *attr, +char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent); +struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox =REG_FIELD_PREP (PCODE_MB_COMMAND ,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (max_freq); + +static ssize_t min_freq_show (struct device *kdev,struct +device_attributeQuoted 8 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c static const struct kobj_type xe_tile_sysfs_kobj_type = { · line 39
Quoted 5 lines
*attr,
drivers/gpu/drm/xe/xe_tile_sysfs.c +4
-0+ char *buf) +{ +struct kobject *kobj = &kdev->kobj; +struct xe_tile *tile =kobj_to_tile (kobj->parent);If you are missing to create a kobject for freq0 , then this should be
kobj->parent->parent.Quoted 4 lines
I don't think a kobject is needed for freq0, since it we are only using
attribute_groupfor it.Similar to
throttle_reasons.Sure, thanks for explanation.
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +5
-0+struct xe_gt *gt = tile->primary_gt; +u32 val, mbox; +int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,
PCODE_FREQUENCY_CONFIG)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_PN)drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0+ | REG_FIELD_PREP(PCODE_MB_PARAM2,
PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +23
-0+ + err =xe_pcode_read (gt, mbox, &val,NULL ); +if (err) +return err; + +/* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *=50 ; + +return sysfs_emit (buf,"%u\n" , val); }static +DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, +NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name ="freq0" , + .attrs = freq_attrs, +}; +static void tile_sysfs_fini (struct drm_device *drm,void *arg) {struct xe_tile *tile = arg;@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile)struct xe_device *xe =tile_to_xe (tile);struct device *dev = xe->drm.dev;struct kobj_tile *kt; +struct kobject *kobj;int err; kt = kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ void
xe_tile_sysfs_init(struct xe_tile *tile)tile->sysfs = &kt->base;Quoted 22 lines
Quoted 4 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 126
Quoted 2 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (xe->info.platform ==XE_PVC ) { + kobj =kobject_create_and_add ("memory" , tile->sysfs);How freq0 is getting added, I am unable to see the freq0 kobject as per the path
"device/tile#/memory/freq0/"
freq0 is being added as an attribute group. It is similar to thethrottle_reasonsimplementation.Quoted 15 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c void xe_tile_sysfs_init(struct xe_tile *tile) · line 137
Quoted 13 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +2
-0+if (!kobj) + drm_warn(&xe->drm, "failed to add memorydirectory, err: %d\n",
-ENOMEM);drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+ } + +if (kobj && xe->info.platform ==XE_PVC ) { + err =sysfs_create_group (kobj, &freq_group_attrs); +if (err) { + drm_warn(&xe->drm, "failed to register vram freqsysfs, err: %d\n", err);
drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0+return ; + } + }Don't we need sysfs cleanup and
kobject_putintile_sysfs_fini()? Have you made sure kmemleak won't complain here on memory leak ?Quoted 1 line
Check the
kobject_release(), this will only get call , when all ref count of thatQuoted 8 lines
kobj is being put.
Quoted 5 lines
Here you are creating a object and it will never be released. Also we need to call the
sysfs_remove_group()as well in fini function ?Thanks,
Anshuman.This is a bit of unique case. In this file we have two issues that keeps us from cleaning up like others.
Current patch looks broken to me, this will leak the kobject on module unload. Please check kmemleak after module unload.
Quoted 4 lines
One, we need to cleanup the base tile directory here. And second, we are creating the kobject only for PVC. If we add the "memory" kobject cleanup to fini, we will be defining tile using kobj. This is causing an error on unload, despite adding platform conditions on fini.
You may try by changing the type of void *arg to "memory" kob to fini function ?
Quoted 3 lines
After testing multiple iterations of the fini function, this was the cleanest way with no errors that worked across platforms.
Quoted 8 lines
Quoted 3 lines
If needed, the only way to accommodate the kobject_put(kobj) and the
sysfs_remove_groupis to move the vram sysfs creation to a separate file, similar tothrottle_reasonsandgt_freq.I think it is needed for a functional working patch, if it can not be handled by using "void *arg" in fini function.
Thanks,
Anshuman Gupta.
Since this is bit contentious even though the patch is functional, I will move these sysfs out of xe_tile_sysfs.c to it own new file.
This should clear up everything.
Thanks,
Suja
Quoted 22 lines
Quoted 22 lines
Thanks,
Suja
Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
Thanks,
Anshuman Gupta.I have already checked for mem leaks during the cleanup. The
kobject_putis not needed.Thanks,
Suja
Quoted 7 lines
Quoted 7 lines
+
err = drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); if (err) drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed,err: %d\n",
--
2.25.1
Quoted 258 lines · Sujaritha
Quoted 247 lines · Anshuman
Quoted 229 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Wednesday, December 27, 2023 3:01 PM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 215 lines · Anshuman
Quoted 143 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Tuesday, December 26, 2023 10:02 AM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 73 lines · Anshuman
Quoted 73 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq
|-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0 Remove definition of
GT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by: Sujaritha Sundaresan
<[email protected]>
---
drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++drivers/gpu/drm/xe/xe_tile_sysfs.c| 86
++++++++++++++++++++++++++++++2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@ #define POWER_SETUP_I1_SHIFT 6 /* 10.6 fixedpoint format */
#definePOWER_SETUP_I1_DATA_MASK
REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct
pcode_err_decode{
int errno;
const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0@@ -7,9 +7,21 @@ #include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h"Quoted 9 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a
configuration.
SureQuoted 41 lines
Quoted 41 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */
+
static voidxe_tile_sysfs_kobj_release(struct kobject *kobj){ kfree(kobj);drivers/gpu/drm/xe/xe_tile_sysfs.c +12
-0@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct +device_attribute *attr, + char *buf) +{ + struct kobject *kobj = &kdev->kobj; + struct xe_tile *tile = kobj_to_tile(kobj->parent); + struct xe_gt *gt = tile->primary_gt; + u32 val, mbox; + int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)
+ | REG_FIELD_PREP(PCODE_MB_PARAM2,PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+ + err = xe_pcode_read(gt, mbox, &val, NULL); + if (err) + return err; + + /* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *= 50; + + return sysfs_emit(buf, "%u\n", val); } static +DEVICE_ATTR_RO (max_freq); + +static ssize_t min_freq_show (struct device *kdev,struct +device_attributeQuoted 8 lines
Quoted 5 lines
*attr,
+ char *buf)
+{
+ struct kobject *kobj =&kdev->kobj;
+ structxe_tile*tile =kobj_to_tile(kobj->parent);If you are missing to create a kobject for freq0 , then this should be
kobj->parent->parent.Quoted 4 lines
I don't think a kobject is needed for freq0, since it we are only using
attribute_groupfor it.Similar to
throttle_reasons.Sure, thanks for explanation.
Quoted 67 lines
Quoted 45 lines
Quoted 45 lines
+ struct
xe_gt*gt =tile->primary_gt;
+ u32 val, mbox;
+ int err;
+
+ mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,PCODE_FREQUENCY_CONFIG)
+ | REG_FIELD_PREP(PCODE_MB_PARAM1,PCODE_MBOX_FC_SC_READ_FUSED_PN)
+ | REG_FIELD_PREP(PCODE_MB_PARAM2,PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +22
-0+ + err = xe_pcode_read(gt, mbox, &val, NULL); + if (err) + return err; + + /* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *= 50; + + return sysfs_emit(buf, "%u\n", val); } static +DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, + NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name = "freq0", + .attrs = freq_attrs, +}; +static void
tile_sysfs_fini(struct drm_device *drm, void *arg){ structxe_tile*tile = arg;drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile) struct xe_device *xe = tile_to_xe(tile); struct device *dev = xe->drm.dev; struct kobj_tile *kt; + struct kobject *kobj; int err;kt =
kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ voidxe_tile_sysfs_init(struct xe_tile *tile)Quoted 6 lines
Quoted 4 lines
tile->sysfs=&kt->base;+ if (
xe->info.platform==XE_PVC) {
+ kobj =kobject_create_and_add("memory", tile->sysfs);How freq0 is getting added, I am unable to see the freq0 kobject as per the path
"device/tile#/memory/freq0/"
freq0 is being added as an attribute group. It is similar to thethrottle_reasonsimplementation.Quoted 13 lines
Quoted 13 lines
+ if (!kobj)
+drm_warn(&xe->drm, "failed to add memory directory, err: %d\n", -ENOMEM);
+ }
+
+ if (kobj &&xe->info.platform==XE_PVC) {
+ err =sysfs_create_group(kobj, &freq_group_attrs); + if (err) {
+drm_warn(&xe->drm, "failed to register vram freq sysfs, err: %d\n", err);
+ return;
+ }
+ }Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Don't we need sysfs cleanup and
kobject_putintile_sysfs_fini()? Have you made sure kmemleak won't complain here on memory leak ?Check the
kobject_release(), this will only get call , when all ref count of thatQuoted 8 lines
kobj is being put.
Quoted 5 lines
Here you are creating a object and it will never be released. Also we need to call the
sysfs_remove_group()as well in fini function ?Thanks,
Anshuman.This is a bit of unique case. In this file we have two issues that keeps us from cleaning up like others.
Current patch looks broken to me, this will leak the kobject on module unload. Please check kmemleak after module unload.
Quoted 4 lines
One, we need to cleanup the base tile directory here. And second, we are creating the kobject only for PVC. If we add the "memory" kobject cleanup to fini, we will be defining tile using kobj. This is causing an error on unload, despite adding platform conditions on fini.
You may try by changing the type of void *arg to "memory" kob to fini function ?
Quoted 3 lines
After testing multiple iterations of the fini function, this was the cleanest way with no errors that worked across platforms.
Quoted 8 lines
Quoted 3 lines
If needed, the only way to accommodate the
kobject_put(kobj)and thesysfs_remove_groupis to move the vram sysfs creation to a separate file, similar tothrottle_reasonsandgt_freq.I think it is needed for a functional working patch, if it can not be handled by using "void *arg" in fini function.
Thanks,
Anshuman Gupta.
Quoted 7 lines
Since this is bit contentious even though the patch is functional, I will move these sysfs out of
xe_tile_sysfs.cto it own new file.This should clear up everything.
Thanks,
Suja
Hi Anshuman,
I've moved everything to a new file called xe_vram_freq.c/h . All kmemleaks and unload/reload checks are clean.
Let me know if the naming works.
The documentation added is as below, let me know if any tweaks are needed;
/**
* DOC: Xe VRAM freq
*
* Provides sysfs entries for vram frequency in tile
*
* device/tile#/memory/freq0/max_freq - This is maximum frequency. This value is read-only as it
* is the fixed fuse point P0. It is not the system
* configuration frequency.
* device/tile#/memory/freq0/min_freq - This is minimum frequency. This value is read-only as it
* is the fixed fuse point PN. It is not the system
* configuration frequency.
*/
Thanks,
Suja
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Thanks,
Suja
Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
Thanks,
Anshuman Gupta.I have already checked for mem leaks during the cleanup. The
kobject_putis not needed.Thanks,
Suja
Quoted 7 lines
Quoted 7 lines
+
err =drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); if (err)
drm_warn(&xe->drm, "%s:drmm_add_action_or_resetfailed,
err: %d\n",Signature · 1 line
2.25.1
Hi Suja
Quoted 248 lines · Sujaritha
Quoted 246 lines · Sujaritha
Quoted 244 lines · Anshuman
Quoted 229 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Wednesday, December 27, 2023 3:01 PM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 215 lines · Anshuman
Quoted 143 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Tuesday, December 26, 2023 10:02 AM
To: Gupta, Anshuman <[email protected]>; intel- [email protected]
Cc: Vivi, Rodrigo <[email protected]>
Subject: Re: [v6] drm/xe: Add vram frequency sysfs attributesQuoted 73 lines · Anshuman
Quoted 73 lines
-----Original Message-----
From: Sundaresan, Sujaritha <[email protected]>
Sent: Friday, December 22, 2023 4:37 PM
To: [email protected]
Cc: Vivi, Rodrigo <[email protected]>; Gupta, Anshuman <[email protected]>; Sundaresan, Sujaritha <[email protected]>
Subject: [v6] drm/xe: Add vram frequency sysfs attributesAdd vram frequency sysfs attributes under the below hierarchy;
/device/tile#/memory/freq0
|-max_freq
|-min_freqv2: Drop "vram" from attribute names (Rodrigo)
v3: Add documentation for new sysfs (Riana)
Drop prefix fromXEHP_PCODE_FREQUENCY_CONFIG(Riana)v4: Create sysfs under tile#/freq0 after removal of
physical_memsizeattrbutev5: Revert back to creating sysfs under tile#/memory/freq0 Remove definition of
GT_FREQUENCY_MULTIPLIER(Rodrigo)v6: Rename attributes to max/min_freq (Anshuman)
Fix review comments (Rodrigo)Signed-off-by: Sujaritha Sundaresan
<[email protected]>
---
drivers/gpu/drm/xe/xe_pcode_api.h | 7 +++drivers/gpu/drm/xe/xe_tile_sysfs.c| 86
++++++++++++++++++++++++++++++2 files changed, 93 insertions(+)drivers/gpu/drm/xe/xe_pcode_api.h +0
-0@@ -42,6 +42,13 @@ #define POWER_SETUP_I1_SHIFT 6 /* 10.6 fixedpoint format */
#definePOWER_SETUP_I1_DATA_MASK
REG_GENMASK(15, 0)drivers/gpu/drm/xe/xe_pcode_api.h +7
-0+#define PCODE_FREQUENCY_CONFIG 0x6e +/* Frequency Config Sub Commands (param1) */ +#define PCODE_MBOX_FC_SC_READ_FUSED_P0 0x0 +#define PCODE_MBOX_FC_SC_READ_FUSED_PN 0x1 +/* Domain IDs (param2) */ +#define PCODE_MBOX_DOMAIN_HBM 0x2 +struct
pcode_err_decode{
int errno;
const char *str;drivers/gpu/drm/xe/xe_tile_sysfs.c +3
-0@@ -7,9 +7,21 @@ #include <linux/sysfs.h> #include <drm/drm_managed.h> +#include "xe_gt_types.h" +#include "xe_pcode.h" +#include "xe_pcode_api.h" #include "xe_tile.h" #include "xe_tile_sysfs.h"Quoted 9 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_tile_sysfs.c +6
-0+/** +* DOC: Xe Tile sysfs +* +* Provides sysfs entries for frequency in tile +* +* device/tile#/memory/freq0/max_freq - Maximum Frequency, not a configuration and read-only.
Let's increase verbosity of doc something explaining it is a fixed fuse point not a
configuration.
SureQuoted 41 lines
Quoted 41 lines
+ * device/tile#/memory/freq0/min_freq - Minimum Frequency, not a configuration and read-only.
+ */
+
static voidxe_tile_sysfs_kobj_release(struct kobject *kobj){ kfree(kobj);drivers/gpu/drm/xe/xe_tile_sysfs.c +12
-0@@ -20,6 +32,65 @@ static const struct kobj_type xe_tile_sysfs_kobj_type = { .sysfs_ops = &kobj_sysfs_ops, }; +static ssize_t max_freq_show (struct device *kdev,struct +device_attribute *attr, + char *buf) +{ + struct kobject *kobj = &kdev->kobj; + struct xe_tile *tile = kobj_to_tile(kobj->parent); + struct xe_gt *gt = tile->primary_gt; + u32 val, mbox; + int err; + + mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,PCODE_FREQUENCY_CONFIG ) + | REG_FIELD_PREP(PCODE_MB_PARAM1,
PCODE_MBOX_FC_SC_READ_FUSED_P0)
+ | REG_FIELD_PREP(PCODE_MB_PARAM2,PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +13
-0+ + err = xe_pcode_read(gt, mbox, &val, NULL); + if (err) + return err; + + /* data_out - Fused P0 for domain ID in units of 50 MHz */ + val *= 50; + + return sysfs_emit(buf, "%u\n", val); } static +DEVICE_ATTR_RO (max_freq); + +static ssize_t min_freq_show (struct device *kdev,struct +device_attributeQuoted 8 lines
Quoted 5 lines
*attr,
+ char *buf)
+{
+ struct kobject *kobj =&kdev->kobj;
+ structxe_tile*tile =kobj_to_tile(kobj->parent);If you are missing to create a kobject for freq0 , then this should be
kobj->parent->parent.Quoted 4 lines
I don't think a kobject is needed for freq0, since it we are only using
attribute_groupfor it.Similar to
throttle_reasons.Sure, thanks for explanation.
Quoted 67 lines
Quoted 45 lines
Quoted 45 lines
+ struct
xe_gt*gt =tile->primary_gt;
+ u32 val, mbox;
+ int err;
+
+ mbox = REG_FIELD_PREP(PCODE_MB_COMMAND,PCODE_FREQUENCY_CONFIG)
+ | REG_FIELD_PREP(PCODE_MB_PARAM1,PCODE_MBOX_FC_SC_READ_FUSED_PN)
+ | REG_FIELD_PREP(PCODE_MB_PARAM2,PCODE_MBOX_DOMAIN_HBM);drivers/gpu/drm/xe/xe_tile_sysfs.c +22
-0+ + err = xe_pcode_read(gt, mbox, &val, NULL); + if (err) + return err; + + /* data_out - Fused Pn for domain ID in units of 50 MHz */ + val *= 50; + + return sysfs_emit(buf, "%u\n", val); } static +DEVICE_ATTR_RO (min_freq); + +static struct attribute *freq_attrs[] = { + &dev_attr_max_freq.attr, + &dev_attr_min_freq.attr, + NULL +}; + +static const struct attribute_group freq_group_attrs = { + .name = "freq0", + .attrs = freq_attrs, +}; +static void
tile_sysfs_fini(struct drm_device *drm, void *arg){ structxe_tile*tile = arg;drivers/gpu/drm/xe/xe_tile_sysfs.c +1
-0@@ -32,6 +103,7 @@ void xe_tile_sysfs_init(struct xe_tile *tile) struct xe_device *xe = tile_to_xe(tile); struct device *dev = xe->drm.dev; struct kobj_tile *kt; + struct kobject *kobj; int err;kt =
kzalloc(sizeof(*kt), GFP_KERNEL); @@ -50,6 +122,20 @@ voidxe_tile_sysfs_init(struct xe_tile *tile)Quoted 6 lines
Quoted 4 lines
tile->sysfs=&kt->base;+ if (
xe->info.platform==XE_PVC) {
+ kobj =kobject_create_and_add("memory", tile->sysfs);How freq0 is getting added, I am unable to see the freq0 kobject as per the path
"device/tile#/memory/freq0/"
freq0 is being added as an attribute group. It is similar to thethrottle_reasonsimplementation.Quoted 13 lines
Quoted 13 lines
+ if (!kobj)
+drm_warn(&xe->drm, "failed to add memory directory, err: %d\n", -ENOMEM);
+ }
+
+ if (kobj &&xe->info.platform==XE_PVC) {
+ err =sysfs_create_group(kobj, &freq_group_attrs); + if (err) {
+drm_warn(&xe->drm, "failed to register vram freq sysfs, err: %d\n", err);
+ return;
+ }
+ }Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Don't we need sysfs cleanup and
kobject_putintile_sysfs_fini()? Have you made sure kmemleak won't complain here on memory leak ?Check the
kobject_release(), this will only get call , when all ref count of thatQuoted 8 lines
kobj is being put.
Quoted 5 lines
Here you are creating a object and it will never be released. Also we need to call the
sysfs_remove_group()as well in fini function ?Thanks,
Anshuman.This is a bit of unique case. In this file we have two issues that keeps us from cleaning up like others.
Current patch looks broken to me, this will leak the kobject on module unload. Please check kmemleak after module unload.
Quoted 4 lines
One, we need to cleanup the base tile directory here. And second, we are creating the kobject only for PVC. If we add the "memory" kobject cleanup to fini, we will be defining tile using kobj. This is causing an error on unload, despite adding platform conditions on fini.
You may try by changing the type of void *arg to "memory" kob to fini function ?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
After testing multiple iterations of the fini function, this was the cleanest way with no errors that worked across platforms.
If needed, the only way to accommodate the
kobject_put(kobj)and thesysfs_remove_groupis to move the vram sysfs creation to a separate file, similar tothrottle_reasonsandgt_freq.I think it is needed for a functional working patch, if it can not be handled by using "void *arg" in fini function.
I think you can try something similar to the below file xe_hw_engine_class_sysfs.c
Has different functions for different hierarchy of kobjects.
Thanks
Riana
Quoted 60 lines
Quoted 11 lines
Quoted 3 lines
Thanks,
Anshuman Gupta.Since this is bit contentious even though the patch is functional, I will move these sysfs out of
xe_tile_sysfs.cto it own new file.This should clear up everything.
Thanks,
Suja
Hi Anshuman,
I've moved everything to a new file called xe_vram_freq.c/h . All kmemleaks and unload/reload checks are clean.
Let me know if the naming works.
The documentation added is as below, let me know if any tweaks are needed;
/**
* DOC: Xe VRAM freq
*
* Provides sysfs entries for vram frequency in tile
*
* device/tile#/memory/freq0/max_freq - This is maximum frequency. This value is read-only as it
* is the fixed fuse point P0. It is not the system
* configuration frequency.
* device/tile#/memory/freq0/min_freq - This is minimum frequency. This value is read-only as it
* is the fixed fuse point PN. It is not the system
* configuration frequency.
*/Thanks,
Suja
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Thanks,
Suja
Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
Thanks,
Anshuman Gupta.I have already checked for mem leaks during the cleanup. The
kobject_putis not needed.Thanks,
Suja
Quoted 7 lines
Quoted 7 lines
+
err =drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); if (err)
drm_warn(&xe->drm, "%s:drmm_add_action_or_resetfailed,
err: %d\n",Signature · 1 line
2.25.1