Commit 5dc1d5c6 authored by Tony luck's avatar Tony luck Committed by Thomas Gleixner

x86/intel_rdt: Simplify info and base file lists

The info directory files and base files need to be different for each
resource like cache and Memory bandwidth. With in each resource, the
files would be further different for monitoring and ctrl. This leads to
a lot of different static array declarations given that we are adding
resctrl monitoring.

Simplify this to one common list of files and then declare a set of
flags to choose the files based on the resource, whether it is info or
base and if it is control type file. This is as a preparation to include
monitoring based info and base files.

No functional change.

[Vikas: Extended the flags to have few bits per category like resource,
	info/base etc]
Signed-off-by: default avatarTony luck <tony.luck@intel.com>
Signed-off-by: default avatarVikas Shivappa <vikas.shivappa@linux.intel.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: ravi.v.shankar@intel.com
Cc: fenghua.yu@intel.com
Cc: peterz@infradead.org
Cc: eranian@google.com
Cc: vikas.shivappa@intel.com
Cc: ak@linux.intel.com
Cc: davidcc@google.com
Cc: reinette.chatre@intel.com
Link: http://lkml.kernel.org/r/1501017287-28083-11-git-send-email-vikas.shivappa@linux.intel.com
parent edf6fa1c
...@@ -83,6 +83,7 @@ struct rdt_resource rdt_resources_all[] = { ...@@ -83,6 +83,7 @@ struct rdt_resource rdt_resources_all[] = {
}, },
.parse_ctrlval = parse_cbm, .parse_ctrlval = parse_cbm,
.format_str = "%d=%0*x", .format_str = "%d=%0*x",
.fflags = RFTYPE_RES_CACHE,
}, },
[RDT_RESOURCE_L3DATA] = [RDT_RESOURCE_L3DATA] =
{ {
...@@ -98,6 +99,7 @@ struct rdt_resource rdt_resources_all[] = { ...@@ -98,6 +99,7 @@ struct rdt_resource rdt_resources_all[] = {
}, },
.parse_ctrlval = parse_cbm, .parse_ctrlval = parse_cbm,
.format_str = "%d=%0*x", .format_str = "%d=%0*x",
.fflags = RFTYPE_RES_CACHE,
}, },
[RDT_RESOURCE_L3CODE] = [RDT_RESOURCE_L3CODE] =
{ {
...@@ -113,6 +115,7 @@ struct rdt_resource rdt_resources_all[] = { ...@@ -113,6 +115,7 @@ struct rdt_resource rdt_resources_all[] = {
}, },
.parse_ctrlval = parse_cbm, .parse_ctrlval = parse_cbm,
.format_str = "%d=%0*x", .format_str = "%d=%0*x",
.fflags = RFTYPE_RES_CACHE,
}, },
[RDT_RESOURCE_L2] = [RDT_RESOURCE_L2] =
{ {
...@@ -128,6 +131,7 @@ struct rdt_resource rdt_resources_all[] = { ...@@ -128,6 +131,7 @@ struct rdt_resource rdt_resources_all[] = {
}, },
.parse_ctrlval = parse_cbm, .parse_ctrlval = parse_cbm,
.format_str = "%d=%0*x", .format_str = "%d=%0*x",
.fflags = RFTYPE_RES_CACHE,
}, },
[RDT_RESOURCE_MBA] = [RDT_RESOURCE_MBA] =
{ {
...@@ -138,6 +142,7 @@ struct rdt_resource rdt_resources_all[] = { ...@@ -138,6 +142,7 @@ struct rdt_resource rdt_resources_all[] = {
.cache_level = 3, .cache_level = 3,
.parse_ctrlval = parse_bw, .parse_ctrlval = parse_bw,
.format_str = "%d=%*d", .format_str = "%d=%*d",
.fflags = RFTYPE_RES_MB,
}, },
}; };
...@@ -233,7 +238,6 @@ static bool rdt_get_mem_config(struct rdt_resource *r) ...@@ -233,7 +238,6 @@ static bool rdt_get_mem_config(struct rdt_resource *r)
return false; return false;
} }
r->data_width = 3; r->data_width = 3;
rdt_get_mba_infofile(r);
r->alloc_capable = true; r->alloc_capable = true;
r->alloc_enabled = true; r->alloc_enabled = true;
...@@ -252,7 +256,6 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r) ...@@ -252,7 +256,6 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
r->cache.cbm_len = eax.split.cbm_len + 1; r->cache.cbm_len = eax.split.cbm_len + 1;
r->default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1; r->default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1;
r->data_width = (r->cache.cbm_len + 3) / 4; r->data_width = (r->cache.cbm_len + 3) / 4;
rdt_get_cache_infofile(r);
r->alloc_capable = true; r->alloc_capable = true;
r->alloc_enabled = true; r->alloc_enabled = true;
} }
......
...@@ -62,6 +62,18 @@ struct rdtgroup { ...@@ -62,6 +62,18 @@ struct rdtgroup {
/* rftype.flags */ /* rftype.flags */
#define RFTYPE_FLAGS_CPUS_LIST 1 #define RFTYPE_FLAGS_CPUS_LIST 1
/*
* Define the file type flags for base and info directories.
*/
#define RFTYPE_INFO BIT(0)
#define RFTYPE_BASE BIT(1)
#define RF_CTRLSHIFT 4
#define RFTYPE_CTRL BIT(RF_CTRLSHIFT)
#define RFTYPE_RES_CACHE BIT(8)
#define RFTYPE_RES_MB BIT(9)
#define RF_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL)
#define RF_CTRL_BASE (RFTYPE_BASE | RFTYPE_CTRL)
/* List of all resource groups */ /* List of all resource groups */
extern struct list_head rdt_all_groups; extern struct list_head rdt_all_groups;
...@@ -75,6 +87,7 @@ int __init rdtgroup_init(void); ...@@ -75,6 +87,7 @@ int __init rdtgroup_init(void);
* @mode: Access mode * @mode: Access mode
* @kf_ops: File operations * @kf_ops: File operations
* @flags: File specific RFTYPE_FLAGS_* flags * @flags: File specific RFTYPE_FLAGS_* flags
* @fflags: File specific RF_* or RFTYPE_* flags
* @seq_show: Show content of the file * @seq_show: Show content of the file
* @write: Write to the file * @write: Write to the file
*/ */
...@@ -83,6 +96,7 @@ struct rftype { ...@@ -83,6 +96,7 @@ struct rftype {
umode_t mode; umode_t mode;
struct kernfs_ops *kf_ops; struct kernfs_ops *kf_ops;
unsigned long flags; unsigned long flags;
unsigned long fflags;
int (*seq_show)(struct kernfs_open_file *of, int (*seq_show)(struct kernfs_open_file *of,
struct seq_file *sf, void *v); struct seq_file *sf, void *v);
...@@ -181,13 +195,12 @@ static inline bool is_llc_occupancy_enabled(void) ...@@ -181,13 +195,12 @@ static inline bool is_llc_occupancy_enabled(void)
* @data_width: Character width of data when displaying * @data_width: Character width of data when displaying
* @domains: All domains for this resource * @domains: All domains for this resource
* @cache: Cache allocation related data * @cache: Cache allocation related data
* @info_files: resctrl info files for the resource
* @nr_info_files: Number of info files
* @format_str: Per resource format string to show domain value * @format_str: Per resource format string to show domain value
* @parse_ctrlval: Per resource function pointer to parse control values * @parse_ctrlval: Per resource function pointer to parse control values
* @evt_list: List of monitoring events * @evt_list: List of monitoring events
* @num_rmid: Number of RMIDs available * @num_rmid: Number of RMIDs available
* @mon_scale: cqm counter * mon_scale = occupancy in bytes * @mon_scale: cqm counter * mon_scale = occupancy in bytes
* @fflags: flags to choose base and info files
*/ */
struct rdt_resource { struct rdt_resource {
bool alloc_enabled; bool alloc_enabled;
...@@ -205,18 +218,15 @@ struct rdt_resource { ...@@ -205,18 +218,15 @@ struct rdt_resource {
struct list_head domains; struct list_head domains;
struct rdt_cache cache; struct rdt_cache cache;
struct rdt_membw membw; struct rdt_membw membw;
struct rftype *info_files;
int nr_info_files;
const char *format_str; const char *format_str;
int (*parse_ctrlval) (char *buf, struct rdt_resource *r, int (*parse_ctrlval) (char *buf, struct rdt_resource *r,
struct rdt_domain *d); struct rdt_domain *d);
struct list_head evt_list; struct list_head evt_list;
int num_rmid; int num_rmid;
unsigned int mon_scale; unsigned int mon_scale;
unsigned long fflags;
}; };
void rdt_get_cache_infofile(struct rdt_resource *r);
void rdt_get_mba_infofile(struct rdt_resource *r);
int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d); int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d);
int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d); int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d);
......
...@@ -125,28 +125,6 @@ static int rdtgroup_add_file(struct kernfs_node *parent_kn, struct rftype *rft) ...@@ -125,28 +125,6 @@ static int rdtgroup_add_file(struct kernfs_node *parent_kn, struct rftype *rft)
return 0; return 0;
} }
static int rdtgroup_add_files(struct kernfs_node *kn, struct rftype *rfts,
int len)
{
struct rftype *rft;
int ret;
lockdep_assert_held(&rdtgroup_mutex);
for (rft = rfts; rft < rfts + len; rft++) {
ret = rdtgroup_add_file(kn, rft);
if (ret)
goto error;
}
return 0;
error:
pr_warn("Failed to add %s, err=%d\n", rft->name, ret);
while (--rft >= rfts)
kernfs_remove_by_name(kn, rft->name);
return ret;
}
static int rdtgroup_seqfile_show(struct seq_file *m, void *arg) static int rdtgroup_seqfile_show(struct seq_file *m, void *arg)
{ {
struct kernfs_open_file *of = m->private; struct kernfs_open_file *of = m->private;
...@@ -476,39 +454,6 @@ static int rdtgroup_tasks_show(struct kernfs_open_file *of, ...@@ -476,39 +454,6 @@ static int rdtgroup_tasks_show(struct kernfs_open_file *of,
return ret; return ret;
} }
/* Files in each rdtgroup */
static struct rftype rdtgroup_base_files[] = {
{
.name = "cpus",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_cpus_write,
.seq_show = rdtgroup_cpus_show,
},
{
.name = "cpus_list",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_cpus_write,
.seq_show = rdtgroup_cpus_show,
.flags = RFTYPE_FLAGS_CPUS_LIST,
},
{
.name = "tasks",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_tasks_write,
.seq_show = rdtgroup_tasks_show,
},
{
.name = "schemata",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_schemata_write,
.seq_show = rdtgroup_schemata_show,
},
};
static int rdt_num_closids_show(struct kernfs_open_file *of, static int rdt_num_closids_show(struct kernfs_open_file *of,
struct seq_file *seq, void *v) struct seq_file *seq, void *v)
{ {
...@@ -564,73 +509,140 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of, ...@@ -564,73 +509,140 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
} }
/* rdtgroup information files for one cache resource. */ /* rdtgroup information files for one cache resource. */
static struct rftype res_cache_info_files[] = { static struct rftype res_common_files[] = {
{ {
.name = "num_closids", .name = "num_closids",
.mode = 0444, .mode = 0444,
.kf_ops = &rdtgroup_kf_single_ops, .kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdt_num_closids_show, .seq_show = rdt_num_closids_show,
.fflags = RF_CTRL_INFO,
}, },
{ {
.name = "cbm_mask", .name = "cbm_mask",
.mode = 0444, .mode = 0444,
.kf_ops = &rdtgroup_kf_single_ops, .kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdt_default_ctrl_show, .seq_show = rdt_default_ctrl_show,
.fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
}, },
{ {
.name = "min_cbm_bits", .name = "min_cbm_bits",
.mode = 0444, .mode = 0444,
.kf_ops = &rdtgroup_kf_single_ops, .kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdt_min_cbm_bits_show, .seq_show = rdt_min_cbm_bits_show,
}, .fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
};
/* rdtgroup information files for memory bandwidth. */
static struct rftype res_mba_info_files[] = {
{
.name = "num_closids",
.mode = 0444,
.kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdt_num_closids_show,
}, },
{ {
.name = "min_bandwidth", .name = "min_bandwidth",
.mode = 0444, .mode = 0444,
.kf_ops = &rdtgroup_kf_single_ops, .kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdt_min_bw_show, .seq_show = rdt_min_bw_show,
.fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
}, },
{ {
.name = "bandwidth_gran", .name = "bandwidth_gran",
.mode = 0444, .mode = 0444,
.kf_ops = &rdtgroup_kf_single_ops, .kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdt_bw_gran_show, .seq_show = rdt_bw_gran_show,
.fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
}, },
{ {
.name = "delay_linear", .name = "delay_linear",
.mode = 0444, .mode = 0444,
.kf_ops = &rdtgroup_kf_single_ops, .kf_ops = &rdtgroup_kf_single_ops,
.seq_show = rdt_delay_linear_show, .seq_show = rdt_delay_linear_show,
.fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
},
{
.name = "cpus",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_cpus_write,
.seq_show = rdtgroup_cpus_show,
.fflags = RFTYPE_BASE,
},
{
.name = "cpus_list",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_cpus_write,
.seq_show = rdtgroup_cpus_show,
.flags = RFTYPE_FLAGS_CPUS_LIST,
.fflags = RFTYPE_BASE,
},
{
.name = "tasks",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_tasks_write,
.seq_show = rdtgroup_tasks_show,
.fflags = RFTYPE_BASE,
},
{
.name = "schemata",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_schemata_write,
.seq_show = rdtgroup_schemata_show,
.fflags = RF_CTRL_BASE,
}, },
}; };
void rdt_get_mba_infofile(struct rdt_resource *r) static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags)
{ {
r->info_files = res_mba_info_files; struct rftype *rfts, *rft;
r->nr_info_files = ARRAY_SIZE(res_mba_info_files); int ret, len;
rfts = res_common_files;
len = ARRAY_SIZE(res_common_files);
lockdep_assert_held(&rdtgroup_mutex);
for (rft = rfts; rft < rfts + len; rft++) {
if ((fflags & rft->fflags) == rft->fflags) {
ret = rdtgroup_add_file(kn, rft);
if (ret)
goto error;
}
}
return 0;
error:
pr_warn("Failed to add %s, err=%d\n", rft->name, ret);
while (--rft >= rfts) {
if ((fflags & rft->fflags) == rft->fflags)
kernfs_remove_by_name(kn, rft->name);
}
return ret;
} }
void rdt_get_cache_infofile(struct rdt_resource *r) static int rdtgroup_mkdir_info_resdir(struct rdt_resource *r, char *name,
unsigned long fflags)
{ {
r->info_files = res_cache_info_files; struct kernfs_node *kn_subdir;
r->nr_info_files = ARRAY_SIZE(res_cache_info_files); int ret;
kn_subdir = kernfs_create_dir(kn_info, name,
kn_info->mode, r);
if (IS_ERR(kn_subdir))
return PTR_ERR(kn_subdir);
kernfs_get(kn_subdir);
ret = rdtgroup_kn_set_ugid(kn_subdir);
if (ret)
return ret;
ret = rdtgroup_add_files(kn_subdir, fflags);
if (!ret)
kernfs_activate(kn_subdir);
return ret;
} }
static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn) static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
{ {
struct kernfs_node *kn_subdir;
struct rftype *res_info_files;
struct rdt_resource *r; struct rdt_resource *r;
int ret, len; unsigned long fflags;
int ret;
/* create the directory */ /* create the directory */
kn_info = kernfs_create_dir(parent_kn, "info", parent_kn->mode, NULL); kn_info = kernfs_create_dir(parent_kn, "info", parent_kn->mode, NULL);
...@@ -639,26 +651,11 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn) ...@@ -639,26 +651,11 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
kernfs_get(kn_info); kernfs_get(kn_info);
for_each_alloc_enabled_rdt_resource(r) { for_each_alloc_enabled_rdt_resource(r) {
kn_subdir = kernfs_create_dir(kn_info, r->name, fflags = r->fflags | RF_CTRL_INFO;
kn_info->mode, r); ret = rdtgroup_mkdir_info_resdir(r, r->name, fflags);
if (IS_ERR(kn_subdir)) {
ret = PTR_ERR(kn_subdir);
goto out_destroy;
}
kernfs_get(kn_subdir);
ret = rdtgroup_kn_set_ugid(kn_subdir);
if (ret) if (ret)
goto out_destroy; goto out_destroy;
res_info_files = r->info_files;
len = r->nr_info_files;
ret = rdtgroup_add_files(kn_subdir, res_info_files, len);
if (ret)
goto out_destroy;
kernfs_activate(kn_subdir);
} }
/* /*
* This extra ref will be put in kernfs_remove() and guarantees * This extra ref will be put in kernfs_remove() and guarantees
* that @rdtgrp->kn is always accessible. * that @rdtgrp->kn is always accessible.
...@@ -1057,8 +1054,7 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -1057,8 +1054,7 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
if (ret) if (ret)
goto out_destroy; goto out_destroy;
ret = rdtgroup_add_files(kn, rdtgroup_base_files, ret = rdtgroup_add_files(kn, RF_CTRL_BASE);
ARRAY_SIZE(rdtgroup_base_files));
if (ret) if (ret)
goto out_destroy; goto out_destroy;
...@@ -1156,8 +1152,7 @@ static int __init rdtgroup_setup_root(void) ...@@ -1156,8 +1152,7 @@ static int __init rdtgroup_setup_root(void)
rdtgroup_default.closid = 0; rdtgroup_default.closid = 0;
list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups); list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups);
ret = rdtgroup_add_files(rdt_root->kn, rdtgroup_base_files, ret = rdtgroup_add_files(rdt_root->kn, RF_CTRL_BASE);
ARRAY_SIZE(rdtgroup_base_files));
if (ret) { if (ret) {
kernfs_destroy_root(rdt_root); kernfs_destroy_root(rdt_root);
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment