aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony luck <tony.luck@intel.com>2017-07-25 17:14:29 -0400
committerThomas Gleixner <tglx@linutronix.de>2017-08-01 16:41:22 -0400
commit5dc1d5c6bac2cfe3420cf353dfb0ef2e543f7c10 (patch)
treeee463657d3c2b7d1ebaf61f010194bc79232bd3a
parentedf6fa1c4a951b3a03e94b63e6483c5d9da3ab11 (diff)
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: Tony luck <tony.luck@intel.com> Signed-off-by: Vikas Shivappa <vikas.shivappa@linux.intel.com> Signed-off-by: Thomas 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
-rw-r--r--arch/x86/kernel/cpu/intel_rdt.c7
-rw-r--r--arch/x86/kernel/cpu/intel_rdt.h22
-rw-r--r--arch/x86/kernel/cpu/intel_rdt_rdtgroup.c187
3 files changed, 112 insertions, 104 deletions
diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c
index d30830a8eafd..7cae4ec75cfe 100644
--- a/arch/x86/kernel/cpu/intel_rdt.c
+++ b/arch/x86/kernel/cpu/intel_rdt.c
@@ -83,6 +83,7 @@ struct rdt_resource rdt_resources_all[] = {
83 }, 83 },
84 .parse_ctrlval = parse_cbm, 84 .parse_ctrlval = parse_cbm,
85 .format_str = "%d=%0*x", 85 .format_str = "%d=%0*x",
86 .fflags = RFTYPE_RES_CACHE,
86 }, 87 },
87 [RDT_RESOURCE_L3DATA] = 88 [RDT_RESOURCE_L3DATA] =
88 { 89 {
@@ -98,6 +99,7 @@ struct rdt_resource rdt_resources_all[] = {
98 }, 99 },
99 .parse_ctrlval = parse_cbm, 100 .parse_ctrlval = parse_cbm,
100 .format_str = "%d=%0*x", 101 .format_str = "%d=%0*x",
102 .fflags = RFTYPE_RES_CACHE,
101 }, 103 },
102 [RDT_RESOURCE_L3CODE] = 104 [RDT_RESOURCE_L3CODE] =
103 { 105 {
@@ -113,6 +115,7 @@ struct rdt_resource rdt_resources_all[] = {
113 }, 115 },
114 .parse_ctrlval = parse_cbm, 116 .parse_ctrlval = parse_cbm,
115 .format_str = "%d=%0*x", 117 .format_str = "%d=%0*x",
118 .fflags = RFTYPE_RES_CACHE,
116 }, 119 },
117 [RDT_RESOURCE_L2] = 120 [RDT_RESOURCE_L2] =
118 { 121 {
@@ -128,6 +131,7 @@ struct rdt_resource rdt_resources_all[] = {
128 }, 131 },
129 .parse_ctrlval = parse_cbm, 132 .parse_ctrlval = parse_cbm,
130 .format_str = "%d=%0*x", 133 .format_str = "%d=%0*x",
134 .fflags = RFTYPE_RES_CACHE,
131 }, 135 },
132 [RDT_RESOURCE_MBA] = 136 [RDT_RESOURCE_MBA] =
133 { 137 {
@@ -138,6 +142,7 @@ struct rdt_resource rdt_resources_all[] = {
138 .cache_level = 3, 142 .cache_level = 3,
139 .parse_ctrlval = parse_bw, 143 .parse_ctrlval = parse_bw,
140 .format_str = "%d=%*d", 144 .format_str = "%d=%*d",
145 .fflags = RFTYPE_RES_MB,
141 }, 146 },
142}; 147};
143 148
@@ -233,7 +238,6 @@ static bool rdt_get_mem_config(struct rdt_resource *r)
233 return false; 238 return false;
234 } 239 }
235 r->data_width = 3; 240 r->data_width = 3;
236 rdt_get_mba_infofile(r);
237 241
238 r->alloc_capable = true; 242 r->alloc_capable = true;
239 r->alloc_enabled = true; 243 r->alloc_enabled = true;
@@ -252,7 +256,6 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
252 r->cache.cbm_len = eax.split.cbm_len + 1; 256 r->cache.cbm_len = eax.split.cbm_len + 1;
253 r->default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1; 257 r->default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1;
254 r->data_width = (r->cache.cbm_len + 3) / 4; 258 r->data_width = (r->cache.cbm_len + 3) / 4;
255 rdt_get_cache_infofile(r);
256 r->alloc_capable = true; 259 r->alloc_capable = true;
257 r->alloc_enabled = true; 260 r->alloc_enabled = true;
258} 261}
diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
index 35bf8eb8437c..aecbe77c8354 100644
--- a/arch/x86/kernel/cpu/intel_rdt.h
+++ b/arch/x86/kernel/cpu/intel_rdt.h
@@ -62,6 +62,18 @@ struct rdtgroup {
62/* rftype.flags */ 62/* rftype.flags */
63#define RFTYPE_FLAGS_CPUS_LIST 1 63#define RFTYPE_FLAGS_CPUS_LIST 1
64 64
65/*
66 * Define the file type flags for base and info directories.
67 */
68#define RFTYPE_INFO BIT(0)
69#define RFTYPE_BASE BIT(1)
70#define RF_CTRLSHIFT 4
71#define RFTYPE_CTRL BIT(RF_CTRLSHIFT)
72#define RFTYPE_RES_CACHE BIT(8)
73#define RFTYPE_RES_MB BIT(9)
74#define RF_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL)
75#define RF_CTRL_BASE (RFTYPE_BASE | RFTYPE_CTRL)
76
65/* List of all resource groups */ 77/* List of all resource groups */
66extern struct list_head rdt_all_groups; 78extern struct list_head rdt_all_groups;
67 79
@@ -75,6 +87,7 @@ int __init rdtgroup_init(void);
75 * @mode: Access mode 87 * @mode: Access mode
76 * @kf_ops: File operations 88 * @kf_ops: File operations
77 * @flags: File specific RFTYPE_FLAGS_* flags 89 * @flags: File specific RFTYPE_FLAGS_* flags
90 * @fflags: File specific RF_* or RFTYPE_* flags
78 * @seq_show: Show content of the file 91 * @seq_show: Show content of the file
79 * @write: Write to the file 92 * @write: Write to the file
80 */ 93 */
@@ -83,6 +96,7 @@ struct rftype {
83 umode_t mode; 96 umode_t mode;
84 struct kernfs_ops *kf_ops; 97 struct kernfs_ops *kf_ops;
85 unsigned long flags; 98 unsigned long flags;
99 unsigned long fflags;
86 100
87 int (*seq_show)(struct kernfs_open_file *of, 101 int (*seq_show)(struct kernfs_open_file *of,
88 struct seq_file *sf, void *v); 102 struct seq_file *sf, void *v);
@@ -181,13 +195,12 @@ static inline bool is_llc_occupancy_enabled(void)
181 * @data_width: Character width of data when displaying 195 * @data_width: Character width of data when displaying
182 * @domains: All domains for this resource 196 * @domains: All domains for this resource
183 * @cache: Cache allocation related data 197 * @cache: Cache allocation related data
184 * @info_files: resctrl info files for the resource
185 * @nr_info_files: Number of info files
186 * @format_str: Per resource format string to show domain value 198 * @format_str: Per resource format string to show domain value
187 * @parse_ctrlval: Per resource function pointer to parse control values 199 * @parse_ctrlval: Per resource function pointer to parse control values
188 * @evt_list: List of monitoring events 200 * @evt_list: List of monitoring events
189 * @num_rmid: Number of RMIDs available 201 * @num_rmid: Number of RMIDs available
190 * @mon_scale: cqm counter * mon_scale = occupancy in bytes 202 * @mon_scale: cqm counter * mon_scale = occupancy in bytes
203 * @fflags: flags to choose base and info files
191 */ 204 */
192struct rdt_resource { 205struct rdt_resource {
193 bool alloc_enabled; 206 bool alloc_enabled;
@@ -205,18 +218,15 @@ struct rdt_resource {
205 struct list_head domains; 218 struct list_head domains;
206 struct rdt_cache cache; 219 struct rdt_cache cache;
207 struct rdt_membw membw; 220 struct rdt_membw membw;
208 struct rftype *info_files;
209 int nr_info_files;
210 const char *format_str; 221 const char *format_str;
211 int (*parse_ctrlval) (char *buf, struct rdt_resource *r, 222 int (*parse_ctrlval) (char *buf, struct rdt_resource *r,
212 struct rdt_domain *d); 223 struct rdt_domain *d);
213 struct list_head evt_list; 224 struct list_head evt_list;
214 int num_rmid; 225 int num_rmid;
215 unsigned int mon_scale; 226 unsigned int mon_scale;
227 unsigned long fflags;
216}; 228};
217 229
218void rdt_get_cache_infofile(struct rdt_resource *r);
219void rdt_get_mba_infofile(struct rdt_resource *r);
220int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d); 230int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d);
221int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d); 231int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d);
222 232
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index ce63d1011e03..7627b31937e9 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -125,28 +125,6 @@ static int rdtgroup_add_file(struct kernfs_node *parent_kn, struct rftype *rft)
125 return 0; 125 return 0;
126} 126}
127 127
128static int rdtgroup_add_files(struct kernfs_node *kn, struct rftype *rfts,
129 int len)
130{
131 struct rftype *rft;
132 int ret;
133
134 lockdep_assert_held(&rdtgroup_mutex);
135
136 for (rft = rfts; rft < rfts + len; rft++) {
137 ret = rdtgroup_add_file(kn, rft);
138 if (ret)
139 goto error;
140 }
141
142 return 0;
143error:
144 pr_warn("Failed to add %s, err=%d\n", rft->name, ret);
145 while (--rft >= rfts)
146 kernfs_remove_by_name(kn, rft->name);
147 return ret;
148}
149
150static int rdtgroup_seqfile_show(struct seq_file *m, void *arg) 128static int rdtgroup_seqfile_show(struct seq_file *m, void *arg)
151{ 129{
152 struct kernfs_open_file *of = m->private; 130 struct kernfs_open_file *of = m->private;
@@ -476,39 +454,6 @@ static int rdtgroup_tasks_show(struct kernfs_open_file *of,
476 return ret; 454 return ret;
477} 455}
478 456
479/* Files in each rdtgroup */
480static struct rftype rdtgroup_base_files[] = {
481 {
482 .name = "cpus",
483 .mode = 0644,
484 .kf_ops = &rdtgroup_kf_single_ops,
485 .write = rdtgroup_cpus_write,
486 .seq_show = rdtgroup_cpus_show,
487 },
488 {
489 .name = "cpus_list",
490 .mode = 0644,
491 .kf_ops = &rdtgroup_kf_single_ops,
492 .write = rdtgroup_cpus_write,
493 .seq_show = rdtgroup_cpus_show,
494 .flags = RFTYPE_FLAGS_CPUS_LIST,
495 },
496 {
497 .name = "tasks",
498 .mode = 0644,
499 .kf_ops = &rdtgroup_kf_single_ops,
500 .write = rdtgroup_tasks_write,
501 .seq_show = rdtgroup_tasks_show,
502 },
503 {
504 .name = "schemata",
505 .mode = 0644,
506 .kf_ops = &rdtgroup_kf_single_ops,
507 .write = rdtgroup_schemata_write,
508 .seq_show = rdtgroup_schemata_show,
509 },
510};
511
512static int rdt_num_closids_show(struct kernfs_open_file *of, 457static int rdt_num_closids_show(struct kernfs_open_file *of,
513 struct seq_file *seq, void *v) 458 struct seq_file *seq, void *v)
514{ 459{
@@ -564,73 +509,140 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
564} 509}
565 510
566/* rdtgroup information files for one cache resource. */ 511/* rdtgroup information files for one cache resource. */
567static struct rftype res_cache_info_files[] = { 512static struct rftype res_common_files[] = {
568 { 513 {
569 .name = "num_closids", 514 .name = "num_closids",
570 .mode = 0444, 515 .mode = 0444,
571 .kf_ops = &rdtgroup_kf_single_ops, 516 .kf_ops = &rdtgroup_kf_single_ops,
572 .seq_show = rdt_num_closids_show, 517 .seq_show = rdt_num_closids_show,
518 .fflags = RF_CTRL_INFO,
573 }, 519 },
574 { 520 {
575 .name = "cbm_mask", 521 .name = "cbm_mask",
576 .mode = 0444, 522 .mode = 0444,
577 .kf_ops = &rdtgroup_kf_single_ops, 523 .kf_ops = &rdtgroup_kf_single_ops,
578 .seq_show = rdt_default_ctrl_show, 524 .seq_show = rdt_default_ctrl_show,
525 .fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
579 }, 526 },
580 { 527 {
581 .name = "min_cbm_bits", 528 .name = "min_cbm_bits",
582 .mode = 0444, 529 .mode = 0444,
583 .kf_ops = &rdtgroup_kf_single_ops, 530 .kf_ops = &rdtgroup_kf_single_ops,
584 .seq_show = rdt_min_cbm_bits_show, 531 .seq_show = rdt_min_cbm_bits_show,
585 }, 532 .fflags = RF_CTRL_INFO | RFTYPE_RES_CACHE,
586};
587
588/* rdtgroup information files for memory bandwidth. */
589static struct rftype res_mba_info_files[] = {
590 {
591 .name = "num_closids",
592 .mode = 0444,
593 .kf_ops = &rdtgroup_kf_single_ops,
594 .seq_show = rdt_num_closids_show,
595 }, 533 },
596 { 534 {
597 .name = "min_bandwidth", 535 .name = "min_bandwidth",
598 .mode = 0444, 536 .mode = 0444,
599 .kf_ops = &rdtgroup_kf_single_ops, 537 .kf_ops = &rdtgroup_kf_single_ops,
600 .seq_show = rdt_min_bw_show, 538 .seq_show = rdt_min_bw_show,
539 .fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
601 }, 540 },
602 { 541 {
603 .name = "bandwidth_gran", 542 .name = "bandwidth_gran",
604 .mode = 0444, 543 .mode = 0444,
605 .kf_ops = &rdtgroup_kf_single_ops, 544 .kf_ops = &rdtgroup_kf_single_ops,
606 .seq_show = rdt_bw_gran_show, 545 .seq_show = rdt_bw_gran_show,
546 .fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
607 }, 547 },
608 { 548 {
609 .name = "delay_linear", 549 .name = "delay_linear",
610 .mode = 0444, 550 .mode = 0444,
611 .kf_ops = &rdtgroup_kf_single_ops, 551 .kf_ops = &rdtgroup_kf_single_ops,
612 .seq_show = rdt_delay_linear_show, 552 .seq_show = rdt_delay_linear_show,
553 .fflags = RF_CTRL_INFO | RFTYPE_RES_MB,
554 },
555 {
556 .name = "cpus",
557 .mode = 0644,
558 .kf_ops = &rdtgroup_kf_single_ops,
559 .write = rdtgroup_cpus_write,
560 .seq_show = rdtgroup_cpus_show,
561 .fflags = RFTYPE_BASE,
562 },
563 {
564 .name = "cpus_list",
565 .mode = 0644,
566 .kf_ops = &rdtgroup_kf_single_ops,
567 .write = rdtgroup_cpus_write,
568 .seq_show = rdtgroup_cpus_show,
569 .flags = RFTYPE_FLAGS_CPUS_LIST,
570 .fflags = RFTYPE_BASE,
571 },
572 {
573 .name = "tasks",
574 .mode = 0644,
575 .kf_ops = &rdtgroup_kf_single_ops,
576 .write = rdtgroup_tasks_write,
577 .seq_show = rdtgroup_tasks_show,
578 .fflags = RFTYPE_BASE,
579 },
580 {
581 .name = "schemata",
582 .mode = 0644,
583 .kf_ops = &rdtgroup_kf_single_ops,
584 .write = rdtgroup_schemata_write,
585 .seq_show = rdtgroup_schemata_show,
586 .fflags = RF_CTRL_BASE,
613 }, 587 },
614}; 588};
615 589
616void rdt_get_mba_infofile(struct rdt_resource *r) 590static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags)
617{ 591{
618 r->info_files = res_mba_info_files; 592 struct rftype *rfts, *rft;
619 r->nr_info_files = ARRAY_SIZE(res_mba_info_files); 593 int ret, len;
594
595 rfts = res_common_files;
596 len = ARRAY_SIZE(res_common_files);
597
598 lockdep_assert_held(&rdtgroup_mutex);
599
600 for (rft = rfts; rft < rfts + len; rft++) {
601 if ((fflags & rft->fflags) == rft->fflags) {
602 ret = rdtgroup_add_file(kn, rft);
603 if (ret)
604 goto error;
605 }
606 }
607
608 return 0;
609error:
610 pr_warn("Failed to add %s, err=%d\n", rft->name, ret);
611 while (--rft >= rfts) {
612 if ((fflags & rft->fflags) == rft->fflags)
613 kernfs_remove_by_name(kn, rft->name);
614 }
615 return ret;
620} 616}
621 617
622void rdt_get_cache_infofile(struct rdt_resource *r) 618static int rdtgroup_mkdir_info_resdir(struct rdt_resource *r, char *name,
619 unsigned long fflags)
623{ 620{
624 r->info_files = res_cache_info_files; 621 struct kernfs_node *kn_subdir;
625 r->nr_info_files = ARRAY_SIZE(res_cache_info_files); 622 int ret;
623
624 kn_subdir = kernfs_create_dir(kn_info, name,
625 kn_info->mode, r);
626 if (IS_ERR(kn_subdir))
627 return PTR_ERR(kn_subdir);
628
629 kernfs_get(kn_subdir);
630 ret = rdtgroup_kn_set_ugid(kn_subdir);
631 if (ret)
632 return ret;
633
634 ret = rdtgroup_add_files(kn_subdir, fflags);
635 if (!ret)
636 kernfs_activate(kn_subdir);
637
638 return ret;
626} 639}
627 640
628static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn) 641static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
629{ 642{
630 struct kernfs_node *kn_subdir;
631 struct rftype *res_info_files;
632 struct rdt_resource *r; 643 struct rdt_resource *r;
633 int ret, len; 644 unsigned long fflags;
645 int ret;
634 646
635 /* create the directory */ 647 /* create the directory */
636 kn_info = kernfs_create_dir(parent_kn, "info", parent_kn->mode, NULL); 648 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 kernfs_get(kn_info); 651 kernfs_get(kn_info);
640 652
641 for_each_alloc_enabled_rdt_resource(r) { 653 for_each_alloc_enabled_rdt_resource(r) {
642 kn_subdir = kernfs_create_dir(kn_info, r->name, 654 fflags = r->fflags | RF_CTRL_INFO;
643 kn_info->mode, r); 655 ret = rdtgroup_mkdir_info_resdir(r, r->name, fflags);
644 if (IS_ERR(kn_subdir)) {
645 ret = PTR_ERR(kn_subdir);
646 goto out_destroy;
647 }
648 kernfs_get(kn_subdir);
649 ret = rdtgroup_kn_set_ugid(kn_subdir);
650 if (ret) 656 if (ret)
651 goto out_destroy; 657 goto out_destroy;
652
653 res_info_files = r->info_files;
654 len = r->nr_info_files;
655
656 ret = rdtgroup_add_files(kn_subdir, res_info_files, len);
657 if (ret)
658 goto out_destroy;
659 kernfs_activate(kn_subdir);
660 } 658 }
661
662 /* 659 /*
663 * This extra ref will be put in kernfs_remove() and guarantees 660 * This extra ref will be put in kernfs_remove() and guarantees
664 * that @rdtgrp->kn is always accessible. 661 * that @rdtgrp->kn is always accessible.
@@ -1057,8 +1054,7 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
1057 if (ret) 1054 if (ret)
1058 goto out_destroy; 1055 goto out_destroy;
1059 1056
1060 ret = rdtgroup_add_files(kn, rdtgroup_base_files, 1057 ret = rdtgroup_add_files(kn, RF_CTRL_BASE);
1061 ARRAY_SIZE(rdtgroup_base_files));
1062 if (ret) 1058 if (ret)
1063 goto out_destroy; 1059 goto out_destroy;
1064 1060
@@ -1156,8 +1152,7 @@ static int __init rdtgroup_setup_root(void)
1156 rdtgroup_default.closid = 0; 1152 rdtgroup_default.closid = 0;
1157 list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups); 1153 list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups);
1158 1154
1159 ret = rdtgroup_add_files(rdt_root->kn, rdtgroup_base_files, 1155 ret = rdtgroup_add_files(rdt_root->kn, RF_CTRL_BASE);
1160 ARRAY_SIZE(rdtgroup_base_files));
1161 if (ret) { 1156 if (ret) {
1162 kernfs_destroy_root(rdt_root); 1157 kernfs_destroy_root(rdt_root);
1163 goto out; 1158 goto out;