From: Hendrik Wuethrich <whendrik@google.com>
To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com,
eduardo@habkost.net, richard.henderson@linaro.org,
marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com
Cc: peternewman@google.com, "Hendrik Wüthrich" <whendrik@google.com>
Subject: [PATCH v2 3/8] i386: Add RDT functionality
Date: Thu, 5 Sep 2024 11:22:32 +0000 [thread overview]
Message-ID: <20240905112237.3586972-4-whendrik@google.com> (raw)
In-Reply-To: <20240905112237.3586972-1-whendrik@google.com>
From: Hendrik Wüthrich <whendrik@google.com>
Add RDT code to Associate CLOSID with RMID / set RMID for monitoring,
write COS, and read monitoring data. This patch does not add code for
the guest to interact through these things with MSRs, only the actual
ability for the RDT device to do them.
Signed-off-by: Hendrik Wüthrich <whendrik@google.com>
---
hw/i386/rdt.c | 124 ++++++++++++++++++++++++++++++++++++++++++
include/hw/i386/rdt.h | 16 ++++++
2 files changed, 140 insertions(+)
diff --git a/hw/i386/rdt.c b/hw/i386/rdt.c
index c395ab91a9..288f1fd107 100644
--- a/hw/i386/rdt.c
+++ b/hw/i386/rdt.c
@@ -21,6 +21,11 @@
#include "qom/object.h"
#include "target/i386/cpu.h"
+/* RDT Monitoring Event Codes */
+#define RDT_EVENT_L3_OCCUPANCY 1
+#define RDT_EVENT_L3_REMOTE_BW 2
+#define RDT_EVENT_L3_LOCAL_BW 3
+
/* Max counts for allocation masks or CBMs. In other words, the size of respective MSRs*/
#define RDT_MAX_L3_MASK_COUNT 128
#define RDT_MAX_L2_MASK_COUNT 48
@@ -29,6 +34,9 @@
#define TYPE_RDT "rdt"
#define RDT_NUM_RMID_PROP "rmids"
+#define QM_CTR_ERROR (1ULL << 63)
+#define QM_CTR_UNAVAILABLE (1ULL << 62)
+
OBJECT_DECLARE_TYPE(RDTState, RDTStateClass, RDT);
struct RDTMonitor {
@@ -69,6 +77,122 @@ struct RDTState {
struct RDTStateClass {
};
+bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc) {
+ X86CPU *cpu = X86_CPU(current_cpu);
+ RDTStatePerCore *rdt = cpu->rdt;
+ RDTAllocation *alloc;
+
+ uint32_t cos_id = (msr_ia32_pqr_assoc & 0xffff0000) >> 16;
+ uint32_t rmid = msr_ia32_pqr_assoc & 0xffff;
+
+ if (cos_id > RDT_MAX_L3_MASK_COUNT || cos_id > RDT_MAX_L2_MASK_COUNT ||
+ cos_id > RDT_MAX_MBA_THRTL_COUNT || rmid > rdt_max_rmid(rdt)) {
+ return false;
+ }
+
+ rdt->active_rmid = rmid;
+
+ alloc = &rdt->rdtstate->allocations[rmid];
+
+ alloc->active_cos = cos_id;
+
+ return true;
+}
+
+uint32_t rdt_read_l3_mask(uint32_t pos)
+{
+ X86CPU *cpu = X86_CPU(current_cpu);
+ RDTStatePerCore *rdt = cpu->rdt;
+
+ uint32_t val = rdt->rdtstate->msr_L3_ia32_mask_n[pos];
+ return val;
+}
+
+uint32_t rdt_read_l2_mask(uint32_t pos)
+{
+ X86CPU *cpu = X86_CPU(current_cpu);
+ RDTStatePerCore *rdt = cpu->rdt;
+
+ uint32_t val = rdt->rdtstate->msr_L2_ia32_mask_n[pos];
+ return val;
+}
+
+uint32_t rdt_read_mba_thrtl(uint32_t pos)
+{
+ X86CPU *cpu = X86_CPU(current_cpu);
+ RDTStatePerCore *rdt = cpu->rdt;
+
+ uint32_t val = rdt->rdtstate->ia32_L2_qos_ext_bw_thrtl_n[pos];
+ return val;
+}
+
+void rdt_write_msr_l3_mask(uint32_t pos, uint32_t val) {
+ X86CPU *cpu = X86_CPU(current_cpu);
+ RDTStatePerCore *rdt = cpu->rdt;
+
+ rdt->rdtstate->msr_L3_ia32_mask_n[pos] = val;
+}
+
+void rdt_write_msr_l2_mask(uint32_t pos, uint32_t val) {
+ X86CPU *cpu = X86_CPU(current_cpu);
+ RDTStatePerCore *rdt = cpu->rdt;
+
+ rdt->rdtstate->msr_L2_ia32_mask_n[pos] = val;
+}
+
+void rdt_write_mba_thrtl(uint32_t pos, uint32_t val) {
+ X86CPU *cpu = X86_CPU(current_cpu);
+ RDTStatePerCore *rdt = cpu->rdt;
+
+ rdt->rdtstate->ia32_L2_qos_ext_bw_thrtl_n[pos] = val;
+}
+
+uint32_t rdt_max_rmid(RDTStatePerCore *rdt)
+{
+ RDTState *rdtdev = rdt->rdtstate;
+ return rdtdev->rmids - 1;
+}
+
+uint64_t rdt_read_event_count(RDTStatePerCore *rdtInstance, uint32_t rmid, uint32_t event_id)
+{
+ CPUState *cs;
+ RDTMonitor *mon;
+ RDTState *rdt = rdtInstance->rdtstate;
+
+ uint32_t count_l3 = 0;
+ uint32_t count_local = 0;
+ uint32_t count_remote = 0;
+
+ if (!rdt) {
+ return 0;
+ }
+
+ CPU_FOREACH(cs) {
+ rdtInstance = &rdt->rdtInstances[cs->cpu_index];
+ if (rmid >= rdtInstance->monitors->len) {
+ return QM_CTR_ERROR;
+ }
+ mon = &g_array_index(rdtInstance->monitors, RDTMonitor, rmid);
+ count_l3 += mon->count_l3;
+ count_local += mon->count_local;
+ count_remote += mon->count_remote;
+ }
+
+ switch (event_id) {
+ case RDT_EVENT_L3_OCCUPANCY:
+ return count_l3 == 0 ? QM_CTR_UNAVAILABLE : count_l3;
+ break;
+ case RDT_EVENT_L3_REMOTE_BW:
+ return count_remote == 0 ? QM_CTR_UNAVAILABLE : count_remote;
+ break;
+ case RDT_EVENT_L3_LOCAL_BW:
+ return count_local == 0 ? QM_CTR_UNAVAILABLE : count_local;
+ break;
+ default:
+ return QM_CTR_ERROR;
+ }
+}
+
OBJECT_DEFINE_TYPE(RDTState, rdt, RDT, ISA_DEVICE);
static Property rdt_properties[] = {
diff --git a/include/hw/i386/rdt.h b/include/hw/i386/rdt.h
index a21d95b265..14b1c64b72 100644
--- a/include/hw/i386/rdt.h
+++ b/include/hw/i386/rdt.h
@@ -17,9 +17,25 @@
#ifndef HW_RDT_H
#define HW_RDT_H
+#include <stdbool.h>
+#include <stdint.h>
+
typedef struct RDTState RDTState;
typedef struct RDTStatePerCore RDTStatePerCore;
typedef struct RDTMonitor RDTMonitor;
typedef struct RDTAllocation RDTAllocation;
+bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc);
+
+void rdt_write_msr_l3_mask(uint32_t pos, uint32_t val);
+void rdt_write_msr_l2_mask(uint32_t pos, uint32_t val);
+void rdt_write_mba_thrtl(uint32_t pos, uint32_t val);
+
+uint32_t rdt_read_l3_mask(uint32_t pos);
+uint32_t rdt_read_l2_mask(uint32_t pos);
+uint32_t rdt_read_mba_thrtl(uint32_t pos);
+
+uint64_t rdt_read_event_count(RDTStatePerCore *rdt, uint32_t rmid, uint32_t event_id);
+uint32_t rdt_max_rmid(RDTStatePerCore *rdt);
+
#endif
--
2.46.0.469.g59c65b2a67-goog
next prev parent reply other threads:[~2024-09-05 11:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 11:22 [PATCH v2 0/8] target:386/ Emulate Intel RDT features needed to mount ResCtrl in Linux Hendrik Wuethrich
2024-09-05 11:22 ` [PATCH v2 1/8] i386: Add Intel RDT device and State to config Hendrik Wuethrich
2024-09-05 11:22 ` [PATCH v2 2/8] i386: Add init and realize functionality for RDT device Hendrik Wuethrich
2024-09-05 11:22 ` Hendrik Wuethrich [this message]
2024-09-05 11:22 ` [PATCH v2 4/8] i386: Add RDT device interface through MSRs Hendrik Wuethrich
2024-09-05 11:22 ` [PATCH v2 5/8] i386: Add CPUID enumeration for RDT Hendrik Wuethrich
2024-11-12 10:28 ` Peter Newman
2024-09-05 11:22 ` [PATCH v2 6/8] i386: Add RDT feature flags Hendrik Wuethrich
2024-09-05 11:22 ` [PATCH v2 7/8] i386/cpu: Adjust CPUID level for RDT features Hendrik Wuethrich
2024-09-05 11:22 ` [PATCH v2 8/8] i386/cpu: Adjust level for RDT on full_cpuid_auto_level Hendrik Wuethrich
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=20240905112237.3586972-4-whendrik@google.com \
--to=whendrik@google.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=eduardo@habkost.net \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peternewman@google.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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;
as well as URLs for NNTP newsgroup(s).