thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-hmat-acpi-Build-Memory-Side-Cache-Information-Struct.patch

ddf19c
From d00453667cb972dc2fe1242081d3b39313a6a925 Mon Sep 17 00:00:00 2001
ddf19c
From: "plai@redhat.com" <plai@redhat.com>
ddf19c
Date: Thu, 21 May 2020 23:56:52 +0100
ddf19c
Subject: [PATCH 09/12] hmat acpi: Build Memory Side Cache Information
ddf19c
 Structure(s)
ddf19c
ddf19c
RH-Author: plai@redhat.com
ddf19c
Message-id: <20200521235655.27141-9-plai@redhat.com>
ddf19c
Patchwork-id: 96741
ddf19c
O-Subject: [RHEL8.2.1 AV qemu-kvm PATCH 08/11] hmat acpi: Build Memory Side Cache Information Structure(s)
ddf19c
Bugzilla: 1600217
ddf19c
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
ddf19c
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
ddf19c
ddf19c
From: Liu Jingqi <jingqi.liu@intel.com>
ddf19c
ddf19c
This structure describes memory side cache information for memory
ddf19c
proximity domains if the memory side cache is present and the
ddf19c
physical device forms the memory side cache.
ddf19c
The software could use this information to effectively place
ddf19c
the data in memory to maximize the performance of the system
ddf19c
memory that use the memory side cache.
ddf19c
ddf19c
Acked-by: Markus Armbruster <armbru@redhat.com>
ddf19c
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
ddf19c
Reviewed-by: Daniel Black <daniel@linux.ibm.com>
ddf19c
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
ddf19c
Signed-off-by: Liu Jingqi <jingqi.liu@intel.com>
ddf19c
Signed-off-by: Tao Xu <tao3.xu@intel.com>
ddf19c
Message-Id: <20191213011929.2520-7-tao3.xu@intel.com>
ddf19c
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
(cherry picked from commit a9c2b841af002db6e21e1297c9026b63fc22c875)
ddf19c
Signed-off-by: Paul Lai <plai@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/acpi/hmat.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
ddf19c
 1 file changed, 68 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c
ddf19c
index 4635d45..7c24bb5 100644
ddf19c
--- a/hw/acpi/hmat.c
ddf19c
+++ b/hw/acpi/hmat.c
ddf19c
@@ -143,14 +143,62 @@ static void build_hmat_lb(GArray *table_data, HMAT_LB_Info *hmat_lb,
ddf19c
     g_free(entry_list);
ddf19c
 }
ddf19c
 
ddf19c
+/* ACPI 6.3: 5.2.27.5 Memory Side Cache Information Structure: Table 5-147 */
ddf19c
+static void build_hmat_cache(GArray *table_data, uint8_t total_levels,
ddf19c
+                             NumaHmatCacheOptions *hmat_cache)
ddf19c
+{
ddf19c
+    /*
ddf19c
+     * Cache Attributes: Bits [3:0] – Total Cache Levels
ddf19c
+     * for this Memory Proximity Domain
ddf19c
+     */
ddf19c
+    uint32_t cache_attr = total_levels;
ddf19c
+
ddf19c
+    /* Bits [7:4] : Cache Level described in this structure */
ddf19c
+    cache_attr |= (uint32_t) hmat_cache->level << 4;
ddf19c
+
ddf19c
+    /* Bits [11:8] - Cache Associativity */
ddf19c
+    cache_attr |= (uint32_t) hmat_cache->associativity << 8;
ddf19c
+
ddf19c
+    /* Bits [15:12] - Write Policy */
ddf19c
+    cache_attr |= (uint32_t) hmat_cache->policy << 12;
ddf19c
+
ddf19c
+    /* Bits [31:16] - Cache Line size in bytes */
ddf19c
+    cache_attr |= (uint32_t) hmat_cache->line << 16;
ddf19c
+
ddf19c
+    /* Type */
ddf19c
+    build_append_int_noprefix(table_data, 2, 2);
ddf19c
+    /* Reserved */
ddf19c
+    build_append_int_noprefix(table_data, 0, 2);
ddf19c
+    /* Length */
ddf19c
+    build_append_int_noprefix(table_data, 32, 4);
ddf19c
+    /* Proximity Domain for the Memory */
ddf19c
+    build_append_int_noprefix(table_data, hmat_cache->node_id, 4);
ddf19c
+    /* Reserved */
ddf19c
+    build_append_int_noprefix(table_data, 0, 4);
ddf19c
+    /* Memory Side Cache Size */
ddf19c
+    build_append_int_noprefix(table_data, hmat_cache->size, 8);
ddf19c
+    /* Cache Attributes */
ddf19c
+    build_append_int_noprefix(table_data, cache_attr, 4);
ddf19c
+    /* Reserved */
ddf19c
+    build_append_int_noprefix(table_data, 0, 2);
ddf19c
+    /*
ddf19c
+     * Number of SMBIOS handles (n)
ddf19c
+     * Linux kernel uses Memory Side Cache Information Structure
ddf19c
+     * without SMBIOS entries for now, so set Number of SMBIOS handles
ddf19c
+     * as 0.
ddf19c
+     */
ddf19c
+    build_append_int_noprefix(table_data, 0, 2);
ddf19c
+}
ddf19c
+
ddf19c
 /* Build HMAT sub table structures */
ddf19c
 static void hmat_build_table_structs(GArray *table_data, NumaState *numa_state)
ddf19c
 {
ddf19c
     uint16_t flags;
ddf19c
     uint32_t num_initiator = 0;
ddf19c
     uint32_t initiator_list[MAX_NODES];
ddf19c
-    int i, hierarchy, type;
ddf19c
+    int i, hierarchy, type, cache_level, total_levels;
ddf19c
     HMAT_LB_Info *hmat_lb;
ddf19c
+    NumaHmatCacheOptions *hmat_cache;
ddf19c
 
ddf19c
     for (i = 0; i < numa_state->num_nodes; i++) {
ddf19c
         flags = 0;
ddf19c
@@ -184,6 +232,25 @@ static void hmat_build_table_structs(GArray *table_data, NumaState *numa_state)
ddf19c
             }
ddf19c
         }
ddf19c
     }
ddf19c
+
ddf19c
+    /*
ddf19c
+     * ACPI 6.3: 5.2.27.5 Memory Side Cache Information Structure:
ddf19c
+     * Table 5-147
ddf19c
+     */
ddf19c
+    for (i = 0; i < numa_state->num_nodes; i++) {
ddf19c
+        total_levels = 0;
ddf19c
+        for (cache_level = 1; cache_level < HMAT_LB_LEVELS; cache_level++) {
ddf19c
+            if (numa_state->hmat_cache[i][cache_level]) {
ddf19c
+                total_levels++;
ddf19c
+            }
ddf19c
+        }
ddf19c
+        for (cache_level = 0; cache_level <= total_levels; cache_level++) {
ddf19c
+            hmat_cache = numa_state->hmat_cache[i][cache_level];
ddf19c
+            if (hmat_cache) {
ddf19c
+                build_hmat_cache(table_data, total_levels, hmat_cache);
ddf19c
+            }
ddf19c
+        }
ddf19c
+    }
ddf19c
 }
ddf19c
 
ddf19c
 void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *numa_state)
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c