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:
Karolina Drobnik
2022-02-02 12:03:09 +01:00
committed by Mike Rapoport
parent 62183279ad
commit 16802e55de
16 changed files with 279 additions and 0 deletions

View 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

View 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

View 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

View 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

View 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

View 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