qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v5 2/8] i386: Add init and realize functionality for RDT device.


From: Hendrik Wuethrich
Subject: [PATCH v5 2/8] i386: Add init and realize functionality for RDT device.
Date: Fri, 13 Dec 2024 17:26:39 +0000

From: ‪Hendrik Wüthrich <whendrik@google.com>

Add code to initialize all necessary state for the RDT device.

Signed-off-by: Hendrik Wüthrich <whendrik@google.com>
---
 hw/i386/rdt.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/hw/i386/rdt.c b/hw/i386/rdt.c
index b2203197e3..920e9c5dbe 100644
--- a/hw/i386/rdt.c
+++ b/hw/i386/rdt.c
@@ -19,6 +19,7 @@
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
 #include "qom/object.h"
+#include "target/i386/cpu.h"
 
 /* Max counts for allocation masks or CBMs. In other words, the size of
  * respective MSRs.
@@ -83,8 +84,36 @@ static void rdt_init(Object *obj)
 {
 }
 
+static void rdt_realize(DeviceState *dev, Error **errp)
+{
+    CPUState *cs = first_cpu;
+    RDTState *rdtDev = RDT(dev);
+
+    rdtDev->rdtInstances = g_malloc(sizeof(RDTStatePerCore) * cs->nr_cores);
+    CPU_FOREACH(cs) {
+        RDTStatePerCore *rdt = &rdtDev->rdtInstances[cs->cpu_index];
+        X86CPU *cpu = X86_CPU(cs);
+
+        rdt->rdtstate = rdtDev;
+        cpu->rdt = rdt;
+
+        rdt->monitors = g_malloc(sizeof(RDTMonitor) * rdtDev->rmids);
+        rdt->rdtstate->allocations = g_malloc(sizeof(RDTAllocation) * 
rdtDev->rmids);
+    }
+}
+
 static void rdt_finalize(Object *obj)
 {
+    CPUState *cs;
+    RDTState *rdt = RDT(obj);
+
+    CPU_FOREACH(cs) {
+        RDTStatePerCore *rdtInstance = &rdt->rdtInstances[cs->cpu_index];
+        g_free(rdtInstance->monitors);
+        g_free(rdtInstance->rdtstate->allocations);
+    }
+
+    g_free(rdt->rdtInstances);
 }
 
 static void rdt_class_init(ObjectClass *klass, void *data)
@@ -94,6 +123,7 @@ static void rdt_class_init(ObjectClass *klass, void *data)
     dc->hotpluggable = false;
     dc->desc = "RDT";
     dc->user_creatable = true;
+    dc->realize = rdt_realize;
 
     device_class_set_props(dc, rdt_properties);
 }
-- 
2.47.1.613.gc27f4b7a9f-goog




reply via email to

[Prev in Thread] Current Thread [Next in Thread]