tools/perf/bench/sched-messaging.c
Source file repositories/reference/linux-study-clean/tools/perf/bench/sched-messaging.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/bench/sched-messaging.c- Extension
.c- Size
- 8528 bytes
- Lines
- 372
- 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.hbench.hpthread.hstdio.hstdlib.hstring.herrno.hunistd.hsys/types.hsys/socket.hsys/wait.hsys/time.hpoll.hlimits.herr.hlinux/list.hlinux/time64.h
Detected Declarations
struct sender_contextstruct receiver_contextfunction fdpairfunction readyfunction create_thread_workerfunction create_process_workerfunction create_workerfunction reap_workerfunction groupfunction sig_handlerfunction bench_sched_messaging
Annotated Snippet
struct sender_context {
struct list_head list;
unsigned int num_fds;
int ready_out;
int wakefd;
int out_fds[];
};
struct receiver_context {
struct list_head list;
unsigned int num_packets;
int in_fds[2];
int ready_out;
int wakefd;
};
union messaging_worker {
pthread_t thread;
pid_t pid;
};
static union messaging_worker *worker_tab;
static void fdpair(int fds[2])
{
if (use_pipes) {
if (pipe(fds) == 0)
return;
} else {
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0)
return;
}
err(EXIT_FAILURE, use_pipes ? "pipe()" : "socketpair()");
}
/* Block until we're ready to go */
static void ready(int ready_out, int wakefd)
{
struct pollfd pollfd = { .fd = wakefd, .events = POLLIN };
/* Tell them we're ready. */
if (write(ready_out, "R", 1) != 1)
err(EXIT_FAILURE, "CLIENT: ready write");
/* Wait for "GO" signal */
if (poll(&pollfd, 1, -1) != 1)
err(EXIT_FAILURE, "poll");
}
/* Sender sprays nr_loops messages down each file descriptor */
static void *sender(struct sender_context *ctx)
{
char data[DATASIZE];
unsigned int i, j;
ready(ctx->ready_out, ctx->wakefd);
memset(data, 'S', sizeof(data));
/* Now pump to every receiver. */
for (i = 0; i < nr_loops; i++) {
for (j = 0; j < ctx->num_fds; j++) {
int ret, done = 0;
again:
ret = write(ctx->out_fds[j], data + done,
sizeof(data) - done);
if (ret < 0)
err(EXIT_FAILURE, "SENDER: write");
done += ret;
if (done < DATASIZE)
goto again;
}
}
return NULL;
}
/* One receiver per fd */
static void *receiver(struct receiver_context* ctx)
{
unsigned int i;
if (!thread_mode)
close(ctx->in_fds[1]);
/* Wait for start... */
ready(ctx->ready_out, ctx->wakefd);
Annotation
- Immediate include surface: `subcmd/parse-options.h`, `bench.h`, `pthread.h`, `stdio.h`, `stdlib.h`, `string.h`, `errno.h`, `unistd.h`.
- Detected declarations: `struct sender_context`, `struct receiver_context`, `function fdpair`, `function ready`, `function create_thread_worker`, `function create_process_worker`, `function create_worker`, `function reap_worker`, `function group`, `function sig_handler`.
- 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.