mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-08 22:32:55 +00:00
memblock tests: Add skeleton of the memblock simulator
Add basic project files, together with local stubs of required headers. Update tools/include/slab.h to include definitions used by memblock. Signed-off-by: Karolina Drobnik <karolinadrobnik@gmail.com> Signed-off-by: Mike Rapoport <rppt@kernel.org> Link: https://lore.kernel.org/r/d296fceb023a04b316a31fbff9acf1e76ac684e4.1643796665.git.karolinadrobnik@gmail.com
This commit is contained in:
parent
62183279ad
commit
16802e55de
@ -12423,6 +12423,7 @@ S: Maintained
|
||||
F: Documentation/core-api/boot-time-mm.rst
|
||||
F: include/linux/memblock.h
|
||||
F: mm/memblock.c
|
||||
F: tools/testing/memblock/
|
||||
|
||||
MEMORY CONTROLLER DRIVERS
|
||||
M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
|
||||
|
@ -13,6 +13,16 @@
|
||||
void *kmalloc(size_t size, gfp_t gfp);
|
||||
void kfree(void *p);
|
||||
|
||||
bool slab_is_available(void);
|
||||
|
||||
enum slab_state {
|
||||
DOWN,
|
||||
PARTIAL,
|
||||
PARTIAL_NODE,
|
||||
UP,
|
||||
FULL
|
||||
};
|
||||
|
||||
static inline void *kzalloc(size_t size, gfp_t gfp)
|
||||
{
|
||||
return kmalloc(size, gfp | __GFP_ZERO);
|
||||
|
4
tools/testing/memblock/.gitignore
vendored
Normal file
4
tools/testing/memblock/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
main
|
||||
memblock.c
|
||||
linux/memblock.h
|
||||
asm/cmpxchg.h
|
52
tools/testing/memblock/Makefile
Normal file
52
tools/testing/memblock/Makefile
Normal file
@ -0,0 +1,52 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
# Memblock simulator requires AddressSanitizer (libasan) and liburcu development
|
||||
# packages installed
|
||||
CFLAGS += -I. -I../../include -Wall -O2 -fsanitize=address \
|
||||
-fsanitize=undefined -D CONFIG_PHYS_ADDR_T_64BIT
|
||||
LDFLAGS += -fsanitize=address -fsanitize=undefined
|
||||
TARGETS = main
|
||||
OFILES = main.o memblock.o lib/slab.o mmzone.o slab.o
|
||||
EXTR_SRC = ../../../mm/memblock.c
|
||||
|
||||
ifeq ($(BUILD), 32)
|
||||
CFLAGS += -m32
|
||||
LDFLAGS += -m32
|
||||
endif
|
||||
|
||||
# Process user parameters
|
||||
include scripts/Makefile.include
|
||||
|
||||
main: $(OFILES)
|
||||
|
||||
$(OFILES): include
|
||||
|
||||
include: ../../../include/linux/memblock.h ../../include/linux/*.h \
|
||||
../../include/asm/*.h
|
||||
|
||||
@mkdir -p linux
|
||||
test -L linux/memblock.h || ln -s ../../../../include/linux/memblock.h linux/memblock.h
|
||||
test -L asm/cmpxchg.h || ln -s ../../../arch/x86/include/asm/cmpxchg.h asm/cmpxchg.h
|
||||
|
||||
memblock.c: $(EXTR_SRC)
|
||||
test -L memblock.c || ln -s $(EXTR_SRC) memblock.c
|
||||
|
||||
clean:
|
||||
$(RM) $(TARGETS) $(OFILES) linux/memblock.h memblock.c asm/cmpxchg.h
|
||||
|
||||
help:
|
||||
@echo 'Memblock simulator'
|
||||
@echo ''
|
||||
@echo 'Available targets:'
|
||||
@echo ' main - Build the memblock simulator'
|
||||
@echo ' clean - Remove generated files and symlinks in the directory'
|
||||
@echo ''
|
||||
@echo 'Configuration:'
|
||||
@echo ' make NUMA=1 - simulate enabled NUMA'
|
||||
@echo ' make MOVABLE_NODE=1 - override `movable_node_is_enabled`'
|
||||
@echo ' definition to simulate movable NUMA nodes'
|
||||
@echo ' make 32BIT_PHYS_ADDR_T=1 - Use 32 bit physical addresses'
|
||||
|
||||
vpath %.c ../../lib
|
||||
|
||||
.PHONY: clean include help
|
5
tools/testing/memblock/asm/dma.h
Normal file
5
tools/testing/memblock/asm/dma.h
Normal file
@ -0,0 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _TOOLS_DMA_H
|
||||
#define _TOOLS_DMA_H
|
||||
|
||||
#endif
|
12
tools/testing/memblock/internal.h
Normal file
12
tools/testing/memblock/internal.h
Normal file
@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#ifndef _MM_INTERNAL_H
|
||||
#define _MM_INTERNAL_H
|
||||
|
||||
struct page {};
|
||||
|
||||
void memblock_free_pages(struct page *page, unsigned long pfn,
|
||||
unsigned int order)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
9
tools/testing/memblock/lib/slab.c
Normal file
9
tools/testing/memblock/lib/slab.c
Normal file
@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/slab.h>
|
||||
|
||||
enum slab_state slab_state;
|
||||
|
||||
bool slab_is_available(void)
|
||||
{
|
||||
return slab_state >= UP;
|
||||
}
|
34
tools/testing/memblock/linux/init.h
Normal file
34
tools/testing/memblock/linux/init.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _LINUX_INIT_H
|
||||
#define _LINUX_INIT_H
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <asm/export.h>
|
||||
#include <linux/memory_hotplug.h>
|
||||
|
||||
#define __section(section) __attribute__((__section__(section)))
|
||||
|
||||
#define __initconst
|
||||
#define __meminit
|
||||
#define __meminitdata
|
||||
#define __refdata
|
||||
#define __initdata
|
||||
|
||||
struct obs_kernel_param {
|
||||
const char *str;
|
||||
int (*setup_func)(char *st);
|
||||
int early;
|
||||
};
|
||||
|
||||
#define __setup_param(str, unique_id, fn, early) \
|
||||
static const char __setup_str_##unique_id[] __initconst \
|
||||
__aligned(1) = str; \
|
||||
static struct obs_kernel_param __setup_##unique_id \
|
||||
__used __section(".init.setup") \
|
||||
__aligned(__alignof__(struct obs_kernel_param)) = \
|
||||
{ __setup_str_##unique_id, fn, early }
|
||||
|
||||
#define early_param(str, fn) \
|
||||
__setup_param(str, fn, fn, 1)
|
||||
|
||||
#endif
|
12
tools/testing/memblock/linux/kernel.h
Normal file
12
tools/testing/memblock/linux/kernel.h
Normal file
@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _MEMBLOCK_LINUX_KERNEL_H
|
||||
#define _MEMBLOCK_LINUX_KERNEL_H
|
||||
|
||||
#include <../../include/linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <string.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/linkage.h>
|
||||
#include <linux/kconfig.h>
|
||||
|
||||
#endif
|
18
tools/testing/memblock/linux/kmemleak.h
Normal file
18
tools/testing/memblock/linux/kmemleak.h
Normal file
@ -0,0 +1,18 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _KMEMLEAK_H
|
||||
#define _KMEMLEAK_H
|
||||
|
||||
static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
|
||||
{
|
||||
}
|
||||
|
||||
static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
|
||||
int min_count, gfp_t gfp)
|
||||
{
|
||||
}
|
||||
|
||||
static inline void dump_stack(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
19
tools/testing/memblock/linux/memory_hotplug.h
Normal file
19
tools/testing/memblock/linux/memory_hotplug.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _LINUX_MEMORY_HOTPLUG_H
|
||||
#define _LINUX_MEMORY_HOTPLUG_H
|
||||
|
||||
#include <linux/numa.h>
|
||||
#include <linux/pfn.h>
|
||||
#include <linux/cache.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
static inline bool movable_node_is_enabled(void)
|
||||
{
|
||||
#ifdef MOVABLE_NODE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
35
tools/testing/memblock/linux/mmzone.h
Normal file
35
tools/testing/memblock/linux/mmzone.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _TOOLS_MMZONE_H
|
||||
#define _TOOLS_MMZONE_H
|
||||
|
||||
#include <linux/atomic.h>
|
||||
|
||||
struct pglist_data *first_online_pgdat(void);
|
||||
struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
|
||||
|
||||
#define for_each_online_pgdat(pgdat) \
|
||||
for (pgdat = first_online_pgdat(); \
|
||||
pgdat; \
|
||||
pgdat = next_online_pgdat(pgdat))
|
||||
|
||||
enum zone_type {
|
||||
__MAX_NR_ZONES
|
||||
};
|
||||
|
||||
#define MAX_NR_ZONES __MAX_NR_ZONES
|
||||
#define MAX_ORDER 11
|
||||
#define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1))
|
||||
|
||||
#define pageblock_order (MAX_ORDER - 1)
|
||||
#define pageblock_nr_pages BIT(pageblock_order)
|
||||
|
||||
struct zone {
|
||||
atomic_long_t managed_pages;
|
||||
};
|
||||
|
||||
typedef struct pglist_data {
|
||||
struct zone node_zones[MAX_NR_ZONES];
|
||||
|
||||
} pg_data_t;
|
||||
|
||||
#endif
|
25
tools/testing/memblock/linux/printk.h
Normal file
25
tools/testing/memblock/linux/printk.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _PRINTK_H
|
||||
#define _PRINTK_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <asm/bug.h>
|
||||
|
||||
/*
|
||||
* memblock_dbg is called with u64 arguments that don't match the "%llu"
|
||||
* specifier in printf. This results in warnings that cannot be fixed without
|
||||
* modifying memblock.c, which we wish to avoid. As these messaged are not used
|
||||
* in testing anyway, the mismatch can be ignored.
|
||||
*/
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#define printk printf
|
||||
#pragma GCC diagnostic push
|
||||
|
||||
#define pr_info printk
|
||||
#define pr_debug printk
|
||||
#define pr_cont printk
|
||||
#define pr_err printk
|
||||
#define pr_warn printk
|
||||
|
||||
#endif
|
6
tools/testing/memblock/main.c
Normal file
6
tools/testing/memblock/main.c
Normal file
@ -0,0 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
20
tools/testing/memblock/mmzone.c
Normal file
20
tools/testing/memblock/mmzone.c
Normal file
@ -0,0 +1,20 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include <linux/mmzone.h>
|
||||
|
||||
struct pglist_data *first_online_pgdat(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void reserve_bootmem_region(phys_addr_t start, phys_addr_t end)
|
||||
{
|
||||
}
|
||||
|
||||
void atomic_long_set(atomic_long_t *v, long i)
|
||||
{
|
||||
}
|
17
tools/testing/memblock/scripts/Makefile.include
Normal file
17
tools/testing/memblock/scripts/Makefile.include
Normal file
@ -0,0 +1,17 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# Definitions for user-provided arguments
|
||||
|
||||
# Simulate CONFIG_NUMA=y
|
||||
ifeq ($(NUMA), 1)
|
||||
CFLAGS += -D CONFIG_NUMA
|
||||
endif
|
||||
|
||||
# Simulate movable NUMA memory regions
|
||||
ifeq ($(MOVABLE_NODE), 1)
|
||||
CFLAGS += -D MOVABLE_NODE
|
||||
endif
|
||||
|
||||
# Use 32 bit physical addresses
|
||||
ifeq ($(32BIT_PHYS_ADDR_T), 1)
|
||||
CFLAGS += -U CONFIG_PHYS_ADDR_T_64BIT
|
||||
endif
|
Loading…
Reference in New Issue
Block a user