tools/testing/selftests/powerpc/benchmarks/null_syscall.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/benchmarks/null_syscall.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/benchmarks/null_syscall.c
Extension
.c
Size
3018 bytes
Lines
155
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: syscall or user/kernel boundary
Status
core implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (strncmp(line, "timebase", 8) == 0) {
			p = strchr(line, ':');
			if (p != NULL) {
				v = strtoull(p + 1, &end, 0);
				if (end != p + 1)
					timebase_frequency = v;
			}
		}

		if (((strncmp(line, "clock", 5) == 0) ||
		     (strncmp(line, "cpu MHz", 7) == 0))) {
			p = strchr(line, ':');
			if (p != NULL) {
				d = strtod(p + 1, &end);
				if (end != p + 1) {
					/* Find fastest clock frequency */
					if ((d * 1000000ULL) > clock_frequency)
						clock_frequency = d * 1000000ULL;
				}
			}
		}
	}

	fclose(f);

	override = getenv("FREQUENCY");
	if (override)
		clock_frequency = strtoull(override, NULL, 10);

	if (timebase_frequency)
		timebase_multiplier = (double)clock_frequency
					/ timebase_frequency;
	else
		timebase_multiplier = 1;
}

static void do_null_syscall(unsigned long nr)
{
	unsigned long i;

	for (i = 0; i < nr; i++)
		syscall(__NR_gettid);
}

#define TIME(A, STR) \

int main(void)
{
	unsigned long tb_start, tb_now;
	struct timespec tv_start, tv_now;
	unsigned long long elapsed_ns, elapsed_tb;

	get_proc_frequency();

	clock_gettime(CLOCK_MONOTONIC, &tv_start);
	tb_start = mftb();

	do_null_syscall(NR_LOOPS);

	clock_gettime(CLOCK_MONOTONIC, &tv_now);
	tb_now = mftb();

	elapsed_ns = (tv_now.tv_sec - tv_start.tv_sec) * 1000000000ULL +
			(tv_now.tv_nsec - tv_start.tv_nsec);
	elapsed_tb = tb_now - tb_start;

	printf("%10.2f ns %10.2f cycles\n", (float)elapsed_ns / NR_LOOPS,
			(float)elapsed_tb * timebase_multiplier / NR_LOOPS);

	return 0;
}

Annotation

Implementation Notes