Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Style, export struct acpisrat_node, and add acp...



details:   https://anonhg.NetBSD.org/src/rev/3c1ba4612f89
branches:  trunk
changeset: 828712:3c1ba4612f89
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Dec 28 08:49:28 2017 +0000

description:
Style, export struct acpisrat_node, and add acpisrat_get_node.

diffstat:

 sys/dev/acpi/acpi_srat.c |  116 +++++++++++++++++++++++++++-------------------
 sys/dev/acpi/acpi_srat.h |   52 ++++++--------------
 2 files changed, 84 insertions(+), 84 deletions(-)

diffs (truncated from 352 to 300 lines):

diff -r 0c2868672621 -r 3c1ba4612f89 sys/dev/acpi/acpi_srat.c
--- a/sys/dev/acpi/acpi_srat.c  Thu Dec 28 08:30:36 2017 +0000
+++ b/sys/dev/acpi/acpi_srat.c  Thu Dec 28 08:49:28 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_srat.c,v 1.4 2017/08/31 08:45:03 msaitoh Exp $ */
+/* $NetBSD: acpi_srat.c,v 1.5 2017/12/28 08:49:28 maxv Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_srat.c,v 1.4 2017/08/31 08:45:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_srat.c,v 1.5 2017/12/28 08:49:28 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -41,14 +41,6 @@
 
 static ACPI_TABLE_SRAT *srat;
 
-struct acpisrat_node {
-       acpisrat_nodeid_t nodeid;
-       uint32_t ncpus; /* Number of cpus in this node */
-       struct acpisrat_cpu **cpu; /* Array of cpus */
-       uint32_t nmems; /* Number of memory ranges in this node */
-       struct acpisrat_mem **mem; /* Array of memory ranges */
-};
-
 static uint32_t nnodes; /* Number of NUMA nodes */
 static struct acpisrat_node *node_array; /* Array of NUMA nodes */
 static uint32_t ncpus; /* Number of CPUs */
@@ -56,7 +48,6 @@
 static uint32_t nmems; /* Number of Memory ranges */
 static struct acpisrat_mem *mem_array;
 
-
 struct cpulist {
        struct acpisrat_cpu cpu;
        TAILQ_ENTRY(cpulist) entry;
@@ -64,12 +55,11 @@
 
 static TAILQ_HEAD(, cpulist) cpulisthead;
 
-#define CPU_INIT               TAILQ_INIT(&cpulisthead);
+#define CPU_INIT()             TAILQ_INIT(&cpulisthead);
 #define CPU_FOREACH(cpu)       TAILQ_FOREACH(cpu, &cpulisthead, entry)
 #define CPU_ADD(cpu)           TAILQ_INSERT_TAIL(&cpulisthead, cpu, entry)
 #define CPU_REM(cpu)           TAILQ_REMOVE(&cpulisthead, cpu, entry)
-#define CPU_FIRST              TAILQ_FIRST(&cpulisthead)
-
+#define CPU_FIRST()            TAILQ_FIRST(&cpulisthead)
 
 struct memlist {
        struct acpisrat_mem mem;
@@ -78,12 +68,12 @@
 
 static TAILQ_HEAD(, memlist) memlisthead;
 
-#define MEM_INIT               TAILQ_INIT(&memlisthead)
+#define MEM_INIT()             TAILQ_INIT(&memlisthead)
 #define MEM_FOREACH(mem)       TAILQ_FOREACH(mem, &memlisthead, entry)
 #define MEM_ADD(mem)           TAILQ_INSERT_TAIL(&memlisthead, mem, entry)
 #define MEM_ADD_BEFORE(mem, b) TAILQ_INSERT_BEFORE(b, mem, entry)
 #define MEM_REM(mem)           TAILQ_REMOVE(&memlisthead, mem, entry)
-#define MEM_FIRST              TAILQ_FIRST(&memlisthead)
+#define MEM_FIRST()            TAILQ_FIRST(&memlisthead)
 
 
 static struct cpulist *
@@ -98,21 +88,6 @@
        kmem_free(c, sizeof(struct cpulist));
 }
 
-#if 0
-static struct cpulist *
-cpu_get(acpisrat_nodeid_t nodeid)
-{
-       struct cpulist *tmp;
-
-       CPU_FOREACH(tmp) {
-               if (tmp->cpu.nodeid == nodeid)
-                       return tmp;
-       }
-
-       return NULL;
-}
-#endif
-
 static struct memlist *
 mem_alloc(void)
 {
@@ -138,7 +113,10 @@
        return NULL;
 }
 
-
+/*
+ * Returns true if ACPI SRAT table is available. If table does not exist, all
+ * functions below have undefined behaviour.
+ */
 bool
 acpisrat_exist(void)
 {
@@ -232,12 +210,13 @@
                                break;
                        nodeid = srat_x2apic->ProximityDomain;
 
-                       /* This table entry overrides
+                       /*
+                        * This table entry overrides
                         * ACPI_SRAT_TYPE_CPU_AFFINITY.
                         */
                        if (!ignore_cpu_affinity) {
                                struct cpulist *citer;
-                               while ((citer = CPU_FIRST) != NULL) {
+                               while ((citer = CPU_FIRST()) != NULL) {
                                        CPU_REM(citer);
                                        cpu_free(citer);
                                }
@@ -273,14 +252,13 @@
 
        /* Some sanity checks. */
 
-       /* Deal with holes in the memory nodes.
-        * BIOS doesn't enlist memory nodes which
-        * don't have any memory modules plugged in.
-        * This behaviour has been observed on AMD machines.
+       /*
+        * Deal with holes in the memory nodes. BIOS doesn't enlist memory
+        * nodes which don't have any memory modules plugged in. This behaviour
+        * has been observed on AMD machines.
         *
-        * Do that by searching for CPUs in NUMA nodes
-        * which don't exist in the memory and then insert
-        * a zero memory range for the missing node.
+        * Do that by searching for CPUs in NUMA nodes which don't exist in the
+        * memory and then insert a zero memory range for the missing node.
         */
        CPU_FOREACH(citer) {
                mem = mem_get(citer->cpu.nodeid);
@@ -303,6 +281,10 @@
        return 0;
 }
 
+/*
+ * Initializes parser. Must be the first function being called when table is
+ * available.
+ */
 int
 acpisrat_init(void)
 {
@@ -311,6 +293,9 @@
        return acpisrat_refresh();
 }
 
+/*
+ * Re-parse ACPI SRAT table. Useful after hotplugging cpu or RAM.
+ */
 int
 acpisrat_refresh(void)
 {
@@ -319,8 +304,8 @@
        struct memlist *miter;
        uint32_t cnodes = 0, mnodes = 0;
 
-       CPU_INIT;
-       MEM_INIT;
+       CPU_INIT();
+       MEM_INIT();
 
        rc = acpisrat_parse();
        if (rc)
@@ -335,7 +320,6 @@
        if (rc)
                return rc;
 
-       nnodes = 0;
        ncpus = 0;
        CPU_FOREACH(citer) {
                cnodes = MAX(citer->cpu.nodeid, cnodes);
@@ -404,12 +388,12 @@
                }
        }
 
-       while ((citer = CPU_FIRST) != NULL) {
+       while ((citer = CPU_FIRST()) != NULL) {
                CPU_REM(citer);
                cpu_free(citer);
        }
 
-       while ((miter = MEM_FIRST) != NULL) {
+       while ((miter = MEM_FIRST()) != NULL) {
                MEM_REM(miter);
                mem_free(miter);
        }
@@ -417,7 +401,10 @@
        return 0;
 }
 
-
+/*
+ * Free allocated memory. Should be called when acpisrat is no longer of any
+ * use.
+ */
 int
 acpisrat_exit(void)
 {
@@ -451,7 +438,6 @@
        return 0;
 }
 
-
 void
 acpisrat_dump(void)
 {
@@ -482,18 +468,27 @@
        }
 }
 
+/*
+ * Get number of NUMA nodes.
+ */
 uint32_t
 acpisrat_nodes(void)
 {
        return nnodes;
 }
 
+/*
+ * Get number of cpus in the node. 0 means, this is a cpu-less node.
+ */
 uint32_t
 acpisrat_node_cpus(acpisrat_nodeid_t nodeid)
 {
        return node_array[nodeid].ncpus;
 }
 
+/*
+ * Get number of memory ranges in the node 0 means, this node has no RAM.
+ */
 uint32_t
 acpisrat_node_memoryranges(acpisrat_nodeid_t nodeid)
 {
@@ -515,3 +510,28 @@
        memcpy(mem, node_array[nodeid].mem[memrange],
            sizeof(struct acpisrat_mem));
 }
+
+/*
+ * Get a node from an APIC id (belonging to a cpu).
+ */
+struct acpisrat_node *
+acpisrat_get_node(uint32_t apicid)
+{
+       struct acpisrat_node *node;
+       struct acpisrat_cpu *cpu;
+       size_t i, n;
+
+       for (i = 0; i < nnodes; i++) {
+               node = &node_array[i];
+
+               for (n = 0; n < node->ncpus; n++) {
+                       cpu = node->cpu[n];
+                       if (cpu->apicid == apicid) {
+                               return node;
+                       }
+               }
+       }
+
+       return NULL;
+}
+
diff -r 0c2868672621 -r 3c1ba4612f89 sys/dev/acpi/acpi_srat.h
--- a/sys/dev/acpi/acpi_srat.h  Thu Dec 28 08:30:36 2017 +0000
+++ b/sys/dev/acpi/acpi_srat.h  Thu Dec 28 08:49:28 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_srat.h,v 1.3 2010/03/05 08:30:48 jruoho Exp $ */
+/* $NetBSD: acpi_srat.h,v 1.4 2017/12/28 08:49:28 maxv Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -40,7 +40,8 @@
        uint32_t sapiceid;
        uint32_t flags;
 
-       /* clockdomain has a meaningful value when the ACPI MADT table has
+       /*
+        * clockdomain has a meaningful value when the ACPI MADT table has
         * ACPI_MADT_TYPE_LOCAL_X2APIC and/or ACPI_MADT_TYPE_LOCAL_X2APIC_NMI
         * entries or ACPI CPU device have a _CDM.
         */
@@ -54,45 +55,24 @@
        uint32_t flags;
 };
 
-/* Returns true if ACPI SRAT table is available.
- *
- * If table does not exist, all functions below



Home | Main Index | Thread Index | Old Index