mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-25 21:24:08 +08:00
memblock tests: add simulation of physical memory with multiple NUMA nodes
Add function setup_numa_memblock() for setting up a memory layout with multiple NUMA nodes in a previously allocated dummy physical memory. This function can be used in place of setup_memblock() in tests that need to simulate a NUMA system. setup_numa_memblock(): - allows for setting up a memory layout by specifying the fraction of MEM_SIZE in each node Set CONFIG_NODES_SHIFT to 4 when building with NUMA=1 to allow for up to 16 NUMA nodes. Reviewed-by: David Hildenbrand <david@redhat.com> Signed-off-by: Rebecca Mckeever <remckee0@gmail.com> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Link: https://lore.kernel.org/r/4566d816a85f009268d4858d1ef06c7571a960f9.1663046060.git.remckee0@gmail.com
This commit is contained in:
parent
42c3ba8658
commit
b338bde5a3
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
# Simulate CONFIG_NUMA=y
|
# Simulate CONFIG_NUMA=y
|
||||||
ifeq ($(NUMA), 1)
|
ifeq ($(NUMA), 1)
|
||||||
CFLAGS += -D CONFIG_NUMA
|
CFLAGS += -D CONFIG_NUMA -D CONFIG_NODES_SHIFT=4
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Use 32 bit physical addresses.
|
# Use 32 bit physical addresses.
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
|
#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
|
||||||
#define PREFIXES_MAX 15
|
#define PREFIXES_MAX 15
|
||||||
#define DELIM ": "
|
#define DELIM ": "
|
||||||
|
#define BASIS 10000
|
||||||
|
|
||||||
static struct test_memory memory_block;
|
static struct test_memory memory_block;
|
||||||
static const char __maybe_unused *prefixes[PREFIXES_MAX];
|
static const char __maybe_unused *prefixes[PREFIXES_MAX];
|
||||||
@ -72,6 +73,36 @@ void setup_memblock(void)
|
|||||||
fill_memblock();
|
fill_memblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setup_numa_memblock:
|
||||||
|
* Set up a memory layout with multiple NUMA nodes in a previously allocated
|
||||||
|
* dummy physical memory.
|
||||||
|
* @node_fracs: an array representing the fraction of MEM_SIZE contained in
|
||||||
|
* each node in basis point units (one hundredth of 1% or 1/10000).
|
||||||
|
* For example, if node 0 should contain 1/8 of MEM_SIZE,
|
||||||
|
* node_fracs[0] = 1250.
|
||||||
|
*
|
||||||
|
* The nids will be set to 0 through NUMA_NODES - 1.
|
||||||
|
*/
|
||||||
|
void setup_numa_memblock(const unsigned int node_fracs[])
|
||||||
|
{
|
||||||
|
phys_addr_t base;
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
reset_memblock_regions();
|
||||||
|
base = (phys_addr_t)memory_block.base;
|
||||||
|
flags = (movable_node_is_enabled()) ? MEMBLOCK_NONE : MEMBLOCK_HOTPLUG;
|
||||||
|
|
||||||
|
for (int i = 0; i < NUMA_NODES; i++) {
|
||||||
|
assert(node_fracs[i] <= BASIS);
|
||||||
|
phys_addr_t size = MEM_SIZE * node_fracs[i] / BASIS;
|
||||||
|
|
||||||
|
memblock_add_node(base, size, i, flags);
|
||||||
|
base += size;
|
||||||
|
}
|
||||||
|
fill_memblock();
|
||||||
|
}
|
||||||
|
|
||||||
void dummy_physical_memory_init(void)
|
void dummy_physical_memory_init(void)
|
||||||
{
|
{
|
||||||
memory_block.base = malloc(MEM_SIZE);
|
memory_block.base = malloc(MEM_SIZE);
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
#include <linux/printk.h>
|
#include <linux/printk.h>
|
||||||
#include <../selftests/kselftest.h>
|
#include <../selftests/kselftest.h>
|
||||||
|
|
||||||
#define MEM_SIZE SZ_16K
|
#define MEM_SIZE SZ_16K
|
||||||
|
#define NUMA_NODES 8
|
||||||
|
|
||||||
enum test_flags {
|
enum test_flags {
|
||||||
/* No special request. */
|
/* No special request. */
|
||||||
@ -102,6 +103,7 @@ struct region {
|
|||||||
void reset_memblock_regions(void);
|
void reset_memblock_regions(void);
|
||||||
void reset_memblock_attributes(void);
|
void reset_memblock_attributes(void);
|
||||||
void setup_memblock(void);
|
void setup_memblock(void);
|
||||||
|
void setup_numa_memblock(const unsigned int node_fracs[]);
|
||||||
void dummy_physical_memory_init(void);
|
void dummy_physical_memory_init(void);
|
||||||
void dummy_physical_memory_cleanup(void);
|
void dummy_physical_memory_cleanup(void);
|
||||||
void parse_args(int argc, char **argv);
|
void parse_args(int argc, char **argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user