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