Hi There are a number of races in monkey right now. This patchset fixes all but two, clock runtime and signal exit. The clock runtime one is a severe one, as at any time a read may happen in the middle of a write, and as many of the clock buffers are pointers, a half-written pointer would point absolutely nowhere.
Atomic instructions are really the only solution that makes sense for the clock runtime issue. The signal one is not too severe, at worst it could cause a crash at exit, but we're exiting anyway. -- Helgrind logs for all these patches are available at http://monkey-project.com/~cand/helgrind_logs/ - you'll see how each patch cuts down a specific warning. The amount of clock warnings fluctuates between runs, but they still form the majority in all runs. -- This first patch solves clock init. If the memory were allocated in a thread, it may happen too late - a worker thread may try to read the memory before it's allocated. - Lauri
>From a31cd451271162432ab86b158e645bba79f06ae4 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen <[email protected]> Date: Fri, 23 Mar 2012 20:50:32 +0200 Subject: [PATCH 1/3] Move sequential clock init to its own function If the memory were allocated in a thread, it may happen too late. Signed-off-by: Lauri Kasanen <[email protected]> --- src/include/mk_clock.h | 1 + src/mk_clock.c | 27 ++++++++++++++++++++------- src/monkey.c | 3 +++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/include/mk_clock.h b/src/include/mk_clock.h index ebef5b1..cf50190 100644 --- a/src/include/mk_clock.h +++ b/src/include/mk_clock.h @@ -39,5 +39,6 @@ extern mk_pointer header_current_time; void *mk_clock_worker_init(void *args); void mk_clock_set_time(void); +void mk_clock_sequential_init(); #endif diff --git a/src/mk_clock.c b/src/mk_clock.c index d7b8d31..2728f8d 100644 --- a/src/mk_clock.c +++ b/src/mk_clock.c @@ -84,6 +84,21 @@ void *mk_clock_worker_init(void *args) mk_utils_worker_rename("monkey: clock"); + while (1) { + cur_time = time(NULL); + + if(cur_time != ((time_t)-1)) { + mk_clock_log_set_time(cur_time); + mk_clock_header_set_time(cur_time); + } + + sleep(1); + } +} + +/* This function must be called before any threads are created */ +void mk_clock_sequential_init() +{ /* Time when monkey was started */ monkey_init_time = time(NULL); @@ -93,14 +108,12 @@ void *mk_clock_worker_init(void *args) log_time_buffers[0] = mk_mem_malloc_z(LOG_TIME_BUFFER_SIZE); log_time_buffers[1] = mk_mem_malloc_z(LOG_TIME_BUFFER_SIZE); - while (1) { - cur_time = time(NULL); - if(cur_time != ((time_t)-1)) { - mk_clock_log_set_time(cur_time); - mk_clock_header_set_time(cur_time); - } + /* Set the time once */ + time_t cur_time = time(NULL); - sleep(1); + if(cur_time != ((time_t)-1)) { + mk_clock_log_set_time(cur_time); + mk_clock_header_set_time(cur_time); } } diff --git a/src/monkey.c b/src/monkey.c index 47ac0bc..4daeb22 100644 --- a/src/monkey.c +++ b/src/monkey.c @@ -165,6 +165,9 @@ int main(int argc, char **argv) /* Register PID of Monkey */ mk_utils_register_pid(); + /* Clock init that must happen before starting threads */ + mk_clock_sequential_init(); + /* Workers: logger and clock */ mk_utils_worker_spawn((void *) mk_clock_worker_init); -- 1.7.2.1
_______________________________________________ Monkey mailing list [email protected] http://lists.monkey-project.com/listinfo/monkey
