| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
| bart | 922304f | 2011-03-13 12:02:44 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2011 Bart Van Assche <bvanassche@acm.org>. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU General Public License as |
| 8 | published by the Free Software Foundation; either version 2 of the |
| 9 | License, or (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 | 02111-1307, USA. |
| 20 | |
| 21 | The GNU General Public License is contained in the file COPYING. |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include "drd_error.h" |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 26 | #include "drd_barrier.h" |
| bart | d2c5eae | 2009-02-21 15:27:04 +0000 | [diff] [blame] | 27 | #include "drd_clientobj.h" |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 28 | #include "drd_cond.h" |
| 29 | #include "drd_mutex.h" |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 30 | #include "drd_segment.h" |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 31 | #include "drd_semaphore.h" |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 32 | #include "drd_suppression.h" |
| 33 | #include "drd_thread.h" |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 34 | #include "pub_tool_vki.h" |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 35 | #include "pub_tool_basics.h" // Addr, SizeT |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 36 | #include "pub_tool_libcassert.h" // tl_assert() |
| 37 | #include "pub_tool_libcbase.h" // VG_(strlen)() |
| 38 | #include "pub_tool_libcprint.h" // VG_(printf)() |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 39 | #include "pub_tool_libcproc.h" // VG_(getenv)() |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 40 | #include "pub_tool_machine.h" |
| 41 | #include "pub_tool_mallocfree.h" // VG_(malloc)(), VG_(free)() |
| sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 42 | #include "pub_tool_options.h" // VG_(clo_backtrace_size) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 43 | #include "pub_tool_threadstate.h" // VG_(get_pthread_id)() |
| 44 | |
| bart | 32ba208 | 2008-06-05 08:53:42 +0000 | [diff] [blame] | 45 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 46 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 47 | /* Local functions. */ |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 48 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 49 | static void thread_append_segment(const DrdThreadId tid, Segment* const sg); |
| 50 | static void thread_discard_segment(const DrdThreadId tid, Segment* const sg); |
| 51 | static void thread_compute_conflict_set(struct bitmap** conflict_set, |
| 52 | const DrdThreadId tid); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 53 | static Bool thread_conflict_set_up_to_date(const DrdThreadId tid); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 54 | |
| 55 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 56 | /* Local variables. */ |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 57 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 58 | static ULong s_context_switch_count; |
| 59 | static ULong s_discard_ordered_segments_count; |
| bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 60 | static ULong s_compute_conflict_set_count; |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 61 | static ULong s_update_conflict_set_count; |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 62 | static ULong s_update_conflict_set_new_sg_count; |
| 63 | static ULong s_update_conflict_set_sync_count; |
| 64 | static ULong s_update_conflict_set_join_count; |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 65 | static ULong s_conflict_set_bitmap_creation_count; |
| 66 | static ULong s_conflict_set_bitmap2_creation_count; |
| 67 | static ThreadId s_vg_running_tid = VG_INVALID_THREADID; |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 68 | DrdThreadId DRD_(g_drd_running_tid) = DRD_INVALID_THREADID; |
| 69 | ThreadInfo DRD_(g_threadinfo)[DRD_N_THREADS]; |
| 70 | struct bitmap* DRD_(g_conflict_set); |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 71 | static Bool s_trace_context_switches = False; |
| 72 | static Bool s_trace_conflict_set = False; |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 73 | static Bool s_trace_conflict_set_bm = False; |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 74 | static Bool s_trace_fork_join = False; |
| 75 | static Bool s_segment_merging = True; |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 76 | static Bool s_new_segments_since_last_merge; |
| bart | 6f1d716 | 2009-06-24 18:34:10 +0000 | [diff] [blame] | 77 | static int s_segment_merge_interval = 10; |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 78 | static unsigned s_join_list_vol = 10; |
| 79 | static unsigned s_deletion_head; |
| 80 | static unsigned s_deletion_tail; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 81 | |
| 82 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 83 | /* Function definitions. */ |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 84 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 85 | /** Enables/disables context switch tracing. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 86 | void DRD_(thread_trace_context_switches)(const Bool t) |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 87 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 88 | tl_assert(t == False || t == True); |
| 89 | s_trace_context_switches = t; |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 92 | /** Enables/disables conflict set tracing. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 93 | void DRD_(thread_trace_conflict_set)(const Bool t) |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 94 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 95 | tl_assert(t == False || t == True); |
| 96 | s_trace_conflict_set = t; |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 99 | /** Enables/disables conflict set bitmap tracing. */ |
| 100 | void DRD_(thread_trace_conflict_set_bm)(const Bool t) |
| 101 | { |
| 102 | tl_assert(t == False || t == True); |
| 103 | s_trace_conflict_set_bm = t; |
| 104 | } |
| 105 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 106 | /** Report whether fork/join tracing is enabled. */ |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 107 | Bool DRD_(thread_get_trace_fork_join)(void) |
| 108 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 109 | return s_trace_fork_join; |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 112 | /** Enables/disables fork/join tracing. */ |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 113 | void DRD_(thread_set_trace_fork_join)(const Bool t) |
| 114 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 115 | tl_assert(t == False || t == True); |
| 116 | s_trace_fork_join = t; |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 119 | /** Enables/disables segment merging. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 120 | void DRD_(thread_set_segment_merging)(const Bool m) |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 121 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 122 | tl_assert(m == False || m == True); |
| 123 | s_segment_merging = m; |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 126 | /** Get the segment merging interval. */ |
| 127 | int DRD_(thread_get_segment_merge_interval)(void) |
| 128 | { |
| 129 | return s_segment_merge_interval; |
| 130 | } |
| 131 | |
| 132 | /** Set the segment merging interval. */ |
| 133 | void DRD_(thread_set_segment_merge_interval)(const int i) |
| 134 | { |
| 135 | s_segment_merge_interval = i; |
| 136 | } |
| 137 | |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 138 | void DRD_(thread_set_join_list_vol)(const int jlv) |
| 139 | { |
| 140 | s_join_list_vol = jlv; |
| 141 | } |
| 142 | |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 143 | void DRD_(thread_init)(void) |
| 144 | { |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 147 | /** |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 148 | * Convert Valgrind's ThreadId into a DrdThreadId. |
| 149 | * |
| 150 | * @return DRD thread ID upon success and DRD_INVALID_THREADID if the passed |
| 151 | * Valgrind ThreadId does not yet exist. |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 152 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 153 | DrdThreadId DRD_(VgThreadIdToDrdThreadId)(const ThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 154 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 155 | int i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 156 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 157 | if (tid == VG_INVALID_THREADID) |
| 158 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 159 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 160 | for (i = 1; i < DRD_N_THREADS; i++) |
| 161 | { |
| 162 | if (DRD_(g_threadinfo)[i].vg_thread_exists == True |
| 163 | && DRD_(g_threadinfo)[i].vg_threadid == tid) |
| 164 | { |
| 165 | return i; |
| 166 | } |
| 167 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 168 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 169 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 172 | /** Allocate a new DRD thread ID for the specified Valgrind thread ID. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 173 | static DrdThreadId DRD_(VgThreadIdToNewDrdThreadId)(const ThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 174 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 175 | int i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 176 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 177 | tl_assert(DRD_(VgThreadIdToDrdThreadId)(tid) == DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 178 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 179 | for (i = 1; i < DRD_N_THREADS; i++) |
| 180 | { |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 181 | if (!DRD_(g_threadinfo)[i].valid) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 182 | { |
| 183 | tl_assert(! DRD_(IsValidDrdThreadId)(i)); |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 184 | |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 185 | DRD_(g_threadinfo)[i].valid = True; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 186 | DRD_(g_threadinfo)[i].vg_thread_exists = True; |
| 187 | DRD_(g_threadinfo)[i].vg_threadid = tid; |
| 188 | DRD_(g_threadinfo)[i].pt_threadid = INVALID_POSIX_THREADID; |
| 189 | DRD_(g_threadinfo)[i].stack_min = 0; |
| 190 | DRD_(g_threadinfo)[i].stack_min_min = 0; |
| 191 | DRD_(g_threadinfo)[i].stack_startup = 0; |
| 192 | DRD_(g_threadinfo)[i].stack_max = 0; |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 193 | DRD_(thread_set_name)(i, ""); |
| bart | 383d613 | 2010-09-02 14:43:18 +0000 | [diff] [blame] | 194 | DRD_(g_threadinfo)[i].on_alt_stack = False; |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 195 | DRD_(g_threadinfo)[i].is_recording_loads = True; |
| 196 | DRD_(g_threadinfo)[i].is_recording_stores = True; |
| bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 197 | DRD_(g_threadinfo)[i].pthread_create_nesting_level = 0; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 198 | DRD_(g_threadinfo)[i].synchr_nesting = 0; |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 199 | DRD_(g_threadinfo)[i].deletion_seq = s_deletion_tail - 1; |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 200 | tl_assert(DRD_(g_threadinfo)[i].sg_first == NULL); |
| 201 | tl_assert(DRD_(g_threadinfo)[i].sg_last == NULL); |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 202 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 203 | tl_assert(DRD_(IsValidDrdThreadId)(i)); |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 204 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 205 | return i; |
| 206 | } |
| 207 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 208 | |
| bart | 3c9afb1 | 2009-07-24 11:11:30 +0000 | [diff] [blame] | 209 | VG_(printf)( |
| 210 | "\nSorry, but the maximum number of threads supported by DRD has been exceeded." |
| 211 | "Aborting.\n"); |
| 212 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 213 | tl_assert(False); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 214 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 215 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 218 | /** Convert a POSIX thread ID into a DRD thread ID. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 219 | DrdThreadId DRD_(PtThreadIdToDrdThreadId)(const PThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 220 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 221 | int i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 222 | |
| bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 223 | if (tid != INVALID_POSIX_THREADID) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 224 | { |
| bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 225 | for (i = 1; i < DRD_N_THREADS; i++) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 226 | { |
| bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 227 | if (DRD_(g_threadinfo)[i].posix_thread_exists |
| 228 | && DRD_(g_threadinfo)[i].pt_threadid == tid) |
| 229 | { |
| 230 | return i; |
| 231 | } |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 237 | /** Convert a DRD thread ID into a Valgrind thread ID. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 238 | ThreadId DRD_(DrdThreadIdToVgThreadId)(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 239 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 240 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 241 | && tid != DRD_INVALID_THREADID); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 242 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 243 | return (DRD_(g_threadinfo)[tid].vg_thread_exists |
| 244 | ? DRD_(g_threadinfo)[tid].vg_threadid |
| 245 | : VG_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 248 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 249 | /** |
| 250 | * Sanity check of the doubly linked list of segments referenced by a |
| 251 | * ThreadInfo struct. |
| 252 | * @return True if sane, False if not. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 253 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 254 | static Bool DRD_(sane_ThreadInfo)(const ThreadInfo* const ti) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 255 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 256 | Segment* p; |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 257 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 258 | for (p = ti->first; p; p = p->next) { |
| 259 | if (p->next && p->next->prev != p) |
| 260 | return False; |
| 261 | if (p->next == 0 && p != ti->last) |
| 262 | return False; |
| 263 | } |
| 264 | for (p = ti->last; p; p = p->prev) { |
| 265 | if (p->prev && p->prev->next != p) |
| 266 | return False; |
| 267 | if (p->prev == 0 && p != ti->first) |
| 268 | return False; |
| 269 | } |
| 270 | return True; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 271 | } |
| bart | 23d3a4e | 2008-04-05 12:53:00 +0000 | [diff] [blame] | 272 | #endif |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 273 | |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 274 | /** |
| 275 | * Create the first segment for a newly started thread. |
| 276 | * |
| 277 | * This function is called from the handler installed via |
| 278 | * VG_(track_pre_thread_ll_create)(). The Valgrind core invokes this handler |
| 279 | * from the context of the creator thread, before the new thread has been |
| 280 | * created. |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 281 | * |
| 282 | * @param[in] creator DRD thread ID of the creator thread. |
| 283 | * @param[in] vg_created Valgrind thread ID of the created thread. |
| 284 | * |
| 285 | * @return DRD thread ID of the created thread. |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 286 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 287 | DrdThreadId DRD_(thread_pre_create)(const DrdThreadId creator, |
| 288 | const ThreadId vg_created) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 289 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 290 | DrdThreadId created; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 291 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 292 | tl_assert(DRD_(VgThreadIdToDrdThreadId)(vg_created) == DRD_INVALID_THREADID); |
| 293 | created = DRD_(VgThreadIdToNewDrdThreadId)(vg_created); |
| 294 | tl_assert(0 <= (int)created && created < DRD_N_THREADS |
| 295 | && created != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 296 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 297 | tl_assert(DRD_(g_threadinfo)[created].sg_first == NULL); |
| 298 | tl_assert(DRD_(g_threadinfo)[created].sg_last == NULL); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 299 | /* Create an initial segment for the newly created thread. */ |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 300 | thread_append_segment(created, DRD_(sg_new)(creator, created)); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 301 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 302 | return created; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 305 | /** |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 306 | * Initialize DRD_(g_threadinfo)[] for a newly created thread. Must be called |
| 307 | * after the thread has been created and before any client instructions are run |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 308 | * on the newly created thread, e.g. from the handler installed via |
| 309 | * VG_(track_pre_thread_first_insn)(). |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 310 | * |
| 311 | * @param[in] vg_created Valgrind thread ID of the newly created thread. |
| 312 | * |
| 313 | * @return DRD thread ID for the new thread. |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 314 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 315 | DrdThreadId DRD_(thread_post_create)(const ThreadId vg_created) |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 316 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 317 | const DrdThreadId created = DRD_(VgThreadIdToDrdThreadId)(vg_created); |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 318 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 319 | tl_assert(0 <= (int)created && created < DRD_N_THREADS |
| 320 | && created != DRD_INVALID_THREADID); |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 321 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 322 | DRD_(g_threadinfo)[created].stack_max |
| 323 | = VG_(thread_get_stack_max)(vg_created); |
| 324 | DRD_(g_threadinfo)[created].stack_startup |
| 325 | = DRD_(g_threadinfo)[created].stack_max; |
| 326 | DRD_(g_threadinfo)[created].stack_min |
| 327 | = DRD_(g_threadinfo)[created].stack_max; |
| 328 | DRD_(g_threadinfo)[created].stack_min_min |
| 329 | = DRD_(g_threadinfo)[created].stack_max; |
| 330 | DRD_(g_threadinfo)[created].stack_size |
| 331 | = VG_(thread_get_stack_size)(vg_created); |
| 332 | tl_assert(DRD_(g_threadinfo)[created].stack_max != 0); |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 333 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 334 | return created; |
| bart | 439c55f | 2009-02-15 10:38:37 +0000 | [diff] [blame] | 335 | } |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 336 | |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 337 | static void DRD_(thread_delayed_delete)(const DrdThreadId tid) |
| 338 | { |
| 339 | int j; |
| 340 | |
| 341 | DRD_(g_threadinfo)[tid].vg_thread_exists = False; |
| 342 | DRD_(g_threadinfo)[tid].posix_thread_exists = False; |
| 343 | DRD_(g_threadinfo)[tid].deletion_seq = s_deletion_head++; |
| 344 | #if 0 |
| 345 | VG_(message)(Vg_DebugMsg, "Adding thread %d to the deletion list\n", tid); |
| 346 | #endif |
| 347 | if (s_deletion_head - s_deletion_tail >= s_join_list_vol) { |
| 348 | for (j = 0; j < DRD_N_THREADS; ++j) { |
| 349 | if (DRD_(IsValidDrdThreadId)(j) |
| 350 | && DRD_(g_threadinfo)[j].deletion_seq == s_deletion_tail) |
| 351 | { |
| 352 | s_deletion_tail++; |
| 353 | #if 0 |
| 354 | VG_(message)(Vg_DebugMsg, "Delayed delete of thread %d\n", j); |
| 355 | #endif |
| 356 | DRD_(thread_delete)(j, False); |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 363 | /** |
| 364 | * Process VG_USERREQ__POST_THREAD_JOIN. This client request is invoked just |
| 365 | * after thread drd_joiner joined thread drd_joinee. |
| 366 | */ |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 367 | void DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee) |
| 368 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 369 | tl_assert(DRD_(IsValidDrdThreadId)(drd_joiner)); |
| 370 | tl_assert(DRD_(IsValidDrdThreadId)(drd_joinee)); |
| bart | 7627be3 | 2009-06-06 12:26:05 +0000 | [diff] [blame] | 371 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 372 | DRD_(thread_new_segment)(drd_joiner); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 373 | DRD_(thread_combine_vc_join)(drd_joiner, drd_joinee); |
| bart | 7627be3 | 2009-06-06 12:26:05 +0000 | [diff] [blame] | 374 | DRD_(thread_new_segment)(drd_joinee); |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 375 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 376 | if (s_trace_fork_join) |
| 377 | { |
| 378 | const ThreadId joiner = DRD_(DrdThreadIdToVgThreadId)(drd_joiner); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 379 | const unsigned msg_size = 256; |
| 380 | char* msg; |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 381 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 382 | msg = VG_(malloc)("drd.main.dptj.1", msg_size); |
| 383 | tl_assert(msg); |
| 384 | VG_(snprintf)(msg, msg_size, |
| bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 385 | "drd_post_thread_join joiner = %d, joinee = %d", |
| 386 | drd_joiner, drd_joinee); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 387 | if (joiner) |
| 388 | { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 389 | char* vc; |
| 390 | |
| 391 | vc = DRD_(vc_aprint)(DRD_(thread_get_vc)(drd_joiner)); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 392 | VG_(snprintf)(msg + VG_(strlen)(msg), msg_size - VG_(strlen)(msg), |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 393 | ", new vc: %s", vc); |
| 394 | VG_(free)(vc); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 395 | } |
| bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 396 | DRD_(trace_msg)("%pS", msg); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 397 | VG_(free)(msg); |
| 398 | } |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 399 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 400 | if (! DRD_(get_check_stack_accesses)()) |
| 401 | { |
| 402 | DRD_(finish_suppression)(DRD_(thread_get_stack_max)(drd_joinee) |
| 403 | - DRD_(thread_get_stack_size)(drd_joinee), |
| 404 | DRD_(thread_get_stack_max)(drd_joinee)); |
| 405 | } |
| 406 | DRD_(clientobj_delete_thread)(drd_joinee); |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 407 | DRD_(thread_delayed_delete)(drd_joinee); |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 410 | /** |
| 411 | * NPTL hack: NPTL allocates the 'struct pthread' on top of the stack, |
| 412 | * and accesses this data structure from multiple threads without locking. |
| 413 | * Any conflicting accesses in the range stack_startup..stack_max will be |
| 414 | * ignored. |
| 415 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 416 | void DRD_(thread_set_stack_startup)(const DrdThreadId tid, |
| 417 | const Addr stack_startup) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 418 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 419 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 420 | && tid != DRD_INVALID_THREADID); |
| 421 | tl_assert(DRD_(g_threadinfo)[tid].stack_min <= stack_startup); |
| 422 | tl_assert(stack_startup <= DRD_(g_threadinfo)[tid].stack_max); |
| 423 | DRD_(g_threadinfo)[tid].stack_startup = stack_startup; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 426 | /** Return the stack pointer for the specified thread. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 427 | Addr DRD_(thread_get_stack_min)(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 428 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 429 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 430 | && tid != DRD_INVALID_THREADID); |
| 431 | return DRD_(g_threadinfo)[tid].stack_min; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 434 | /** |
| 435 | * Return the lowest value that was ever assigned to the stack pointer |
| 436 | * for the specified thread. |
| 437 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 438 | Addr DRD_(thread_get_stack_min_min)(const DrdThreadId tid) |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 439 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 440 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 441 | && tid != DRD_INVALID_THREADID); |
| 442 | return DRD_(g_threadinfo)[tid].stack_min_min; |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 445 | /** Return the top address for the stack of the specified thread. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 446 | Addr DRD_(thread_get_stack_max)(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 447 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 448 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 449 | && tid != DRD_INVALID_THREADID); |
| 450 | return DRD_(g_threadinfo)[tid].stack_max; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 453 | /** Return the maximum stack size for the specified thread. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 454 | SizeT DRD_(thread_get_stack_size)(const DrdThreadId tid) |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 455 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 456 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 457 | && tid != DRD_INVALID_THREADID); |
| 458 | return DRD_(g_threadinfo)[tid].stack_size; |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| bart | 383d613 | 2010-09-02 14:43:18 +0000 | [diff] [blame] | 461 | Bool DRD_(thread_get_on_alt_stack)(const DrdThreadId tid) |
| 462 | { |
| 463 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 464 | && tid != DRD_INVALID_THREADID); |
| 465 | return DRD_(g_threadinfo)[tid].on_alt_stack; |
| 466 | } |
| 467 | |
| 468 | void DRD_(thread_set_on_alt_stack)(const DrdThreadId tid, |
| 469 | const Bool on_alt_stack) |
| 470 | { |
| 471 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 472 | && tid != DRD_INVALID_THREADID); |
| 473 | tl_assert(on_alt_stack == !!on_alt_stack); |
| 474 | DRD_(g_threadinfo)[tid].on_alt_stack = on_alt_stack; |
| 475 | } |
| 476 | |
| 477 | Int DRD_(thread_get_threads_on_alt_stack)(void) |
| 478 | { |
| 479 | int i, n = 0; |
| 480 | |
| 481 | for (i = 1; i < DRD_N_THREADS; i++) |
| 482 | n += DRD_(g_threadinfo)[i].on_alt_stack; |
| 483 | return n; |
| 484 | } |
| 485 | |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 486 | /** |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 487 | * Clean up thread-specific data structures. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 488 | */ |
| bart | 9194e93 | 2011-02-09 11:55:12 +0000 | [diff] [blame] | 489 | void DRD_(thread_delete)(const DrdThreadId tid, const Bool detached) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 490 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 491 | Segment* sg; |
| 492 | Segment* sg_prev; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 493 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 494 | tl_assert(DRD_(IsValidDrdThreadId)(tid)); |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 495 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 496 | tl_assert(DRD_(g_threadinfo)[tid].synchr_nesting >= 0); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 497 | for (sg = DRD_(g_threadinfo)[tid].sg_last; sg; sg = sg_prev) { |
| 498 | sg_prev = sg->thr_prev; |
| 499 | sg->thr_next = NULL; |
| 500 | sg->thr_prev = NULL; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 501 | DRD_(sg_put)(sg); |
| 502 | } |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 503 | DRD_(g_threadinfo)[tid].valid = False; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 504 | DRD_(g_threadinfo)[tid].vg_thread_exists = False; |
| 505 | DRD_(g_threadinfo)[tid].posix_thread_exists = False; |
| bart | 9194e93 | 2011-02-09 11:55:12 +0000 | [diff] [blame] | 506 | if (detached) |
| 507 | DRD_(g_threadinfo)[tid].detached_posix_thread = False; |
| 508 | else |
| 509 | tl_assert(!DRD_(g_threadinfo)[tid].detached_posix_thread); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 510 | DRD_(g_threadinfo)[tid].sg_first = NULL; |
| 511 | DRD_(g_threadinfo)[tid].sg_last = NULL; |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 512 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 513 | tl_assert(!DRD_(IsValidDrdThreadId)(tid)); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 516 | /** |
| 517 | * Called after a thread performed its last memory access and before |
| 518 | * thread_delete() is called. Note: thread_delete() is only called for |
| 519 | * joinable threads, not for detached threads. |
| 520 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 521 | void DRD_(thread_finished)(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 522 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 523 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 524 | && tid != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 525 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 526 | DRD_(g_threadinfo)[tid].vg_thread_exists = False; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 527 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 528 | if (DRD_(g_threadinfo)[tid].detached_posix_thread) |
| 529 | { |
| 530 | /* |
| 531 | * Once a detached thread has finished, its stack is deallocated and |
| 532 | * should no longer be taken into account when computing the conflict set. |
| 533 | */ |
| 534 | DRD_(g_threadinfo)[tid].stack_min = DRD_(g_threadinfo)[tid].stack_max; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 535 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 536 | /* |
| 537 | * For a detached thread, calling pthread_exit() invalidates the |
| 538 | * POSIX thread ID associated with the detached thread. For joinable |
| 539 | * POSIX threads however, the POSIX thread ID remains live after the |
| 540 | * pthread_exit() call until pthread_join() is called. |
| 541 | */ |
| 542 | DRD_(g_threadinfo)[tid].posix_thread_exists = False; |
| 543 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| bart | 5c7e6b6 | 2011-02-03 17:47:50 +0000 | [diff] [blame] | 546 | /** Called just after fork() in the child process. */ |
| 547 | void DRD_(drd_thread_atfork_child)(const DrdThreadId tid) |
| 548 | { |
| 549 | unsigned i; |
| 550 | |
| 551 | for (i = 1; i < DRD_N_THREADS; i++) |
| 552 | { |
| 553 | if (i == tid) |
| 554 | continue; |
| 555 | if (DRD_(IsValidDrdThreadId(i))) |
| bart | 9194e93 | 2011-02-09 11:55:12 +0000 | [diff] [blame] | 556 | DRD_(thread_delete)(i, True); |
| bart | 5c7e6b6 | 2011-02-03 17:47:50 +0000 | [diff] [blame] | 557 | tl_assert(!DRD_(IsValidDrdThreadId(i))); |
| bart | f7a5b3f | 2011-12-11 20:34:03 +0000 | [diff] [blame] | 558 | } |
| bart | 5c7e6b6 | 2011-02-03 17:47:50 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| bart | 9b2974a | 2008-09-27 12:35:31 +0000 | [diff] [blame] | 561 | /** Called just before pthread_cancel(). */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 562 | void DRD_(thread_pre_cancel)(const DrdThreadId tid) |
| bart | af0691b | 2008-09-27 12:26:50 +0000 | [diff] [blame] | 563 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 564 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 565 | && tid != DRD_INVALID_THREADID); |
| 566 | tl_assert(DRD_(g_threadinfo)[tid].pt_threadid != INVALID_POSIX_THREADID); |
| bart | af0691b | 2008-09-27 12:26:50 +0000 | [diff] [blame] | 567 | |
| bart | 0c0cd77 | 2011-03-03 19:59:20 +0000 | [diff] [blame] | 568 | if (DRD_(thread_get_trace_fork_join)()) |
| bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 569 | DRD_(trace_msg)("[%d] drd_thread_pre_cancel %d", |
| bart | b92ff0f | 2011-10-08 08:29:29 +0000 | [diff] [blame] | 570 | DRD_(g_drd_running_tid), tid); |
| bart | af0691b | 2008-09-27 12:26:50 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| bart | e7dff24 | 2009-04-23 17:12:39 +0000 | [diff] [blame] | 573 | /** |
| 574 | * Store the POSIX thread ID for the specified thread. |
| 575 | * |
| 576 | * @note This function can be called two times for the same thread -- see also |
| 577 | * the comment block preceding the pthread_create() wrapper in |
| 578 | * drd_pthread_intercepts.c. |
| 579 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 580 | void DRD_(thread_set_pthreadid)(const DrdThreadId tid, const PThreadId ptid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 581 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 582 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 583 | && tid != DRD_INVALID_THREADID); |
| bart | e7dff24 | 2009-04-23 17:12:39 +0000 | [diff] [blame] | 584 | tl_assert(DRD_(g_threadinfo)[tid].pt_threadid == INVALID_POSIX_THREADID |
| 585 | || DRD_(g_threadinfo)[tid].pt_threadid == ptid); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 586 | tl_assert(ptid != INVALID_POSIX_THREADID); |
| 587 | DRD_(g_threadinfo)[tid].posix_thread_exists = True; |
| 588 | DRD_(g_threadinfo)[tid].pt_threadid = ptid; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 591 | /** Returns true for joinable threads and false for detached threads. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 592 | Bool DRD_(thread_get_joinable)(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 593 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 594 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 595 | && tid != DRD_INVALID_THREADID); |
| 596 | return ! DRD_(g_threadinfo)[tid].detached_posix_thread; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 599 | /** Store the thread mode: joinable or detached. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 600 | void DRD_(thread_set_joinable)(const DrdThreadId tid, const Bool joinable) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 601 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 602 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 603 | && tid != DRD_INVALID_THREADID); |
| 604 | tl_assert(!! joinable == joinable); |
| 605 | tl_assert(DRD_(g_threadinfo)[tid].pt_threadid != INVALID_POSIX_THREADID); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 606 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 607 | DRD_(g_threadinfo)[tid].detached_posix_thread = ! joinable; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 610 | /** Tells DRD that the calling thread is about to enter pthread_create(). */ |
| 611 | void DRD_(thread_entering_pthread_create)(const DrdThreadId tid) |
| 612 | { |
| 613 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 614 | && tid != DRD_INVALID_THREADID); |
| 615 | tl_assert(DRD_(g_threadinfo)[tid].pt_threadid != INVALID_POSIX_THREADID); |
| 616 | tl_assert(DRD_(g_threadinfo)[tid].pthread_create_nesting_level >= 0); |
| 617 | |
| 618 | DRD_(g_threadinfo)[tid].pthread_create_nesting_level++; |
| 619 | } |
| 620 | |
| 621 | /** Tells DRD that the calling thread has left pthread_create(). */ |
| 622 | void DRD_(thread_left_pthread_create)(const DrdThreadId tid) |
| 623 | { |
| 624 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 625 | && tid != DRD_INVALID_THREADID); |
| 626 | tl_assert(DRD_(g_threadinfo)[tid].pt_threadid != INVALID_POSIX_THREADID); |
| 627 | tl_assert(DRD_(g_threadinfo)[tid].pthread_create_nesting_level > 0); |
| 628 | |
| 629 | DRD_(g_threadinfo)[tid].pthread_create_nesting_level--; |
| 630 | } |
| 631 | |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 632 | /** Obtain the thread number and the user-assigned thread name. */ |
| 633 | const char* DRD_(thread_get_name)(const DrdThreadId tid) |
| 634 | { |
| 635 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 636 | && tid != DRD_INVALID_THREADID); |
| 637 | |
| 638 | return DRD_(g_threadinfo)[tid].name; |
| 639 | } |
| 640 | |
| 641 | /** Set the name of the specified thread. */ |
| 642 | void DRD_(thread_set_name)(const DrdThreadId tid, const char* const name) |
| 643 | { |
| 644 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 645 | && tid != DRD_INVALID_THREADID); |
| bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 646 | |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 647 | if (name == NULL || name[0] == 0) |
| 648 | VG_(snprintf)(DRD_(g_threadinfo)[tid].name, |
| 649 | sizeof(DRD_(g_threadinfo)[tid].name), |
| 650 | "Thread %d", |
| 651 | tid); |
| 652 | else |
| 653 | VG_(snprintf)(DRD_(g_threadinfo)[tid].name, |
| 654 | sizeof(DRD_(g_threadinfo)[tid].name), |
| 655 | "Thread %d (%s)", |
| 656 | tid, name); |
| 657 | DRD_(g_threadinfo)[tid].name[sizeof(DRD_(g_threadinfo)[tid].name) - 1] = 0; |
| 658 | } |
| 659 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 660 | /** |
| 661 | * Update s_vg_running_tid, DRD_(g_drd_running_tid) and recalculate the |
| 662 | * conflict set. |
| 663 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 664 | void DRD_(thread_set_vg_running_tid)(const ThreadId vg_tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 665 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 666 | tl_assert(vg_tid != VG_INVALID_THREADID); |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 667 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 668 | if (vg_tid != s_vg_running_tid) |
| 669 | { |
| 670 | DRD_(thread_set_running_tid)(vg_tid, |
| 671 | DRD_(VgThreadIdToDrdThreadId)(vg_tid)); |
| 672 | } |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 673 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 674 | tl_assert(s_vg_running_tid != VG_INVALID_THREADID); |
| 675 | tl_assert(DRD_(g_drd_running_tid) != DRD_INVALID_THREADID); |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 678 | /** |
| 679 | * Update s_vg_running_tid, DRD_(g_drd_running_tid) and recalculate the |
| 680 | * conflict set. |
| 681 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 682 | void DRD_(thread_set_running_tid)(const ThreadId vg_tid, |
| 683 | const DrdThreadId drd_tid) |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 684 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 685 | tl_assert(vg_tid != VG_INVALID_THREADID); |
| 686 | tl_assert(drd_tid != DRD_INVALID_THREADID); |
| bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 687 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 688 | if (vg_tid != s_vg_running_tid) |
| 689 | { |
| 690 | if (s_trace_context_switches |
| 691 | && DRD_(g_drd_running_tid) != DRD_INVALID_THREADID) |
| 692 | { |
| 693 | VG_(message)(Vg_DebugMsg, |
| bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 694 | "Context switch from thread %d to thread %d;" |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 695 | " segments: %llu\n", |
| bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 696 | DRD_(g_drd_running_tid), drd_tid, |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 697 | DRD_(sg_get_segments_alive_count)()); |
| 698 | } |
| 699 | s_vg_running_tid = vg_tid; |
| 700 | DRD_(g_drd_running_tid) = drd_tid; |
| 701 | thread_compute_conflict_set(&DRD_(g_conflict_set), drd_tid); |
| 702 | s_context_switch_count++; |
| 703 | } |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 704 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 705 | tl_assert(s_vg_running_tid != VG_INVALID_THREADID); |
| 706 | tl_assert(DRD_(g_drd_running_tid) != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 709 | /** |
| 710 | * Increase the synchronization nesting counter. Must be called before the |
| 711 | * client calls a synchronization function. |
| 712 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 713 | int DRD_(thread_enter_synchr)(const DrdThreadId tid) |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 714 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 715 | tl_assert(DRD_(IsValidDrdThreadId)(tid)); |
| 716 | return DRD_(g_threadinfo)[tid].synchr_nesting++; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 719 | /** |
| 720 | * Decrease the synchronization nesting counter. Must be called after the |
| 721 | * client left a synchronization function. |
| 722 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 723 | int DRD_(thread_leave_synchr)(const DrdThreadId tid) |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 724 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 725 | tl_assert(DRD_(IsValidDrdThreadId)(tid)); |
| 726 | tl_assert(DRD_(g_threadinfo)[tid].synchr_nesting >= 1); |
| 727 | return --DRD_(g_threadinfo)[tid].synchr_nesting; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 730 | /** Returns the synchronization nesting counter. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 731 | int DRD_(thread_get_synchr_nesting_count)(const DrdThreadId tid) |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 732 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 733 | tl_assert(DRD_(IsValidDrdThreadId)(tid)); |
| 734 | return DRD_(g_threadinfo)[tid].synchr_nesting; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 737 | /** Append a new segment at the end of the segment list. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 738 | static |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 739 | void thread_append_segment(const DrdThreadId tid, Segment* const sg) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 740 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 741 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 742 | && tid != DRD_INVALID_THREADID); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 743 | |
| 744 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 745 | tl_assert(DRD_(sane_ThreadInfo)(&DRD_(g_threadinfo)[tid])); |
| 746 | #endif |
| 747 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 748 | // add at tail |
| 749 | sg->thr_prev = DRD_(g_threadinfo)[tid].sg_last; |
| 750 | sg->thr_next = NULL; |
| 751 | if (DRD_(g_threadinfo)[tid].sg_last) |
| 752 | DRD_(g_threadinfo)[tid].sg_last->thr_next = sg; |
| 753 | DRD_(g_threadinfo)[tid].sg_last = sg; |
| 754 | if (DRD_(g_threadinfo)[tid].sg_first == NULL) |
| 755 | DRD_(g_threadinfo)[tid].sg_first = sg; |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 756 | |
| 757 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 758 | tl_assert(DRD_(sane_ThreadInfo)(&DRD_(g_threadinfo)[tid])); |
| 759 | #endif |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 762 | /** |
| 763 | * Remove a segment from the segment list of thread threadid, and free the |
| 764 | * associated memory. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 765 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 766 | static |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 767 | void thread_discard_segment(const DrdThreadId tid, Segment* const sg) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 768 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 769 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 770 | && tid != DRD_INVALID_THREADID); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 771 | |
| 772 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 773 | tl_assert(DRD_(sane_ThreadInfo)(&DRD_(g_threadinfo)[tid])); |
| 774 | #endif |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 775 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 776 | if (sg->thr_prev) |
| 777 | sg->thr_prev->thr_next = sg->thr_next; |
| 778 | if (sg->thr_next) |
| 779 | sg->thr_next->thr_prev = sg->thr_prev; |
| 780 | if (sg == DRD_(g_threadinfo)[tid].sg_first) |
| 781 | DRD_(g_threadinfo)[tid].sg_first = sg->thr_next; |
| 782 | if (sg == DRD_(g_threadinfo)[tid].sg_last) |
| 783 | DRD_(g_threadinfo)[tid].sg_last = sg->thr_prev; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 784 | DRD_(sg_put)(sg); |
| bart | 3f74967 | 2008-03-22 09:49:40 +0000 | [diff] [blame] | 785 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 786 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 787 | tl_assert(DRD_(sane_ThreadInfo)(&DRD_(g_threadinfo)[tid])); |
| 788 | #endif |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 791 | /** |
| 792 | * Returns a pointer to the vector clock of the most recent segment associated |
| 793 | * with thread 'tid'. |
| 794 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 795 | VectorClock* DRD_(thread_get_vc)(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 796 | { |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 797 | Segment* latest_sg; |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 798 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 799 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 800 | && tid != DRD_INVALID_THREADID); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 801 | latest_sg = DRD_(g_threadinfo)[tid].sg_last; |
| 802 | tl_assert(latest_sg); |
| 803 | return &latest_sg->vc; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 806 | /** |
| 807 | * Return the latest segment of thread 'tid' and increment its reference count. |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 808 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 809 | void DRD_(thread_get_latest_segment)(Segment** sg, const DrdThreadId tid) |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 810 | { |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 811 | Segment* latest_sg; |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 812 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 813 | tl_assert(sg); |
| 814 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 815 | && tid != DRD_INVALID_THREADID); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 816 | latest_sg = DRD_(g_threadinfo)[tid].sg_last; |
| 817 | tl_assert(latest_sg); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 818 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 819 | DRD_(sg_put)(*sg); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 820 | *sg = DRD_(sg_get)(latest_sg); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 823 | /** |
| 824 | * Compute the minimum of all latest vector clocks of all threads |
| 825 | * (Michiel Ronsse calls this "clock snooping" in his papers about DIOTA). |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 826 | * |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 827 | * @param vc pointer to a vectorclock, holds result upon return. |
| 828 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 829 | static void DRD_(thread_compute_minimum_vc)(VectorClock* vc) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 830 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 831 | unsigned i; |
| 832 | Bool first; |
| 833 | Segment* latest_sg; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 834 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 835 | first = True; |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 836 | for (i = 0; i < DRD_N_THREADS; i++) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 837 | { |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 838 | latest_sg = DRD_(g_threadinfo)[i].sg_last; |
| 839 | if (latest_sg) { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 840 | if (first) |
| 841 | DRD_(vc_assign)(vc, &latest_sg->vc); |
| 842 | else |
| 843 | DRD_(vc_min)(vc, &latest_sg->vc); |
| 844 | first = False; |
| 845 | } |
| 846 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 849 | /** |
| 850 | * Compute the maximum of all latest vector clocks of all threads. |
| 851 | * |
| 852 | * @param vc pointer to a vectorclock, holds result upon return. |
| 853 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 854 | static void DRD_(thread_compute_maximum_vc)(VectorClock* vc) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 855 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 856 | unsigned i; |
| 857 | Bool first; |
| 858 | Segment* latest_sg; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 859 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 860 | first = True; |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 861 | for (i = 0; i < DRD_N_THREADS; i++) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 862 | { |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 863 | latest_sg = DRD_(g_threadinfo)[i].sg_last; |
| 864 | if (latest_sg) { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 865 | if (first) |
| 866 | DRD_(vc_assign)(vc, &latest_sg->vc); |
| 867 | else |
| 868 | DRD_(vc_combine)(vc, &latest_sg->vc); |
| 869 | first = False; |
| 870 | } |
| 871 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /** |
| bart | 5bd9f2d | 2008-03-03 20:31:58 +0000 | [diff] [blame] | 875 | * Discard all segments that have a defined order against the latest vector |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 876 | * clock of all threads -- these segments can no longer be involved in a |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 877 | * data race. |
| 878 | */ |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 879 | static void thread_discard_ordered_segments(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 880 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 881 | unsigned i; |
| 882 | VectorClock thread_vc_min; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 883 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 884 | s_discard_ordered_segments_count++; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 885 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 886 | DRD_(vc_init)(&thread_vc_min, 0, 0); |
| 887 | DRD_(thread_compute_minimum_vc)(&thread_vc_min); |
| 888 | if (DRD_(sg_get_trace)()) |
| 889 | { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 890 | char *vc_min, *vc_max; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 891 | VectorClock thread_vc_max; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 892 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 893 | DRD_(vc_init)(&thread_vc_max, 0, 0); |
| 894 | DRD_(thread_compute_maximum_vc)(&thread_vc_max); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 895 | vc_min = DRD_(vc_aprint)(&thread_vc_min); |
| 896 | vc_max = DRD_(vc_aprint)(&thread_vc_max); |
| 897 | VG_(message)(Vg_DebugMsg, |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 898 | "Discarding ordered segments -- min vc is %s, max vc is %s\n", |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 899 | vc_min, vc_max); |
| 900 | VG_(free)(vc_min); |
| 901 | VG_(free)(vc_max); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 902 | DRD_(vc_cleanup)(&thread_vc_max); |
| 903 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 904 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 905 | for (i = 0; i < DRD_N_THREADS; i++) { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 906 | Segment* sg; |
| 907 | Segment* sg_next; |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 908 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 909 | for (sg = DRD_(g_threadinfo)[i].sg_first; |
| 910 | sg && (sg_next = sg->thr_next) |
| 911 | && DRD_(vc_lte)(&sg->vc, &thread_vc_min); |
| 912 | sg = sg_next) |
| 913 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 914 | thread_discard_segment(i, sg); |
| 915 | } |
| 916 | } |
| 917 | DRD_(vc_cleanup)(&thread_vc_min); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 920 | /** |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 921 | * An implementation of the property 'equiv(sg1, sg2)' as defined in the paper |
| 922 | * by Mark Christiaens e.a. The property equiv(sg1, sg2) holds if and only if |
| 923 | * all segments in the set CS are ordered consistently against both sg1 and |
| 924 | * sg2. The set CS is defined as the set of segments that can immediately |
| 925 | * precede future segments via inter-thread synchronization operations. In |
| 926 | * DRD the set CS consists of the latest segment of each thread combined with |
| 927 | * all segments for which the reference count is strictly greater than one. |
| 928 | * The code below is an optimized version of the following: |
| 929 | * |
| 930 | * for (i = 0; i < DRD_N_THREADS; i++) |
| 931 | * { |
| 932 | * Segment* sg; |
| 933 | * |
| 934 | * for (sg = DRD_(g_threadinfo)[i].first; sg; sg = sg->next) |
| 935 | * { |
| 936 | * if (sg == DRD_(g_threadinfo)[i].last || DRD_(sg_get_refcnt)(sg) > 1) |
| 937 | * { |
| 938 | * if ( DRD_(vc_lte)(&sg1->vc, &sg->vc) |
| 939 | * != DRD_(vc_lte)(&sg2->vc, &sg->vc) |
| 940 | * || DRD_(vc_lte)(&sg->vc, &sg1->vc) |
| 941 | * != DRD_(vc_lte)(&sg->vc, &sg2->vc)) |
| 942 | * { |
| 943 | * return False; |
| 944 | * } |
| 945 | * } |
| 946 | * } |
| 947 | * } |
| 948 | */ |
| 949 | static Bool thread_consistent_segment_ordering(const DrdThreadId tid, |
| 950 | Segment* const sg1, |
| 951 | Segment* const sg2) |
| 952 | { |
| 953 | unsigned i; |
| 954 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 955 | tl_assert(sg1->thr_next); |
| 956 | tl_assert(sg2->thr_next); |
| 957 | tl_assert(sg1->thr_next == sg2); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 958 | tl_assert(DRD_(vc_lte)(&sg1->vc, &sg2->vc)); |
| 959 | |
| 960 | for (i = 0; i < DRD_N_THREADS; i++) |
| 961 | { |
| 962 | Segment* sg; |
| 963 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 964 | for (sg = DRD_(g_threadinfo)[i].sg_first; sg; sg = sg->thr_next) { |
| 965 | if (!sg->thr_next || DRD_(sg_get_refcnt)(sg) > 1) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 966 | if (DRD_(vc_lte)(&sg2->vc, &sg->vc)) |
| 967 | break; |
| 968 | if (DRD_(vc_lte)(&sg1->vc, &sg->vc)) |
| 969 | return False; |
| 970 | } |
| 971 | } |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 972 | for (sg = DRD_(g_threadinfo)[i].sg_last; sg; sg = sg->thr_prev) { |
| 973 | if (!sg->thr_next || DRD_(sg_get_refcnt)(sg) > 1) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 974 | if (DRD_(vc_lte)(&sg->vc, &sg1->vc)) |
| 975 | break; |
| 976 | if (DRD_(vc_lte)(&sg->vc, &sg2->vc)) |
| 977 | return False; |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | return True; |
| 982 | } |
| 983 | |
| 984 | /** |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 985 | * Merge all segments that may be merged without triggering false positives |
| 986 | * or discarding real data races. For the theoretical background of segment |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 987 | * merging, see also the following paper: Mark Christiaens, Michiel Ronsse |
| 988 | * and Koen De Bosschere. Bounding the number of segment histories during |
| 989 | * data race detection. Parallel Computing archive, Volume 28, Issue 9, |
| 990 | * pp 1221-1238, September 2002. This paper contains a proof that merging |
| 991 | * consecutive segments for which the property equiv(s1,s2) holds can be |
| 992 | * merged without reducing the accuracy of datarace detection. Furthermore |
| 993 | * it is also proven that the total number of all segments will never grow |
| 994 | * unbounded if all segments s1, s2 for which equiv(s1, s2) holds are merged |
| 995 | * every time a new segment is created. The property equiv(s1, s2) is defined |
| 996 | * as follows: equiv(s1, s2) <=> for all segments in the set CS, the vector |
| 997 | * clocks of segments s and s1 are ordered in the same way as those of segments |
| 998 | * s and s2. The set CS is defined as the set of existing segments s that have |
| 999 | * the potential to conflict with not yet created segments, either because the |
| 1000 | * segment s is the latest segment of a thread or because it can become the |
| 1001 | * immediate predecessor of a new segment due to a synchronization operation. |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 1002 | */ |
| 1003 | static void thread_merge_segments(void) |
| 1004 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1005 | unsigned i; |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 1006 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1007 | s_new_segments_since_last_merge = 0; |
| 1008 | |
| 1009 | for (i = 0; i < DRD_N_THREADS; i++) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1010 | { |
| 1011 | Segment* sg; |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 1012 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1013 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 1014 | tl_assert(DRD_(sane_ThreadInfo)(&DRD_(g_threadinfo)[i])); |
| 1015 | #endif |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 1016 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1017 | for (sg = DRD_(g_threadinfo)[i].sg_first; sg; sg = sg->thr_next) { |
| 1018 | if (DRD_(sg_get_refcnt)(sg) == 1 && sg->thr_next) { |
| 1019 | Segment* const sg_next = sg->thr_next; |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 1020 | if (DRD_(sg_get_refcnt)(sg_next) == 1 |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1021 | && sg_next->thr_next |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 1022 | && thread_consistent_segment_ordering(i, sg, sg_next)) |
| 1023 | { |
| 1024 | /* Merge sg and sg_next into sg. */ |
| 1025 | DRD_(sg_merge)(sg, sg_next); |
| 1026 | thread_discard_segment(i, sg_next); |
| 1027 | } |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1028 | } |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 1029 | } |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 1030 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1031 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 1032 | tl_assert(DRD_(sane_ThreadInfo)(&DRD_(g_threadinfo)[i])); |
| 1033 | #endif |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1034 | } |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 1037 | /** |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 1038 | * Create a new segment for the specified thread, and discard any segments |
| 1039 | * that cannot cause races anymore. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1040 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 1041 | void DRD_(thread_new_segment)(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1042 | { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1043 | Segment* last_sg; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1044 | Segment* new_sg; |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 1045 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1046 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1047 | && tid != DRD_INVALID_THREADID); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1048 | tl_assert(thread_conflict_set_up_to_date(DRD_(g_drd_running_tid))); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1049 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1050 | last_sg = DRD_(g_threadinfo)[tid].sg_last; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1051 | new_sg = DRD_(sg_new)(tid, tid); |
| 1052 | thread_append_segment(tid, new_sg); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1053 | if (tid == DRD_(g_drd_running_tid) && last_sg) |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1054 | { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1055 | DRD_(thread_update_conflict_set)(tid, &last_sg->vc); |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1056 | s_update_conflict_set_new_sg_count++; |
| 1057 | } |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 1058 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1059 | tl_assert(thread_conflict_set_up_to_date(DRD_(g_drd_running_tid))); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1060 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1061 | if (s_segment_merging |
| 1062 | && ++s_new_segments_since_last_merge >= s_segment_merge_interval) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1063 | { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1064 | thread_discard_ordered_segments(); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1065 | thread_merge_segments(); |
| 1066 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1069 | /** Call this function after thread 'joiner' joined thread 'joinee'. */ |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1070 | void DRD_(thread_combine_vc_join)(DrdThreadId joiner, DrdThreadId joinee) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1071 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1072 | tl_assert(joiner != joinee); |
| 1073 | tl_assert(0 <= (int)joiner && joiner < DRD_N_THREADS |
| 1074 | && joiner != DRD_INVALID_THREADID); |
| 1075 | tl_assert(0 <= (int)joinee && joinee < DRD_N_THREADS |
| 1076 | && joinee != DRD_INVALID_THREADID); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1077 | tl_assert(DRD_(g_threadinfo)[joiner].sg_first); |
| 1078 | tl_assert(DRD_(g_threadinfo)[joiner].sg_last); |
| 1079 | tl_assert(DRD_(g_threadinfo)[joinee].sg_first); |
| 1080 | tl_assert(DRD_(g_threadinfo)[joinee].sg_last); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1081 | |
| 1082 | if (DRD_(sg_get_trace)()) |
| 1083 | { |
| 1084 | char *str1, *str2; |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1085 | str1 = DRD_(vc_aprint)(DRD_(thread_get_vc)(joiner)); |
| 1086 | str2 = DRD_(vc_aprint)(DRD_(thread_get_vc)(joinee)); |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1087 | VG_(message)(Vg_DebugMsg, "Before join: joiner %s, joinee %s\n", |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1088 | str1, str2); |
| 1089 | VG_(free)(str1); |
| 1090 | VG_(free)(str2); |
| 1091 | } |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1092 | if (joiner == DRD_(g_drd_running_tid)) { |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1093 | VectorClock old_vc; |
| 1094 | |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1095 | DRD_(vc_copy)(&old_vc, DRD_(thread_get_vc)(joiner)); |
| 1096 | DRD_(vc_combine)(DRD_(thread_get_vc)(joiner), |
| 1097 | DRD_(thread_get_vc)(joinee)); |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1098 | DRD_(thread_update_conflict_set)(joiner, &old_vc); |
| 1099 | s_update_conflict_set_join_count++; |
| 1100 | DRD_(vc_cleanup)(&old_vc); |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1101 | } else { |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1102 | DRD_(vc_combine)(DRD_(thread_get_vc)(joiner), |
| 1103 | DRD_(thread_get_vc)(joinee)); |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | thread_discard_ordered_segments(); |
| 1107 | |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1108 | if (DRD_(sg_get_trace)()) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1109 | char* str; |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1110 | |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1111 | str = DRD_(vc_aprint)(DRD_(thread_get_vc)(joiner)); |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1112 | VG_(message)(Vg_DebugMsg, "After join: %s\n", str); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1113 | VG_(free)(str); |
| 1114 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 1117 | /** |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1118 | * Update the vector clock of the last segment of thread tid with the |
| bart | f6ec1fe | 2009-06-21 18:07:35 +0000 | [diff] [blame] | 1119 | * the vector clock of segment sg. |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1120 | */ |
| bart | f6ec1fe | 2009-06-21 18:07:35 +0000 | [diff] [blame] | 1121 | static void thread_combine_vc_sync(DrdThreadId tid, const Segment* sg) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1122 | { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1123 | const VectorClock* const vc = &sg->vc; |
| 1124 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1125 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1126 | && tid != DRD_INVALID_THREADID); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1127 | tl_assert(DRD_(g_threadinfo)[tid].sg_first); |
| 1128 | tl_assert(DRD_(g_threadinfo)[tid].sg_last); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1129 | tl_assert(sg); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1130 | tl_assert(vc); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1131 | |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1132 | if (tid != sg->tid) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1133 | VectorClock old_vc; |
| 1134 | |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1135 | DRD_(vc_copy)(&old_vc, DRD_(thread_get_vc)(tid)); |
| 1136 | DRD_(vc_combine)(DRD_(thread_get_vc)(tid), vc); |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1137 | if (DRD_(sg_get_trace)()) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1138 | char *str1, *str2; |
| 1139 | str1 = DRD_(vc_aprint)(&old_vc); |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1140 | str2 = DRD_(vc_aprint)(DRD_(thread_get_vc)(tid)); |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1141 | VG_(message)(Vg_DebugMsg, "thread %d: vc %s -> %s\n", tid, str1, str2); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1142 | VG_(free)(str1); |
| 1143 | VG_(free)(str2); |
| 1144 | } |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1145 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1146 | thread_discard_ordered_segments(); |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1147 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1148 | DRD_(thread_update_conflict_set)(tid, &old_vc); |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1149 | s_update_conflict_set_sync_count++; |
| 1150 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1151 | DRD_(vc_cleanup)(&old_vc); |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1152 | } else { |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1153 | tl_assert(DRD_(vc_lte)(vc, DRD_(thread_get_vc)(tid))); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1154 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 1157 | /** |
| bart | f6ec1fe | 2009-06-21 18:07:35 +0000 | [diff] [blame] | 1158 | * Create a new segment for thread tid and update the vector clock of the last |
| 1159 | * segment of this thread with the the vector clock of segment sg. Call this |
| 1160 | * function after thread tid had to wait because of thread synchronization |
| 1161 | * until the memory accesses in the segment sg finished. |
| 1162 | */ |
| 1163 | void DRD_(thread_new_segment_and_combine_vc)(DrdThreadId tid, const Segment* sg) |
| 1164 | { |
| 1165 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1166 | && tid != DRD_INVALID_THREADID); |
| 1167 | tl_assert(thread_conflict_set_up_to_date(DRD_(g_drd_running_tid))); |
| 1168 | tl_assert(sg); |
| 1169 | |
| 1170 | thread_append_segment(tid, DRD_(sg_new)(tid, tid)); |
| 1171 | |
| 1172 | thread_combine_vc_sync(tid, sg); |
| 1173 | |
| 1174 | if (s_segment_merging |
| 1175 | && ++s_new_segments_since_last_merge >= s_segment_merge_interval) |
| 1176 | { |
| 1177 | thread_discard_ordered_segments(); |
| 1178 | thread_merge_segments(); |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | /** |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 1183 | * Call this function whenever a thread is no longer using the memory |
| 1184 | * [ a1, a2 [, e.g. because of a call to free() or a stack pointer |
| 1185 | * increase. |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1186 | */ |
| bart | 23ef19d | 2011-03-12 12:34:44 +0000 | [diff] [blame] | 1187 | void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1188 | { |
| bart | 178b686 | 2011-07-29 12:30:43 +0000 | [diff] [blame] | 1189 | Segment* p; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1190 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1191 | for (p = DRD_(g_sg_list); p; p = p->g_next) |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 1192 | DRD_(bm_clear)(DRD_(sg_bm)(p), a1, a2); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1193 | |
| bart | 178b686 | 2011-07-29 12:30:43 +0000 | [diff] [blame] | 1194 | DRD_(bm_clear)(DRD_(g_conflict_set), a1, a2); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 1197 | /** Specify whether memory loads should be recorded. */ |
| 1198 | void DRD_(thread_set_record_loads)(const DrdThreadId tid, const Bool enabled) |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 1199 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1200 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1201 | && tid != DRD_INVALID_THREADID); |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 1202 | tl_assert(enabled == !! enabled); |
| 1203 | |
| 1204 | DRD_(g_threadinfo)[tid].is_recording_loads = enabled; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 1207 | /** Specify whether memory stores should be recorded. */ |
| 1208 | void DRD_(thread_set_record_stores)(const DrdThreadId tid, const Bool enabled) |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 1209 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1210 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1211 | && tid != DRD_INVALID_THREADID); |
| bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 1212 | tl_assert(enabled == !! enabled); |
| 1213 | |
| 1214 | DRD_(g_threadinfo)[tid].is_recording_stores = enabled; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1217 | /** |
| 1218 | * Print the segment information for all threads. |
| 1219 | * |
| 1220 | * This function is only used for debugging purposes. |
| 1221 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 1222 | void DRD_(thread_print_all)(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1223 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1224 | unsigned i; |
| 1225 | Segment* p; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1226 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1227 | for (i = 0; i < DRD_N_THREADS; i++) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1228 | { |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1229 | p = DRD_(g_threadinfo)[i].sg_first; |
| 1230 | if (p) { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1231 | VG_(printf)("**************\n" |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 1232 | "* thread %3d (%d/%d/%d/%d/0x%lx/%d) *\n" |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1233 | "**************\n", |
| 1234 | i, |
| bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 1235 | DRD_(g_threadinfo)[i].valid, |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1236 | DRD_(g_threadinfo)[i].vg_thread_exists, |
| 1237 | DRD_(g_threadinfo)[i].vg_threadid, |
| 1238 | DRD_(g_threadinfo)[i].posix_thread_exists, |
| 1239 | DRD_(g_threadinfo)[i].pt_threadid, |
| 1240 | DRD_(g_threadinfo)[i].detached_posix_thread); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1241 | for ( ; p; p = p->thr_next) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1242 | DRD_(sg_print)(p); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1243 | } |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1244 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1247 | /** Show a call stack involved in a data race. */ |
| bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 1248 | static void show_call_stack(const DrdThreadId tid, ExeContext* const callstack) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1249 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1250 | const ThreadId vg_tid = DRD_(DrdThreadIdToVgThreadId)(tid); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1251 | |
| bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 1252 | if (vg_tid != VG_INVALID_THREADID) { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1253 | if (callstack) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1254 | VG_(pp_ExeContext)(callstack); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1255 | else |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1256 | VG_(get_and_pp_StackTrace)(vg_tid, VG_(clo_backtrace_size)); |
| bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 1257 | } else { |
| 1258 | if (!VG_(clo_xml)) |
| 1259 | VG_(message)(Vg_UserMsg, |
| 1260 | " (thread finished, call stack no longer available)\n"); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1261 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1264 | /** Print information about the segments involved in a data race. */ |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1265 | static void |
| 1266 | thread_report_conflicting_segments_segment(const DrdThreadId tid, |
| 1267 | const Addr addr, |
| 1268 | const SizeT size, |
| 1269 | const BmAccessTypeT access_type, |
| 1270 | const Segment* const p) |
| 1271 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1272 | unsigned i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1273 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1274 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1275 | && tid != DRD_INVALID_THREADID); |
| 1276 | tl_assert(p); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1277 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1278 | for (i = 0; i < DRD_N_THREADS; i++) { |
| 1279 | if (i != tid) { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1280 | Segment* q; |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 1281 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1282 | for (q = DRD_(g_threadinfo)[i].sg_last; q; q = q->thr_prev) { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1283 | /* |
| bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 1284 | * Since q iterates over the segments of thread i in order of |
| 1285 | * decreasing vector clocks, if q->vc <= p->vc, then |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1286 | * q->next->vc <= p->vc will also hold. Hence, break out of the |
| 1287 | * loop once this condition is met. |
| 1288 | */ |
| 1289 | if (DRD_(vc_lte)(&q->vc, &p->vc)) |
| 1290 | break; |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1291 | if (!DRD_(vc_lte)(&p->vc, &q->vc)) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1292 | if (DRD_(bm_has_conflict_with)(DRD_(sg_bm)(q), addr, addr + size, |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1293 | access_type)) { |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 1294 | Segment* q_next; |
| 1295 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1296 | tl_assert(q->stacktrace); |
| bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 1297 | if (VG_(clo_xml)) |
| 1298 | VG_(printf_xml)(" <other_segment_start>\n"); |
| 1299 | else |
| 1300 | VG_(message)(Vg_UserMsg, |
| 1301 | "Other segment start (thread %d)\n", i); |
| 1302 | show_call_stack(i, q->stacktrace); |
| 1303 | if (VG_(clo_xml)) |
| 1304 | VG_(printf_xml)(" </other_segment_start>\n" |
| 1305 | " <other_segment_end>\n"); |
| 1306 | else |
| 1307 | VG_(message)(Vg_UserMsg, |
| 1308 | "Other segment end (thread %d)\n", i); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1309 | q_next = q->thr_next; |
| bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 1310 | show_call_stack(i, q_next ? q_next->stacktrace : 0); |
| bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 1311 | if (VG_(clo_xml)) |
| 1312 | VG_(printf_xml)(" </other_segment_end>\n"); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1316 | } |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1317 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1320 | /** Print information about all segments involved in a data race. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 1321 | void DRD_(thread_report_conflicting_segments)(const DrdThreadId tid, |
| 1322 | const Addr addr, |
| 1323 | const SizeT size, |
| 1324 | const BmAccessTypeT access_type) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1325 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1326 | Segment* p; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1327 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1328 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1329 | && tid != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1330 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1331 | for (p = DRD_(g_threadinfo)[tid].sg_first; p; p = p->thr_next) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1332 | if (DRD_(bm_has)(DRD_(sg_bm)(p), addr, addr + size, access_type)) |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1333 | thread_report_conflicting_segments_segment(tid, addr, size, |
| 1334 | access_type, p); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1335 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1336 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1337 | |
| bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 1338 | /** |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1339 | * Verify whether the conflict set for thread tid is up to date. Only perform |
| 1340 | * the check if the environment variable DRD_VERIFY_CONFLICT_SET has been set. |
| 1341 | */ |
| 1342 | static Bool thread_conflict_set_up_to_date(const DrdThreadId tid) |
| 1343 | { |
| 1344 | static int do_verify_conflict_set = -1; |
| 1345 | Bool result; |
| 1346 | struct bitmap* computed_conflict_set = 0; |
| 1347 | |
| 1348 | if (do_verify_conflict_set < 0) |
| 1349 | do_verify_conflict_set = VG_(getenv)("DRD_VERIFY_CONFLICT_SET") != 0; |
| 1350 | |
| 1351 | if (do_verify_conflict_set == 0) |
| 1352 | return True; |
| 1353 | |
| 1354 | thread_compute_conflict_set(&computed_conflict_set, tid); |
| 1355 | result = DRD_(bm_equal)(DRD_(g_conflict_set), computed_conflict_set); |
| 1356 | if (! result) |
| 1357 | { |
| 1358 | VG_(printf)("actual conflict set:\n"); |
| 1359 | DRD_(bm_print)(DRD_(g_conflict_set)); |
| 1360 | VG_(printf)("\n"); |
| 1361 | VG_(printf)("computed conflict set:\n"); |
| 1362 | DRD_(bm_print)(computed_conflict_set); |
| 1363 | VG_(printf)("\n"); |
| 1364 | } |
| 1365 | DRD_(bm_delete)(computed_conflict_set); |
| 1366 | return result; |
| 1367 | } |
| 1368 | |
| 1369 | /** |
| 1370 | * Compute the conflict set: a bitmap that represents the union of all memory |
| 1371 | * accesses of all segments that are unordered to the current segment of the |
| 1372 | * thread tid. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1373 | */ |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1374 | static void thread_compute_conflict_set(struct bitmap** conflict_set, |
| 1375 | const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1376 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1377 | Segment* p; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1378 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1379 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1380 | && tid != DRD_INVALID_THREADID); |
| 1381 | tl_assert(tid == DRD_(g_drd_running_tid)); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1382 | |
| bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 1383 | s_compute_conflict_set_count++; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1384 | s_conflict_set_bitmap_creation_count |
| 1385 | -= DRD_(bm_get_bitmap_creation_count)(); |
| 1386 | s_conflict_set_bitmap2_creation_count |
| 1387 | -= DRD_(bm_get_bitmap2_creation_count)(); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1388 | |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1389 | if (*conflict_set) { |
| bart | f6ec1fe | 2009-06-21 18:07:35 +0000 | [diff] [blame] | 1390 | DRD_(bm_cleanup)(*conflict_set); |
| 1391 | DRD_(bm_init)(*conflict_set); |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1392 | } else { |
| bart | f6ec1fe | 2009-06-21 18:07:35 +0000 | [diff] [blame] | 1393 | *conflict_set = DRD_(bm_new)(); |
| 1394 | } |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1395 | |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1396 | if (s_trace_conflict_set) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1397 | char* str; |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1398 | |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1399 | str = DRD_(vc_aprint)(DRD_(thread_get_vc)(tid)); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1400 | VG_(message)(Vg_DebugMsg, |
| bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 1401 | "computing conflict set for thread %d with vc %s\n", |
| 1402 | tid, str); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1403 | VG_(free)(str); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1404 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1405 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1406 | p = DRD_(g_threadinfo)[tid].sg_last; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1407 | { |
| 1408 | unsigned j; |
| 1409 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1410 | if (s_trace_conflict_set) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1411 | char* vc; |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1412 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1413 | vc = DRD_(vc_aprint)(&p->vc); |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1414 | VG_(message)(Vg_DebugMsg, "conflict set: thread [%d] at vc %s\n", |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1415 | tid, vc); |
| 1416 | VG_(free)(vc); |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1417 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1418 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1419 | for (j = 0; j < DRD_N_THREADS; j++) { |
| 1420 | if (j != tid && DRD_(IsValidDrdThreadId)(j)) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1421 | Segment* q; |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1422 | |
| 1423 | for (q = DRD_(g_threadinfo)[j].sg_last; q; q = q->thr_prev) { |
| 1424 | if (!DRD_(vc_lte)(&q->vc, &p->vc) |
| 1425 | && !DRD_(vc_lte)(&p->vc, &q->vc)) { |
| 1426 | if (s_trace_conflict_set) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1427 | char* str; |
| 1428 | |
| 1429 | str = DRD_(vc_aprint)(&q->vc); |
| 1430 | VG_(message)(Vg_DebugMsg, |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1431 | "conflict set: [%d] merging segment %s\n", |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1432 | j, str); |
| 1433 | VG_(free)(str); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1434 | } |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1435 | DRD_(bm_merge2)(*conflict_set, DRD_(sg_bm)(q)); |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1436 | } else { |
| 1437 | if (s_trace_conflict_set) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1438 | char* str; |
| 1439 | |
| 1440 | str = DRD_(vc_aprint)(&q->vc); |
| 1441 | VG_(message)(Vg_DebugMsg, |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1442 | "conflict set: [%d] ignoring segment %s\n", |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1443 | j, str); |
| 1444 | VG_(free)(str); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1451 | |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1452 | s_conflict_set_bitmap_creation_count |
| 1453 | += DRD_(bm_get_bitmap_creation_count)(); |
| 1454 | s_conflict_set_bitmap2_creation_count |
| 1455 | += DRD_(bm_get_bitmap2_creation_count)(); |
| 1456 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1457 | if (s_trace_conflict_set_bm) { |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1458 | VG_(message)(Vg_DebugMsg, "[%d] new conflict set:\n", tid); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1459 | DRD_(bm_print)(*conflict_set); |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1460 | VG_(message)(Vg_DebugMsg, "[%d] end of new conflict set.\n", tid); |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1461 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1464 | /** |
| 1465 | * Update the conflict set after the vector clock of thread tid has been |
| 1466 | * updated from old_vc to its current value, either because a new segment has |
| 1467 | * been created or because of a synchronization operation. |
| 1468 | */ |
| 1469 | void DRD_(thread_update_conflict_set)(const DrdThreadId tid, |
| 1470 | const VectorClock* const old_vc) |
| 1471 | { |
| 1472 | const VectorClock* new_vc; |
| 1473 | Segment* p; |
| 1474 | unsigned j; |
| 1475 | |
| 1476 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1477 | && tid != DRD_INVALID_THREADID); |
| 1478 | tl_assert(old_vc); |
| 1479 | tl_assert(tid == DRD_(g_drd_running_tid)); |
| 1480 | tl_assert(DRD_(g_conflict_set)); |
| 1481 | |
| bart | ae37e6d | 2012-01-22 08:58:31 +0000 | [diff] [blame] | 1482 | if (s_trace_conflict_set) { |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1483 | char* str; |
| 1484 | |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1485 | str = DRD_(vc_aprint)(DRD_(thread_get_vc)(tid)); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1486 | VG_(message)(Vg_DebugMsg, |
| bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 1487 | "updating conflict set for thread %d with vc %s\n", |
| 1488 | tid, str); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1489 | VG_(free)(str); |
| 1490 | } |
| 1491 | |
| bart | c6bf184 | 2012-01-22 08:40:42 +0000 | [diff] [blame] | 1492 | new_vc = DRD_(thread_get_vc)(tid); |
| bart | f5fe4b6 | 2011-07-03 11:39:30 +0000 | [diff] [blame] | 1493 | tl_assert(DRD_(vc_lte)(old_vc, new_vc)); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1494 | |
| 1495 | DRD_(bm_unmark)(DRD_(g_conflict_set)); |
| 1496 | |
| 1497 | for (j = 0; j < DRD_N_THREADS; j++) |
| 1498 | { |
| 1499 | Segment* q; |
| 1500 | |
| 1501 | if (j == tid || ! DRD_(IsValidDrdThreadId)(j)) |
| 1502 | continue; |
| 1503 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1504 | for (q = DRD_(g_threadinfo)[j].sg_last; |
| 1505 | q && !DRD_(vc_lte)(&q->vc, new_vc); |
| 1506 | q = q->thr_prev) { |
| 1507 | const Bool included_in_old_conflict_set |
| 1508 | = !DRD_(vc_lte)(old_vc, &q->vc); |
| 1509 | const Bool included_in_new_conflict_set |
| 1510 | = !DRD_(vc_lte)(new_vc, &q->vc); |
| bart | 178b686 | 2011-07-29 12:30:43 +0000 | [diff] [blame] | 1511 | |
| 1512 | if (UNLIKELY(s_trace_conflict_set)) { |
| 1513 | char* str; |
| 1514 | |
| 1515 | str = DRD_(vc_aprint)(&q->vc); |
| 1516 | VG_(message)(Vg_DebugMsg, |
| 1517 | "conflict set: [%d] %s segment %s\n", j, |
| 1518 | included_in_old_conflict_set |
| 1519 | != included_in_new_conflict_set |
| 1520 | ? "merging" : "ignoring", str); |
| 1521 | VG_(free)(str); |
| 1522 | } |
| 1523 | if (included_in_old_conflict_set != included_in_new_conflict_set) |
| 1524 | DRD_(bm_mark)(DRD_(g_conflict_set), DRD_(sg_bm)(q)); |
| 1525 | } |
| 1526 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1527 | for ( ; q && !DRD_(vc_lte)(&q->vc, old_vc); q = q->thr_prev) { |
| 1528 | const Bool included_in_old_conflict_set |
| 1529 | = !DRD_(vc_lte)(old_vc, &q->vc); |
| 1530 | const Bool included_in_new_conflict_set |
| 1531 | = !DRD_(vc_lte)(&q->vc, new_vc) |
| 1532 | && !DRD_(vc_lte)(new_vc, &q->vc); |
| bart | 178b686 | 2011-07-29 12:30:43 +0000 | [diff] [blame] | 1533 | |
| 1534 | if (UNLIKELY(s_trace_conflict_set)) { |
| bart | ac5b95b | 2011-07-03 11:43:45 +0000 | [diff] [blame] | 1535 | char* str; |
| 1536 | |
| 1537 | str = DRD_(vc_aprint)(&q->vc); |
| 1538 | VG_(message)(Vg_DebugMsg, |
| 1539 | "conflict set: [%d] %s segment %s\n", j, |
| 1540 | included_in_old_conflict_set |
| 1541 | != included_in_new_conflict_set |
| 1542 | ? "merging" : "ignoring", str); |
| 1543 | VG_(free)(str); |
| 1544 | } |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1545 | if (included_in_old_conflict_set != included_in_new_conflict_set) |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1546 | DRD_(bm_mark)(DRD_(g_conflict_set), DRD_(sg_bm)(q)); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | DRD_(bm_clear_marked)(DRD_(g_conflict_set)); |
| 1551 | |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1552 | p = DRD_(g_threadinfo)[tid].sg_last; |
| 1553 | for (j = 0; j < DRD_N_THREADS; j++) { |
| 1554 | if (j != tid && DRD_(IsValidDrdThreadId)(j)) { |
| bart | 4b3fdb2 | 2011-07-03 11:40:49 +0000 | [diff] [blame] | 1555 | Segment* q; |
| bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 1556 | for (q = DRD_(g_threadinfo)[j].sg_last; |
| 1557 | q && !DRD_(vc_lte)(&q->vc, &p->vc); |
| 1558 | q = q->thr_prev) { |
| bart | 178b686 | 2011-07-29 12:30:43 +0000 | [diff] [blame] | 1559 | if (!DRD_(vc_lte)(&p->vc, &q->vc)) |
| bart | 4b3fdb2 | 2011-07-03 11:40:49 +0000 | [diff] [blame] | 1560 | DRD_(bm_merge2_marked)(DRD_(g_conflict_set), DRD_(sg_bm)(q)); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | DRD_(bm_remove_cleared_marked)(DRD_(g_conflict_set)); |
| 1566 | |
| bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 1567 | s_update_conflict_set_count++; |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1568 | |
| 1569 | if (s_trace_conflict_set_bm) |
| 1570 | { |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1571 | VG_(message)(Vg_DebugMsg, "[%d] updated conflict set:\n", tid); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1572 | DRD_(bm_print)(DRD_(g_conflict_set)); |
| sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 1573 | VG_(message)(Vg_DebugMsg, "[%d] end of updated conflict set.\n", tid); |
| bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | tl_assert(thread_conflict_set_up_to_date(DRD_(g_drd_running_tid))); |
| 1577 | } |
| 1578 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1579 | /** Report the number of context switches performed. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 1580 | ULong DRD_(thread_get_context_switch_count)(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1581 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1582 | return s_context_switch_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1585 | /** Report the number of ordered segments that have been discarded. */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 1586 | ULong DRD_(thread_get_discard_ordered_segments_count)(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1587 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1588 | return s_discard_ordered_segments_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 1591 | /** Return how many times the conflict set has been updated entirely. */ |
| 1592 | ULong DRD_(thread_get_compute_conflict_set_count)() |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1593 | { |
| bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 1594 | return s_compute_conflict_set_count; |
| 1595 | } |
| 1596 | |
| 1597 | /** Return how many times the conflict set has been updated partially. */ |
| 1598 | ULong DRD_(thread_get_update_conflict_set_count)(void) |
| 1599 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1600 | return s_update_conflict_set_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1603 | /** |
| bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 1604 | * Return how many times the conflict set has been updated partially |
| 1605 | * because a new segment has been created. |
| 1606 | */ |
| 1607 | ULong DRD_(thread_get_update_conflict_set_new_sg_count)(void) |
| 1608 | { |
| 1609 | return s_update_conflict_set_new_sg_count; |
| 1610 | } |
| 1611 | |
| 1612 | /** |
| 1613 | * Return how many times the conflict set has been updated partially |
| 1614 | * because of combining vector clocks due to synchronization operations |
| 1615 | * other than reader/writer lock or barrier operations. |
| 1616 | */ |
| 1617 | ULong DRD_(thread_get_update_conflict_set_sync_count)(void) |
| 1618 | { |
| 1619 | return s_update_conflict_set_sync_count; |
| 1620 | } |
| 1621 | |
| 1622 | /** |
| 1623 | * Return how many times the conflict set has been updated partially |
| 1624 | * because of thread joins. |
| 1625 | */ |
| 1626 | ULong DRD_(thread_get_update_conflict_set_join_count)(void) |
| 1627 | { |
| 1628 | return s_update_conflict_set_join_count; |
| 1629 | } |
| 1630 | |
| 1631 | /** |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1632 | * Return the number of first-level bitmaps that have been created during |
| 1633 | * conflict set updates. |
| 1634 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 1635 | ULong DRD_(thread_get_conflict_set_bitmap_creation_count)(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1636 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1637 | return s_conflict_set_bitmap_creation_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 1640 | /** |
| 1641 | * Return the number of second-level bitmaps that have been created during |
| 1642 | * conflict set updates. |
| 1643 | */ |
| bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 1644 | ULong DRD_(thread_get_conflict_set_bitmap2_creation_count)(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1645 | { |
| bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1646 | return s_conflict_set_bitmap2_creation_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1647 | } |