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 <perf/cpumap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <internal/cpumap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #define NBITS 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) static unsigned long *get_bitmap(const char *str, int nbits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 	struct perf_cpu_map *map = perf_cpu_map__new(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 	unsigned long *bm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	bm = bitmap_alloc(nbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	if (map && bm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 		for (i = 0; i < map->nr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 			set_bit(map->map[i], bm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	if (map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 		perf_cpu_map__put(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	return bm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int test_bitmap(const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	unsigned long *bm = get_bitmap(str, NBITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	char buf[100];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	bitmap_scnprintf(bm, NBITS, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	pr_debug("bitmap: %s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	ret = !strcmp(buf, str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	free(bm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int test__bitmap_print(struct test *test __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	TEST_ASSERT_VAL("failed to convert map", test_bitmap("1"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,5"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3,5,7,9,11,13,15,17,19,21-40"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	TEST_ASSERT_VAL("failed to convert map", test_bitmap("2-5"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	TEST_ASSERT_VAL("failed to convert map", test_bitmap("1-10,12-20,22-30,32-40"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }