提交 98418b13 编写于 作者: R Ravi Bangoria 提交者: Xie Haocheng

perf/amd/ibs: Use ->is_visible callback for dynamic attributes

mainline inclusion
from mainline-v5.15
commit 2a7a7e65
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5S3WV
CVE: NA

-------------------------------------------------

Currently, some attributes are added at build time whereas others
at boot time depending on IBS pmu capabilities. Instead, we can
just add all attribute groups at build time but hide individual
group at boot time using more appropriate ->is_visible() callback.

Also, struct perf_ibs has bunch of fields for pmu attributes which
just pass on the pointer, does not do anything else. Remove them.
Signed-off-by: NRavi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220509044914.1473-3-ravi.bangoria@amd.comSigned-off-by: NXie Haocheng <haocheng.xie@amd.com>
上级 e134ca6d
...@@ -94,10 +94,6 @@ struct perf_ibs { ...@@ -94,10 +94,6 @@ struct perf_ibs {
unsigned int fetch_ignore_if_zero_rip : 1; unsigned int fetch_ignore_if_zero_rip : 1;
struct cpu_perf_ibs __percpu *pcpu; struct cpu_perf_ibs __percpu *pcpu;
struct attribute **format_attrs;
struct attribute_group format_group;
const struct attribute_group *attr_groups[2];
u64 (*get_count)(u64 config); u64 (*get_count)(u64 config);
}; };
...@@ -528,16 +524,61 @@ static void perf_ibs_del(struct perf_event *event, int flags) ...@@ -528,16 +524,61 @@ static void perf_ibs_del(struct perf_event *event, int flags)
static void perf_ibs_read(struct perf_event *event) { } static void perf_ibs_read(struct perf_event *event) { }
/*
* We need to initialize with empty group if all attributes in the
* group are dynamic.
*/
static struct attribute *attrs_empty[] = {
NULL,
};
static struct attribute_group empty_format_group = {
.name = "format",
.attrs = attrs_empty,
};
static const struct attribute_group *empty_attr_groups[] = {
&empty_format_group,
NULL,
};
PMU_FORMAT_ATTR(rand_en, "config:57"); PMU_FORMAT_ATTR(rand_en, "config:57");
PMU_FORMAT_ATTR(cnt_ctl, "config:19"); PMU_FORMAT_ATTR(cnt_ctl, "config:19");
static struct attribute *ibs_fetch_format_attrs[] = { static struct attribute *rand_en_attrs[] = {
&format_attr_rand_en.attr, &format_attr_rand_en.attr,
NULL, NULL,
}; };
static struct attribute *ibs_op_format_attrs[] = { static struct attribute_group group_rand_en = {
NULL, /* &format_attr_cnt_ctl.attr if IBS_CAPS_OPCNT */ .name = "format",
.attrs = rand_en_attrs,
};
static const struct attribute_group *fetch_attr_groups[] = {
&group_rand_en,
NULL,
};
static umode_t
cnt_ctl_is_visible(struct kobject *kobj, struct attribute *attr, int i)
{
return ibs_caps & IBS_CAPS_OPCNT ? attr->mode : 0;
}
static struct attribute *cnt_ctl_attrs[] = {
&format_attr_cnt_ctl.attr,
NULL,
};
static struct attribute_group group_cnt_ctl = {
.name = "format",
.attrs = cnt_ctl_attrs,
.is_visible = cnt_ctl_is_visible,
};
static const struct attribute_group *op_attr_update[] = {
&group_cnt_ctl,
NULL, NULL,
}; };
...@@ -561,7 +602,6 @@ static struct perf_ibs perf_ibs_fetch = { ...@@ -561,7 +602,6 @@ static struct perf_ibs perf_ibs_fetch = {
.max_period = IBS_FETCH_MAX_CNT << 4, .max_period = IBS_FETCH_MAX_CNT << 4,
.offset_mask = { MSR_AMD64_IBSFETCH_REG_MASK }, .offset_mask = { MSR_AMD64_IBSFETCH_REG_MASK },
.offset_max = MSR_AMD64_IBSFETCH_REG_COUNT, .offset_max = MSR_AMD64_IBSFETCH_REG_COUNT,
.format_attrs = ibs_fetch_format_attrs,
.get_count = get_ibs_fetch_count, .get_count = get_ibs_fetch_count,
}; };
...@@ -587,7 +627,6 @@ static struct perf_ibs perf_ibs_op = { ...@@ -587,7 +627,6 @@ static struct perf_ibs perf_ibs_op = {
.max_period = IBS_OP_MAX_CNT << 4, .max_period = IBS_OP_MAX_CNT << 4,
.offset_mask = { MSR_AMD64_IBSOP_REG_MASK }, .offset_mask = { MSR_AMD64_IBSOP_REG_MASK },
.offset_max = MSR_AMD64_IBSOP_REG_COUNT, .offset_max = MSR_AMD64_IBSOP_REG_COUNT,
.format_attrs = ibs_op_format_attrs,
.get_count = get_ibs_op_count, .get_count = get_ibs_op_count,
}; };
...@@ -757,17 +796,6 @@ static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name) ...@@ -757,17 +796,6 @@ static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name)
perf_ibs->pcpu = pcpu; perf_ibs->pcpu = pcpu;
/* register attributes */
if (perf_ibs->format_attrs[0]) {
memset(&perf_ibs->format_group, 0, sizeof(perf_ibs->format_group));
perf_ibs->format_group.name = "format";
perf_ibs->format_group.attrs = perf_ibs->format_attrs;
memset(&perf_ibs->attr_groups, 0, sizeof(perf_ibs->attr_groups));
perf_ibs->attr_groups[0] = &perf_ibs->format_group;
perf_ibs->pmu.attr_groups = perf_ibs->attr_groups;
}
ret = perf_pmu_register(&perf_ibs->pmu, name, -1); ret = perf_pmu_register(&perf_ibs->pmu, name, -1);
if (ret) { if (ret) {
perf_ibs->pcpu = NULL; perf_ibs->pcpu = NULL;
...@@ -779,7 +807,6 @@ static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name) ...@@ -779,7 +807,6 @@ static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name)
static __init int perf_event_ibs_init(void) static __init int perf_event_ibs_init(void)
{ {
struct attribute **attr = ibs_op_format_attrs;
int ret; int ret;
/* /*
...@@ -792,14 +819,14 @@ static __init int perf_event_ibs_init(void) ...@@ -792,14 +819,14 @@ static __init int perf_event_ibs_init(void)
if (boot_cpu_data.x86 == 0x19 && boot_cpu_data.x86_model < 0x10) if (boot_cpu_data.x86 == 0x19 && boot_cpu_data.x86_model < 0x10)
perf_ibs_fetch.fetch_ignore_if_zero_rip = 1; perf_ibs_fetch.fetch_ignore_if_zero_rip = 1;
perf_ibs_fetch.pmu.attr_groups = fetch_attr_groups;
ret = perf_ibs_pmu_init(&perf_ibs_fetch, "ibs_fetch"); ret = perf_ibs_pmu_init(&perf_ibs_fetch, "ibs_fetch");
if (ret) if (ret)
return ret; return ret;
if (ibs_caps & IBS_CAPS_OPCNT) { if (ibs_caps & IBS_CAPS_OPCNT)
perf_ibs_op.config_mask |= IBS_OP_CNT_CTL; perf_ibs_op.config_mask |= IBS_OP_CNT_CTL;
*attr++ = &format_attr_cnt_ctl.attr;
}
if (ibs_caps & IBS_CAPS_OPCNTEXT) { if (ibs_caps & IBS_CAPS_OPCNTEXT) {
perf_ibs_op.max_period |= IBS_OP_MAX_CNT_EXT_MASK; perf_ibs_op.max_period |= IBS_OP_MAX_CNT_EXT_MASK;
...@@ -807,6 +834,9 @@ static __init int perf_event_ibs_init(void) ...@@ -807,6 +834,9 @@ static __init int perf_event_ibs_init(void)
perf_ibs_op.cnt_mask |= IBS_OP_MAX_CNT_EXT_MASK; perf_ibs_op.cnt_mask |= IBS_OP_MAX_CNT_EXT_MASK;
} }
perf_ibs_op.pmu.attr_groups = empty_attr_groups;
perf_ibs_op.pmu.attr_update = op_attr_update;
ret = perf_ibs_pmu_init(&perf_ibs_op, "ibs_op"); ret = perf_ibs_pmu_init(&perf_ibs_op, "ibs_op");
if (ret) if (ret)
goto err_op; goto err_op;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册