Skip to content

Commit d48d7a5

Browse files
rchatreKAGA-KOKO
authored andcommitted
x86/intel_rdt: Introduce resource group's mode resctrl file
A new resctrl file "mode" associated with each resource group is introduced. This file will display the resource group's current mode and an administrator can also use it to modify the resource group's mode. Only shareable mode is currently supported. Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: fenghua.yu@intel.com Cc: tony.luck@intel.com Cc: vikas.shivappa@linux.intel.com Cc: gavin.hindman@intel.com Cc: jithu.joseph@intel.com Cc: dave.hansen@intel.com Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/20ab78fda26a8c8d98e18ec555f6a1f728948972.1529706536.git.reinette.chatre@intel.com
1 parent 472ef09 commit d48d7a5

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

arch/x86/kernel/cpu/intel_rdt_rdtgroup.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ enum rdtgrp_mode rdtgroup_mode_by_closid(int closid)
147147
return RDT_NUM_MODES;
148148
}
149149

150+
static const char * const rdt_mode_str[] = {
151+
[RDT_MODE_SHAREABLE] = "shareable",
152+
};
153+
154+
/**
155+
* rdtgroup_mode_str - Return the string representation of mode
156+
* @mode: the resource group mode as &enum rdtgroup_mode
157+
*
158+
* Return: string representation of valid mode, "unknown" otherwise
159+
*/
160+
static const char *rdtgroup_mode_str(enum rdtgrp_mode mode)
161+
{
162+
if (mode < RDT_MODE_SHAREABLE || mode >= RDT_NUM_MODES)
163+
return "unknown";
164+
165+
return rdt_mode_str[mode];
166+
}
167+
150168
/* set uid and gid of rdtgroup dirs and files to that of the creator */
151169
static int rdtgroup_kn_set_ugid(struct kernfs_node *kn)
152170
{
@@ -761,6 +779,63 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
761779
return nbytes;
762780
}
763781

782+
/*
783+
* rdtgroup_mode_show - Display mode of this resource group
784+
*/
785+
static int rdtgroup_mode_show(struct kernfs_open_file *of,
786+
struct seq_file *s, void *v)
787+
{
788+
struct rdtgroup *rdtgrp;
789+
790+
rdtgrp = rdtgroup_kn_lock_live(of->kn);
791+
if (!rdtgrp) {
792+
rdtgroup_kn_unlock(of->kn);
793+
return -ENOENT;
794+
}
795+
796+
seq_printf(s, "%s\n", rdtgroup_mode_str(rdtgrp->mode));
797+
798+
rdtgroup_kn_unlock(of->kn);
799+
return 0;
800+
}
801+
802+
static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
803+
char *buf, size_t nbytes, loff_t off)
804+
{
805+
struct rdtgroup *rdtgrp;
806+
enum rdtgrp_mode mode;
807+
int ret = 0;
808+
809+
/* Valid input requires a trailing newline */
810+
if (nbytes == 0 || buf[nbytes - 1] != '\n')
811+
return -EINVAL;
812+
buf[nbytes - 1] = '\0';
813+
814+
rdtgrp = rdtgroup_kn_lock_live(of->kn);
815+
if (!rdtgrp) {
816+
rdtgroup_kn_unlock(of->kn);
817+
return -ENOENT;
818+
}
819+
820+
rdt_last_cmd_clear();
821+
822+
mode = rdtgrp->mode;
823+
824+
if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE))
825+
goto out;
826+
827+
if (!strcmp(buf, "shareable")) {
828+
rdtgrp->mode = RDT_MODE_SHAREABLE;
829+
} else {
830+
rdt_last_cmd_printf("unknown/unsupported mode\n");
831+
ret = -EINVAL;
832+
}
833+
834+
out:
835+
rdtgroup_kn_unlock(of->kn);
836+
return ret ?: nbytes;
837+
}
838+
764839
/* rdtgroup information files for one cache resource. */
765840
static struct rftype res_common_files[] = {
766841
{
@@ -874,6 +949,14 @@ static struct rftype res_common_files[] = {
874949
.seq_show = rdtgroup_schemata_show,
875950
.fflags = RF_CTRL_BASE,
876951
},
952+
{
953+
.name = "mode",
954+
.mode = 0644,
955+
.kf_ops = &rdtgroup_kf_single_ops,
956+
.write = rdtgroup_mode_write,
957+
.seq_show = rdtgroup_mode_show,
958+
.fflags = RF_CTRL_BASE,
959+
},
877960
};
878961

879962
static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags)

0 commit comments

Comments
 (0)