| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
| sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2008 Bart Van Assche |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | bart.vanassche@gmail.com |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307, USA. |
| 21 | |
| 22 | The GNU General Public License is contained in the file COPYING. |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include "drd_error.h" |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 27 | #include "drd_barrier.h" |
| 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 |
| 36 | #include "pub_tool_errormgr.h" // VG_(unique_error)() |
| 37 | #include "pub_tool_libcassert.h" // tl_assert() |
| 38 | #include "pub_tool_libcbase.h" // VG_(strlen)() |
| 39 | #include "pub_tool_libcprint.h" // VG_(printf)() |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 40 | #include "pub_tool_libcproc.h" // VG_(getenv)() |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 41 | #include "pub_tool_machine.h" |
| 42 | #include "pub_tool_mallocfree.h" // VG_(malloc)(), VG_(free)() |
| sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 43 | #include "pub_tool_options.h" // VG_(clo_backtrace_size) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 44 | #include "pub_tool_threadstate.h" // VG_(get_pthread_id)() |
| 45 | |
| bart | 32ba208 | 2008-06-05 08:53:42 +0000 | [diff] [blame] | 46 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 47 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 48 | // Local functions. |
| 49 | |
| 50 | static void thread_append_segment(const DrdThreadId tid, |
| 51 | Segment* const sg); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 52 | static void thread_discard_segment(const DrdThreadId tid, Segment* const sg); |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 53 | static Bool thread_conflict_set_up_to_date(const DrdThreadId tid); |
| 54 | static void thread_compute_conflict_set(struct bitmap** conflict_set, |
| 55 | const DrdThreadId tid); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | // Local variables. |
| 59 | |
| 60 | static ULong s_context_switch_count; |
| 61 | static ULong s_discard_ordered_segments_count; |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 62 | static ULong s_update_conflict_set_count; |
| 63 | static ULong s_conflict_set_new_segment_count; |
| 64 | static ULong s_conflict_set_combine_vc_count; |
| 65 | static ULong s_conflict_set_bitmap_creation_count; |
| 66 | static ULong s_conflict_set_bitmap2_creation_count; |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 67 | static ThreadId s_vg_running_tid = VG_INVALID_THREADID; |
| bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 68 | DrdThreadId s_drd_running_tid = DRD_INVALID_THREADID; |
| 69 | ThreadInfo s_threadinfo[DRD_N_THREADS]; |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 70 | struct bitmap* s_conflict_set; |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 71 | static Bool s_trace_context_switches = False; |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 72 | static Bool s_trace_conflict_set = False; |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 73 | static Bool s_trace_fork_join = False; |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 74 | static Bool s_segment_merging = True; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 75 | |
| 76 | |
| 77 | // Function definitions. |
| 78 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 79 | void thread_trace_context_switches(const Bool t) |
| 80 | { |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 81 | tl_assert(t == False || t == True); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 82 | s_trace_context_switches = t; |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 85 | void thread_trace_conflict_set(const Bool t) |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 86 | { |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 87 | tl_assert(t == False || t == True); |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 88 | s_trace_conflict_set = t; |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 91 | Bool DRD_(thread_get_trace_fork_join)(void) |
| 92 | { |
| 93 | return s_trace_fork_join; |
| 94 | } |
| 95 | |
| 96 | void DRD_(thread_set_trace_fork_join)(const Bool t) |
| 97 | { |
| 98 | tl_assert(t == False || t == True); |
| 99 | s_trace_fork_join = t; |
| 100 | } |
| 101 | |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 102 | void thread_set_segment_merging(const Bool m) |
| 103 | { |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 104 | tl_assert(m == False || m == True); |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 105 | s_segment_merging = m; |
| 106 | } |
| 107 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 108 | /** |
| 109 | * Convert Valgrind's ThreadId into a DrdThreadId. Report failure if |
| 110 | * Valgrind's ThreadId does not yet exist. |
| 111 | **/ |
| 112 | DrdThreadId VgThreadIdToDrdThreadId(const ThreadId tid) |
| 113 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 114 | int i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 115 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 116 | if (tid == VG_INVALID_THREADID) |
| 117 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 118 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 119 | for (i = 1; i < DRD_N_THREADS; i++) |
| 120 | { |
| 121 | if (s_threadinfo[i].vg_thread_exists == True |
| 122 | && s_threadinfo[i].vg_threadid == tid) |
| 123 | { |
| 124 | return i; |
| 125 | } |
| 126 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 127 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 128 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static |
| 132 | DrdThreadId VgThreadIdToNewDrdThreadId(const ThreadId tid) |
| 133 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 134 | int i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 135 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 136 | tl_assert(VgThreadIdToDrdThreadId(tid) == DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 137 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 138 | for (i = 1; i < DRD_N_THREADS; i++) |
| 139 | { |
| 140 | if (s_threadinfo[i].vg_thread_exists == False |
| 141 | && s_threadinfo[i].posix_thread_exists == False |
| 142 | && s_threadinfo[i].detached_posix_thread == False) |
| 143 | { |
| 144 | s_threadinfo[i].vg_thread_exists = True; |
| 145 | s_threadinfo[i].vg_threadid = tid; |
| 146 | s_threadinfo[i].pt_threadid = INVALID_POSIX_THREADID; |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 147 | s_threadinfo[i].stack_min = 0; |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 148 | s_threadinfo[i].stack_min_min = 0; |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 149 | s_threadinfo[i].stack_startup = 0; |
| 150 | s_threadinfo[i].stack_max = 0; |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 151 | s_threadinfo[i].is_recording = True; |
| 152 | s_threadinfo[i].synchr_nesting = 0; |
| 153 | if (s_threadinfo[i].first != 0) |
| 154 | VG_(printf)("drd thread id = %d\n", i); |
| 155 | tl_assert(s_threadinfo[i].first == 0); |
| 156 | tl_assert(s_threadinfo[i].last == 0); |
| 157 | return i; |
| 158 | } |
| 159 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 160 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 161 | tl_assert(False); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 162 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 163 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | DrdThreadId PtThreadIdToDrdThreadId(const PThreadId tid) |
| 167 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 168 | int i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 169 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 170 | tl_assert(tid != INVALID_POSIX_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 171 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 172 | for (i = 1; i < DRD_N_THREADS; i++) |
| 173 | { |
| 174 | if (s_threadinfo[i].posix_thread_exists |
| 175 | && s_threadinfo[i].pt_threadid == tid) |
| 176 | { |
| 177 | return i; |
| 178 | } |
| 179 | } |
| 180 | return DRD_INVALID_THREADID; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | ThreadId DrdThreadIdToVgThreadId(const DrdThreadId tid) |
| 184 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 185 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 186 | && tid != DRD_INVALID_THREADID); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 187 | return (s_threadinfo[tid].vg_thread_exists |
| 188 | ? s_threadinfo[tid].vg_threadid |
| 189 | : VG_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| bart | 23d3a4e | 2008-04-05 12:53:00 +0000 | [diff] [blame] | 192 | #if 0 |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 193 | /** Sanity check of the doubly linked list of segments referenced by a |
| 194 | * ThreadInfo struct. |
| 195 | * @return True if sane, False if not. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 196 | */ |
| 197 | static Bool sane_ThreadInfo(const ThreadInfo* const ti) |
| 198 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 199 | Segment* p; |
| 200 | for (p = ti->first; p; p = p->next) { |
| 201 | if (p->next && p->next->prev != p) |
| 202 | return False; |
| 203 | if (p->next == 0 && p != ti->last) |
| 204 | return False; |
| 205 | } |
| 206 | for (p = ti->last; p; p = p->prev) { |
| 207 | if (p->prev && p->prev->next != p) |
| 208 | return False; |
| 209 | if (p->prev == 0 && p != ti->first) |
| 210 | return False; |
| 211 | } |
| 212 | return True; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 213 | } |
| bart | 23d3a4e | 2008-04-05 12:53:00 +0000 | [diff] [blame] | 214 | #endif |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 215 | |
| 216 | DrdThreadId thread_pre_create(const DrdThreadId creator, |
| 217 | const ThreadId vg_created) |
| 218 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 219 | DrdThreadId created; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 220 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 221 | tl_assert(VgThreadIdToDrdThreadId(vg_created) == DRD_INVALID_THREADID); |
| 222 | created = VgThreadIdToNewDrdThreadId(vg_created); |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 223 | tl_assert(0 <= (int)created && created < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 224 | && created != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 225 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 226 | tl_assert(s_threadinfo[created].first == 0); |
| 227 | tl_assert(s_threadinfo[created].last == 0); |
| 228 | thread_append_segment(created, sg_new(creator, created)); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 229 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 230 | return created; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 233 | |
| 234 | /* Process VG_USERREQ__POST_THREAD_JOIN. This client request is invoked just */ |
| 235 | /* after thread drd_joiner joined thread drd_joinee. */ |
| 236 | void DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee) |
| 237 | { |
| 238 | tl_assert(IsValidDrdThreadId(drd_joiner)); |
| 239 | tl_assert(IsValidDrdThreadId(drd_joinee)); |
| 240 | thread_new_segment(drd_joinee); |
| 241 | thread_combine_vc(drd_joiner, drd_joinee); |
| 242 | thread_new_segment(drd_joiner); |
| 243 | |
| 244 | if (s_trace_fork_join) |
| 245 | { |
| 246 | const ThreadId joiner = DrdThreadIdToVgThreadId(drd_joiner); |
| 247 | const ThreadId joinee = DrdThreadIdToVgThreadId(drd_joinee); |
| 248 | const unsigned msg_size = 256; |
| 249 | char* msg; |
| 250 | |
| 251 | msg = VG_(malloc)("drd.main.dptj.1", msg_size); |
| 252 | tl_assert(msg); |
| 253 | VG_(snprintf)(msg, msg_size, |
| 254 | "drd_post_thread_join joiner = %d/%d, joinee = %d/%d", |
| 255 | joiner, drd_joiner, joinee, drd_joinee); |
| 256 | if (joiner) |
| 257 | { |
| 258 | VG_(snprintf)(msg + VG_(strlen)(msg), msg_size - VG_(strlen)(msg), |
| 259 | ", new vc: "); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 260 | DRD_(vc_snprint)(msg + VG_(strlen)(msg), msg_size - VG_(strlen)(msg), |
| 261 | thread_get_vc(drd_joiner)); |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 262 | } |
| 263 | VG_(message)(Vg_DebugMsg, "%s", msg); |
| 264 | VG_(free)(msg); |
| 265 | } |
| 266 | |
| 267 | if (! DRD_(get_check_stack_accesses)()) |
| 268 | { |
| bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 269 | DRD_(finish_suppression)(thread_get_stack_max(drd_joinee) |
| 270 | - thread_get_stack_size(drd_joinee), |
| 271 | thread_get_stack_max(drd_joinee)); |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 272 | } |
| 273 | thread_delete(drd_joinee); |
| 274 | mutex_thread_delete(drd_joinee); |
| 275 | cond_thread_delete(drd_joinee); |
| 276 | semaphore_thread_delete(drd_joinee); |
| 277 | barrier_thread_delete(drd_joinee); |
| 278 | } |
| 279 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 280 | /** Allocate the first segment for a thread. Call this just after |
| 281 | * pthread_create(). |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 282 | */ |
| 283 | DrdThreadId thread_post_create(const ThreadId vg_created) |
| 284 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 285 | const DrdThreadId created = VgThreadIdToDrdThreadId(vg_created); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 286 | |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 287 | tl_assert(0 <= (int)created && created < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 288 | && created != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 289 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 290 | s_threadinfo[created].stack_max = VG_(thread_get_stack_max)(vg_created); |
| 291 | s_threadinfo[created].stack_startup = s_threadinfo[created].stack_max; |
| 292 | s_threadinfo[created].stack_min = s_threadinfo[created].stack_max; |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 293 | s_threadinfo[created].stack_min_min = s_threadinfo[created].stack_max; |
| 294 | s_threadinfo[created].stack_size = VG_(thread_get_stack_size)(vg_created); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 295 | tl_assert(s_threadinfo[created].stack_max != 0); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 296 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 297 | return created; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* NPTL hack: NPTL allocates the 'struct pthread' on top of the stack, */ |
| 301 | /* and accesses this data structure from multiple threads without locking. */ |
| 302 | /* Any conflicting accesses in the range stack_startup..stack_max will be */ |
| 303 | /* ignored. */ |
| 304 | void thread_set_stack_startup(const DrdThreadId tid, const Addr stack_startup) |
| 305 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 306 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 307 | && tid != DRD_INVALID_THREADID); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 308 | tl_assert(s_threadinfo[tid].stack_min <= stack_startup); |
| 309 | tl_assert(stack_startup <= s_threadinfo[tid].stack_max); |
| 310 | s_threadinfo[tid].stack_startup = stack_startup; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | Addr thread_get_stack_min(const DrdThreadId tid) |
| 314 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 315 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 316 | && tid != DRD_INVALID_THREADID); |
| 317 | return s_threadinfo[tid].stack_min; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 320 | Addr thread_get_stack_min_min(const DrdThreadId tid) |
| 321 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 322 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 323 | && tid != DRD_INVALID_THREADID); |
| 324 | return s_threadinfo[tid].stack_min_min; |
| 325 | } |
| 326 | |
| bart | d43f8d3 | 2008-03-16 17:29:20 +0000 | [diff] [blame] | 327 | Addr thread_get_stack_max(const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 328 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 329 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | d43f8d3 | 2008-03-16 17:29:20 +0000 | [diff] [blame] | 330 | && tid != DRD_INVALID_THREADID); |
| 331 | return s_threadinfo[tid].stack_max; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 334 | SizeT thread_get_stack_size(const DrdThreadId tid) |
| 335 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 336 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | cac5346 | 2008-03-29 09:27:08 +0000 | [diff] [blame] | 337 | && tid != DRD_INVALID_THREADID); |
| 338 | return s_threadinfo[tid].stack_size; |
| 339 | } |
| 340 | |
| bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 341 | /** |
| 342 | * Clean up thread-specific data structures. Call this just after |
| 343 | * pthread_join(). |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 344 | */ |
| 345 | void thread_delete(const DrdThreadId tid) |
| 346 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 347 | Segment* sg; |
| 348 | Segment* sg_prev; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 349 | |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 350 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 351 | && tid != DRD_INVALID_THREADID); |
| bart | 5c3da01 | 2009-02-14 14:46:16 +0000 | [diff] [blame] | 352 | tl_assert(s_threadinfo[tid].synchr_nesting >= 0); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 353 | for (sg = s_threadinfo[tid].last; sg; sg = sg_prev) |
| 354 | { |
| 355 | sg_prev = sg->prev; |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 356 | sg->prev = 0; |
| 357 | sg->next = 0; |
| 358 | sg_put(sg); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 359 | } |
| 360 | s_threadinfo[tid].vg_thread_exists = False; |
| 361 | s_threadinfo[tid].posix_thread_exists = False; |
| 362 | tl_assert(s_threadinfo[tid].detached_posix_thread == False); |
| 363 | s_threadinfo[tid].first = 0; |
| 364 | s_threadinfo[tid].last = 0; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* Called after a thread performed its last memory access and before */ |
| 368 | /* thread_delete() is called. Note: thread_delete() is only called for */ |
| 369 | /* joinable threads, not for detached threads. */ |
| 370 | void thread_finished(const DrdThreadId tid) |
| 371 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 372 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 373 | && tid != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 374 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 375 | s_threadinfo[tid].vg_thread_exists = False; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 376 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 377 | if (s_threadinfo[tid].detached_posix_thread) |
| 378 | { |
| 379 | /* Once a detached thread has finished, its stack is deallocated and */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 380 | /* should no longer be taken into account when computing the conflict set*/ |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 381 | s_threadinfo[tid].stack_min = s_threadinfo[tid].stack_max; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 382 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 383 | /* For a detached thread, calling pthread_exit() invalidates the */ |
| 384 | /* POSIX thread ID associated with the detached thread. For joinable */ |
| 385 | /* POSIX threads however, the POSIX thread ID remains live after the */ |
| 386 | /* pthread_exit() call until pthread_join() is called. */ |
| 387 | s_threadinfo[tid].posix_thread_exists = False; |
| 388 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| bart | 9b2974a | 2008-09-27 12:35:31 +0000 | [diff] [blame] | 391 | /** Called just before pthread_cancel(). */ |
| bart | af0691b | 2008-09-27 12:26:50 +0000 | [diff] [blame] | 392 | void thread_pre_cancel(const DrdThreadId tid) |
| 393 | { |
| 394 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 395 | && tid != DRD_INVALID_THREADID); |
| 396 | tl_assert(s_threadinfo[tid].pt_threadid != INVALID_POSIX_THREADID); |
| 397 | |
| 398 | s_threadinfo[tid].synchr_nesting = 0; |
| 399 | } |
| 400 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 401 | void thread_set_pthreadid(const DrdThreadId tid, const PThreadId ptid) |
| 402 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 403 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 404 | && tid != DRD_INVALID_THREADID); |
| 405 | tl_assert(s_threadinfo[tid].pt_threadid == INVALID_POSIX_THREADID); |
| 406 | tl_assert(ptid != INVALID_POSIX_THREADID); |
| 407 | s_threadinfo[tid].posix_thread_exists = True; |
| 408 | s_threadinfo[tid].pt_threadid = ptid; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | Bool thread_get_joinable(const DrdThreadId tid) |
| 412 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 413 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 414 | && tid != DRD_INVALID_THREADID); |
| 415 | return ! s_threadinfo[tid].detached_posix_thread; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | void thread_set_joinable(const DrdThreadId tid, const Bool joinable) |
| 419 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 420 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 421 | && tid != DRD_INVALID_THREADID); |
| 422 | tl_assert(!! joinable == joinable); |
| 423 | tl_assert(s_threadinfo[tid].pt_threadid != INVALID_POSIX_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 424 | #if 0 |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 425 | VG_(message)(Vg_DebugMsg, |
| 426 | "thread_set_joinable(%d/%d, %s)", |
| 427 | tid, |
| 428 | s_threadinfo[tid].vg_threadid, |
| 429 | joinable ? "joinable" : "detached"); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 430 | #endif |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 431 | s_threadinfo[tid].detached_posix_thread = ! joinable; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 434 | void thread_set_vg_running_tid(const ThreadId vg_tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 435 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 436 | tl_assert(vg_tid != VG_INVALID_THREADID); |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 437 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 438 | if (vg_tid != s_vg_running_tid) |
| 439 | { |
| 440 | thread_set_running_tid(vg_tid, VgThreadIdToDrdThreadId(vg_tid)); |
| 441 | } |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 442 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 443 | tl_assert(s_vg_running_tid != VG_INVALID_THREADID); |
| 444 | tl_assert(s_drd_running_tid != DRD_INVALID_THREADID); |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | void thread_set_running_tid(const ThreadId vg_tid, const DrdThreadId drd_tid) |
| 448 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 449 | tl_assert(vg_tid != VG_INVALID_THREADID); |
| 450 | tl_assert(drd_tid != DRD_INVALID_THREADID); |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 451 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 452 | if (vg_tid != s_vg_running_tid) |
| 453 | { |
| 454 | if (s_trace_context_switches |
| 455 | && s_drd_running_tid != DRD_INVALID_THREADID) |
| 456 | { |
| 457 | VG_(message)(Vg_DebugMsg, |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 458 | "Context switch from thread %d/%d to thread %d/%d;" |
| 459 | " segments: %llu", |
| bart | aa97a54 | 2008-03-16 17:57:01 +0000 | [diff] [blame] | 460 | s_vg_running_tid, s_drd_running_tid, |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 461 | DrdThreadIdToVgThreadId(drd_tid), drd_tid, |
| 462 | sg_get_alive_segments_count()); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 463 | } |
| 464 | s_vg_running_tid = vg_tid; |
| 465 | s_drd_running_tid = drd_tid; |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 466 | thread_compute_conflict_set(&s_conflict_set, drd_tid); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 467 | s_context_switch_count++; |
| 468 | } |
| sewardj | 8b09d4f | 2007-12-04 21:27:18 +0000 | [diff] [blame] | 469 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 470 | tl_assert(s_vg_running_tid != VG_INVALID_THREADID); |
| 471 | tl_assert(s_drd_running_tid != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 474 | int thread_enter_synchr(const DrdThreadId tid) |
| 475 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 476 | tl_assert(IsValidDrdThreadId(tid)); |
| 477 | return s_threadinfo[tid].synchr_nesting++; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | int thread_leave_synchr(const DrdThreadId tid) |
| 481 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 482 | tl_assert(IsValidDrdThreadId(tid)); |
| 483 | tl_assert(s_threadinfo[tid].synchr_nesting >= 1); |
| 484 | return --s_threadinfo[tid].synchr_nesting; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | int thread_get_synchr_nesting_count(const DrdThreadId tid) |
| 488 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 489 | tl_assert(IsValidDrdThreadId(tid)); |
| 490 | return s_threadinfo[tid].synchr_nesting; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 493 | /** Append a new segment at the end of the segment list. */ |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 494 | static void thread_append_segment(const DrdThreadId tid, Segment* const sg) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 495 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 496 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 497 | && tid != DRD_INVALID_THREADID); |
| bart | 23d3a4e | 2008-04-05 12:53:00 +0000 | [diff] [blame] | 498 | // tl_assert(sane_ThreadInfo(&s_threadinfo[tid])); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 499 | sg->prev = s_threadinfo[tid].last; |
| 500 | sg->next = 0; |
| 501 | if (s_threadinfo[tid].last) |
| 502 | s_threadinfo[tid].last->next = sg; |
| 503 | s_threadinfo[tid].last = sg; |
| 504 | if (s_threadinfo[tid].first == 0) |
| 505 | s_threadinfo[tid].first = sg; |
| bart | 23d3a4e | 2008-04-05 12:53:00 +0000 | [diff] [blame] | 506 | // tl_assert(sane_ThreadInfo(&s_threadinfo[tid])); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 509 | /** Remove a segment from the segment list of thread threadid, and free the |
| 510 | * associated memory. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 511 | */ |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 512 | static void thread_discard_segment(const DrdThreadId tid, Segment* const sg) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 513 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 514 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 515 | && tid != DRD_INVALID_THREADID); |
| bart | 3f74967 | 2008-03-22 09:49:40 +0000 | [diff] [blame] | 516 | //tl_assert(sane_ThreadInfo(&s_threadinfo[tid])); |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 517 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 518 | if (sg->prev) |
| 519 | sg->prev->next = sg->next; |
| 520 | if (sg->next) |
| 521 | sg->next->prev = sg->prev; |
| 522 | if (sg == s_threadinfo[tid].first) |
| 523 | s_threadinfo[tid].first = sg->next; |
| 524 | if (sg == s_threadinfo[tid].last) |
| 525 | s_threadinfo[tid].last = sg->prev; |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 526 | sg_put(sg); |
| bart | 3f74967 | 2008-03-22 09:49:40 +0000 | [diff] [blame] | 527 | |
| 528 | //tl_assert(sane_ThreadInfo(&s_threadinfo[tid])); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | VectorClock* thread_get_vc(const DrdThreadId tid) |
| 532 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 533 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 534 | && tid != DRD_INVALID_THREADID); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 535 | tl_assert(s_threadinfo[tid].last); |
| 536 | return &s_threadinfo[tid].last->vc; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 539 | /** Return the latest segment of thread 'tid' and increment its reference |
| 540 | * count. |
| 541 | */ |
| 542 | void thread_get_latest_segment(Segment** sg, const DrdThreadId tid) |
| 543 | { |
| 544 | tl_assert(sg); |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 545 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 546 | && tid != DRD_INVALID_THREADID); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 547 | tl_assert(s_threadinfo[tid].last); |
| 548 | |
| 549 | sg_put(*sg); |
| 550 | *sg = sg_get(s_threadinfo[tid].last); |
| 551 | } |
| 552 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 553 | /** |
| 554 | * Compute the minimum of all latest vector clocks of all threads |
| 555 | * (Michiel Ronsse calls this "clock snooping" in his papers about DIOTA). |
| 556 | * @param vc pointer to a vectorclock, holds result upon return. |
| 557 | */ |
| 558 | static void thread_compute_minimum_vc(VectorClock* vc) |
| 559 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 560 | unsigned i; |
| 561 | Bool first; |
| 562 | Segment* latest_sg; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 563 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 564 | first = True; |
| 565 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 566 | { |
| 567 | latest_sg = s_threadinfo[i].last; |
| 568 | if (latest_sg) |
| 569 | { |
| 570 | if (first) |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 571 | DRD_(vc_assign)(vc, &latest_sg->vc); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 572 | else |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 573 | DRD_(vc_min)(vc, &latest_sg->vc); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 574 | first = False; |
| 575 | } |
| 576 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | static void thread_compute_maximum_vc(VectorClock* vc) |
| 580 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 581 | unsigned i; |
| 582 | Bool first; |
| 583 | Segment* latest_sg; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 584 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 585 | first = True; |
| 586 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 587 | { |
| 588 | latest_sg = s_threadinfo[i].last; |
| 589 | if (latest_sg) |
| 590 | { |
| 591 | if (first) |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 592 | DRD_(vc_assign)(vc, &latest_sg->vc); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 593 | else |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 594 | DRD_(vc_combine)(vc, &latest_sg->vc); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 595 | first = False; |
| 596 | } |
| 597 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /** |
| bart | 5bd9f2d | 2008-03-03 20:31:58 +0000 | [diff] [blame] | 601 | * Discard all segments that have a defined order against the latest vector |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 602 | * clock of every thread -- these segments can no longer be involved in a |
| 603 | * data race. |
| 604 | */ |
| 605 | static void thread_discard_ordered_segments(void) |
| 606 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 607 | unsigned i; |
| 608 | VectorClock thread_vc_min; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 609 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 610 | s_discard_ordered_segments_count++; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 611 | |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 612 | DRD_(vc_init)(&thread_vc_min, 0, 0); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 613 | thread_compute_minimum_vc(&thread_vc_min); |
| 614 | if (sg_get_trace()) |
| 615 | { |
| 616 | char msg[256]; |
| 617 | VectorClock thread_vc_max; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 618 | |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 619 | DRD_(vc_init)(&thread_vc_max, 0, 0); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 620 | thread_compute_maximum_vc(&thread_vc_max); |
| 621 | VG_(snprintf)(msg, sizeof(msg), |
| 622 | "Discarding ordered segments -- min vc is "); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 623 | DRD_(vc_snprint)(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg), |
| 624 | &thread_vc_min); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 625 | VG_(snprintf)(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg), |
| 626 | ", max vc is "); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 627 | DRD_(vc_snprint)(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg), |
| 628 | &thread_vc_max); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 629 | VG_(message)(Vg_UserMsg, "%s", msg); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 630 | DRD_(vc_cleanup)(&thread_vc_max); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 631 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 632 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 633 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 634 | { |
| 635 | Segment* sg; |
| 636 | Segment* sg_next; |
| 637 | for (sg = s_threadinfo[i].first; |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 638 | sg && (sg_next = sg->next) && DRD_(vc_lte)(&sg->vc, &thread_vc_min); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 639 | sg = sg_next) |
| 640 | { |
| 641 | thread_discard_segment(i, sg); |
| 642 | } |
| 643 | } |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 644 | DRD_(vc_cleanup)(&thread_vc_min); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 647 | /** Merge all segments that may be merged without triggering false positives |
| 648 | * or discarding real data races. For the theoretical background of segment |
| 649 | * merging, see also the following paper: |
| 650 | * Mark Christiaens, Michiel Ronsse and Koen De Bosschere. |
| 651 | * Bounding the number of segment histories during data race detection. |
| 652 | * Parallel Computing archive, Volume 28, Issue 9, pp 1221-1238, |
| 653 | * September 2002. |
| 654 | */ |
| 655 | static void thread_merge_segments(void) |
| 656 | { |
| 657 | unsigned i; |
| 658 | |
| 659 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 660 | { |
| 661 | Segment* sg; |
| 662 | |
| bart | 23d3a4e | 2008-04-05 12:53:00 +0000 | [diff] [blame] | 663 | // tl_assert(sane_ThreadInfo(&s_threadinfo[i])); |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 664 | |
| 665 | for (sg = s_threadinfo[i].first; sg; sg = sg->next) |
| 666 | { |
| 667 | if (sg_get_refcnt(sg) == 1 |
| 668 | && sg->next |
| 669 | && sg_get_refcnt(sg->next) == 1 |
| 670 | && sg->next->next) |
| 671 | { |
| 672 | /* Merge sg and sg->next into sg. */ |
| 673 | sg_merge(sg, sg->next); |
| 674 | thread_discard_segment(i, sg->next); |
| 675 | } |
| 676 | } |
| 677 | |
| bart | 23d3a4e | 2008-04-05 12:53:00 +0000 | [diff] [blame] | 678 | // tl_assert(sane_ThreadInfo(&s_threadinfo[i])); |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 682 | /** Every change in the vector clock of a thread may cause segments that |
| 683 | * were previously ordered to this thread to become unordered. Hence, |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 684 | * it may be necessary to recalculate the conflict set if the vector clock |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 685 | * of the current thread is updated. This function check whether such a |
| 686 | * recalculation is necessary. |
| 687 | * |
| 688 | * @param tid Thread ID of the thread to which a new segment has been |
| 689 | * appended. |
| 690 | * @param new_sg Pointer to the most recent segment of thread tid. |
| 691 | */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 692 | static Bool conflict_set_update_needed(const DrdThreadId tid, |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 693 | const Segment* const new_sg) |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 694 | { |
| bart | 5d421ba | 2008-04-19 15:15:12 +0000 | [diff] [blame] | 695 | #if 0 |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 696 | unsigned i; |
| 697 | const Segment* old_sg; |
| 698 | |
| 699 | tl_assert(new_sg); |
| 700 | |
| 701 | /* If a new segment was added to another thread than the running thread, */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 702 | /* just tell the caller to update the conflict set. */ |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 703 | if (tid != s_drd_running_tid) |
| 704 | return True; |
| 705 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 706 | /* Always let the caller update the conflict set after creation of the */ |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 707 | /* first segment. */ |
| 708 | old_sg = new_sg->prev; |
| 709 | if (old_sg == 0) |
| 710 | return True; |
| 711 | |
| 712 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 713 | { |
| 714 | Segment* q; |
| 715 | |
| 716 | if (i == s_drd_running_tid) |
| 717 | continue; |
| 718 | |
| 719 | for (q = s_threadinfo[i].last; q; q = q->prev) |
| 720 | { |
| 721 | /* If the expression below evaluates to false, this expression will */ |
| 722 | /* also evaluate to false for all subsequent iterations. So stop */ |
| 723 | /* iterating. */ |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 724 | if (DRD_(vc_lte)(&q->vc, &old_sg->vc)) |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 725 | break; |
| 726 | /* If the vector clock of the 2nd the last segment is not ordered */ |
| 727 | /* to the vector clock of segment q, and the last segment is, ask */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 728 | /* the caller to update the conflict set. */ |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 729 | if (! DRD_(vc_lte)(&old_sg->vc, &q->vc)) |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 730 | { |
| 731 | return True; |
| 732 | } |
| 733 | /* If the vector clock of the last segment is not ordered to the */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 734 | /* vector clock of segment q, ask the caller to update the conflict */ |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 735 | /* set. */ |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 736 | if (! DRD_(vc_lte)(&q->vc, &new_sg->vc) && ! DRD_(vc_lte)(&new_sg->vc, &q->vc)) |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 737 | { |
| 738 | return True; |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | return False; |
| bart | 5d421ba | 2008-04-19 15:15:12 +0000 | [diff] [blame] | 744 | #else |
| 745 | return True; |
| 746 | #endif |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 749 | /** Create a new segment for the specified thread, and discard any segments |
| 750 | * that cannot cause races anymore. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 751 | */ |
| 752 | void thread_new_segment(const DrdThreadId tid) |
| 753 | { |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 754 | Segment* new_sg; |
| 755 | |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 756 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 757 | && tid != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 758 | |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 759 | new_sg = sg_new(tid, tid); |
| 760 | thread_append_segment(tid, new_sg); |
| 761 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 762 | if (conflict_set_update_needed(tid, new_sg)) |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 763 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 764 | thread_compute_conflict_set(&s_conflict_set, s_drd_running_tid); |
| 765 | s_conflict_set_new_segment_count++; |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 766 | } |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 767 | else if (tid == s_drd_running_tid) |
| 768 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 769 | tl_assert(thread_conflict_set_up_to_date(s_drd_running_tid)); |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 770 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 771 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 772 | thread_discard_ordered_segments(); |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 773 | |
| bart | a9c3739 | 2008-03-22 09:38:48 +0000 | [diff] [blame] | 774 | if (s_segment_merging) |
| 775 | thread_merge_segments(); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 778 | /** Call this function after thread 'joiner' joined thread 'joinee'. */ |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 779 | void thread_combine_vc(DrdThreadId joiner, DrdThreadId joinee) |
| 780 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 781 | tl_assert(joiner != joinee); |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 782 | tl_assert(0 <= (int)joiner && joiner < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 783 | && joiner != DRD_INVALID_THREADID); |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 784 | tl_assert(0 <= (int)joinee && joinee < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 785 | && joinee != DRD_INVALID_THREADID); |
| 786 | tl_assert(s_threadinfo[joiner].last); |
| 787 | tl_assert(s_threadinfo[joinee].last); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 788 | DRD_(vc_combine)(&s_threadinfo[joiner].last->vc, &s_threadinfo[joinee].last->vc); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 789 | thread_discard_ordered_segments(); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 790 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 791 | if (joiner == s_drd_running_tid) |
| 792 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 793 | thread_compute_conflict_set(&s_conflict_set, joiner); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 794 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 797 | /** Call this function after thread 'tid' had to wait because of thread |
| 798 | * synchronization until the memory accesses in the segment with vector clock |
| 799 | * 'vc' finished. |
| 800 | */ |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 801 | void thread_combine_vc2(DrdThreadId tid, const VectorClock* const vc) |
| 802 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 803 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 804 | && tid != DRD_INVALID_THREADID); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 805 | tl_assert(s_threadinfo[tid].last); |
| 806 | tl_assert(vc); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 807 | DRD_(vc_combine)(&s_threadinfo[tid].last->vc, vc); |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 808 | thread_compute_conflict_set(&s_conflict_set, tid); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 809 | thread_discard_ordered_segments(); |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 810 | s_conflict_set_combine_vc_count++; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 813 | /** Call this function whenever a thread is no longer using the memory |
| 814 | * [ a1, a2 [, e.g. because of a call to free() or a stack pointer |
| 815 | * increase. |
| 816 | */ |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 817 | void thread_stop_using_mem(const Addr a1, const Addr a2) |
| 818 | { |
| bart | d43f8d3 | 2008-03-16 17:29:20 +0000 | [diff] [blame] | 819 | DrdThreadId other_user; |
| 820 | unsigned i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 821 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 822 | /* For all threads, mark the range [ a1, a2 [ as no longer in use. */ |
| bart | d43f8d3 | 2008-03-16 17:29:20 +0000 | [diff] [blame] | 823 | other_user = DRD_INVALID_THREADID; |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 824 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 825 | { |
| 826 | Segment* p; |
| 827 | for (p = s_threadinfo[i].first; p; p = p->next) |
| 828 | { |
| 829 | if (other_user == DRD_INVALID_THREADID |
| bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 830 | && i != s_drd_running_tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 831 | { |
| bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 832 | if (UNLIKELY(bm_test_and_clear(p->bm, a1, a2))) |
| 833 | { |
| 834 | other_user = i; |
| 835 | } |
| 836 | continue; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 837 | } |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 838 | bm_clear(p->bm, a1, a2); |
| 839 | } |
| 840 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 841 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 842 | /* If any other thread had accessed memory in [ a1, a2 [, update the */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 843 | /* conflict set. */ |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 844 | if (other_user != DRD_INVALID_THREADID |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 845 | && bm_has_any_access(s_conflict_set, a1, a2)) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 846 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 847 | thread_compute_conflict_set(&s_conflict_set, thread_get_running_tid()); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 848 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 851 | void thread_start_recording(const DrdThreadId tid) |
| 852 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 853 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 854 | && tid != DRD_INVALID_THREADID); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 855 | tl_assert(! s_threadinfo[tid].is_recording); |
| 856 | s_threadinfo[tid].is_recording = True; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | void thread_stop_recording(const DrdThreadId tid) |
| 860 | { |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 861 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 862 | && tid != DRD_INVALID_THREADID); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 863 | tl_assert(s_threadinfo[tid].is_recording); |
| 864 | s_threadinfo[tid].is_recording = False; |
| bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 867 | void thread_print_all(void) |
| 868 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 869 | unsigned i; |
| 870 | Segment* p; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 871 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 872 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 873 | { |
| 874 | if (s_threadinfo[i].first) |
| 875 | { |
| 876 | VG_(printf)("**************\n" |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 877 | "* thread %3d (%d/%d/%d/0x%lx/%d) *\n" |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 878 | "**************\n", |
| 879 | i, |
| 880 | s_threadinfo[i].vg_thread_exists, |
| 881 | s_threadinfo[i].vg_threadid, |
| 882 | s_threadinfo[i].posix_thread_exists, |
| 883 | s_threadinfo[i].pt_threadid, |
| bart | 354009c | 2008-03-16 10:42:33 +0000 | [diff] [blame] | 884 | s_threadinfo[i].detached_posix_thread); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 885 | for (p = s_threadinfo[i].first; p; p = p->next) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 886 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 887 | sg_print(p); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 888 | } |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static void show_call_stack(const DrdThreadId tid, |
| 894 | const Char* const msg, |
| 895 | ExeContext* const callstack) |
| 896 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 897 | const ThreadId vg_tid = DrdThreadIdToVgThreadId(tid); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 898 | |
| bart | aa97a54 | 2008-03-16 17:57:01 +0000 | [diff] [blame] | 899 | VG_(message)(Vg_UserMsg, "%s (thread %d/%d)", msg, vg_tid, tid); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 900 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 901 | if (vg_tid != VG_INVALID_THREADID) |
| 902 | { |
| 903 | if (callstack) |
| 904 | { |
| 905 | VG_(pp_ExeContext)(callstack); |
| 906 | } |
| 907 | else |
| 908 | { |
| 909 | VG_(get_and_pp_StackTrace)(vg_tid, VG_(clo_backtrace_size)); |
| 910 | } |
| 911 | } |
| 912 | else |
| 913 | { |
| 914 | VG_(message)(Vg_UserMsg, |
| 915 | " (thread finished, call stack no longer available)"); |
| 916 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 919 | static void |
| 920 | thread_report_conflicting_segments_segment(const DrdThreadId tid, |
| 921 | const Addr addr, |
| 922 | const SizeT size, |
| 923 | const BmAccessTypeT access_type, |
| 924 | const Segment* const p) |
| 925 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 926 | unsigned i; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 927 | |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 928 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 929 | && tid != DRD_INVALID_THREADID); |
| 930 | tl_assert(p); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 931 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 932 | for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) |
| 933 | { |
| 934 | if (i != tid) |
| 935 | { |
| 936 | Segment* q; |
| 937 | for (q = s_threadinfo[i].last; q; q = q->prev) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 938 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 939 | // Since q iterates over the segments of thread i in order of |
| 940 | // decreasing vector clocks, if q->vc <= p->vc, then |
| 941 | // q->next->vc <= p->vc will also hold. Hence, break out of the |
| 942 | // loop once this condition is met. |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 943 | if (DRD_(vc_lte)(&q->vc, &p->vc)) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 944 | break; |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 945 | if (! DRD_(vc_lte)(&p->vc, &q->vc)) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 946 | { |
| 947 | if (bm_has_conflict_with(q->bm, addr, addr + size, access_type)) |
| 948 | { |
| 949 | tl_assert(q->stacktrace); |
| 950 | show_call_stack(i, "Other segment start", |
| 951 | q->stacktrace); |
| 952 | show_call_stack(i, "Other segment end", |
| 953 | q->next ? q->next->stacktrace : 0); |
| 954 | } |
| 955 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 956 | } |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 957 | } |
| 958 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | void thread_report_conflicting_segments(const DrdThreadId tid, |
| 962 | const Addr addr, |
| 963 | const SizeT size, |
| 964 | const BmAccessTypeT access_type) |
| 965 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 966 | Segment* p; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 967 | |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 968 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 969 | && tid != DRD_INVALID_THREADID); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 970 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 971 | for (p = s_threadinfo[tid].first; p; p = p->next) |
| 972 | { |
| 973 | if (bm_has(p->bm, addr, addr + size, access_type)) |
| 974 | { |
| 975 | thread_report_conflicting_segments_segment(tid, addr, size, |
| 976 | access_type, p); |
| 977 | } |
| 978 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 979 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 980 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 981 | /** Verify whether the conflict set for thread tid is up to date. Only perform |
| 982 | * the check if the environment variable DRD_VERIFY_CONFLICT_SET has been set. |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 983 | */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 984 | static Bool thread_conflict_set_up_to_date(const DrdThreadId tid) |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 985 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 986 | static int do_verify_conflict_set = -1; |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 987 | Bool result; |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 988 | struct bitmap* computed_conflict_set = 0; |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 989 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 990 | if (do_verify_conflict_set < 0) |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 991 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 992 | //VG_(message)(Vg_DebugMsg, "%s", VG_(getenv)("DRD_VERIFY_CONFLICT_SET")); |
| 993 | do_verify_conflict_set = VG_(getenv)("DRD_VERIFY_CONFLICT_SET") != 0; |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 994 | } |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 995 | if (do_verify_conflict_set == 0) |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 996 | return True; |
| 997 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 998 | thread_compute_conflict_set(&computed_conflict_set, tid); |
| 999 | result = bm_equal(s_conflict_set, computed_conflict_set); |
| 1000 | bm_delete(computed_conflict_set); |
| bart | 82195c1 | 2008-04-13 17:35:08 +0000 | [diff] [blame] | 1001 | return result; |
| 1002 | } |
| 1003 | |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1004 | /** Compute a bitmap that represents the union of all memory accesses of all |
| 1005 | * segments that are unordered to the current segment of the thread tid. |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1006 | */ |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1007 | static void thread_compute_conflict_set(struct bitmap** conflict_set, |
| 1008 | const DrdThreadId tid) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1009 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1010 | Segment* p; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1011 | |
| bart | 74a5f21 | 2008-05-11 06:43:07 +0000 | [diff] [blame] | 1012 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 1013 | && tid != DRD_INVALID_THREADID); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1014 | tl_assert(tid == s_drd_running_tid); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1015 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1016 | s_update_conflict_set_count++; |
| 1017 | s_conflict_set_bitmap_creation_count -= bm_get_bitmap_creation_count(); |
| 1018 | s_conflict_set_bitmap2_creation_count -= bm_get_bitmap2_creation_count(); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1019 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1020 | if (*conflict_set) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1021 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1022 | bm_delete(*conflict_set); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1023 | } |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1024 | *conflict_set = bm_new(); |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1025 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1026 | if (s_trace_conflict_set) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1027 | { |
| 1028 | char msg[256]; |
| 1029 | |
| 1030 | VG_(snprintf)(msg, sizeof(msg), |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1031 | "computing conflict set for thread %d/%d with vc ", |
| bart | aa97a54 | 2008-03-16 17:57:01 +0000 | [diff] [blame] | 1032 | DrdThreadIdToVgThreadId(tid), tid); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 1033 | DRD_(vc_snprint)(msg + VG_(strlen)(msg), |
| 1034 | sizeof(msg) - VG_(strlen)(msg), |
| 1035 | &s_threadinfo[tid].last->vc); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 1036 | VG_(message)(Vg_UserMsg, "%s", msg); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | p = s_threadinfo[tid].last; |
| 1040 | { |
| 1041 | unsigned j; |
| 1042 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1043 | if (s_trace_conflict_set) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1044 | { |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1045 | char msg[256]; |
| 1046 | |
| 1047 | VG_(snprintf)(msg, sizeof(msg), |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1048 | "conflict set: thread [%d] at vc ", |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1049 | tid); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 1050 | DRD_(vc_snprint)(msg + VG_(strlen)(msg), |
| 1051 | sizeof(msg) - VG_(strlen)(msg), |
| 1052 | &p->vc); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 1053 | VG_(message)(Vg_UserMsg, "%s", msg); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1054 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1055 | |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1056 | for (j = 0; j < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); j++) |
| 1057 | { |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 1058 | if (j != tid && IsValidDrdThreadId(j)) |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1059 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1060 | const Segment* q; |
| 1061 | for (q = s_threadinfo[j].last; q; q = q->prev) |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 1062 | { |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 1063 | if (! DRD_(vc_lte)(&q->vc, &p->vc) && ! DRD_(vc_lte)(&p->vc, &q->vc)) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1064 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1065 | if (s_trace_conflict_set) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1066 | { |
| 1067 | char msg[256]; |
| 1068 | VG_(snprintf)(msg, sizeof(msg), |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1069 | "conflict set: [%d] merging segment ", j); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 1070 | DRD_(vc_snprint)(msg + VG_(strlen)(msg), |
| 1071 | sizeof(msg) - VG_(strlen)(msg), |
| 1072 | &q->vc); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 1073 | VG_(message)(Vg_UserMsg, "%s", msg); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1074 | } |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1075 | bm_merge2(*conflict_set, q->bm); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1076 | } |
| 1077 | else |
| 1078 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1079 | if (s_trace_conflict_set) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1080 | { |
| 1081 | char msg[256]; |
| 1082 | VG_(snprintf)(msg, sizeof(msg), |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1083 | "conflict set: [%d] ignoring segment ", j); |
| bart | 41b226c | 2009-02-14 16:55:19 +0000 | [diff] [blame^] | 1084 | DRD_(vc_snprint)(msg + VG_(strlen)(msg), |
| 1085 | sizeof(msg) - VG_(strlen)(msg), |
| 1086 | &q->vc); |
| bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 1087 | VG_(message)(Vg_UserMsg, "%s", msg); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1088 | } |
| 1089 | } |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 1090 | } |
| bart | 26f73e1 | 2008-02-24 18:37:08 +0000 | [diff] [blame] | 1091 | } |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1092 | } |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1093 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1094 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1095 | s_conflict_set_bitmap_creation_count += bm_get_bitmap_creation_count(); |
| 1096 | s_conflict_set_bitmap2_creation_count += bm_get_bitmap2_creation_count(); |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1097 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1098 | if (0 && s_trace_conflict_set) |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1099 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1100 | VG_(message)(Vg_UserMsg, "[%d] new conflict set:", tid); |
| 1101 | bm_print(*conflict_set); |
| 1102 | VG_(message)(Vg_UserMsg, "[%d] end of new conflict set.", tid); |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1103 | } |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1106 | ULong thread_get_context_switch_count(void) |
| 1107 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1108 | return s_context_switch_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1111 | ULong thread_get_discard_ordered_segments_count(void) |
| 1112 | { |
| bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1113 | return s_discard_ordered_segments_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1116 | ULong thread_get_update_conflict_set_count(ULong* dsnsc, ULong* dscvc) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1117 | { |
| bart | d66e3a8 | 2008-04-06 15:02:17 +0000 | [diff] [blame] | 1118 | tl_assert(dsnsc); |
| 1119 | tl_assert(dscvc); |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1120 | *dsnsc = s_conflict_set_new_segment_count; |
| 1121 | *dscvc = s_conflict_set_combine_vc_count; |
| 1122 | return s_update_conflict_set_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1125 | ULong thread_get_conflict_set_bitmap_creation_count(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1126 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1127 | return s_conflict_set_bitmap_creation_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1130 | ULong thread_get_conflict_set_bitmap2_creation_count(void) |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1131 | { |
| bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 1132 | return s_conflict_set_bitmap2_creation_count; |
| sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1133 | } |