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