[RFC PATCH v3 22/37] mm/damon/sysfs: implement cpumask file under sample filter dir

SeongJae Park
2025-12-08T06:30:22Z

The DAON sample filter directory has files for only common properties.
Add a file to further specify the CPUs to filter in or out.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 74594e6e461c..d6b0b6513fd1 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -758,6 +758,7 @@ struct damon_sysfs_sample_filter {
enum damon_sample_filter_type type;
bool matching;
bool allow;
+ cpumask_t cpumask;
};

static struct damon_sysfs_sample_filter *damon_sysfs_sample_filter_alloc(void)
@@ -765,6 +766,19 @@ static struct damon_sysfs_sample_filter *damon_sysfs_sample_filter_alloc(void)
return kzalloc(sizeof(struct damon_sysfs_sample_filter), GFP_KERNEL);
}

+struct damon_sysfs_sample_filter_type_name {
+ enum damon_sample_filter_type type;
+ char *name;
+};
+
+static const struct damon_sysfs_sample_filter_type_name
+damon_sysfs_sample_filter_type_names[] = {
+ {
+ .type = DAMON_FILTER_TYPE_CPUMASK,
+ .name = "cpumask",
+ },
+};
+
static ssize_t type_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@@ -851,6 +865,29 @@ static ssize_t allow_store(struct kobject *kobj,
return count;
}

+static ssize_t cpumask_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct damon_sysfs_sample_filter *filter = container_of(kobj,
+ struct damon_sysfs_sample_filter, kobj);
+
+ return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(&filter->cpumask));
+}
+
+static ssize_t cpumask_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct damon_sysfs_sample_filter *filter = container_of(kobj,
+ struct damon_sysfs_sample_filter, kobj);
+ cpumask_t cpumask;
+ int err = cpulist_parse(buf, &cpumask);
+
+ if (err)
+ return err;
+ filter->cpumask = cpumask;
+ return count;
+}
+
static void damon_sysfs_sample_filter_release(struct kobject *kobj)
{
struct damon_sysfs_sample_filter *filter = container_of(kobj,
@@ -868,10 +905,14 @@ static struct kobj_attribute damon_sysfs_sample_filter_matching_attr =
static struct kobj_attribute damon_sysfs_sample_filter_allow_attr =
__ATTR_RW_MODE(allow, 0600);

+static struct kobj_attribute damon_sysfs_sample_filter_cpumask_attr =
+ __ATTR_RW_MODE(cpumask, 0600);
+
static struct attribute *damon_sysfs_sample_filter_attrs[] = {
&damon_sysfs_sample_filter_type_attr.attr,
&damon_sysfs_sample_filter_matching_attr.attr,
&damon_sysfs_sample_filter_allow_attr.attr,
+ &damon_sysfs_sample_filter_cpumask_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(damon_sysfs_sample_filter);
--
2.47.3