projects
/
urcu.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add unit tests for possible_cpus_array_len
[urcu.git]
/
tests
/
benchmark
/
test_urcu_assign.c
diff --git
a/tests/benchmark/test_urcu_assign.c
b/tests/benchmark/test_urcu_assign.c
index fe34af3971a29322f78fb3c9c43de3310e2d1b73..88889a89d0421097b90177f1853f7ac3fa5cb0db 100644
(file)
--- a/
tests/benchmark/test_urcu_assign.c
+++ b/
tests/benchmark/test_urcu_assign.c
@@
-28,12
+28,11
@@
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
-#include <assert.h>
#include <errno.h>
#include <urcu/arch.h>
#include <errno.h>
#include <urcu/arch.h>
+#include <urcu/assert.h>
#include <urcu/tls-compat.h>
#include <urcu/tls-compat.h>
-#include "cpuset.h"
#include "thread-id.h"
#include "../common/debug-yield.h"
#include "thread-id.h"
#include "../common/debug-yield.h"
@@
-85,7
+84,7
@@
pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER;
static void set_affinity(void)
{
static void set_affinity(void)
{
-#if HAVE_SCHED_SETAFFINITY
+#if
def
HAVE_SCHED_SETAFFINITY
cpu_set_t mask;
int cpu, ret;
#endif /* HAVE_SCHED_SETAFFINITY */
cpu_set_t mask;
int cpu, ret;
#endif /* HAVE_SCHED_SETAFFINITY */
@@
-93,7
+92,7
@@
static void set_affinity(void)
if (!use_affinity)
return;
if (!use_affinity)
return;
-#if HAVE_SCHED_SETAFFINITY
+#if
def
HAVE_SCHED_SETAFFINITY
ret = pthread_mutex_lock(&affinity_mutex);
if (ret) {
perror("Error in pthread mutex lock");
ret = pthread_mutex_lock(&affinity_mutex);
if (ret) {
perror("Error in pthread mutex lock");
@@
-108,11
+107,7
@@
static void set_affinity(void)
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
-#if SCHED_SETAFFINITY_ARGS == 2
- sched_setaffinity(0, &mask);
-#else
sched_setaffinity(0, sizeof(mask), &mask);
sched_setaffinity(0, sizeof(mask), &mask);
-#endif
#endif /* HAVE_SCHED_SETAFFINITY */
}
#endif /* HAVE_SCHED_SETAFFINITY */
}
@@
-137,6
+132,7
@@
static unsigned int nr_writers;
pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER;
+static
void rcu_copy_mutex_lock(void)
{
int ret;
void rcu_copy_mutex_lock(void)
{
int ret;
@@
-147,6
+143,7
@@
void rcu_copy_mutex_lock(void)
}
}
}
}
+static
void rcu_copy_mutex_unlock(void)
{
int ret;
void rcu_copy_mutex_unlock(void)
{
int ret;
@@
-165,8
+162,8
@@
void rcu_copy_mutex_unlock(void)
* both alloc and free, which insures we never run over our tail.
*/
#define ARRAY_SIZE (1048576 * nr_writers)
* both alloc and free, which insures we never run over our tail.
*/
#define ARRAY_SIZE (1048576 * nr_writers)
-#define ARRAY_POISON 0xDEADBEEF
-static int array_index;
+#define ARRAY_POISON
(int)
0xDEADBEEF
+static
unsigned
int array_index;
static struct test_array *test_array;
static struct test_array *test_array_alloc(void)
static struct test_array *test_array;
static struct test_array *test_array_alloc(void)
@@
-175,7
+172,7
@@
static struct test_array *test_array_alloc(void)
int index;
index = array_index % ARRAY_SIZE;
int index;
index = array_index % ARRAY_SIZE;
- assert(test_array[index].a == ARRAY_POISON ||
+
urcu_posix_
assert(test_array[index].a == ARRAY_POISON ||
test_array[index].a == 0);
ret = &test_array[index];
array_index++;
test_array[index].a == 0);
ret = &test_array[index];
array_index++;
@@
-191,6
+188,7
@@
static void test_array_free(struct test_array *ptr)
ptr->a = ARRAY_POISON;
}
ptr->a = ARRAY_POISON;
}
+static
void *thr_reader(void *_count)
{
unsigned long long *count = _count;
void *thr_reader(void *_count)
{
unsigned long long *count = _count;
@@
-213,7
+211,7
@@
void *thr_reader(void *_count)
local_ptr = rcu_dereference(test_rcu_pointer);
rcu_debug_yield_read();
if (local_ptr)
local_ptr = rcu_dereference(test_rcu_pointer);
rcu_debug_yield_read();
if (local_ptr)
- assert(local_ptr->a == 8);
+
urcu_posix_
assert(local_ptr->a == 8);
if (caa_unlikely(rduration))
loop_sleep(rduration);
rcu_read_unlock();
if (caa_unlikely(rduration))
loop_sleep(rduration);
rcu_read_unlock();
@@
-231,6
+229,7
@@
void *thr_reader(void *_count)
}
}
+static
void *thr_writer(void *_count)
{
unsigned long long *count = _count;
void *thr_writer(void *_count)
{
unsigned long long *count = _count;
@@
-272,7
+271,8
@@
void *thr_writer(void *_count)
return ((void*)2);
}
return ((void*)2);
}
-void show_usage(int argc, char **argv)
+static
+void show_usage(char **argv)
{
printf("Usage : %s nr_readers nr_writers duration (s) <OPTIONS>\n",
argv[0]);
{
printf("Usage : %s nr_readers nr_writers duration (s) <OPTIONS>\n",
argv[0]);
@@
-294,27
+294,28
@@
int main(int argc, char **argv)
unsigned long long *count_reader, *count_writer;
unsigned long long tot_reads = 0, tot_writes = 0;
int i, a;
unsigned long long *count_reader, *count_writer;
unsigned long long tot_reads = 0, tot_writes = 0;
int i, a;
+ unsigned int i_thr;
if (argc < 4) {
if (argc < 4) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
err = sscanf(argv[1], "%u", &nr_readers);
if (err != 1) {
return -1;
}
err = sscanf(argv[1], "%u", &nr_readers);
if (err != 1) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
err = sscanf(argv[2], "%u", &nr_writers);
if (err != 1) {
return -1;
}
err = sscanf(argv[2], "%u", &nr_writers);
if (err != 1) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
return -1;
}
-
+
err = sscanf(argv[3], "%lu", &duration);
if (err != 1) {
err = sscanf(argv[3], "%lu", &duration);
if (err != 1) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
return -1;
}
@@
-330,7
+331,7
@@
int main(int argc, char **argv)
break;
case 'a':
if (argc < i + 2) {
break;
case 'a':
if (argc < i + 2) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
a = atoi(argv[++i]);
return -1;
}
a = atoi(argv[++i]);
@@
-340,21
+341,21
@@
int main(int argc, char **argv)
break;
case 'c':
if (argc < i + 2) {
break;
case 'c':
if (argc < i + 2) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
rduration = atol(argv[++i]);
break;
case 'd':
if (argc < i + 2) {
return -1;
}
rduration = atol(argv[++i]);
break;
case 'd':
if (argc < i + 2) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
wdelay = atol(argv[++i]);
break;
case 'e':
if (argc < i + 2) {
return -1;
}
wdelay = atol(argv[++i]);
break;
case 'e':
if (argc < i + 2) {
- show_usage(arg
c, arg
v);
+ show_usage(argv);
return -1;
}
wduration = atol(argv[++i]);
return -1;
}
wduration = atol(argv[++i]);
@@
-380,15
+381,15
@@
int main(int argc, char **argv)
next_aff = 0;
next_aff = 0;
- for (i
= 0; i < nr_readers; i
++) {
- err = pthread_create(&tid_reader[i], NULL, thr_reader,
- &count_reader[i]);
+ for (i
_thr = 0; i_thr < nr_readers; i_thr
++) {
+ err = pthread_create(&tid_reader[i
_thr
], NULL, thr_reader,
+ &count_reader[i
_thr
]);
if (err != 0)
exit(1);
}
if (err != 0)
exit(1);
}
- for (i
= 0; i < nr_writers; i
++) {
- err = pthread_create(&tid_writer[i], NULL, thr_writer,
- &count_writer[i]);
+ for (i
_thr = 0; i_thr < nr_writers; i_thr
++) {
+ err = pthread_create(&tid_writer[i
_thr
], NULL, thr_writer,
+ &count_writer[i
_thr
]);
if (err != 0)
exit(1);
}
if (err != 0)
exit(1);
}
@@
-401,19
+402,19
@@
int main(int argc, char **argv)
test_stop = 1;
test_stop = 1;
- for (i
= 0; i < nr_readers; i
++) {
- err = pthread_join(tid_reader[i], &tret);
+ for (i
_thr = 0; i_thr < nr_readers; i_thr
++) {
+ err = pthread_join(tid_reader[i
_thr
], &tret);
if (err != 0)
exit(1);
if (err != 0)
exit(1);
- tot_reads += count_reader[i];
+ tot_reads += count_reader[i
_thr
];
}
}
- for (i
= 0; i < nr_writers; i
++) {
- err = pthread_join(tid_writer[i], &tret);
+ for (i
_thr = 0; i_thr < nr_writers; i_thr
++) {
+ err = pthread_join(tid_writer[i
_thr
], &tret);
if (err != 0)
exit(1);
if (err != 0)
exit(1);
- tot_writes += count_writer[i];
+ tot_writes += count_writer[i
_thr
];
}
}
-
+
printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads,
tot_writes);
printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu wdur %6lu "
printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads,
tot_writes);
printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu wdur %6lu "
@@
-422,11
+423,13
@@
int main(int argc, char **argv)
argv[0], duration, nr_readers, rduration, wduration,
nr_writers, wdelay, tot_reads, tot_writes,
tot_reads + tot_writes);
argv[0], duration, nr_readers, rduration, wduration,
nr_writers, wdelay, tot_reads, tot_writes,
tot_reads + tot_writes);
+
test_array_free(test_rcu_pointer);
free(test_array);
free(tid_reader);
free(tid_writer);
free(count_reader);
free(count_writer);
test_array_free(test_rcu_pointer);
free(test_array);
free(tid_reader);
free(tid_writer);
free(count_reader);
free(count_writer);
+
return 0;
}
return 0;
}
This page took
0.028289 seconds
and
4
git commands to generate.