Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <perf/cpumap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <internal/cpumap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include "env.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "mem2node.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static struct node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 	int		 node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 	const char 	*map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) } test_nodes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	{ .node = 0, .map = "0"     },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	{ .node = 1, .map = "1-2"   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	{ .node = 3, .map = "5-7,9" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define T TEST_ASSERT_VAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static unsigned long *get_bitmap(const char *str, int nbits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	struct perf_cpu_map *map = perf_cpu_map__new(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	unsigned long *bm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	bm = bitmap_alloc(nbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	if (map && bm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		for (i = 0; i < map->nr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 			set_bit(map->map[i], bm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	if (map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		perf_cpu_map__put(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		free(bm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	return bm && map ? bm : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int test__mem2node(struct test *t __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	struct mem2node map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	struct memory_node nodes[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	struct perf_env env = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		.memory_nodes    = (struct memory_node *) &nodes[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		.nr_memory_nodes = ARRAY_SIZE(nodes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		.memory_bsize    = 0x100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	for (i = 0; i < ARRAY_SIZE(nodes); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		nodes[i].node = test_nodes[i].node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		nodes[i].size = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		T("failed: alloc bitmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		  (nodes[i].set = get_bitmap(test_nodes[i].map, 10)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	T("failed: mem2node__init", !mem2node__init(&map, &env));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	T("failed: mem2node__node",  0 == mem2node__node(&map,   0x50));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	T("failed: mem2node__node",  1 == mem2node__node(&map,  0x100));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	T("failed: mem2node__node",  1 == mem2node__node(&map,  0x250));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	T("failed: mem2node__node",  3 == mem2node__node(&map,  0x500));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	T("failed: mem2node__node",  3 == mem2node__node(&map,  0x650));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	T("failed: mem2node__node", -1 == mem2node__node(&map,  0x450));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	T("failed: mem2node__node", -1 == mem2node__node(&map, 0x1050));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	for (i = 0; i < ARRAY_SIZE(nodes); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 		zfree(&nodes[i].set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	mem2node__exit(&map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }