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