X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=execution.cc;h=53aa5212f0b017622d0c284f1cbc765e0620fddd;hp=57ce6fef4cc62b8ff8aff79970bdfe2de786f4b3;hb=9e091f7017e3e22742b26f991f8f06bc2fb874f4;hpb=50e0465f724dc182d5d7504004e93f1a1b4644b9 diff --git a/execution.cc b/execution.cc index 57ce6fef..53aa5212 100644 --- a/execution.cc +++ b/execution.cc @@ -264,8 +264,19 @@ bool ModelExecution::is_deadlocked() const return blocking_threads; } +/** + * @brief Check if we are yield-blocked + * + * A program can be "yield-blocked" if all threads are ready to execute a + * yield. + * + * @return True if the program is yield-blocked; false otherwise + */ bool ModelExecution::is_yieldblocked() const { + if (!params->yieldblock) + return false; + for (unsigned int i = 0; i < get_num_threads(); i++) { thread_id_t tid = int_to_id(i); Thread *t = get_thread(tid); @@ -284,7 +295,7 @@ bool ModelExecution::is_yieldblocked() const */ bool ModelExecution::is_complete_execution() const { - if (params->yieldblock && is_yieldblocked()) + if (is_yieldblocked()) return false; for (unsigned int i = 0; i < get_num_threads(); i++) if (is_enabled(int_to_id(i))) @@ -744,12 +755,13 @@ bool ModelExecution::process_mutex(ModelAction *curr) /** * @brief Check if the current pending promises allow a future value to be sent * - * If one of the following is true: - * (a) there are no pending promises - * (b) the reader and writer do not cross any promises - * Then, it is safe to pass a future value back now. + * It is unsafe to pass a future value back if there exists a pending promise Pr + * such that: + * + * reader --exec-> Pr --exec-> writer * - * Otherwise, we must save the pending future value until (a) or (b) is true + * If such Pr exists, we must save the pending future value until Pr is + * resolved. * * @param writer The operation which sends the future value. Must be a write. * @param reader The operation which will observe the value. Must be a read. @@ -758,8 +770,6 @@ bool ModelExecution::process_mutex(ModelAction *curr) bool ModelExecution::promises_may_allow(const ModelAction *writer, const ModelAction *reader) const { - if (promises.empty()) - return true; for (int i = promises.size() - 1; i >= 0; i--) { ModelAction *pr = promises[i]->get_reader(0); //reader is after promise...doesn't cross any promise @@ -806,9 +816,10 @@ void ModelExecution::add_future_value(const ModelAction *writer, ModelAction *re /** * Process a write ModelAction * @param curr The ModelAction to process + * @param work The work queue, for adding fixup work * @return True if the mo_graph was updated or promises were resolved */ -bool ModelExecution::process_write(ModelAction *curr) +bool ModelExecution::process_write(ModelAction *curr, work_queue_t *work) { /* Readers to which we may send our future value */ ModelVector send_fv; @@ -821,7 +832,7 @@ bool ModelExecution::process_write(ModelAction *curr) if (promise) { earliest_promise_reader = promise->get_reader(0); - updated_promises = resolve_promise(curr, promise); + updated_promises = resolve_promise(curr, promise, work); } else earliest_promise_reader = NULL; @@ -1014,21 +1025,9 @@ void ModelExecution::process_relseq_fixup(ModelAction *curr, work_queue_t *work_ /* Must synchronize */ if (!synchronize(release, acquire)) return; - /* Re-check all pending release sequences */ - work_queue->push_back(CheckRelSeqWorkEntry(NULL)); - /* Re-check act for mo_graph edges */ - work_queue->push_back(MOEdgeWorkEntry(acquire)); - - /* propagate synchronization to later actions */ - action_list_t::reverse_iterator rit = action_trace.rbegin(); - for (; (*rit) != acquire; rit++) { - ModelAction *propagate = *rit; - if (acquire->happens_before(propagate)) { - synchronize(acquire, propagate); - /* Re-check 'propagate' for mo_graph edges */ - work_queue->push_back(MOEdgeWorkEntry(propagate)); - } - } + + /* Propagate the changed clock vector */ + propagate_clockvector(acquire, work_queue); } else { /* Break release sequence with new edges: * release --mo--> write --mo--> rf */ @@ -1194,9 +1193,10 @@ void ModelExecution::thread_blocking_check_promises(Thread *blocker, Thread *wai /** * @brief Check whether a model action is enabled. * - * Checks whether a lock or join operation would be successful (i.e., is the - * lock already locked, or is the joined thread already complete). If not, put - * the action in a waiter list. + * Checks whether an operation would be successful (i.e., is a lock already + * locked, or is the joined thread already complete). + * + * For yield-blocking, yields are never enabled. * * @param curr is the ModelAction to check whether it is enabled. * @return a bool that indicates whether the action is enabled. @@ -1272,7 +1272,7 @@ ModelAction * ModelExecution::check_current_action(ModelAction *curr) if (act->is_read() && !second_part_of_rmw && process_read(act)) update = true; - if (act->is_write() && process_write(act)) + if (act->is_write() && process_write(act, &work_queue)) update = true; if (act->is_fence() && process_fence(act)) @@ -1388,7 +1388,7 @@ void ModelExecution::print_infeasibility(const char *prefix) const if (promises.size() != 0) ptr += sprintf(ptr, "[unresolved promise]"); if (ptr != buf) - model_print("%s: %s\n", prefix ? prefix : "Infeasible", buf); + model_print("%s: %s", prefix ? prefix : "Infeasible", buf); } /** @@ -1819,6 +1819,7 @@ bool ModelExecution::thin_air_constraint_may_allow(const ModelAction *writer, co * require compiler support): * * If X --hb-> Y --mo-> Z, then X should not read from Z. + * If X --hb-> Y, A --rf-> Y, and A --mo-> Z, then X should not read from Z. */ bool ModelExecution::mo_may_allow(const ModelAction *writer, const ModelAction *reader) { @@ -2050,6 +2051,37 @@ void ModelExecution::get_release_seq_heads(ModelAction *acquire, } } +/** + * @brief Propagate a modified clock vector to actions later in the execution + * order + * + * After an acquire operation lazily completes a release-sequence + * synchronization, we must update all clock vectors for operations later than + * the acquire in the execution order. + * + * @param acquire The ModelAction whose clock vector must be propagated + * @param work The work queue to which we can add work items, if this + * propagation triggers more updates (e.g., to the modification order) + */ +void ModelExecution::propagate_clockvector(ModelAction *acquire, work_queue_t *work) +{ + /* Re-check all pending release sequences */ + work->push_back(CheckRelSeqWorkEntry(NULL)); + /* Re-check read-acquire for mo_graph edges */ + work->push_back(MOEdgeWorkEntry(acquire)); + + /* propagate synchronization to later actions */ + action_list_t::reverse_iterator rit = action_trace.rbegin(); + for (; (*rit) != acquire; rit++) { + ModelAction *propagate = *rit; + if (acquire->happens_before(propagate)) { + synchronize(acquire, propagate); + /* Re-check 'propagate' for mo_graph edges */ + work->push_back(MOEdgeWorkEntry(propagate)); + } + } +} + /** * Attempt to resolve all stashed operations that might synchronize with a * release sequence for a given location. This implements the "lazy" portion of @@ -2088,22 +2120,8 @@ bool ModelExecution::resolve_release_sequences(void *location, work_queue_t *wor updated = true; if (updated) { - /* Re-check all pending release sequences */ - work_queue->push_back(CheckRelSeqWorkEntry(NULL)); - /* Re-check read-acquire for mo_graph edges */ - if (acquire->is_read()) - work_queue->push_back(MOEdgeWorkEntry(acquire)); - - /* propagate synchronization to later actions */ - action_list_t::reverse_iterator rit = action_trace.rbegin(); - for (; (*rit) != acquire; rit++) { - ModelAction *propagate = *rit; - if (acquire->happens_before(propagate)) { - synchronize(acquire, propagate); - /* Re-check 'propagate' for mo_graph edges */ - work_queue->push_back(MOEdgeWorkEntry(propagate)); - } - } + /* Propagate the changed clock vector */ + propagate_clockvector(acquire, work_queue); } if (complete) { it = pending_rel_seqs.erase(it); @@ -2316,15 +2334,20 @@ Promise * ModelExecution::pop_promise_to_resolve(const ModelAction *curr) * Resolve a Promise with a current write. * @param write The ModelAction that is fulfilling Promises * @param promise The Promise to resolve + * @param work The work queue, for adding new fixup work * @return True if the Promise was successfully resolved; false otherwise */ -bool ModelExecution::resolve_promise(ModelAction *write, Promise *promise) +bool ModelExecution::resolve_promise(ModelAction *write, Promise *promise, + work_queue_t *work) { ModelVector actions_to_check; for (unsigned int i = 0; i < promise->get_num_readers(); i++) { ModelAction *read = promise->get_reader(i); - read_from(read, write); + if (read_from(read, write)) { + /* Propagate the changed clock vector */ + propagate_clockvector(read, work); + } actions_to_check.push_back(read); } /* Make sure the promise's value matches the write's value */ @@ -2607,7 +2630,9 @@ static void print_list(const action_list_t *list) { action_list_t::const_iterator it; - model_print("---------------------------------------------------------------------\n"); + model_print("------------------------------------------------------------------------------------\n"); + model_print("# t Action type MO Location Value Rf CV\n"); + model_print("------------------------------------------------------------------------------------\n"); unsigned int hash = 0; @@ -2618,7 +2643,7 @@ static void print_list(const action_list_t *list) hash = hash^(hash<<3)^((*it)->hash()); } model_print("HASH %u\n", hash); - model_print("---------------------------------------------------------------------\n"); + model_print("------------------------------------------------------------------------------------\n"); } #if SUPPORT_MOD_ORDER_DUMP @@ -2631,7 +2656,7 @@ void ModelExecution::dumpGraph(char *filename) const mo_graph->dumpNodes(file); ModelAction **thread_array = (ModelAction **)model_calloc(1, sizeof(ModelAction *) * get_num_threads()); - for (action_list_t::iterator it = action_trace.begin(); it != action_trace.end(); it++) { + for (action_list_t::const_iterator it = action_trace.begin(); it != action_trace.end(); it++) { ModelAction *act = *it; if (act->is_read()) { mo_graph->dot_print_node(file, act); @@ -2672,17 +2697,21 @@ void ModelExecution::print_summary() const dumpGraph(buffername); #endif - model_print("Execution %d:", get_execution_number()); + model_print("Execution trace %d:", get_execution_number()); if (isfeasibleprefix()) { - if (params->yieldblock && is_yieldblocked()) + if (is_yieldblocked()) model_print(" YIELD BLOCKED"); if (scheduler->all_threads_sleeping()) model_print(" SLEEP-SET REDUNDANT"); - model_print("\n"); + if (have_bug_reports()) + model_print(" DETECTED BUG(S)"); } else print_infeasibility(" INFEASIBLE"); + model_print("\n"); + print_list(&action_trace); model_print("\n"); + if (!promises.empty()) { model_print("Pending promises:\n"); for (unsigned int i = 0; i < promises.size(); i++) {