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