From aa653d6ec854b70b92b9cbb0fe452fbb0e300979 Mon Sep 17 00:00:00 2001 From: weiyu Date: Mon, 17 Jun 2019 13:08:01 -0700 Subject: [PATCH] implement usleep and sleep system calls as no operation which returns control to model thread --- Makefile | 3 ++- action.cc | 4 ++-- action.h | 2 +- execution.cc | 4 ++-- sleeps.cc | 26 ++++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 sleeps.cc diff --git a/Makefile b/Makefile index b0d946d2..7c73b9ba 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ OBJECTS := libthreads.o schedule.o model.o threads.o librace.o action.o \ nodestack.o clockvector.o main.o snapshot-interface.o cyclegraph.o \ datarace.o impatomic.o cmodelint.o \ snapshot.o malloc.o mymemory.o common.o mutex.o conditionvariable.o \ - context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o + context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o \ + sleeps.o CPPFLAGS += -Iinclude -I. LDFLAGS := -ldl -lrt -rdynamic diff --git a/action.cc b/action.cc index af849074..df44af19 100644 --- a/action.cc +++ b/action.cc @@ -45,7 +45,7 @@ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, seq_number(ACTION_INITIAL_CLOCK) { /* References to NULL atomic variables can end up here */ - ASSERT(loc || type == ATOMIC_FENCE); + ASSERT(loc || type == ATOMIC_FENCE || type == NOOP); Thread *t = thread ? thread : thread_current(); this->tid = t->get_id(); @@ -117,7 +117,7 @@ ModelAction::ModelAction(action_type_t type, const char * position, memory_order Thread *t = thread ? thread : thread_current(); this->tid = t->get_id(); - model_print("position: %s\n", position); + // model_print("position: %s\n", position); } diff --git a/action.h b/action.h index e65b8db9..1797e618 100644 --- a/action.h +++ b/action.h @@ -70,7 +70,7 @@ typedef enum action_type { ATOMIC_NOTIFY_ALL, // < A notify all action ATOMIC_WAIT, // < A wait action ATOMIC_ANNOTATION, // < An annotation action to pass information to a trace analysis - NOOP + NOOP // no operation, which returns control to scheduler } action_type_t; diff --git a/execution.cc b/execution.cc index 213b2606..4a351a98 100644 --- a/execution.cc +++ b/execution.cc @@ -682,7 +682,7 @@ ModelAction * ModelExecution::check_current_action(ModelAction *curr) wake_up_sleeping_actions(curr); /* Add the action to lists before any other model-checking tasks */ - if (!second_part_of_rmw) + if (!second_part_of_rmw && curr->get_type() != NOOP) add_action_to_lists(curr); SnapVector * rf_set = NULL; @@ -1106,7 +1106,7 @@ bool ModelExecution::release_seq_heads(const ModelAction *rf, rel_heads_list_t * * @see ModelExecution::release_seq_heads */ void ModelExecution::get_release_seq_heads(ModelAction *acquire, - ModelAction *read, rel_heads_list_t *release_heads) + ModelAction *read, rel_heads_list_t *release_heads) { const ModelAction *rf = read->get_reads_from(); diff --git a/sleeps.cc b/sleeps.cc new file mode 100644 index 00000000..0528374b --- /dev/null +++ b/sleeps.cc @@ -0,0 +1,26 @@ +#include +#include + +#include "action.h" +#include "model.h" + +unsigned int __sleep (unsigned int seconds) +{ + model->switch_to_master( + new ModelAction(NOOP, std::memory_order_seq_cst, NULL) + ); + return 0; +} + +unsigned int sleep(unsigned int seconds) +{ + return __sleep(seconds); +} + +int usleep (useconds_t useconds) +{ + model->switch_to_master( + new ModelAction(NOOP, std::memory_order_seq_cst, NULL) + ); + return 0; +} -- 2.34.1