Add number of reader/writers parameters to tests
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Mon, 8 Jun 2009 18:57:27 +0000 (14:57 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Mon, 8 Jun 2009 18:57:27 +0000 (14:57 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
test_perthreadlock_timing.c
test_qsbr_timing.c
test_rwlock_timing.c
test_urcu_timing.c

index 479895ee1b32f978f02f8cb04774244da0784fec..625f999daf4d404ce1af78f3ebb1909e18d2da2a 100644 (file)
@@ -70,11 +70,14 @@ static struct per_thread_lock *per_thread_lock;
 #define INNER_WRITE_LOOP 200U
 #define WRITE_LOOP ((unsigned long long)OUTER_WRITE_LOOP * INNER_WRITE_LOOP)
 
-#define NR_READ 10
-#define NR_WRITE 9
+static int num_read;
+static int num_write;
 
-static cycles_t reader_time[NR_READ] __attribute__((aligned(128)));
-static cycles_t writer_time[NR_WRITE] __attribute__((aligned(128)));
+#define NR_READ num_read
+#define NR_WRITE num_write
+
+static cycles_t __attribute__((aligned(128))) *reader_time;
+static cycles_t __attribute__((aligned(128))) *writer_time;
 
 void *thr_reader(void *arg)
 {
@@ -136,15 +139,27 @@ void *thr_writer(void *arg)
        return ((void*)2);
 }
 
-int main()
+int main(int argc, char **argv)
 {
        int err;
-       pthread_t tid_reader[NR_READ], tid_writer[NR_WRITE];
+       pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        cycles_t tot_rtime = 0;
        cycles_t tot_wtime = 0;
 
+       if (argc < 2) {
+               printf("Usage : %s nr_readers nr_writers\n", argv[0]);
+               exit(-1);
+       }
+       num_read = atoi(argv[1]);
+       num_write = atoi(argv[2]);
+
+       reader_time = malloc(sizeof(*reader_time) * num_read);
+       writer_time = malloc(sizeof(*writer_time) * num_write);
+       tid_reader = malloc(sizeof(*tid_reader) * num_read);
+       tid_writer = malloc(sizeof(*tid_writer) * num_write);
+
        printf("thread %-6s, thread id : %lx, tid %lu\n",
                        "main", pthread_self(), (unsigned long)gettid());
 
@@ -186,5 +201,10 @@ int main()
               (double)tot_wtime / ((double)NR_WRITE * (double)WRITE_LOOP));
        free(per_thread_lock);
 
+       free(reader_time);
+       free(writer_time);
+       free(tid_reader);
+       free(tid_writer);
+
        return 0;
 }
index bdbb5819a404e1dde19da859323c6b5c5b287b8d..e296ced657d8d28a3d3fa74fd62669046e1e6e74 100644 (file)
@@ -87,11 +87,14 @@ static struct test_array *test_rcu_pointer;
 #define INNER_WRITE_LOOP 200U
 #define WRITE_LOOP ((unsigned long long)OUTER_WRITE_LOOP * INNER_WRITE_LOOP)
 
-#define NR_READ 10
-#define NR_WRITE 9
+static int num_read;
+static int num_write;
 
-static cycles_t reader_time[NR_READ] __attribute__((aligned(128)));
-static cycles_t writer_time[NR_WRITE] __attribute__((aligned(128)));
+#define NR_READ num_read
+#define NR_WRITE num_write
+
+static cycles_t __attribute__((aligned(128))) *reader_time;
+static cycles_t __attribute__((aligned(128))) *writer_time;
 
 void *thr_reader(void *arg)
 {
@@ -168,15 +171,27 @@ void *thr_writer(void *arg)
        return ((void*)2);
 }
 
-int main()
+int main(int argc, char **argv)
 {
        int err;
-       pthread_t tid_reader[NR_READ], tid_writer[NR_WRITE];
+       pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        cycles_t tot_rtime = 0;
        cycles_t tot_wtime = 0;
 
+       if (argc < 2) {
+               printf("Usage : %s nr_readers nr_writers\n", argv[0]);
+               exit(-1);
+       }
+       num_read = atoi(argv[1]);
+       num_write = atoi(argv[2]);
+
+       reader_time = malloc(sizeof(*reader_time) * num_read);
+       writer_time = malloc(sizeof(*writer_time) * num_write);
+       tid_reader = malloc(sizeof(*tid_reader) * num_read);
+       tid_writer = malloc(sizeof(*tid_writer) * num_write);
+
        printf("thread %-6s, thread id : %lx, tid %lu\n",
                        "main", pthread_self(), (unsigned long)gettid());
 
@@ -213,5 +228,10 @@ int main()
        printf("Time per write : %g cycles\n",
               (double)tot_wtime / ((double)NR_WRITE * (double)WRITE_LOOP));
 
+       free(reader_time);
+       free(writer_time);
+       free(tid_reader);
+       free(tid_writer);
+
        return 0;
 }
index 3f0b0c9a51f56ee422ce7f66509f2505b51e5c54..cd2087650437b9d8be01896fcc920112c100513a 100644 (file)
@@ -66,11 +66,14 @@ static struct test_array test_array = { 8 };
 #define INNER_WRITE_LOOP 200U
 #define WRITE_LOOP ((unsigned long long)OUTER_WRITE_LOOP * INNER_WRITE_LOOP)
 
-#define NR_READ 10
-#define NR_WRITE 9
+static int num_read;
+static int num_write;
 
-static cycles_t reader_time[NR_READ] __attribute__((aligned(128)));
-static cycles_t writer_time[NR_WRITE] __attribute__((aligned(128)));
+#define NR_READ num_read
+#define NR_WRITE num_write
+
+static cycles_t __attribute__((aligned(128))) *reader_time;
+static cycles_t __attribute__((aligned(128))) *writer_time;
 
 void *thr_reader(void *arg)
 {
@@ -126,15 +129,27 @@ void *thr_writer(void *arg)
        return ((void*)2);
 }
 
-int main()
+int main(int argc, char **argv)
 {
        int err;
-       pthread_t tid_reader[NR_READ], tid_writer[NR_WRITE];
+       pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        cycles_t tot_rtime = 0;
        cycles_t tot_wtime = 0;
 
+       if (argc < 2) {
+               printf("Usage : %s nr_readers nr_writers\n", argv[0]);
+               exit(-1);
+       }
+       num_read = atoi(argv[1]);
+       num_write = atoi(argv[2]);
+
+       reader_time = malloc(sizeof(*reader_time) * num_read);
+       writer_time = malloc(sizeof(*writer_time) * num_write);
+       tid_reader = malloc(sizeof(*tid_reader) * num_read);
+       tid_writer = malloc(sizeof(*tid_writer) * num_write);
+
        printf("thread %-6s, thread id : %lx, tid %lu\n",
                        "main", pthread_self(), (unsigned long)gettid());
 
@@ -170,5 +185,10 @@ int main()
        printf("Time per write : %g cycles\n",
               (double)tot_wtime / ((double)NR_WRITE * (double)WRITE_LOOP));
 
+       free(reader_time);
+       free(writer_time);
+       free(tid_reader);
+       free(tid_writer);
+
        return 0;
 }
index 6b4aac8b12de0aeaf2f317c6408cc19d37be7d74..5f75bae448ee3a3e883377e3a6e284c725df7fc7 100644 (file)
@@ -87,11 +87,14 @@ static struct test_array *test_rcu_pointer;
 #define INNER_WRITE_LOOP 200U
 #define WRITE_LOOP ((unsigned long long)OUTER_WRITE_LOOP * INNER_WRITE_LOOP)
 
-#define NR_READ 10
-#define NR_WRITE 9
+static int num_read;
+static int num_write;
 
-static cycles_t reader_time[NR_READ] __attribute__((aligned(128)));
-static cycles_t writer_time[NR_WRITE] __attribute__((aligned(128)));
+#define NR_READ num_read
+#define NR_WRITE num_write
+
+static cycles_t __attribute__((aligned(128))) *reader_time;
+static cycles_t __attribute__((aligned(128))) *writer_time;
 
 void *thr_reader(void *arg)
 {
@@ -167,15 +170,27 @@ void *thr_writer(void *arg)
        return ((void*)2);
 }
 
-int main()
+int main(int argc, char **argv)
 {
        int err;
-       pthread_t tid_reader[NR_READ], tid_writer[NR_WRITE];
+       pthread_t *tid_reader, *tid_writer;
        void *tret;
        int i;
        cycles_t tot_rtime = 0;
        cycles_t tot_wtime = 0;
 
+       if (argc < 2) {
+               printf("Usage : %s nr_readers nr_writers\n", argv[0]);
+               exit(-1);
+       }
+       num_read = atoi(argv[1]);
+       num_write = atoi(argv[2]);
+
+       reader_time = malloc(sizeof(*reader_time) * num_read);
+       writer_time = malloc(sizeof(*writer_time) * num_write);
+       tid_reader = malloc(sizeof(*tid_reader) * num_read);
+       tid_writer = malloc(sizeof(*tid_writer) * num_write);
+
        printf("thread %-6s, thread id : %lx, tid %lu\n",
                        "main", pthread_self(), (unsigned long)gettid());
 
@@ -212,5 +227,10 @@ int main()
        printf("Time per write : %g cycles\n",
               (double)tot_wtime / ((double)NR_WRITE * (double)WRITE_LOOP));
 
+       free(reader_time);
+       free(writer_time);
+       free(tid_reader);
+       free(tid_writer);
+
        return 0;
 }
This page took 0.029052 seconds and 4 git commands to generate.