tools/perf/bench/sched-pipe.c

Source file repositories/reference/linux-study-clean/tools/perf/bench/sched-pipe.c

File Facts

System
Linux kernel
Corpus path
tools/perf/bench/sched-pipe.c
Extension
.c
Size
6996 bytes
Lines
330
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

struct thread_data {
	int			nr;
	int			pipe_read;
	int			pipe_write;
	struct epoll_event      epoll_ev;
	int			epoll_fd;
	bool			cgroup_failed;
	pthread_t		pthread;
};

#define LOOPS_DEFAULT 1000000
static	int			loops = LOOPS_DEFAULT;

/* Use processes by default: */
static bool			threaded;

static bool			nonblocking;
static char			*cgrp_names[2];
static struct cgroup		*cgrps[2];

static int parse_two_cgroups(const struct option *opt __maybe_unused,
			     const char *str, int unset __maybe_unused)
{
	char *p = strdup(str);
	char *q;
	int ret = -1;

	if (p == NULL) {
		fprintf(stderr, "memory allocation failure\n");
		return -1;
	}

	q = strchr(p, ',');
	if (q == NULL) {
		fprintf(stderr, "it should have two cgroup names: %s\n", p);
		goto out;
	}
	*q = '\0';

	cgrp_names[0] = strdup(p);
	cgrp_names[1] = strdup(q + 1);

	if (cgrp_names[0] == NULL || cgrp_names[1] == NULL) {
		fprintf(stderr, "memory allocation failure\n");
		goto out;
	}
	ret = 0;

out:
	free(p);
	return ret;
}

static const struct option options[] = {
	OPT_BOOLEAN('n', "nonblocking",	&nonblocking,	"Use non-blocking operations"),
	OPT_INTEGER('l', "loop",	&loops,		"Specify number of loops"),
	OPT_BOOLEAN('T', "threaded",	&threaded,	"Specify threads/process based task setup"),
	OPT_CALLBACK('G', "cgroups", NULL, "SEND,RECV",
		     "Put sender and receivers in given cgroups",
		     parse_two_cgroups),
	OPT_END()
};

static const char * const bench_sched_pipe_usage[] = {
	"perf bench sched pipe <options>",
	NULL
};

static int enter_cgroup(int nr)
{
	char buf[32];
	int fd, len, ret;
	int saved_errno;
	struct cgroup *cgrp;
	pid_t pid;

	if (cgrp_names[nr] == NULL)
		return 0;

	if (cgrps[nr] == NULL) {
		cgrps[nr] = cgroup__new(cgrp_names[nr], /*do_open=*/true);
		if (cgrps[nr] == NULL)
			goto err;
	}
	cgrp = cgrps[nr];

	if (threaded)
		pid = syscall(__NR_gettid);
	else
		pid = getpid();

Annotation

Implementation Notes