implement usleep and sleep system calls as no operation which returns control to...
authorweiyu <weiyuluo1232@gmail.com>
Mon, 17 Jun 2019 20:08:01 +0000 (13:08 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Mon, 17 Jun 2019 20:08:01 +0000 (13:08 -0700)
Makefile
action.cc
action.h
execution.cc
sleeps.cc [new file with mode: 0644]

index b0d946d2123bdccf3d794810072c622a04a81e6a..7c73b9ba92ab8744b55598a3d57a6436e26238d2 100644 (file)
--- 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 \
           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
 
 CPPFLAGS += -Iinclude -I.
 LDFLAGS := -ldl -lrt -rdynamic
index af849074a199cc15d5e5d30e1e727a240cc81284..df44af19953e334e47ba65d56a249e9cd47840a2 100644 (file)
--- 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 */
        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();
 
        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();
 
        Thread *t = thread ? thread : thread_current();
        this->tid = t->get_id();
-       model_print("position: %s\n", position);
+       // model_print("position: %s\n", position);
 }
 
 
 }
 
 
index e65b8db9ef1493e88b402be87d176401bed055dc..1797e618d9940564183bc727673a2c93bdc67e22 100644 (file)
--- 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
        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;
 
 
 } action_type_t;
 
 
index 213b26067bfda027be973d0166a1a7e1db634f51..4a351a98f8397fb4634d1ae3dd2da6c2aa32e198 100644 (file)
@@ -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 */
        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<ModelAction *> * rf_set = NULL;
                add_action_to_lists(curr);
 
        SnapVector<ModelAction *> * 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,
  * @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();
 
 {
        const ModelAction *rf = read->get_reads_from();
 
diff --git a/sleeps.cc b/sleeps.cc
new file mode 100644 (file)
index 0000000..0528374
--- /dev/null
+++ b/sleeps.cc
@@ -0,0 +1,26 @@
+#include <time.h>
+#include <unistd.h>
+
+#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;
+}