Skip to content

Commit

Permalink
x86/intel_rdt: Introduce resource group's mode resctrl file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Reinette Chatre authored and Thomas Gleixner committed Jun 23, 2018
1 parent 472ef09 commit d48d7a5
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ enum rdtgrp_mode rdtgroup_mode_by_closid(int closid)
return RDT_NUM_MODES;
}

static const char * const rdt_mode_str[] = {
[RDT_MODE_SHAREABLE] = "shareable",
};

/**
* rdtgroup_mode_str - Return the string representation of mode
* @mode: the resource group mode as &enum rdtgroup_mode
*
* Return: string representation of valid mode, "unknown" otherwise
*/
static const char *rdtgroup_mode_str(enum rdtgrp_mode mode)
{
if (mode < RDT_MODE_SHAREABLE || mode >= RDT_NUM_MODES)
return "unknown";

return rdt_mode_str[mode];
}

/* set uid and gid of rdtgroup dirs and files to that of the creator */
static int rdtgroup_kn_set_ugid(struct kernfs_node *kn)
{
Expand Down Expand Up @@ -761,6 +779,63 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
return nbytes;
}

/*
* rdtgroup_mode_show - Display mode of this resource group
*/
static int rdtgroup_mode_show(struct kernfs_open_file *of,
struct seq_file *s, void *v)
{
struct rdtgroup *rdtgrp;

rdtgrp = rdtgroup_kn_lock_live(of->kn);
if (!rdtgrp) {
rdtgroup_kn_unlock(of->kn);
return -ENOENT;
}

seq_printf(s, "%s\n", rdtgroup_mode_str(rdtgrp->mode));

rdtgroup_kn_unlock(of->kn);
return 0;
}

static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
struct rdtgroup *rdtgrp;
enum rdtgrp_mode mode;
int ret = 0;

/* Valid input requires a trailing newline */
if (nbytes == 0 || buf[nbytes - 1] != '\n')
return -EINVAL;
buf[nbytes - 1] = '\0';

rdtgrp = rdtgroup_kn_lock_live(of->kn);
if (!rdtgrp) {
rdtgroup_kn_unlock(of->kn);
return -ENOENT;
}

rdt_last_cmd_clear();

mode = rdtgrp->mode;

if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE))
goto out;

if (!strcmp(buf, "shareable")) {
rdtgrp->mode = RDT_MODE_SHAREABLE;
} else {
rdt_last_cmd_printf("unknown/unsupported mode\n");
ret = -EINVAL;
}

out:
rdtgroup_kn_unlock(of->kn);
return ret ?: nbytes;
}

/* rdtgroup information files for one cache resource. */
static struct rftype res_common_files[] = {
{
Expand Down Expand Up @@ -874,6 +949,14 @@ static struct rftype res_common_files[] = {
.seq_show = rdtgroup_schemata_show,
.fflags = RF_CTRL_BASE,
},
{
.name = "mode",
.mode = 0644,
.kf_ops = &rdtgroup_kf_single_ops,
.write = rdtgroup_mode_write,
.seq_show = rdtgroup_mode_show,
.fflags = RF_CTRL_BASE,
},
};

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

0 comments on commit d48d7a5

Please sign in to comment.