Merge pull request #312 from reshke/master

fix bench compile errors
This commit is contained in:
Andrey Borodin 2021-05-05 00:23:35 +05:00 committed by GitHub
commit 58793a65a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 5 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ test/odyssey_test
test/odyssey/data
third_party/machinarium/sources/build.h
third_party/machinarium/benchmark/benchmark_csw
third_party/machinarium/benchmark/benchmark_csw2
third_party/machinarium/benchmark/benchmark_channel
third_party/machinarium/benchmark/benchmark_channel_shared
build/

View File

@ -3,10 +3,12 @@ RM = rm
CFLAGS = -I. -Wall -g -O3 -I../sources
LFLAGS_LIB = ../sources/libmachinarium.a -pthread -lssl -lcrypto
LFLAGS = $(LFLAGS_LIB)
EXAMPLES = benchmark_csw benchmark_channel benchmark_channel_shared
EXAMPLES = benchmark_csw benchmark_csw2 benchmark_channel benchmark_channel_shared
all: clean $(EXAMPLES)
benchmark_csw:
$(CC) $(CFLAGS) benchmark_csw.c $(LFLAGS) -o benchmark_csw
benchmark_csw2:
$(CC) $(CFLAGS) benchmark_csw2.c $(LFLAGS) -o benchmark_csw2
benchmark_channel:
$(CC) $(CFLAGS) benchmark_channel.c $(LFLAGS) -o benchmark_channel
benchmark_channel_shared:

View File

@ -26,7 +26,7 @@ static void benchmark_writer(void *arg)
machine_channel_t *channel = arg;
while (machine_active()) {
machine_msg_t *msg;
msg = machine_msg_create(0, 0);
msg = machine_msg_create(0);
machine_channel_write(channel, msg);
ops++;
machine_sleep(0);
@ -44,7 +44,7 @@ static void benchmark_runner(void *arg)
int w = machine_coroutine_create(benchmark_writer, channel);
machine_sleep(1000);
machine_stop();
machine_stop_current();
machine_cancel(r);
machine_join(r);
machine_join(w);

View File

@ -44,7 +44,7 @@ static void benchmark_runner(void *arg)
int w = machine_coroutine_create(benchmark_writer, q);
machine_sleep(1000);
machine_stop();
machine_stop_current();
machine_cancel(r);
machine_join(r);
machine_join(w);

View File

@ -31,7 +31,7 @@ static void benchmark_runner(void *arg)
machine_sleep(1000);
printf("done.\n");
printf("context switches %d in 1 sec.\n", csw);
machine_stop();
machine_stop_current();
}
int main(int argc, char *argv[])

View File

@ -0,0 +1,57 @@
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
/*
* This example shows coroutine context switch (yield)
* performance done in one second.
*/
#include <machinarium.h>
#define MAX_COROUTINES 1000
int csws[MAX_COROUTINES];
static void benchmark_worker(void *arg)
{
int id = arg;
// printf("worker started.\n");
while (machine_active()) {
csws[id]++;
machine_sleep(0);
}
// printf("worker done.\n");
}
static void benchmark_runner(void *arg)
{
printf("benchmark started.\n");
for (int i = 0; i < MAX_COROUTINES; ++i) {
machine_coroutine_create(benchmark_worker, i);
}
machine_sleep(1000);
printf("done.\n");
int csw = 0;
for (int i = 0; i < MAX_COROUTINES; ++i) {
csw += csws[i];
}
fflush(stdout);
printf("_______________________________\n");
printf("context switches %d in 1 sec.\n", csw);
machine_stop_current();
}
int main(int argc, char *argv[])
{
machinarium_init();
int id = machine_create("benchmark_csw", benchmark_runner, NULL);
int rc = machine_wait(id);
printf("retcode from machine wait %d.\n", rc);
machinarium_free();
return 0;
}