From 201627de9aef9473f6a8ceb4898070a1e22615e3 Mon Sep 17 00:00:00 2001 From: Adam Michalski Date: Mon, 3 Jan 2022 15:10:31 +0100 Subject: [PATCH] Add real tries parameterization Let the user specify the number of real tries in each of the IPC tests. Take the default number of real tries as 1000, as it was previously hard-coded. Change-Id: I016e1f38479ecf4a81ed72a38900e51ccae54231 --- benchmark/gdbus.c | 17 +++++++++++++---- benchmark/libdbus.c | 21 +++++++++++++++------ benchmark/p2p-gdbus.c | 2 +- benchmark/pipe.c | 17 +++++++++++++---- benchmark/sharedmem.c | 17 +++++++++++++---- benchmark/socket.c | 17 +++++++++++++---- 6 files changed, 68 insertions(+), 23 deletions(-) diff --git a/benchmark/gdbus.c b/benchmark/gdbus.c index c4df6ab..eab0420 100644 --- a/benchmark/gdbus.c +++ b/benchmark/gdbus.c @@ -15,6 +15,7 @@ typedef struct _state { int nprocs; int msize; +int n_real_tries; int lt_cnt; double min, max, total; unsigned long long bw; @@ -110,7 +111,7 @@ static void handle_method_call (GDBusConnection *connection, + (unsigned long long)clock.tv_nsec; } - if(bw_cnt == REAL_TRY) { + if(bw_cnt == n_real_tries) { clock_gettime (CLOCK_REALTIME, &clock); end = (unsigned long long)clock.tv_sec * NS +(unsigned long long)clock.tv_nsec; @@ -157,7 +158,7 @@ void Receive(register int size, const char *name, const char *path, bool is_lt) GDBusNodeInfo *introspection_data = NULL; introspection_data = g_dbus_node_info_new_for_xml (_interface_introspection_xml, NULL); - state.iters = WARMUP_TRY + REAL_TRY; + state.iters = WARMUP_TRY + n_real_tries; state.is_lt = is_lt; state.buf = buf; state.main_loop = g_main_loop; @@ -187,7 +188,7 @@ void Send(register int size, const char *name, const char *path, bool is_lt) g_assert(conn != NULL); sleep(2); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { struct timespec clock; memset(cptr, 0, size); @@ -415,9 +416,10 @@ main(int argc, char **argv) if(nprocs == 1) nprocs = 2; + n_real_tries = REAL_TRY; msize = 3; lt_on = bw_on = false; - while((opt = getopt(argc, argv, "m:p:blhr")) != -1) { + while((opt = getopt(argc, argv, "m:p:blhrt:")) != -1) { switch(opt) { case 'm': msize = atoi(optarg); @@ -439,6 +441,13 @@ main(int argc, char **argv) case 'l': lt_on = true; break; + case 't': + n_real_tries = atoi(optarg); + if (n_real_tries <= 0) { + printf("Number of real tries must be larger than 0\n"); + exit(0); + } + break; case 'r': raw_data_on = true; /* dump raw data */ break; diff --git a/benchmark/libdbus.c b/benchmark/libdbus.c index de38164..c13cf3a 100644 --- a/benchmark/libdbus.c +++ b/benchmark/libdbus.c @@ -14,6 +14,7 @@ typedef struct _state { int nprocs; int msize; +int n_real_tries; int lt_cnt; double min, max, total; unsigned long long bw; @@ -72,7 +73,7 @@ static DBusHandlerResult message_func (DBusConnection *connection, + (unsigned long long)clock.tv_nsec; } - if(bw_cnt == REAL_TRY) { + if(bw_cnt == n_real_tries) { clock_gettime (CLOCK_REALTIME, &clock); end = (unsigned long long)clock.tv_sec * NS +(unsigned long long)clock.tv_nsec; @@ -120,12 +121,12 @@ void Receive(register int size, const char *name, const char *path, bool is_lt) exit(1); } - state.iters = WARMUP_TRY + REAL_TRY; + state.iters = WARMUP_TRY + n_real_tries; state.is_lt = is_lt; state.buf = buf; dbus_connection_register_object_path (conn, path, &vtable, &state); - //for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + //for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { while(1) { if(!dbus_connection_read_write_dispatch(conn, -1)) { printf("read on parent error\n"); @@ -156,7 +157,7 @@ void Send(register int size, const char *name, const char *path, const char *cli } sleep(2); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { struct timespec clock; memset(cptr, 0, size); @@ -380,9 +381,10 @@ main(int argc, char **argv) if(nprocs == 1) nprocs = 2; + n_real_tries = REAL_TRY; msize = 3; lt_on = bw_on = false; - while((opt = getopt(argc, argv, "m:p:blhr")) != -1) { + while((opt = getopt(argc, argv, "m:p:blhrt:")) != -1) { switch(opt) { case 'm': msize = atoi(optarg); @@ -390,7 +392,7 @@ main(int argc, char **argv) case 'p': nprocs = atoi(optarg); if(nprocs <= 0) { - printf("The number of process should be larger than 0\n"); + printf("The number of process must be larger than 0\n"); exit(0); } if(nprocs % 2 != 0) { @@ -404,6 +406,13 @@ main(int argc, char **argv) case 'l': lt_on = true; break; + case 't': + n_real_tries = atoi(optarg); + if (n_real_tries <= 0) { + printf("Number of real tries should be larger than 0\n"); + exit(0); + } + break; case 'r': raw_data_on = true; /* dump raw data */ break; diff --git a/benchmark/p2p-gdbus.c b/benchmark/p2p-gdbus.c index fb63e8c..7f4888e 100644 --- a/benchmark/p2p-gdbus.c +++ b/benchmark/p2p-gdbus.c @@ -610,7 +610,7 @@ int main(int argc, char *argv[]) case 't': n_real_tries = atoi(optarg); if (n_real_tries <= 0) { - printf("Number of real tries should be larger than 0\n"); + printf("Number of real tries must be larger than 0\n"); exit(0); } break; diff --git a/benchmark/pipe.c b/benchmark/pipe.c index 0b649cb..be7bb91 100644 --- a/benchmark/pipe.c +++ b/benchmark/pipe.c @@ -7,6 +7,7 @@ int nprocs; int msize; +int n_real_tries; int lt_cnt; double min, max, total; unsigned long long bw; @@ -23,7 +24,7 @@ void Receive(int rfd1, int rfd2, register int size, bool is_lt) unsigned long long end; register char *buf = (char *)malloc(size); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { if(is_lt) { if (read(rfd1, (void *)&start, sizeof(unsigned long long)) != sizeof(unsigned long long)) { @@ -67,7 +68,7 @@ void Receive(int rfd1, int rfd2, register int size, bool is_lt) + (unsigned long long)clock.tv_nsec; } - if(bw_cnt == REAL_TRY) { + if(bw_cnt == n_real_tries) { clock_gettime (CLOCK_REALTIME, &clock); end = (unsigned long long)clock.tv_sec * NS +(unsigned long long)clock.tv_nsec; @@ -86,7 +87,7 @@ void Send(int wfd1, int wfd2, register int size, bool is_lt) register char *cptr = (char *)malloc(size); sleep(2); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { int wres1, wres2; struct timespec clock; @@ -331,9 +332,10 @@ main(int argc, char **argv) if(nprocs == 1) nprocs = 2; + n_real_tries = REAL_TRY; msize = 3; lt_on = bw_on = false; - while((opt = getopt(argc, argv, "m:p:blhr")) != -1) { + while((opt = getopt(argc, argv, "m:p:blhrt:")) != -1) { switch(opt) { case 'm': msize = atoi(optarg); @@ -355,6 +357,13 @@ main(int argc, char **argv) case 'l': lt_on = true; break; + case 't': + n_real_tries = atoi(optarg); + if (n_real_tries <= 0) { + printf("Number of real tries must be larger than 0\n"); + exit(0); + } + break; case 'r': raw_data_on = true; /* dump raw data */ break; diff --git a/benchmark/sharedmem.c b/benchmark/sharedmem.c index ccfe4cc..fe4ba98 100644 --- a/benchmark/sharedmem.c +++ b/benchmark/sharedmem.c @@ -13,6 +13,7 @@ const char *shm_name2 = "sharedmem2"; int nprocs; int msize; +int n_real_tries; int lt_cnt; double min, max, total; unsigned long long bw; @@ -31,7 +32,7 @@ void Receive(void *r1, register char *r2, register int size, bool is_lt) register char read_cnt = 0; register char *buf = (char *)malloc(size); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { repeat: if(r2[1] == read_cnt) goto repeat; @@ -73,7 +74,7 @@ repeat: + (unsigned long long)clock.tv_nsec; } - if(bw_cnt == REAL_TRY) { + if(bw_cnt == n_real_tries) { clock_gettime (CLOCK_REALTIME, &clock); end = (unsigned long long)clock.tv_sec * NS +(unsigned long long)clock.tv_nsec; @@ -93,7 +94,7 @@ void Send(void *w1, register char *w2, register int size, bool is_lt) register char *cptr = (char *)malloc(size); sleep(2); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { struct timespec clock; repeat: if(w2[2] == write_cnt) { @@ -422,9 +423,10 @@ main(int argc, char **argv) if(nprocs == 1) nprocs = 2; + n_real_tries = REAL_TRY; msize = 3; lt_on = bw_on = false; - while((opt = getopt(argc, argv, "m:p:blrh")) != -1) { + while((opt = getopt(argc, argv, "m:p:blrht:")) != -1) { switch(opt) { case 'm': msize = atoi(optarg); @@ -446,6 +448,13 @@ main(int argc, char **argv) case 'l': lt_on = true; break; + case 't': + n_real_tries = atoi(optarg); + if (n_real_tries <= 0) { + printf("Number of real tries must be larger than 0\n"); + exit(0); + } + break; case 'r': raw_data_on = true; /* dump raw data */ break; diff --git a/benchmark/socket.c b/benchmark/socket.c index 7541689..b3f17ed 100644 --- a/benchmark/socket.c +++ b/benchmark/socket.c @@ -7,6 +7,7 @@ int nprocs; int msize; +int n_real_tries; int lt_cnt; double min, max, total; unsigned long long bw; @@ -23,7 +24,7 @@ void Receive(int rfd1, int rfd2, register int size, bool is_lt) unsigned long long end; register char *buf = (char *)malloc(size); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { if(is_lt) { if (read(rfd1, (void *)&start, sizeof(unsigned long long)) != sizeof(unsigned long long)) { @@ -67,7 +68,7 @@ void Receive(int rfd1, int rfd2, register int size, bool is_lt) + (unsigned long long)clock.tv_nsec; } - if(bw_cnt == REAL_TRY) { + if(bw_cnt == n_real_tries) { clock_gettime (CLOCK_REALTIME, &clock); end = (unsigned long long)clock.tv_sec * NS +(unsigned long long)clock.tv_nsec; @@ -86,7 +87,7 @@ void Send(int wfd1, int wfd2, register int size, bool is_lt) register char *cptr = (char *)malloc(size); sleep(2); - for(int i = 0; i < WARMUP_TRY + REAL_TRY; i++) { + for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) { int wres1, wres2; struct timespec clock; @@ -328,9 +329,10 @@ main(int argc, char **argv) if(nprocs == 1) nprocs = 2; + n_real_tries = REAL_TRY; msize = 3; lt_on = bw_on = false; - while((opt = getopt(argc, argv, "m:p:blrh")) != -1) { + while((opt = getopt(argc, argv, "m:p:blrht:")) != -1) { switch(opt) { case 'm': msize = atoi(optarg); @@ -352,6 +354,13 @@ main(int argc, char **argv) case 'l': lt_on = true; break; + case 't': + n_real_tries = atoi(optarg); + if (n_real_tries <= 0) { + printf("Number of real tries must be larger than 0\n"); + exit(0); + } + break; case 'r': raw_data_on = true; /* dump raw data */ break; -- 2.34.1