public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Reinette Chatre <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, linux-kernel@vger.kernel.org,
	reinette.chatre@intel.com, tglx@linutronix.de, hpa@zytor.com
Subject: [tip:x86/cache] x86/intel_rdt: Initialize new resource group with sane defaults
Date: Tue, 19 Jun 2018 17:16:18 -0700	[thread overview]
Message-ID: <tip-9b72ac2e7a2345b64fa1311078b473698f13bd49@git.kernel.org> (raw)
In-Reply-To: <44af4ecef879e88ec1b74c5decbf5dccaf998866.1528405422.git.reinette.chatre@intel.com>

Commit-ID:  9b72ac2e7a2345b64fa1311078b473698f13bd49
Gitweb:     https://git.kernel.org/tip/9b72ac2e7a2345b64fa1311078b473698f13bd49
Author:     Reinette Chatre <reinette.chatre@intel.com>
AuthorDate: Thu, 7 Jun 2018 14:24:25 -0700
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 20 Jun 2018 00:56:29 +0200

x86/intel_rdt: Initialize new resource group with sane defaults

Currently when a new resource group is created its allocations would be
those that belonged to the resource group to which its closid belonged
previously.

That is, we can encounter a case like:
mkdir newgroup
cat newgroup/schemata
L2:0=ff;1=ff
echo 'L2:0=0xf0;1=0xf0' > newgroup/schemata
cat newgroup/schemata
L2:0=0xf0;1=0xf0
rmdir newgroup
mkdir newnewgroup
cat newnewgroup/schemata
L2:0=0xf0;1=0xf0

When the new group is created it would be reasonable to expect its
allocations to be initialized with all regions that it can possibly use.
At this time these regions would be all that are shareable by other
resource groups as well as regions that are not currently used.
If the available cache region is found to be non-contiguous the
available region is adjusted to enforce validity.

When a new resource group is created the hardware is initialized with
these new default allocations.

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/44af4ecef879e88ec1b74c5decbf5dccaf998866.1528405422.git.reinette.chatre@intel.com

---
 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 115 ++++++++++++++++++++++++++++++-
 1 file changed, 112 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index 35e538eed977..e59c8751293b 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -133,7 +133,7 @@ void closid_free(int closid)
  * Return: true if @closid is currently associated with a resource group,
  * false if @closid is free
  */
-static bool __attribute__ ((unused)) closid_allocated(unsigned int closid)
+static bool closid_allocated(unsigned int closid)
 {
 	return (closid_free_map & (1 << closid)) == 0;
 }
@@ -1799,6 +1799,110 @@ out_destroy:
 	return ret;
 }
 
+/**
+ * cbm_ensure_valid - Enforce validity on provided CBM
+ * @_val:	Candidate CBM
+ * @r:		RDT resource to which the CBM belongs
+ *
+ * The provided CBM represents all cache portions available for use. This
+ * may be represented by a bitmap that does not consist of contiguous ones
+ * and thus be an invalid CBM.
+ * Here the provided CBM is forced to be a valid CBM by only considering
+ * the first set of contiguous bits as valid and clearing all bits.
+ * The intention here is to provide a valid default CBM with which a new
+ * resource group is initialized. The user can follow this with a
+ * modification to the CBM if the default does not satisfy the
+ * requirements.
+ */
+static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r)
+{
+	/*
+	 * Convert the u32 _val to an unsigned long required by all the bit
+	 * operations within this function. No more than 32 bits of this
+	 * converted value can be accessed because all bit operations are
+	 * additionally provided with cbm_len that is initialized during
+	 * hardware enumeration using five bits from the EAX register and
+	 * thus never can exceed 32 bits.
+	 */
+	unsigned long *val = (unsigned long *)_val;
+	unsigned int cbm_len = r->cache.cbm_len;
+	unsigned long first_bit, zero_bit;
+
+	if (*val == 0)
+		return;
+
+	first_bit = find_first_bit(val, cbm_len);
+	zero_bit = find_next_zero_bit(val, cbm_len, first_bit);
+
+	/* Clear any remaining bits to ensure contiguous region */
+	bitmap_clear(val, zero_bit, cbm_len - zero_bit);
+}
+
+/**
+ * rdtgroup_init_alloc - Initialize the new RDT group's allocations
+ *
+ * A new RDT group is being created on an allocation capable (CAT)
+ * supporting system. Set this group up to start off with all usable
+ * allocations. That is, all shareable and unused bits.
+ *
+ * All-zero CBM is invalid. If there are no more shareable bits available
+ * on any domain then the entire allocation will fail.
+ */
+static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
+{
+	u32 used_b = 0, unused_b = 0;
+	u32 closid = rdtgrp->closid;
+	struct rdt_resource *r;
+	enum rdtgrp_mode mode;
+	struct rdt_domain *d;
+	int i, ret;
+	u32 *ctrl;
+
+	for_each_alloc_enabled_rdt_resource(r) {
+		list_for_each_entry(d, &r->domains, list) {
+			d->have_new_ctrl = false;
+			d->new_ctrl = r->cache.shareable_bits;
+			used_b = r->cache.shareable_bits;
+			ctrl = d->ctrl_val;
+			for (i = 0; i < r->num_closid; i++, ctrl++) {
+				if (closid_allocated(i) && i != closid) {
+					mode = rdtgroup_mode_by_closid(i);
+					used_b |= *ctrl;
+					if (mode == RDT_MODE_SHAREABLE)
+						d->new_ctrl |= *ctrl;
+				}
+			}
+			unused_b = used_b ^ (BIT_MASK(r->cache.cbm_len) - 1);
+			unused_b &= BIT_MASK(r->cache.cbm_len) - 1;
+			d->new_ctrl |= unused_b;
+			/*
+			 * Force the initial CBM to be valid, user can
+			 * modify the CBM based on system availability.
+			 */
+			cbm_ensure_valid(&d->new_ctrl, r);
+			if (bitmap_weight((unsigned long *) &d->new_ctrl,
+					  r->cache.cbm_len) <
+					r->cache.min_cbm_bits) {
+				rdt_last_cmd_printf("no space on %s:%d\n",
+						    r->name, d->id);
+				return -ENOSPC;
+			}
+			d->have_new_ctrl = true;
+		}
+	}
+
+	for_each_alloc_enabled_rdt_resource(r) {
+		ret = update_domains(r, rdtgrp->closid);
+		if (ret < 0) {
+			rdt_last_cmd_puts("failed to initialize allocations\n");
+			return ret;
+		}
+		rdtgrp->mode = RDT_MODE_SHAREABLE;
+	}
+
+	return 0;
+}
+
 static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
 			     struct kernfs_node *prgrp_kn,
 			     const char *name, umode_t mode,
@@ -1957,6 +2061,10 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
 	ret = 0;
 
 	rdtgrp->closid = closid;
+	ret = rdtgroup_init_alloc(rdtgrp);
+	if (ret < 0)
+		goto out_id_free;
+
 	list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups);
 
 	if (rdt_mon_capable) {
@@ -1967,15 +2075,16 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
 		ret = mongroup_create_dir(kn, NULL, "mon_groups", NULL);
 		if (ret) {
 			rdt_last_cmd_puts("kernfs subdir error\n");
-			goto out_id_free;
+			goto out_del_list;
 		}
 	}
 
 	goto out_unlock;
 
+out_del_list:
+	list_del(&rdtgrp->rdtgroup_list);
 out_id_free:
 	closid_free(closid);
-	list_del(&rdtgrp->rdtgroup_list);
 out_common_fail:
 	mkdir_rdt_prepare_clean(rdtgrp);
 out_unlock:

  parent reply	other threads:[~2018-06-20  0:16 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29 12:57 [PATCH V5 00/38] Intel(R) Resource Director Technology Cache Pseudo-Locking enabling Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 01/38] x86/intel_rdt: Document new mode, size, and bit_usage Reinette Chatre
2018-06-20  0:12   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 02/38] x86/intel_rdt: Introduce RDT resource group mode Reinette Chatre
2018-06-20  0:13   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 03/38] x86/intel_rdt: Associate mode with each RDT resource group Reinette Chatre
2018-06-20  0:14   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 04/38] x86/intel_rdt: Introduce resource group's mode resctrl file Reinette Chatre
2018-06-20  0:14   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 05/38] x86/intel_rdt: Introduce test to determine if closid is in use Reinette Chatre
2018-06-20  0:15   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 06/38] x86/intel_rdt: Make useful functions available internally Reinette Chatre
2018-06-20  0:15   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 07/38] x86/intel_rdt: Initialize new resource group with sane defaults Reinette Chatre
2018-06-07 21:24   ` [PATCH V6 " Reinette Chatre
2018-06-19 12:31     ` Thomas Gleixner
2018-06-19 16:33       ` Reinette Chatre
2018-06-19 16:53         ` Thomas Gleixner
2018-06-19 17:06           ` Reinette Chatre
2018-06-20  0:16     ` tip-bot for Reinette Chatre [this message]
2018-05-29 12:57 ` [PATCH V5 08/38] x86/intel_rdt: Introduce new "exclusive" mode Reinette Chatre
2018-06-20  0:16   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 09/38] x86/intel_rdt: Enable setting of exclusive mode Reinette Chatre
2018-06-20  0:17   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 10/38] x86/intel_rdt: Making CBM name and type more explicit Reinette Chatre
2018-06-20  0:17   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 11/38] x86/intel_rdt: Support flexible data to parsing callbacks Reinette Chatre
2018-06-20  0:18   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 12/38] x86/intel_rdt: Ensure requested schemata respects mode Reinette Chatre
2018-06-20  0:18   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 13/38] x86/intel_rdt: Introduce "bit_usage" to display cache allocations details Reinette Chatre
2018-06-20  0:19   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 14/38] x86/intel_rdt: Display resource groups' allocations' size in bytes Reinette Chatre
2018-06-20  0:20   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 15/38] x86/intel_rdt: Documentation for Cache Pseudo-Locking Reinette Chatre
2018-06-20  0:20   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 16/38] x86/intel_rdt: Introduce the Cache Pseudo-Locking modes Reinette Chatre
2018-06-20  0:21   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 17/38] x86/intel_rdt: Respect read and write access Reinette Chatre
2018-06-20  0:21   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 18/38] x86/intel_rdt: Add utility to test if tasks assigned to resource group Reinette Chatre
2018-06-20  0:22   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 19/38] x86/intel_rdt: Add utility to restrict/restore access to resctrl files Reinette Chatre
2018-06-20  0:22   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 20/38] x86/intel_rdt: Protect against resource group changes during locking Reinette Chatre
2018-06-20  0:23   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 21/38] x86/intel_rdt: Utilities to restrict/restore access to specific files Reinette Chatre
2018-06-20  0:23   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 22/38] x86/intel_rdt: Add check to determine if monitoring in progress Reinette Chatre
2018-06-20  0:24   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 23/38] x86/intel_rdt: Introduce pseudo-locked region Reinette Chatre
2018-06-20  0:25   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 24/38] x86/intel_rdt: Support enter/exit of locksetup mode Reinette Chatre
2018-06-20  0:25   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 25/38] x86/intel_rdt: Enable entering of pseudo-locksetup mode Reinette Chatre
2018-06-07 21:26   ` [PATCH V6 " Reinette Chatre
2018-06-20  0:26     ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 26/38] x86/intel_rdt: Split resource group removal in two Reinette Chatre
2018-06-20  0:26   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 27/38] x86/intel_rdt: Add utilities to test pseudo-locked region possibility Reinette Chatre
2018-06-01 13:09   ` [PATCH V6 " Reinette Chatre
2018-06-20  0:27     ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 28/38] x86/intel_rdt: Discover supported platforms via prefetch disable bits Reinette Chatre
2018-06-20  0:27   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 29/38] x86/intel_rdt: Pseudo-lock region creation/removal core Reinette Chatre
2018-05-31 21:06   ` [PATCH V6 " Reinette Chatre
2018-06-20  0:28     ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 30/38] x86/intel_rdt: Support creation/removal of pseudo-locked region Reinette Chatre
2018-06-20  0:29   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 31/38] x86/intel_rdt: resctrl files reflect pseudo-locked information Reinette Chatre
2018-06-20  0:29   ` [tip:x86/cache] x86/intel_rdt: Resctrl " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 32/38] x86/intel_rdt: Ensure RDT cleanup on exit Reinette Chatre
2018-06-20  0:30   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 33/38] x86/intel_rdt: Create resctrl debug area Reinette Chatre
2018-06-20  0:30   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:57 ` [PATCH V5 34/38] x86/intel_rdt: Create debugfs files for pseudo-locking testing Reinette Chatre
2018-06-20  0:31   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:58 ` [PATCH V5 35/38] x86/intel_rdt: Create character device exposing pseudo-locked region Reinette Chatre
2018-06-20  0:31   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:58 ` [PATCH V5 36/38] x86/intel_rdt: More precise L2 hit/miss measurements Reinette Chatre
2018-06-20  0:32   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:58 ` [PATCH V5 37/38] x86/intel_rdt: Support L3 cache performance event of Broadwell Reinette Chatre
2018-06-20  0:32   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-05-29 12:58 ` [PATCH V5 38/38] x86/intel_rdt: Limit C-states dynamically when pseudo-locking active Reinette Chatre
2018-06-20  0:33   ` [tip:x86/cache] " tip-bot for Reinette Chatre
2018-06-19 16:57 ` [PATCH V5 00/38] Intel(R) Resource Director Technology Cache Pseudo-Locking enabling Thomas Gleixner
2018-06-19 17:06   ` Reinette Chatre
2018-06-20  6:21     ` Thomas Gleixner
2018-06-20  6:38       ` Reinette Chatre
  -- strict thread matches above, loose matches on Subject: below --
2018-06-22 22:41 [PATCH V7 08/41] x86/intel_rdt: Initialize new resource group with sane defaults Reinette Chatre
2018-06-23 12:10 ` [tip:x86/cache] " tip-bot for Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-9b72ac2e7a2345b64fa1311078b473698f13bd49@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox