mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-18 21:08:46 -05:00
perf bench messaging: Factor out create_worker()
Refactor the create_worker() helper:
1. Modify the return value and use pthread pointer as a parameter to
facilitate value assignment in create_worker().
2. The thread worker creation and process worker creation are abstracted
into independent helpers.
No functional change.
Test result:
# perf bench sched messaging
# Running 'sched/messaging' benchmark:
# 20 sender and receiver processes per group
# 10 groups == 400 processes run
Total time: 6.332 [sec]
# perf bench sched messaging -t
# Running 'sched/messaging' benchmark:
# 20 sender and receiver threads per group
# 10 groups == 400 threads run
Total time: 5.545 [sec]
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20230923093037.961232-3-yangjihong1@huawei.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
committed by
Namhyung Kim
parent
8870261a70
commit
5d2050453d
@@ -139,30 +139,12 @@ static void *receiver(struct receiver_context* ctx)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static pthread_t create_worker(void *ctx, void *(*func)(void *))
|
||||
static void create_thread_worker(pthread_t *thread,
|
||||
void *ctx, void *(*func)(void *))
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
pthread_t childid;
|
||||
int ret;
|
||||
|
||||
if (!thread_mode) {
|
||||
/* process mode */
|
||||
/* Fork the receiver. */
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
err(EXIT_FAILURE, "fork()");
|
||||
break;
|
||||
case 0:
|
||||
(*func) (ctx);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (pthread_t)0;
|
||||
}
|
||||
|
||||
if (pthread_attr_init(&attr) != 0)
|
||||
err(EXIT_FAILURE, "pthread_attr_init:");
|
||||
|
||||
@@ -171,12 +153,32 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *))
|
||||
err(EXIT_FAILURE, "pthread_attr_setstacksize");
|
||||
#endif
|
||||
|
||||
ret = pthread_create(&childid, &attr, func, ctx);
|
||||
ret = pthread_create(thread, &attr, func, ctx);
|
||||
if (ret != 0)
|
||||
err(EXIT_FAILURE, "pthread_create failed");
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
return childid;
|
||||
}
|
||||
|
||||
static void create_process_worker(void *ctx, void *(*func)(void *))
|
||||
{
|
||||
/* Fork the receiver. */
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == -1) {
|
||||
err(EXIT_FAILURE, "fork()");
|
||||
} else if (pid == 0) {
|
||||
(*func) (ctx);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void create_worker(pthread_t *thread, void *ctx, void *(*func)(void *))
|
||||
{
|
||||
if (!thread_mode)
|
||||
return create_process_worker(ctx, func);
|
||||
else
|
||||
return create_thread_worker(thread, ctx, func);
|
||||
}
|
||||
|
||||
static void reap_worker(pthread_t id)
|
||||
@@ -226,7 +228,7 @@ static unsigned int group(pthread_t *pth,
|
||||
ctx->ready_out = ready_out;
|
||||
ctx->wakefd = wakefd;
|
||||
|
||||
pth[i] = create_worker(ctx, (void *)receiver);
|
||||
create_worker(pth + i, ctx, (void *)receiver);
|
||||
|
||||
snd_ctx->out_fds[i] = fds[1];
|
||||
if (!thread_mode)
|
||||
@@ -239,7 +241,7 @@ static unsigned int group(pthread_t *pth,
|
||||
snd_ctx->wakefd = wakefd;
|
||||
snd_ctx->num_fds = num_fds;
|
||||
|
||||
pth[num_fds + i] = create_worker(snd_ctx, (void *)sender);
|
||||
create_worker(pth + num_fds + i, snd_ctx, (void *)sender);
|
||||
}
|
||||
|
||||
/* Close the fds we have left */
|
||||
|
||||
Reference in New Issue
Block a user