From dfb47d6bc6aacb0ce93a6e497d8abd027c12ec50 Mon Sep 17 00:00:00 2001 From: weiyu Date: Fri, 14 Jun 2019 15:31:03 -0700 Subject: [PATCH] add source line number as a parameter to ModelAction --- action.cc | 43 ++++++- action.h | 5 + cmodelint.cc | 290 +++++++++++++++++++++++++------------------- include/cmodelint.h | 115 +++++++++--------- 4 files changed, 269 insertions(+), 184 deletions(-) diff --git a/action.cc b/action.cc index 9c0e2992..af849074 100644 --- a/action.cc +++ b/action.cc @@ -31,8 +31,8 @@ * @param thread (optional) The Thread in which this action occurred. If NULL * (default), then a Thread is assigned according to the scheduler. */ -ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, - uint64_t value, Thread *thread) : +ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, + uint64_t value, Thread *thread) : location(loc), reads_from(NULL), last_fence_release(NULL), @@ -65,7 +65,7 @@ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, * (default), then a Thread is assigned according to the scheduler. */ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, - uint64_t value, int size) : + uint64_t value, int size) : location(loc), reads_from(NULL), last_fence_release(NULL), @@ -84,6 +84,43 @@ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, this->tid = t->get_id(); } + +/** + * @brief Construct a new ModelAction with source line number (requires llvm support) + * + * @param type The type of action + * @param position The source line number of this atomic operation + * @param order The memory order of this action. A "don't care" for non-ATOMIC + * actions (e.g., THREAD_* or MODEL_* actions). + * @param loc The location that this action acts upon + * @param value (optional) A value associated with the action (e.g., the value + * read or written). Defaults to a given macro constant, for debugging purposes. + * @param thread (optional) The Thread in which this action occurred. If NULL + * (default), then a Thread is assigned according to the scheduler. + */ +ModelAction::ModelAction(action_type_t type, const char * position, memory_order order, + void *loc, uint64_t value, Thread *thread) : + location(loc), + position(position), + reads_from(NULL), + last_fence_release(NULL), + node(NULL), + cv(NULL), + value(value), + type(type), + order(order), + original_order(order), + seq_number(ACTION_INITIAL_CLOCK) +{ + /* References to NULL atomic variables can end up here */ + ASSERT(loc || type == ATOMIC_FENCE); + + Thread *t = thread ? thread : thread_current(); + this->tid = t->get_id(); + model_print("position: %s\n", position); +} + + /** @brief ModelAction destructor */ ModelAction::~ModelAction() { diff --git a/action.h b/action.h index b4fb80fc..4b49f145 100644 --- a/action.h +++ b/action.h @@ -86,6 +86,7 @@ class ModelAction { public: ModelAction(action_type_t type, memory_order order, void *loc, uint64_t value = VALUE_NONE, Thread *thread = NULL); ModelAction(action_type_t type, memory_order order, void *loc, uint64_t value, int size); + ModelAction(action_type_t type, const char * position, memory_order order, void *loc, uint64_t value = VALUE_NONE, Thread *thread = NULL); ~ModelAction(); void print() const; @@ -95,6 +96,7 @@ public: memory_order get_original_mo() const { return original_order; } void set_mo(memory_order order) { this->order = order; } void * get_location() const { return location; } + const char * get_position() const { return position; } modelclock_t get_seq_number() const { return seq_number; } uint64_t get_value() const { return value; } uint64_t get_reads_from_value() const; @@ -182,6 +184,9 @@ private: /** @brief A pointer to the memory location for this action. */ void *location; + /** @brief A pointer to the source line for this atomic action. */ + const char * position; + union { /** * @brief The store that this action reads from diff --git a/cmodelint.cc b/cmodelint.cc index 454c4a06..2f892f0c 100644 --- a/cmodelint.cc +++ b/cmodelint.cc @@ -48,231 +48,273 @@ void model_fence_action(memory_order ord) { model->switch_to_master(new ModelAction(ATOMIC_FENCE, ord, FENCE_LOCATION)); } -// --------------------- helper functions -------------------------------- -uint64_t model_rmwr_action_helper(void *obj, int atomic_index) { - return model->switch_to_master(new ModelAction(ATOMIC_RMWR, orders[atomic_index], obj)); +/* --- helper functions --- */ +uint64_t model_rmwr_action_helper(void *obj, int atomic_index, const char *position) { + return model->switch_to_master( + new ModelAction(ATOMIC_RMWR, position, orders[atomic_index], obj) + ); } -void model_rmw_action_helper(void *obj, int atomic_index, uint64_t val) { +void model_rmw_action_helper(void *obj, uint64_t val, int atomic_index, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_RMW, position, orders[atomic_index], obj, val) + ); +} + +/* +void model_rmw_action_helper(void *obj, uint64_t val, int atomic_index) { model->switch_to_master(new ModelAction(ATOMIC_RMW, orders[atomic_index], obj, val)); } +*/ -void model_rmwc_action_helper(void *obj, int atomic_index) { - model->switch_to_master(new ModelAction(ATOMIC_RMWC, orders[atomic_index], obj)); +void model_rmwc_action_helper(void *obj, int atomic_index, const char *position) { + model->switch_to_master( + new ModelAction(ATOMIC_RMWC, position, orders[atomic_index], obj) + ); } +/* void model_fence_action_helper(int atomic_index) { - model->switch_to_master(new ModelAction(ATOMIC_FENCE, orders[atomic_index], FENCE_LOCATION)); + model->switch_to_master( + new ModelAction(ATOMIC_FENCE, orders[atomic_index], FENCE_LOCATION) + ); } +*/ // cds atomic inits -void cds_atomic_init8(void * obj, uint8_t val) { - model->switch_to_master(new ModelAction(ATOMIC_INIT, memory_order_relaxed, obj, (uint64_t) val)); +void cds_atomic_init8(void * obj, uint8_t val, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val) + ); } -void cds_atomic_init16(void * obj, uint16_t val) { - model->switch_to_master(new ModelAction(ATOMIC_INIT, memory_order_relaxed, obj, (uint64_t) val)); +void cds_atomic_init16(void * obj, uint16_t val, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val) + ); } -void cds_atomic_init32(void * obj, uint32_t val) { - model->switch_to_master(new ModelAction(ATOMIC_INIT, memory_order_relaxed, obj, (uint64_t) val)); +void cds_atomic_init32(void * obj, uint32_t val, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val) + ); } -void cds_atomic_init64(void * obj, uint64_t val) { - model->switch_to_master(new ModelAction(ATOMIC_INIT, memory_order_relaxed, obj, val)); +void cds_atomic_init64(void * obj, uint64_t val, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, val) + ); } // cds atomic loads -uint8_t cds_atomic_load8(void * obj, int atomic_index) { - return (uint8_t) ( model->switch_to_master(new ModelAction(ATOMIC_READ, orders[atomic_index], obj)) ); +uint8_t cds_atomic_load8(void * obj, int atomic_index, const char * position) { + return (uint8_t) ( model->switch_to_master( + new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj)) + ); } -uint16_t cds_atomic_load16(void * obj, int atomic_index) { - return (uint16_t) ( model->switch_to_master(new ModelAction(ATOMIC_READ, orders[atomic_index], obj)) ); +uint16_t cds_atomic_load16(void * obj, int atomic_index, const char * position) { + return (uint16_t) ( model->switch_to_master( + new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj)) + ); } -uint32_t cds_atomic_load32(void * obj, int atomic_index) { - return (uint32_t) ( model->switch_to_master(new ModelAction(ATOMIC_READ, orders[atomic_index], obj)) ); +uint32_t cds_atomic_load32(void * obj, int atomic_index, const char * position) { + return (uint32_t) ( model->switch_to_master( + new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj)) + ); } -uint64_t cds_atomic_load64(void * obj, int atomic_index) { - return model->switch_to_master(new ModelAction(ATOMIC_READ, orders[atomic_index], obj)); +uint64_t cds_atomic_load64(void * obj, int atomic_index, const char * position) { + return model->switch_to_master( + new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj) + ); } // cds atomic stores -void cds_atomic_store8(void * obj, uint8_t val, int atomic_index) { - model->switch_to_master(new ModelAction(ATOMIC_WRITE, orders[atomic_index], obj, (uint64_t) val)); +void cds_atomic_store8(void * obj, uint8_t val, int atomic_index, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val) + ); } -void cds_atomic_store16(void * obj, uint16_t val, int atomic_index) { - model->switch_to_master(new ModelAction(ATOMIC_WRITE, orders[atomic_index], obj, (uint64_t) val)); +void cds_atomic_store16(void * obj, uint16_t val, int atomic_index, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val) + ); } -void cds_atomic_store32(void * obj, uint32_t val, int atomic_index) { - model->switch_to_master(new ModelAction(ATOMIC_WRITE, orders[atomic_index], obj, (uint64_t) val)); +void cds_atomic_store32(void * obj, uint32_t val, int atomic_index, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val) + ); } -void cds_atomic_store64(void * obj, uint64_t val, int atomic_index) { - model->switch_to_master(new ModelAction(ATOMIC_WRITE, orders[atomic_index], obj, val)); +void cds_atomic_store64(void * obj, uint64_t val, int atomic_index, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, val) + ); } -/* -#define _ATOMIC_RMW_(__op__, size, addr, atomic_index, val ) \ -({ \ - uint##size##_t _old = model_rmwr_action_helper(addr, atomic_index); \ - uint##size##_t _copy = _old; \ - _copy __op__ ( uint##size##_t ) _val; \ - model_rmw_action_helper(addr, atomic_index, (uint64_t) _copy); \ - return _old; \ -})*/ - -#define _ATOMIC_RMW_(__op__, size, addr, atomic_index, val ) \ +#define _ATOMIC_RMW_(__op__, size, addr, val, atomic_index, position) \ ({ \ - uint##size##_t _old = model_rmwr_action_helper(addr, atomic_index); \ + uint##size##_t _old = model_rmwr_action_helper(addr, atomic_index, position); \ uint##size##_t _copy = _old; \ uint##size##_t _val = val; \ _copy __op__ _val; \ - model_rmw_action_helper(addr, atomic_index, (uint64_t) _copy); \ + model_rmw_action_helper(addr, (uint64_t) _copy, atomic_index, position); \ return _old; \ }) // cds atomic exchange -uint8_t cds_atomic_exchange8(void* addr, uint8_t val, int atomic_index) { - _ATOMIC_RMW_( = , 8, addr, atomic_index, val); +uint8_t cds_atomic_exchange8(void* addr, uint8_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( = , 8, addr, val, atomic_index, position); } -uint16_t cds_atomic_exchange16(void* addr, uint16_t val, int atomic_index) { - _ATOMIC_RMW_( = , 16, addr, atomic_index, val); +uint16_t cds_atomic_exchange16(void* addr, uint16_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( = , 16, addr, val, atomic_index, position); } -uint32_t cds_atomic_exchange32(void* addr, uint32_t val, int atomic_index) { - _ATOMIC_RMW_( = , 32, addr, atomic_index, val); +uint32_t cds_atomic_exchange32(void* addr, uint32_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( = , 32, addr, val, atomic_index, position); } -uint64_t cds_atomic_exchange64(void* addr, uint64_t val, int atomic_index) { - _ATOMIC_RMW_( = , 64, addr, atomic_index, val); +uint64_t cds_atomic_exchange64(void* addr, uint64_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( = , 64, addr, val, atomic_index, position); } // cds atomic fetch add -uint8_t cds_atomic_fetch_add8(void* addr, uint8_t val, int atomic_index) { - _ATOMIC_RMW_( += , 8, addr, atomic_index, val); +uint8_t cds_atomic_fetch_add8(void* addr, uint8_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( += , 8, addr, val, atomic_index, position); } -uint16_t cds_atomic_fetch_add16(void* addr, uint16_t val, int atomic_index) { - _ATOMIC_RMW_( += , 16, addr, atomic_index, val); +uint16_t cds_atomic_fetch_add16(void* addr, uint16_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( += , 16, addr, val, atomic_index, position); } -uint32_t cds_atomic_fetch_add32(void* addr, uint32_t val, int atomic_index) { - _ATOMIC_RMW_( += , 32, addr, atomic_index, val); +uint32_t cds_atomic_fetch_add32(void* addr, uint32_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( += , 32, addr, val, atomic_index, position); } -uint64_t cds_atomic_fetch_add64(void* addr, uint64_t val, int atomic_index) { - _ATOMIC_RMW_( += , 64, addr, atomic_index, val); +uint64_t cds_atomic_fetch_add64(void* addr, uint64_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( += , 64, addr, val, atomic_index, position); } // cds atomic fetch sub -uint8_t cds_atomic_fetch_sub8(void* addr, uint8_t val, int atomic_index) { - _ATOMIC_RMW_( -= , 8, addr, atomic_index, val); +uint8_t cds_atomic_fetch_sub8(void* addr, uint8_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( -= , 8, addr, val, atomic_index, position); } -uint16_t cds_atomic_fetch_sub16(void* addr, uint16_t val, int atomic_index) { - _ATOMIC_RMW_( -= , 16, addr, atomic_index, val); +uint16_t cds_atomic_fetch_sub16(void* addr, uint16_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( -= , 16, addr, val, atomic_index, position); } -uint32_t cds_atomic_fetch_sub32(void* addr, uint32_t val, int atomic_index) { - _ATOMIC_RMW_( -= , 32, addr, atomic_index, val); +uint32_t cds_atomic_fetch_sub32(void* addr, uint32_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( -= , 32, addr, val, atomic_index, position); } -uint64_t cds_atomic_fetch_sub64(void* addr, uint64_t val, int atomic_index) { - _ATOMIC_RMW_( -= , 64, addr, atomic_index, val); +uint64_t cds_atomic_fetch_sub64(void* addr, uint64_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( -= , 64, addr, val, atomic_index, position); } // cds atomic fetch and -uint8_t cds_atomic_fetch_and8(void* addr, uint8_t val, int atomic_index) { - _ATOMIC_RMW_( &= , 8, addr, atomic_index, val); +uint8_t cds_atomic_fetch_and8(void* addr, uint8_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( &= , 8, addr, val, atomic_index, position); } -uint16_t cds_atomic_fetch_and16(void* addr, uint16_t val, int atomic_index) { - _ATOMIC_RMW_( &= , 16, addr, atomic_index, val); +uint16_t cds_atomic_fetch_and16(void* addr, uint16_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( &= , 16, addr, val, atomic_index, position); } -uint32_t cds_atomic_fetch_and32(void* addr, uint32_t val, int atomic_index) { - _ATOMIC_RMW_( &= , 32, addr, atomic_index, val); +uint32_t cds_atomic_fetch_and32(void* addr, uint32_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( &= , 32, addr, val, atomic_index, position); } -uint64_t cds_atomic_fetch_and64(void* addr, uint64_t val, int atomic_index) { - _ATOMIC_RMW_( &= , 64, addr, atomic_index, val); +uint64_t cds_atomic_fetch_and64(void* addr, uint64_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( &= , 64, addr, val, atomic_index, position); } // cds atomic fetch or -uint8_t cds_atomic_fetch_or8(void* addr, uint8_t val, int atomic_index) { - _ATOMIC_RMW_( |= , 8, addr, atomic_index, val); +uint8_t cds_atomic_fetch_or8(void* addr, uint8_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( |= , 8, addr, val, atomic_index, position); } -uint16_t cds_atomic_fetch_or16(void* addr, uint16_t val, int atomic_index) { - _ATOMIC_RMW_( |= , 16, addr, atomic_index, val); +uint16_t cds_atomic_fetch_or16(void* addr, uint16_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( |= , 16, addr, val, atomic_index, position); } -uint32_t cds_atomic_fetch_or32(void* addr, uint32_t val, int atomic_index) { - _ATOMIC_RMW_( |= , 32, addr, atomic_index, val); +uint32_t cds_atomic_fetch_or32(void* addr, uint32_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( |= , 32, addr, val, atomic_index, position); } -uint64_t cds_atomic_fetch_or64(void* addr, uint64_t val, int atomic_index) { - _ATOMIC_RMW_( |= , 64, addr, atomic_index, val); +uint64_t cds_atomic_fetch_or64(void* addr, uint64_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( |= , 64, addr, val, atomic_index, position); } // cds atomic fetch xor -uint8_t cds_atomic_fetch_xor8(void* addr, uint8_t val, int atomic_index) { - _ATOMIC_RMW_( ^= , 8, addr, atomic_index, val); +uint8_t cds_atomic_fetch_xor8(void* addr, uint8_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( ^= , 8, addr, val, atomic_index, position); } -uint16_t cds_atomic_fetch_xor16(void* addr, uint16_t val, int atomic_index) { - _ATOMIC_RMW_( ^= , 16, addr, atomic_index, val); +uint16_t cds_atomic_fetch_xor16(void* addr, uint16_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( ^= , 16, addr, val, atomic_index, position); } -uint32_t cds_atomic_fetch_xor32(void* addr, uint32_t val, int atomic_index) { - _ATOMIC_RMW_( ^= , 32, addr, atomic_index, val); +uint32_t cds_atomic_fetch_xor32(void* addr, uint32_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( ^= , 32, addr, val, atomic_index, position); } -uint64_t cds_atomic_fetch_xor64(void* addr, uint64_t val, int atomic_index) { - _ATOMIC_RMW_( ^= , 64, addr, atomic_index, val); +uint64_t cds_atomic_fetch_xor64(void* addr, uint64_t val, int atomic_index, const char * position) { + _ATOMIC_RMW_( ^= , 64, addr, val, atomic_index, position); } // cds atomic compare and exchange // In order to accomodate the LLVM PASS, the return values are not true or false. #define _ATOMIC_CMPSWP_WEAK_ _ATOMIC_CMPSWP_ -#define _ATOMIC_CMPSWP_(size, addr, expected, desired, atomic_index) \ +#define _ATOMIC_CMPSWP_(size, addr, expected, desired, atomic_index, position) \ ({ \ uint##size##_t _desired = desired; \ uint##size##_t _expected = expected; \ - uint##size##_t _old = model_rmwr_action_helper(addr, atomic_index); \ - if (_old == _expected ) { \ - model_rmw_action_helper(addr, atomic_index, (uint64_t) _desired ); return _expected; } \ + uint##size##_t _old = model_rmwr_action_helper(addr, atomic_index, position); \ + if (_old == _expected) { \ + model_rmw_action_helper(addr, (uint64_t) _desired, atomic_index, position); return _expected; } \ else { \ - model_rmwc_action_helper(addr, atomic_index); _expected = _old; return _old; } \ + model_rmwc_action_helper(addr, atomic_index, position); _expected = _old; return _old; } \ }) // atomic_compare_exchange version 1: the CmpOperand (corresponds to expected) // extracted from LLVM IR is an integer type. -uint8_t cds_atomic_compare_exchange8_v1(void* addr, uint8_t expected, - uint8_t desired, int atomic_index_succ, int atomic_index_fail ) { - _ATOMIC_CMPSWP_(8, addr, expected, desired, atomic_index_succ ); +uint8_t cds_atomic_compare_exchange8_v1(void* addr, uint8_t expected, uint8_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position ) +{ + _ATOMIC_CMPSWP_(8, addr, expected, desired, + atomic_index_succ, position); } -uint16_t cds_atomic_compare_exchange16_v1(void* addr, uint16_t expected, - uint16_t desired, int atomic_index_succ, int atomic_index_fail ) { - _ATOMIC_CMPSWP_(16, addr, expected, desired, atomic_index_succ ); +uint16_t cds_atomic_compare_exchange16_v1(void* addr, uint16_t expected, uint16_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position) +{ + _ATOMIC_CMPSWP_(16, addr, expected, desired, + atomic_index_succ, position); } -uint32_t cds_atomic_compare_exchange32_v1(void* addr, uint32_t expected, - uint32_t desired, int atomic_index_succ, int atomic_index_fail ) { - _ATOMIC_CMPSWP_(32, addr, expected, desired, atomic_index_succ ); +uint32_t cds_atomic_compare_exchange32_v1(void* addr, uint32_t expected, uint32_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position) +{ + _ATOMIC_CMPSWP_(32, addr, expected, desired, + atomic_index_succ, position); } -uint64_t cds_atomic_compare_exchange64_v1(void* addr, uint64_t expected, - uint64_t desired, int atomic_index_succ, int atomic_index_fail ) { - _ATOMIC_CMPSWP_(64, addr, expected, desired, atomic_index_succ ); +uint64_t cds_atomic_compare_exchange64_v1(void* addr, uint64_t expected, uint64_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position) +{ + _ATOMIC_CMPSWP_(64, addr, expected, desired, + atomic_index_succ, position); } // atomic_compare_exchange version 2 -bool cds_atomic_compare_exchange8_v2(void* addr, uint8_t* expected, - uint8_t desired, int atomic_index_succ, int atomic_index_fail ) { +bool cds_atomic_compare_exchange8_v2(void* addr, uint8_t* expected, uint8_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position ) +{ uint8_t ret = cds_atomic_compare_exchange8_v1(addr, *expected, - desired, atomic_index_succ, atomic_index_fail ); + desired, atomic_index_succ, atomic_index_fail, position); if (ret == *expected) return true; else return false; } -bool cds_atomic_compare_exchange16_v2(void* addr, uint16_t* expected, - uint16_t desired, int atomic_index_succ, int atomic_index_fail ) { +bool cds_atomic_compare_exchange16_v2(void* addr, uint16_t* expected, uint16_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position) +{ uint16_t ret = cds_atomic_compare_exchange16_v1(addr, *expected, - desired, atomic_index_succ, atomic_index_fail ); + desired, atomic_index_succ, atomic_index_fail, position); if (ret == *expected) return true; else return false; } -bool cds_atomic_compare_exchange32_v2(void* addr, uint32_t* expected, - uint32_t desired, int atomic_index_succ, int atomic_index_fail ) { +bool cds_atomic_compare_exchange32_v2(void* addr, uint32_t* expected, uint32_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position) +{ uint32_t ret = cds_atomic_compare_exchange32_v1(addr, *expected, - desired, atomic_index_succ, atomic_index_fail ); + desired, atomic_index_succ, atomic_index_fail, position); if (ret == *expected) return true; else return false; } -bool cds_atomic_compare_exchange64_v2(void* addr, uint64_t* expected, - uint64_t desired, int atomic_index_succ, int atomic_index_fail ) { +bool cds_atomic_compare_exchange64_v2(void* addr, uint64_t* expected, uint64_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position) +{ uint64_t ret = cds_atomic_compare_exchange64_v1(addr, *expected, - desired, atomic_index_succ, atomic_index_fail ); + desired, atomic_index_succ, atomic_index_fail, position); if (ret == *expected) return true; else return false; } @@ -280,8 +322,10 @@ bool cds_atomic_compare_exchange64_v2(void* addr, uint64_t* expected, // cds atomic thread fence -void cds_atomic_thread_fence(int atomic_index) { - model->switch_to_master(new ModelAction(ATOMIC_FENCE, orders[atomic_index], FENCE_LOCATION)); +void cds_atomic_thread_fence(int atomic_index, const char * position) { + model->switch_to_master( + new ModelAction(ATOMIC_FENCE, position, orders[atomic_index], FENCE_LOCATION) + ); } /* diff --git a/include/cmodelint.h b/include/cmodelint.h index d2f11e77..0355a47e 100644 --- a/include/cmodelint.h +++ b/include/cmodelint.h @@ -21,82 +21,81 @@ void model_rmw_action(void *obj, memory_order ord, uint64_t val); void model_rmwc_action(void *obj, memory_order ord); void model_fence_action(memory_order ord); -// void model_init_action_helper(void * obj, uint64_t val); -uint64_t model_rmwr_action_helper(void *obj, int atomic_index); -void model_rmw_action_helper(void *obj, int atomic_index, uint64_t val); -void model_rmwc_action_helper(void *obj, int atomic_index); -void model_fence_action_helper(int atomic_index); +uint64_t model_rmwr_action_helper(void *obj, int atomic_index, const char *position); +void model_rmw_action_helper(void *obj, uint64_t val, int atomic_index, const char *position); +void model_rmwc_action_helper(void *obj, int atomic_index, const char *position); +// void model_fence_action_helper(int atomic_index); /* the following functions are used by llvm pass */ -void cds_atomic_init8(void * obj, uint8_t val); -void cds_atomic_init16(void * obj, uint16_t val); -void cds_atomic_init32(void * obj, uint32_t val); -void cds_atomic_init64(void * obj, uint64_t val); +void cds_atomic_init8(void * obj, uint8_t val, const char * position); +void cds_atomic_init16(void * obj, uint16_t val, const char * position); +void cds_atomic_init32(void * obj, uint32_t val, const char * position); +void cds_atomic_init64(void * obj, uint64_t val, const char * position); -uint8_t cds_atomic_load8(void * obj, int atomic_index); -uint16_t cds_atomic_load16(void * obj, int atomic_index); -uint32_t cds_atomic_load32(void * obj, int atomic_index); -uint64_t cds_atomic_load64(void * obj, int atomic_index); +uint8_t cds_atomic_load8(void * obj, int atomic_index, const char * position); +uint16_t cds_atomic_load16(void * obj, int atomic_index, const char * position); +uint32_t cds_atomic_load32(void * obj, int atomic_index, const char * position); +uint64_t cds_atomic_load64(void * obj, int atomic_index, const char * position); -void cds_atomic_store8(void * obj, uint8_t val, int atomic_index); -void cds_atomic_store16(void * obj, uint16_t val, int atomic_index); -void cds_atomic_store32(void * obj, uint32_t val, int atomic_index); -void cds_atomic_store64(void * obj, uint64_t val, int atomic_index); +void cds_atomic_store8(void * obj, uint8_t val, int atomic_index, const char * position); +void cds_atomic_store16(void * obj, uint16_t val, int atomic_index, const char * position); +void cds_atomic_store32(void * obj, uint32_t val, int atomic_index, const char * position); +void cds_atomic_store64(void * obj, uint64_t val, int atomic_index, const char * position); // cds atomic exchange -uint8_t cds_atomic_exchange8(void* addr, uint8_t val, int atomic_index); -uint16_t cds_atomic_exchange16(void* addr, uint16_t val, int atomic_index); -uint32_t cds_atomic_exchange32(void* addr, uint32_t val, int atomic_index); -uint64_t cds_atomic_exchange64(void* addr, uint64_t val, int atomic_index); +uint8_t cds_atomic_exchange8(void* addr, uint8_t val, int atomic_index, const char * position); +uint16_t cds_atomic_exchange16(void* addr, uint16_t val, int atomic_index, const char * position); +uint32_t cds_atomic_exchange32(void* addr, uint32_t val, int atomic_index, const char * position); +uint64_t cds_atomic_exchange64(void* addr, uint64_t val, int atomic_index, const char * position); // cds atomic fetch add -uint8_t cds_atomic_fetch_add8(void* addr, uint8_t val, int atomic_index); -uint16_t cds_atomic_fetch_add16(void* addr, uint16_t val, int atomic_index); -uint32_t cds_atomic_fetch_add32(void* addr, uint32_t val, int atomic_index); -uint64_t cds_atomic_fetch_add64(void* addr, uint64_t val, int atomic_index); +uint8_t cds_atomic_fetch_add8(void* addr, uint8_t val, int atomic_index, const char * position); +uint16_t cds_atomic_fetch_add16(void* addr, uint16_t val, int atomic_index, const char * position); +uint32_t cds_atomic_fetch_add32(void* addr, uint32_t val, int atomic_index, const char * position); +uint64_t cds_atomic_fetch_add64(void* addr, uint64_t val, int atomic_index, const char * position); // cds atomic fetch sub -uint8_t cds_atomic_fetch_sub8(void* addr, uint8_t val, int atomic_index); -uint16_t cds_atomic_fetch_sub16(void* addr, uint16_t val, int atomic_index); -uint32_t cds_atomic_fetch_sub32(void* addr, uint32_t val, int atomic_index); -uint64_t cds_atomic_fetch_sub64(void* addr, uint64_t val, int atomic_index); +uint8_t cds_atomic_fetch_sub8(void* addr, uint8_t val, int atomic_index, const char * position); +uint16_t cds_atomic_fetch_sub16(void* addr, uint16_t val, int atomic_index, const char * position); +uint32_t cds_atomic_fetch_sub32(void* addr, uint32_t val, int atomic_index, const char * position); +uint64_t cds_atomic_fetch_sub64(void* addr, uint64_t val, int atomic_index, const char * position); // cds atomic fetch and -uint8_t cds_atomic_fetch_and8(void* addr, uint8_t val, int atomic_index); -uint16_t cds_atomic_fetch_and16(void* addr, uint16_t val, int atomic_index); -uint32_t cds_atomic_fetch_and32(void* addr, uint32_t val, int atomic_index); -uint64_t cds_atomic_fetch_and64(void* addr, uint64_t val, int atomic_index); +uint8_t cds_atomic_fetch_and8(void* addr, uint8_t val, int atomic_index, const char * position); +uint16_t cds_atomic_fetch_and16(void* addr, uint16_t val, int atomic_index, const char * position); +uint32_t cds_atomic_fetch_and32(void* addr, uint32_t val, int atomic_index, const char * position); +uint64_t cds_atomic_fetch_and64(void* addr, uint64_t val, int atomic_index, const char * position); // cds atomic fetch or -uint8_t cds_atomic_fetch_or8(void* addr, uint8_t val, int atomic_index); -uint16_t cds_atomic_fetch_or16(void* addr, uint16_t val, int atomic_index); -uint32_t cds_atomic_fetch_or32(void* addr, uint32_t val, int atomic_index); -uint64_t cds_atomic_fetch_or64(void* addr, uint64_t val, int atomic_index); +uint8_t cds_atomic_fetch_or8(void* addr, uint8_t val, int atomic_index, const char * position); +uint16_t cds_atomic_fetch_or16(void* addr, uint16_t val, int atomic_index, const char * position); +uint32_t cds_atomic_fetch_or32(void* addr, uint32_t val, int atomic_index, const char * position); +uint64_t cds_atomic_fetch_or64(void* addr, uint64_t val, int atomic_index, const char * position); // cds atomic fetch xor -uint8_t cds_atomic_fetch_xor8(void* addr, uint8_t val, int atomic_index); -uint16_t cds_atomic_fetch_xor16(void* addr, uint16_t val, int atomic_index); -uint32_t cds_atomic_fetch_xor32(void* addr, uint32_t val, int atomic_index); -uint64_t cds_atomic_fetch_xor64(void* addr, uint64_t val, int atomic_index); +uint8_t cds_atomic_fetch_xor8(void* addr, uint8_t val, int atomic_index, const char * position); +uint16_t cds_atomic_fetch_xor16(void* addr, uint16_t val, int atomic_index, const char * position); +uint32_t cds_atomic_fetch_xor32(void* addr, uint32_t val, int atomic_index, const char * position); +uint64_t cds_atomic_fetch_xor64(void* addr, uint64_t val, int atomic_index, const char * position); // cds atomic compare and exchange (strong) -uint8_t cds_atomic_compare_exchange8_v1(void* addr, uint8_t expected, - uint8_t desire, int atomic_index_succ, int atomic_index_fail ); -uint16_t cds_atomic_compare_exchange16_v1(void* addr, uint16_t expected, - uint16_t desire, int atomic_index_succ, int atomic_index_fail ); -uint32_t cds_atomic_compare_exchange32_v1(void* addr, uint32_t expected, - uint32_t desire, int atomic_index_succ, int atomic_index_fail ); -uint64_t cds_atomic_compare_exchange64_v1(void* addr, uint64_t expected, - uint64_t desire, int atomic_index_succ, int atomic_index_fail ); +uint8_t cds_atomic_compare_exchange8_v1(void* addr, uint8_t expected, uint8_t desire, + int atomic_index_succ, int atomic_index_fail, const char *position); +uint16_t cds_atomic_compare_exchange16_v1(void* addr, uint16_t expected, uint16_t desire, + int atomic_index_succ, int atomic_index_fail, const char *position); +uint32_t cds_atomic_compare_exchange32_v1(void* addr, uint32_t expected, uint32_t desire, + int atomic_index_succ, int atomic_index_fail, const char *position); +uint64_t cds_atomic_compare_exchange64_v1(void* addr, uint64_t expected, uint64_t desire, + int atomic_index_succ, int atomic_index_fail, const char *position); -bool cds_atomic_compare_exchange8_v2(void* addr, uint8_t* expected, - uint8_t desired, int atomic_index_succ, int atomic_index_fail ); -bool cds_atomic_compare_exchange16_v2(void* addr, uint16_t* expected, - uint16_t desired, int atomic_index_succ, int atomic_index_fail ); -bool cds_atomic_compare_exchange32_v2(void* addr, uint32_t* expected, - uint32_t desired, int atomic_index_succ, int atomic_index_fail ); -bool cds_atomic_compare_exchange64_v2(void* addr, uint64_t* expected, - uint64_t desired, int atomic_index_succ, int atomic_index_fail ); +bool cds_atomic_compare_exchange8_v2(void* addr, uint8_t* expected, uint8_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position); +bool cds_atomic_compare_exchange16_v2(void* addr, uint16_t* expected, uint16_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position); +bool cds_atomic_compare_exchange32_v2(void* addr, uint32_t* expected, uint32_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position); +bool cds_atomic_compare_exchange64_v2(void* addr, uint64_t* expected, uint64_t desired, + int atomic_index_succ, int atomic_index_fail, const char *position); // cds atomic thread fence -void cds_atomic_thread_fence(int atomic_index); +void cds_atomic_thread_fence(int atomic_index, const char * position); #if __cplusplus } -- 2.34.1