History

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.

Karolina Drobnik committed 4 years ago

Commit 16802e51 parent 621832716 files · +279 −0Browse files

Unified · Split

16 files
  1. MAINTAINERS +1 −0
  2. tools/include/linux/slab.h +10 −0
  3. tools/testing/memblock/.gitignore +4 −0
  4. tools/testing/memblock/Makefile +52 −0
  5. tools/testing/memblock/asm/dma.h +5 −0
  6. tools/testing/memblock/internal.h +12 −0
  7. tools/testing/memblock/lib/slab.c +9 −0
  8. tools/testing/memblock/linux/init.h +34 −0
  9. tools/testing/memblock/linux/kernel.h +12 −0
  10. tools/testing/memblock/linux/kmemleak.h +18 −0
  11. tools/testing/memblock/linux/memory_hotplug.h +19 −0
  12. tools/testing/memblock/linux/mmzone.h +35 −0
  13. tools/testing/memblock/linux/printk.h +25 −0
  14. tools/testing/memblock/main.c +6 −0
  15. tools/testing/memblock/mmzone.c +20 −0
  16. tools/testing/memblock/scripts/Makefile.include +17 −0
MAINTAINERS+1−0
@@ -12423,6 +12423,7 @@ S: Maintained · 12422 unmodified lines
12423F: Documentation/core-api/boot-time-mm.rst12423F: Documentation/core-api/boot-time-mm.rst
12424F: include/linux/memblock.h12424F: include/linux/memblock.h
12425F: mm/memblock.c12425F: mm/memblock.c
12426F: tools/testing/memblock/
12426 12427
12427MEMORY CONTROLLER DRIVERS12428MEMORY CONTROLLER DRIVERS
12428M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>12429M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
tools/include/linux/slab.h+10−0
@@ -13,6 +13,16 @@ · 12 unmodified lines
13void *kmalloc(size_t size, gfp_t gfp);13void *kmalloc(size_t size, gfp_t gfp);
14void kfree(void *p);14void kfree(void *p);
15 15
16bool slab_is_available(void);
17
18enum slab_state {
19 DOWN,
20 PARTIAL,
21 PARTIAL_NODE,
22 UP,
23 FULL
24};
25
16static inline void *kzalloc(size_t size, gfp_t gfp)26static inline void *kzalloc(size_t size, gfp_t gfp)
17{27{
18 return kmalloc(size, gfp | __GFP_ZERO);28 return kmalloc(size, gfp | __GFP_ZERO);
tools/testing/memblock/.gitignore+4−0
@@ -0,0 +1,4 @@
1main
2memblock.c
3linux/memblock.h
4asm/cmpxchg.h
tools/testing/memblock/Makefile+52−0
@@ -0,0 +1,52 @@
1# SPDX-License-Identifier: GPL-2.0
2
3# Memblock simulator requires AddressSanitizer (libasan) and liburcu development
4# packages installed
5CFLAGS += -I. -I../../include -Wall -O2 -fsanitize=address \
6 -fsanitize=undefined -D CONFIG_PHYS_ADDR_T_64BIT
7LDFLAGS += -fsanitize=address -fsanitize=undefined
8TARGETS = main
9OFILES = main.o memblock.o lib/slab.o mmzone.o slab.o
10EXTR_SRC = ../../../mm/memblock.c
11
12ifeq ($(BUILD), 32)
13 CFLAGS += -m32
14 LDFLAGS += -m32
15endif
16
17# Process user parameters
18include scripts/Makefile.include
19
20main: $(OFILES)
21
22$(OFILES): include
23
24include: ../../../include/linux/memblock.h ../../include/linux/*.h \
25 ../../include/asm/*.h
26
27 @mkdir -p linux
28 test -L linux/memblock.h || ln -s ../../../../include/linux/memblock.h linux/memblock.h
29 test -L asm/cmpxchg.h || ln -s ../../../arch/x86/include/asm/cmpxchg.h asm/cmpxchg.h
30
31memblock.c: $(EXTR_SRC)
32 test -L memblock.c || ln -s $(EXTR_SRC) memblock.c
33
34clean:
35 $(RM) $(TARGETS) $(OFILES) linux/memblock.h memblock.c asm/cmpxchg.h
36
37help:
38 @echo 'Memblock simulator'
39 @echo ''
40 @echo 'Available targets:'
41 @echo ' main - Build the memblock simulator'
42 @echo ' clean - Remove generated files and symlinks in the directory'
43 @echo ''
44 @echo 'Configuration:'
45 @echo ' make NUMA=1 - simulate enabled NUMA'
46 @echo ' make MOVABLE_NODE=1 - override `movable_node_is_enabled`'
47 @echo ' definition to simulate movable NUMA nodes'
48 @echo ' make 32BIT_PHYS_ADDR_T=1 - Use 32 bit physical addresses'
49
50vpath %.c ../../lib
51
52.PHONY: clean include help
tools/testing/memblock/asm/dma.h+5−0
@@ -0,0 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _TOOLS_DMA_H
3#define _TOOLS_DMA_H
4
5#endif
tools/testing/memblock/internal.h+12−0
@@ -0,0 +1,12 @@
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2#ifndef _MM_INTERNAL_H
3#define _MM_INTERNAL_H
4
5struct page {};
6
7void memblock_free_pages(struct page *page, unsigned long pfn,
8 unsigned int order)
9{
10}
11
12#endif
tools/testing/memblock/lib/slab.c+9−0
@@ -0,0 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/slab.h>
3
4enum slab_state slab_state;
5
6bool slab_is_available(void)
7{
8 return slab_state >= UP;
9}
tools/testing/memblock/linux/init.h+34−0
@@ -0,0 +1,34 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_INIT_H
3#define _LINUX_INIT_H
4
5#include <linux/compiler.h>
6#include <asm/export.h>
7#include <linux/memory_hotplug.h>
8
9#define __section(section) __attribute__((__section__(section)))
10
11#define __initconst
12#define __meminit
13#define __meminitdata
14#define __refdata
15#define __initdata
16
17struct obs_kernel_param {
18 const char *str;
19 int (*setup_func)(char *st);
20 int early;
21};
22
23#define __setup_param(str, unique_id, fn, early) \
24 static const char __setup_str_##unique_id[] __initconst \
25 __aligned(1) = str; \
26 static struct obs_kernel_param __setup_##unique_id \
27 __used __section(".init.setup") \
28 __aligned(__alignof__(struct obs_kernel_param)) = \
29 { __setup_str_##unique_id, fn, early }
30
31#define early_param(str, fn) \
32 __setup_param(str, fn, fn, 1)
33
34#endif
tools/testing/memblock/linux/kernel.h+12−0
@@ -0,0 +1,12 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef _MEMBLOCK_LINUX_KERNEL_H
3#define _MEMBLOCK_LINUX_KERNEL_H
4
5#include <../../include/linux/kernel.h>
6#include <linux/errno.h>
7#include <string.h>
8#include <linux/printk.h>
9#include <linux/linkage.h>
10#include <linux/kconfig.h>
11
12#endif
tools/testing/memblock/linux/kmemleak.h+18−0
@@ -0,0 +1,18 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef _KMEMLEAK_H
3#define _KMEMLEAK_H
4
5static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
6{
7}
8
9static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
10 int min_count, gfp_t gfp)
11{
12}
13
14static inline void dump_stack(void)
15{
16}
17
18#endif
tools/testing/memblock/linux/memory_hotplug.h+19−0
@@ -0,0 +1,19 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_MEMORY_HOTPLUG_H
3#define _LINUX_MEMORY_HOTPLUG_H
4
5#include <linux/numa.h>
6#include <linux/pfn.h>
7#include <linux/cache.h>
8#include <linux/types.h>
9
10static inline bool movable_node_is_enabled(void)
11{
12#ifdef MOVABLE_NODE
13 return true;
14#else
15 return false;
16#endif
17}
18
19#endif
tools/testing/memblock/linux/mmzone.h+35−0
@@ -0,0 +1,35 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _TOOLS_MMZONE_H
3#define _TOOLS_MMZONE_H
4
5#include <linux/atomic.h>
6
7struct pglist_data *first_online_pgdat(void);
8struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
9
10#define for_each_online_pgdat(pgdat) \
11 for (pgdat = first_online_pgdat(); \
12 pgdat; \
13 pgdat = next_online_pgdat(pgdat))
14
15enum zone_type {
16 __MAX_NR_ZONES
17};
18
19#define MAX_NR_ZONES __MAX_NR_ZONES
20#define MAX_ORDER 11
21#define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1))
22
23#define pageblock_order (MAX_ORDER - 1)
24#define pageblock_nr_pages BIT(pageblock_order)
25
26struct zone {
27 atomic_long_t managed_pages;
28};
29
30typedef struct pglist_data {
31 struct zone node_zones[MAX_NR_ZONES];
32
33} pg_data_t;
34
35#endif
tools/testing/memblock/linux/printk.h+25−0
@@ -0,0 +1,25 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _PRINTK_H
3#define _PRINTK_H
4
5#include <stdio.h>
6#include <asm/bug.h>
7
8/*
9 * memblock_dbg is called with u64 arguments that don't match the "%llu"
10 * specifier in printf. This results in warnings that cannot be fixed without
11 * modifying memblock.c, which we wish to avoid. As these messaged are not used
12 * in testing anyway, the mismatch can be ignored.
13 */
14#pragma GCC diagnostic push
15#pragma GCC diagnostic ignored "-Wformat"
16#define printk printf
17#pragma GCC diagnostic push
18
19#define pr_info printk
20#define pr_debug printk
21#define pr_cont printk
22#define pr_err printk
23#define pr_warn printk
24
25#endif
tools/testing/memblock/main.c+6−0
@@ -0,0 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3int main(int argc, char **argv)
4{
5 return 0;
6}
tools/testing/memblock/mmzone.c+20−0
@@ -0,0 +1,20 @@
1// SPDX-License-Identifier: GPL-2.0-or-later
2#include <linux/mmzone.h>
3
4struct pglist_data *first_online_pgdat(void)
5{
6 return NULL;
7}
8
9struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
10{
11 return NULL;
12}
13
14void reserve_bootmem_region(phys_addr_t start, phys_addr_t end)
15{
16}
17
18void atomic_long_set(atomic_long_t *v, long i)
19{
20}
tools/testing/memblock/scripts/Makefile.include+17−0
@@ -0,0 +1,17 @@
1# SPDX-License-Identifier: GPL-2.0
2# Definitions for user-provided arguments
3
4# Simulate CONFIG_NUMA=y
5ifeq ($(NUMA), 1)
6 CFLAGS += -D CONFIG_NUMA
7endif
8
9# Simulate movable NUMA memory regions
10ifeq ($(MOVABLE_NODE), 1)
11 CFLAGS += -D MOVABLE_NODE
12endif
13
14# Use 32 bit physical addresses
15ifeq ($(32BIT_PHYS_ADDR_T), 1)
16 CFLAGS += -U CONFIG_PHYS_ADDR_T_64BIT
17endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t