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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/benchmarks/fork.c
Extension
.c
Size
5163 bytes
Lines
326
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source 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 (pid == -1) {
			perror("fork");
			exit(1);
		}
		if (pid == 0) {
			if (do_exec)
				run_exec();
			_exit(0);
		}
		pid = waitpid(pid, NULL, 0);
		if (pid == -1) {
			perror("waitpid");
			exit(1);
		}
		iterations++;
	}
}

static void bench_vfork(void)
{
	while (1) {
		pid_t pid = vfork();
		if (pid == -1) {
			perror("fork");
			exit(1);
		}
		if (pid == 0) {
			if (do_exec)
				run_exec();
			_exit(0);
		}
		pid = waitpid(pid, NULL, 0);
		if (pid == -1) {
			perror("waitpid");
			exit(1);
		}
		iterations++;
	}
}

static void *null_fn(void *arg)
{
	pthread_exit(NULL);
}

static void bench_thread(void)
{
	pthread_t tid;
	cpu_set_t cpuset;
	pthread_attr_t attr;
	int rc;

	rc = pthread_attr_init(&attr);
	if (rc) {
		errno = rc;
		perror("pthread_attr_init");
		exit(1);
	}

	if (cpu != -1) {
		CPU_ZERO(&cpuset);
		CPU_SET(cpu, &cpuset);

		rc = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
		if (rc) {
			errno = rc;
			perror("pthread_attr_setaffinity_np");
			exit(1);
		}
	}

	while (1) {
		rc = pthread_create(&tid, &attr, null_fn, NULL);
		if (rc) {
			errno = rc;
			perror("pthread_create");
			exit(1);
		}
		rc = pthread_join(tid, NULL);
		if (rc) {
			errno = rc;
			perror("pthread_join");
			exit(1);
		}
		iterations++;
	}
}

static void sigalrm_handler(int junk)
{

Annotation

Implementation Notes