// SPDX-License-Identifier: GPL-2.0 /* * * sched-messaging.c * * messaging: Benchmark for scheduler and IPC mechanisms * * Based on hackbench by Rusty Russell <rusty@rustcorp.com.au> * Ported to perf by Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp> *
*/
snd_ctx->out_fds[i] = fds[1]; if (!thread_mode)
close(fds[0]);
}
/* Now we have all the fds, fork the senders */ for (i = 0; i < num_fds; i++) {
snd_ctx->ready_out = ready_out;
snd_ctx->wakefd = wakefd;
snd_ctx->num_fds = num_fds;
create_worker(worker + num_fds + i, snd_ctx, (void *)sender);
}
/* Close the fds we have left */ if (!thread_mode) for (i = 0; i < num_fds; i++)
close(snd_ctx->out_fds[i]);
/* Return number of children to reap */ return num_fds * 2;
}
staticvoid sig_handler(int sig __maybe_unused)
{ unsignedint i;
/* * When exit abnormally, kill all forked child processes.
*/ for (i = 0; i < total_children; i++)
kill(worker_tab[i].pid, SIGKILL);
}
staticconststruct option options[] = {
OPT_BOOLEAN('p', "pipe", &use_pipes, "Use pipe() instead of socketpair()"),
OPT_BOOLEAN('t', "thread", &thread_mode, "Be multi thread instead of multi process"),
OPT_UINTEGER('g', "group", &num_groups, "Specify number of groups"),
OPT_UINTEGER('l', "nr_loops", &nr_loops, "Specify the number of loops to run (default: 100)"),
OPT_END()
};
if (!thread_mode) {
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
}
for (i = 0; i < num_groups; i++)
total_children += group(worker_tab + total_children, num_fds,
readyfds[1], wakefds[0]);
/* Wait for everyone to be ready */ for (i = 0; i < total_children; i++) if (read(readyfds[0], &dummy, 1) != 1)
err(EXIT_FAILURE, "Reading for readyfds");
gettimeofday(&start, NULL);
/* Kick them off */ if (write(wakefds[1], &dummy, 1) != 1)
err(EXIT_FAILURE, "Writing to start them");
/* Reap them all */ for (i = 0; i < total_children; i++)
reap_worker(worker_tab + i);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.