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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
subcmd/parse-options.hapi/fs/fs.hbench.hutil/cgroup.hunistd.hstdio.hstdlib.hsignal.hsys/wait.hstring.herrno.hfcntl.hassert.hsys/epoll.hsys/time.hsys/types.hsys/syscall.hlinux/time64.hpthread.h
Detected Declarations
struct thread_datafunction parse_two_cgroupsfunction enter_cgroupfunction exit_cgroupfunction read_pipefunction bench_sched_pipe
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
- Immediate include surface: `subcmd/parse-options.h`, `api/fs/fs.h`, `bench.h`, `util/cgroup.h`, `unistd.h`, `stdio.h`, `stdlib.h`, `signal.h`.
- Detected declarations: `struct thread_data`, `function parse_two_cgroups`, `function enter_cgroup`, `function exit_cgroup`, `function read_pipe`, `function bench_sched_pipe`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.