NUMA code cleanup
cover NUMA code cleanup
This cleans up some of the NUMA code: moves declarations to numa.h, rename some functions, and remove some existing code that was inside main().
Eduardo Habkost (7):
numa: Move NUMA declarations from sysemu.h to numa.h vl.c: Remove unnecessary zero-initialization of NUMA globals
numa: Move NUMA globals to numa.c
numa: Make max_numa_nodeid static
numa: Move QemuOpts parsing to set_numa_nodes()
numa: Rename option parsing functions
numa: Rename set_numa_modes() to numa_post_machine_init()
hw/i386/pc.c | 1 + hw/mem/pc-dimm.c | 1 + hw/ppc/spapr.c | 1 + include/sysemu/numa.h | 24 ++++++++++++++++++++++++ include/sysemu/sysemu.h | 18 ------------------ monitor.c | 1 + numa.c | 20 ++++++++++++++++---- vl.c | 22 +++------------------- 8 files changed, 47 insertions(+), 41 deletions(-) create mode 100644 include/sysemu/numa.h
Signature · 1 line
2.1.0
PATCH 1/7 numa: Move NUMA declarations from sysemu.h to numa.h
Not all sysemu.h users need the NUMA declarations, and keeping them in a separate file makes easier to see what are the interfaces provided by numa.c.
--- hw/i386/pc.c | 1 + hw/mem/pc-dimm.c | 1 + hw/ppc/spapr.c | 1 + include/sysemu/numa.h | 28 ++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 18 ------------------ monitor.c | 1 + numa.c | 2 +- vl.c | 1 + 8 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 include/sysemu/numa.h
hw/i386/pc.c +1 -0
@@ -41,6 +41,7 @@#include "hw/pci/msi.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "sysemu/kvm.h" #include "kvm_i386.h" #include "hw/xen/xen.h"
hw/mem/pc-dimm.c +1 -0
@@ -22,6 +22,7 @@#include "qemu/config-file.h" #include "qapi/visitor.h" #include "qemu/range.h" +#include "sysemu/numa.h" typedef struct pc_dimms_capacity { uint64_t size;
hw/ppc/spapr.c +1 -0
@@ -25,6 +25,7 @@* */ #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "hw/hw.h" #include "hw/fw-path-provider.h" #include "elf.h"
include/sysemu/numa.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef SYSEMU_NUMA_H +#define SYSEMU_NUMA_H + +#include <stdint.h> +#include "qemu/bitmap.h" +#include "qemu/option.h" +#include "sysemu/sysemu.h" +#include "sysemu/hostmem.h" + +extern int nb_numa_nodes;/* Number of NUMA nodes */ +extern int max_numa_nodeid;/* Highest specified NUMA node ID, plus one. +* For all nodes, nodeid < max_numa_nodeid +*/ + +typedef struct node_info { +uint64_t node_mem; + DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); +struct HostMemoryBackend *node_memdev; +bool present; +}NodeInfo ; +extern NodeInfo numa_info[MAX_NODES ]; +void set_numa_nodes (void ); +void set_numa_modes (void ); +void query_numa_node_mem (uint64_t node_mem[]); +extern QemuOptsList qemu_numa_opts; +int numa_init_func (QemuOpts *opts,void *opaque); + +#endif
include/sysemu/sysemu.h +0 -18
@@ -147,24 +147,6 @@ extern int mem_prealloc;*/ #define MAX_CPUMASK_BITS 255 -extern int nb_numa_nodes;/* Number of NUMA nodes */ -extern int max_numa_nodeid;/* Highest specified NUMA node ID, plus one. -* For all nodes, nodeid < max_numa_nodeid -*/ - -typedef struct node_info { -uint64_t node_mem; - DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); -struct HostMemoryBackend *node_memdev; -bool present; -}NodeInfo ; -extern NodeInfo numa_info[MAX_NODES ]; -void set_numa_nodes (void ); -void set_numa_modes (void ); -void query_numa_node_mem (uint64_t node_mem[]); -extern QemuOptsList qemu_numa_opts; -int numa_init_func (QemuOpts *opts,void *opaque); -#define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name;
monitor.c +1 -0
@@ -35,6 +35,7 @@#include "sysemu/char.h" #include "ui/qemu-spice.h" #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "monitor/monitor.h" #include "qemu/readline.h" #include "ui/console.h"
numa.c +1 -1
@@ -22,7 +22,7 @@* THE SOFTWARE. */ -#include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "exec/cpu-common.h" #include "qemu/bitmap.h" #include "qom/cpu.h"
vl.c +1 -0
@@ -78,6 +78,7 @@ int main(int argc, char **argv)#include "monitor/monitor.h" #include "ui/console.h" #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "exec/gdbstub.h" #include "qemu/timer.h" #include "sysemu/char.h"
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH 1/7] numa: Move NUMA declarations from sysemu.h to numa.h
Quoted 2 lines · Eduardo Habkost
Not all
sysemu.husers need the NUMA declarations, and keeping them in a separate file makes easier to see what are the interfaces provided by
s/makes easier/makes it easier/
Quoted 153 lines
numa.c.Signed-off-by Eduardo Habkost <[email protected]>--- hw/i386/pc.c | 1 + hw/mem/pc-dimm.c | 1 + hw/ppc/spapr.c | 1 + include/sysemu/numa.h | 28 ++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 18 ------------------ monitor.c | 1 + numa.c | 2 +- vl.c | 1 + 8 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 include/sysemu/numa.hhw/i386/pc.c +1
-0@@ -41,6 +41,7 @@#include "hw/pci/msi.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "sysemu/kvm.h" #include "kvm_i386.h" #include "hw/xen/xen.h" hw/mem/pc-dimm.c +1
-0@@ -22,6 +22,7 @@#include "qemu/config-file.h" #include "qapi/visitor.h" #include "qemu/range.h" +#include "sysemu/numa.h" typedef struct pc_dimms_capacity { uint64_t size;hw/ppc/spapr.c +1
-0@@ -25,6 +25,7 @@* */ #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "hw/hw.h" #include "hw/fw-path-provider.h" #include "elf.h" include/sysemu/numa.h new file +28
-0@@ -0,0 +1,28 @@ +#ifndef SYSEMU_NUMA_H +#define SYSEMU_NUMA_H + +#include <stdint.h> +#include "qemu/bitmap.h" +#include "qemu/option.h" +#include "sysemu/sysemu.h" +#include "sysemu/hostmem.h" + +extern int nb_numa_nodes;/* Number of NUMA nodes */ +extern int max_numa_nodeid;/* Highest specified NUMA node ID, plus one. +* For all nodes, nodeid < max_numa_nodeid +*/ + +typedef struct node_info { +uint64_t node_mem; + DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); +struct HostMemoryBackend *node_memdev; +bool present; +}NodeInfo ; +extern NodeInfo numa_info[MAX_NODES ]; +void set_numa_nodes (void ); +void set_numa_modes (void ); +void query_numa_node_mem (uint64_t node_mem[]); +extern QemuOptsList qemu_numa_opts; +int numa_init_func (QemuOpts *opts,void *opaque); + +#endif include/sysemu/sysemu.h +0
-18@@ -147,24 +147,6 @@ extern int mem_prealloc;*/ #define MAX_CPUMASK_BITS 255 -extern int nb_numa_nodes;/* Number of NUMA nodes */ -extern int max_numa_nodeid;/* Highest specified NUMA node ID, plus one. -* For all nodes, nodeid < max_numa_nodeid -*/ - -typedef struct node_info { -uint64_t node_mem; - DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); -struct HostMemoryBackend *node_memdev; -bool present; -}NodeInfo ; -extern NodeInfo numa_info[MAX_NODES ]; -void set_numa_nodes (void ); -void set_numa_modes (void ); -void query_numa_node_mem (uint64_t node_mem[]); -extern QemuOptsList qemu_numa_opts; -int numa_init_func (QemuOpts *opts,void *opaque); -#define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name;monitor.c +1
-0@@ -35,6 +35,7 @@#include "sysemu/char.h" #include "ui/qemu-spice.h" #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "monitor/monitor.h" #include "qemu/readline.h" #include "ui/console.h" numa.c +1
-1@@ -22,7 +22,7 @@* THE SOFTWARE. */ -#include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "exec/cpu-common.h" #include "qemu/bitmap.h" #include "qom/cpu.h" vl.c +1
-0@@ -78,6 +78,7 @@ int main(int argc, char **argv)#include "monitor/monitor.h" #include "ui/console.h" #include "sysemu/sysemu.h" +#include "sysemu/numa.h" #include "exec/gdbstub.h" #include "qemu/timer.h" #include "sysemu/char.h" Signature · 1 line
2.1.0
PATCH 2/7 vl.c: Remove unnecessary zero-initialization of NUMA globals
In reply to Eduardo HabkostThere's no need to zero-initialize globals, they are automatically initialized to zero.
--- vl.c | 8 -------- 1 file changed, 8 deletions(-)
vl.c +0 -8
@@ -2818,14 +2818,6 @@ int main(int argc, char **argv, char **envp) cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; -for (i =0 ; i <MAX_NODES ; i++) { - numa_info[i].node_mem =0 ; - numa_info[i].present = false; -bitmap_zero (numa_info[i].node_cpu,MAX_CPUMASK_BITS ); - } - - nb_numa_nodes =0 ; - max_numa_nodeid =0 ; nb_nics =0 ;bdrv_init_with_whitelist ();
Signature · 1 line
2.1.0
PATCH 3/7 numa: Move NUMA globals to numa.c
In reply to Eduardo Habkost--- numa.c | 3 +++ vl.c | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-)
numa.c +3 -0
@@ -45,6 +45,9 @@ QemuOptsList qemu_numa_opts = { };static int have_memdevs =-1 ; +int nb_numa_nodes; +int max_numa_nodeid; +NodeInfo numa_info[MAX_NODES ];static void numa_node_parse (NumaNodeOptions *node,QemuOpts *opts,Error **errp) {
vl.c +0 -4
@@ -184,10 +184,6 @@ uint8_t qemu_extra_params_fw[2];int icount_align_option; -int nb_numa_nodes; -int max_numa_nodeid; -NodeInfo numa_info[MAX_NODES ]; -/* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the * little-endian "wire format" described in the SMBIOS 2.6 specification. */
Signature · 1 line
2.1.0
PATCH 4/7 numa: Make max_numa_nodeid static
In reply to Eduardo HabkostNow the only code that uses the variable is inside numa.c.
--- include/sysemu/numa.h | 3 --- numa.c | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-)
include/sysemu/numa.h +0 -3
@@ -8,9 +8,6 @@#include "sysemu/hostmem.h" extern int nb_numa_nodes;/* Number of NUMA nodes */ -extern int max_numa_nodeid;/* Highest specified NUMA node ID, plus one. -* For all nodes, nodeid < max_numa_nodeid -*/ typedef struct node_info { uint64_t node_mem;
numa.c +3 -1
@@ -45,8 +45,10 @@ QemuOptsList qemu_numa_opts = { };static int have_memdevs =-1 ; +static int max_numa_nodeid;/* Highest specified NUMA node ID, plus one. +* For all nodes, nodeid < max_numa_nodeid +*/ int nb_numa_nodes; -int max_numa_nodeid;NodeInfo numa_info[MAX_NODES ];static void numa_node_parse (NumaNodeOptions *node,QemuOpts *opts,Error **errp)
Signature · 1 line
2.1.0
PATCH 5/7 numa: Move QemuOpts parsing to set_numa_nodes()
In reply to Eduardo HabkostThis allows us to make numa_init_func() static.
--- include/sysemu/numa.h | 1 - numa.c | 9 ++++++++- vl.c | 5 ----- 3 files changed, 8 insertions(+), 7 deletions(-)
include/sysemu/numa.h +0 -1
@@ -20,6 +20,5 @@ void set_numa_nodes(void);void set_numa_modes (void );void query_numa_node_mem (uint64_t node_mem[]);extern QemuOptsList qemu_numa_opts; -int numa_init_func (QemuOpts *opts,void *opaque);#endif
numa.c +8 -1
@@ -36,6 +36,8 @@#include "sysemu/hostmem.h" #include "qmp-commands.h" #include "hw/mem/pc-dimm.h" +#include "qemu/option.h" +#include "qemu/config-file.h" QemuOptsList qemu_numa_opts = { .name ="numa" ,
@@ -121,7 +123,7 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) max_numa_nodeid =MAX (max_numa_nodeid, nodenr +1 ); } -int numa_init_func (QemuOpts *opts,void *opaque) +static int numa_init_func (QemuOpts *opts,void *opaque) {NumaOptions *object =NULL ;Error *err =NULL ;
@@ -168,6 +170,11 @@ void set_numa_nodes(void) {int i; +if (qemu_opts_foreach (qemu_find_opts ("numa" ), numa_init_func, +NULL ,1 ) !=0 ) { +exit (1 ); + } +assert (max_numa_nodeid <=MAX_NODES );/* No support for sparse NUMA node IDs yet: */
vl.c +0 -5
@@ -4154,11 +4154,6 @@ int main(int argc, char **argv, char **envp)default_drive (default_floppy, snapshot,IF_FLOPPY ,0 ,FD_OPTS );default_drive (default_sdcard, snapshot,IF_SD ,0 ,SD_OPTS ); -if (qemu_opts_foreach (qemu_find_opts ("numa" ), numa_init_func, -NULL ,1 ) !=0 ) { -exit (1 ); - } -set_numa_nodes ();if (qemu_opts_foreach (qemu_find_opts ("mon" ), mon_init_func,NULL ,1 ) !=0 ) {
Signature · 1 line
2.1.0
PATCH 6/7 numa: Rename option parsing functions
In reply to Eduardo HabkostRenaming set_numa_nodes() and numa_init_func() to parse_numa_opts() and parse_numa() makes the purpose of those functions clearer.
--- include/sysemu/numa.h | 2 +- numa.c | 6 +++--- vl.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
include/sysemu/numa.h +1 -1
@@ -16,7 +16,7 @@ typedef struct node_info {bool present; } NodeInfo;extern NodeInfo numa_info[MAX_NODES ]; -void set_numa_nodes (void ); +void parse_numa_opts (void );void set_numa_modes (void );void query_numa_node_mem (uint64_t node_mem[]);extern QemuOptsList qemu_numa_opts;
numa.c +3 -3
@@ -123,7 +123,7 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) max_numa_nodeid =MAX (max_numa_nodeid, nodenr +1 ); } -static int numa_init_func (QemuOpts *opts,void *opaque) +static int parse_numa (QemuOpts *opts,void *opaque) {NumaOptions *object =NULL ;Error *err =NULL ;
@@ -166,11 +166,11 @@ error:return -1 ; } -void set_numa_nodes (void ) +void parse_numa_opts (void ) {int i; -if (qemu_opts_foreach (qemu_find_opts ("numa" ), numa_init_func, +if (qemu_opts_foreach (qemu_find_opts ("numa" ), parse_numa,NULL ,1 ) !=0 ) {exit (1 ); }
vl.c +1 -1
@@ -4154,7 +4154,7 @@ int main(int argc, char **argv, char **envp)default_drive (default_floppy, snapshot,IF_FLOPPY ,0 ,FD_OPTS );default_drive (default_sdcard, snapshot,IF_SD ,0 ,SD_OPTS ); -set_numa_nodes (); +parse_numa_opts ();if (qemu_opts_foreach (qemu_find_opts ("mon" ), mon_init_func,NULL ,1 ) !=0 ) {exit (1 );
Signature · 1 line
2.1.0
PATCH 7/7 numa: Rename set_numa_modes() to numa_post_machine_init()
In reply to Eduardo HabkostThis function does some initialization that needs to be done after machine init. The function may be eventually removed if we move the CPUState.numa_node initialization to the CPU init code, but while the function exists, lets give it a name that makes sense.
--- include/sysemu/numa.h | 2 +- numa.c | 2 +- vl.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
include/sysemu/numa.h +1 -1
@@ -17,7 +17,7 @@ typedef struct node_info { } NodeInfo;extern NodeInfo numa_info[MAX_NODES ];void parse_numa_opts (void ); -void set_numa_modes (void ); +void numa_post_machine_init (void );void query_numa_node_mem (uint64_t node_mem[]);extern QemuOptsList qemu_numa_opts;
numa.c +1 -1
@@ -246,7 +246,7 @@ void parse_numa_opts(void) } } -void set_numa_modes (void ) +void numa_post_machine_init (void ) {CPUState *cpu;int i;
vl.c +1 -1
@@ -4213,7 +4213,7 @@ int main(int argc, char **argv, char **envp)cpu_synchronize_all_post_init (); -set_numa_modes (); +numa_post_machine_init ();/* init USB devices */ if (usb_enabled ()) {
Signature · 1 line
2.1.0
Quoted 11 lines · Eduardo Habkost
This cleans up some of the NUMA code: moves declarations to
numa.h, rename some functions, and remove some existing code that was insidemain().Eduardo Habkost (7):
numa: Move NUMA declarations fromsysemu.htonuma.hvl.c: Remove unnecessary zero-initialization of NUMA globals
numa: Move NUMA globals tonuma.c
numa: Makemax_numa_nodeidstatic
numa: Move QemuOpts parsing toset_numa_nodes()
numa: Rename option parsing functions
numa: Renameset_numa_modes()tonuma_post_machine_init()
Nice!
Quoted 15 lines · Paolo Bonzini
Quoted 11 lines · Eduardo Habkost
This cleans up some of the NUMA code: moves declarations to
numa.h, rename some functions, and remove some existing code that was insidemain().Eduardo Habkost (7):
numa: Move NUMA declarations fromsysemu.htonuma.hvl.c: Remove unnecessary zero-initialization of NUMA globals
numa: Move NUMA globals tonuma.c
numa: Makemax_numa_nodeidstatic
numa: Move QemuOpts parsing toset_numa_nodes()
numa: Rename option parsing functions
numa: Renameset_numa_modes()tonuma_post_machine_init()
Quoted 3 lines
Nice!
Reviewed-by Paolo Bonzini <[email protected]>
Thanks!
Do you think this should go through Michael's tree, like past NUMA patches, or through yours?
Signature · 1 line
Eduardo
Quoted 4 lines · Eduardo Habkost
Thanks!
Do you think this should go through Michael's tree, like past NUMA patches, or through yours?
Through Michael's tree or yours :)
Paolo
Quoted 16 lines · Eduardo Habkost
Quoted 15 lines · Paolo Bonzini
Quoted 11 lines · Eduardo Habkost
This cleans up some of the NUMA code: moves declarations to
numa.h, rename some functions, and remove some existing code that was insidemain().Eduardo Habkost (7):
numa: Move NUMA declarations fromsysemu.htonuma.hvl.c: Remove unnecessary zero-initialization of NUMA globals
numa: Move NUMA globals tonuma.c
numa: Makemax_numa_nodeidstatic
numa: Move QemuOpts parsing toset_numa_nodes()
numa: Rename option parsing functions
numa: Renameset_numa_modes()tonuma_post_machine_init()
Quoted 8 lines
Quoted 3 lines
Nice!
Reviewed-by Paolo Bonzini <[email protected]>Thanks!
Do you think this should go through Michael's tree, like past NUMA patches, or through yours?
kvm tree does not seem appropriate.
I can merge this if you wish, let me know.
Quoted 2 lines
Signature · 1 line
Eduardo
Michael S. Tsirkin
Acked-byQuoted 21 lines · Michael S. Tsirkin
Quoted 20 lines · Eduardo Habkost
Quoted 18 lines · Paolo Bonzini
Quoted 11 lines · Eduardo Habkost
This cleans up some of the NUMA code: moves declarations to
numa.h, rename some functions, and remove some existing code that was insidemain().Eduardo Habkost (7):
numa: Move NUMA declarations fromsysemu.htonuma.hvl.c: Remove unnecessary zero-initialization of NUMA globals
numa: Move NUMA globals tonuma.c
numa: Makemax_numa_nodeidstatic
numa: Move QemuOpts parsing toset_numa_nodes()
numa: Rename option parsing functions
numa: Renameset_numa_modes()tonuma_post_machine_init()Nice!
Reviewed-by Paolo Bonzini <[email protected]>
Quoted 7 lines
Quoted 4 lines
Thanks!
Do you think this should go through Michael's tree, like past NUMA patches, or through yours?
kvm tree does not seem appropriate.
I can merge this if you wish, let me know.
Or if you want to merge it through another tree:
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
Eduardo