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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Benchmark of /proc/kallsyms parsing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright 2020 Google LLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include "bench.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include "../util/stat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/time64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <subcmd/parse-options.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <symbol/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static unsigned int iterations = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static const struct option options[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	OPT_UINTEGER('i', "iterations", &iterations,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 		"Number of iterations used to compute average"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	OPT_END()
^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) static const char *const bench_usage[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	"perf bench internals kallsyms-parse <options>",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static int bench_process_symbol(void *arg __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 				const char *name __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 				char type __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 				u64 start __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int do_kallsyms_parse(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	struct timeval start, end, diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	u64 runtime_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	double time_average, time_stddev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	struct stats time_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	init_stats(&time_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	for (i = 0; i < iterations; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		gettimeofday(&start, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		err = kallsyms__parse("/proc/kallsyms", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 				bench_process_symbol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		gettimeofday(&end, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		timersub(&end, &start, &diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		runtime_us = diff.tv_sec * USEC_PER_SEC + diff.tv_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		update_stats(&time_stats, runtime_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	time_average = avg_stats(&time_stats) / USEC_PER_MSEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	time_stddev = stddev_stats(&time_stats) / USEC_PER_MSEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	printf("  Average kallsyms__parse took: %.3f ms (+- %.3f ms)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		time_average, time_stddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int bench_kallsyms_parse(int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	argc = parse_options(argc, argv, options, bench_usage, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	if (argc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		usage_with_options(bench_usage, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 		exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	return do_kallsyms_parse();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }