blob: 001fd4d810502e17070c885c54090a680c67aad8 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
2 This file is part of drd, a data race detector.
3
sewardj85642922008-01-14 11:54:56 +00004 Copyright (C) 2006-2008 Bart Van Assche
sewardjaf44c822007-11-25 14:01:38 +00005 bart.vanassche@gmail.com
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307, USA.
21
22 The GNU General Public License is contained in the file COPYING.
23*/
24
25
26#include "drd_error.h"
27#include "drd_segment.h"
28#include "drd_suppression.h"
29#include "drd_thread.h"
sewardjaf44c822007-11-25 14:01:38 +000030#include "pub_tool_basics.h" // Addr, SizeT
31#include "pub_tool_errormgr.h" // VG_(unique_error)()
32#include "pub_tool_libcassert.h" // tl_assert()
33#include "pub_tool_libcbase.h" // VG_(strlen)()
34#include "pub_tool_libcprint.h" // VG_(printf)()
35#include "pub_tool_machine.h"
36#include "pub_tool_mallocfree.h" // VG_(malloc)(), VG_(free)()
sewardj85642922008-01-14 11:54:56 +000037#include "pub_tool_options.h" // VG_(clo_backtrace_size)
sewardjaf44c822007-11-25 14:01:38 +000038#include "pub_tool_threadstate.h" // VG_(get_pthread_id)()
39
40
sewardjaf44c822007-11-25 14:01:38 +000041// Local functions.
42
43static void thread_append_segment(const DrdThreadId tid,
44 Segment* const sg);
barta2b6e1b2008-03-17 18:32:39 +000045static void thread_discard_segment(const DrdThreadId tid, Segment* const sg);
sewardjaf44c822007-11-25 14:01:38 +000046static void thread_update_danger_set(const DrdThreadId tid);
47
48
49// Local variables.
50
51static ULong s_context_switch_count;
52static ULong s_discard_ordered_segments_count;
sewardjaf44c822007-11-25 14:01:38 +000053static ULong s_update_danger_set_count;
54static ULong s_danger_set_bitmap_creation_count;
55static ULong s_danger_set_bitmap2_creation_count;
sewardj8b09d4f2007-12-04 21:27:18 +000056static ThreadId s_vg_running_tid = VG_INVALID_THREADID;
bartf00a85b2008-03-13 18:49:23 +000057DrdThreadId s_drd_running_tid = DRD_INVALID_THREADID;
58ThreadInfo s_threadinfo[DRD_N_THREADS];
bart1a473c72008-03-13 19:03:38 +000059struct bitmap* s_danger_set;
bart26f73e12008-02-24 18:37:08 +000060static Bool s_trace_context_switches = False;
61static Bool s_trace_danger_set = False;
barta9c37392008-03-22 09:38:48 +000062static Bool s_segment_merging = True;
sewardjaf44c822007-11-25 14:01:38 +000063
64
65// Function definitions.
66
bart26f73e12008-02-24 18:37:08 +000067void thread_trace_context_switches(const Bool t)
68{
bart3772a982008-03-15 08:11:03 +000069 s_trace_context_switches = t;
bart26f73e12008-02-24 18:37:08 +000070}
71
72void thread_trace_danger_set(const Bool t)
73{
bart3772a982008-03-15 08:11:03 +000074 s_trace_danger_set = t;
bart26f73e12008-02-24 18:37:08 +000075}
76
barta9c37392008-03-22 09:38:48 +000077void thread_set_segment_merging(const Bool m)
78{
79 s_segment_merging = m;
80}
81
sewardjaf44c822007-11-25 14:01:38 +000082__inline__ Bool IsValidDrdThreadId(const DrdThreadId tid)
83{
bart3772a982008-03-15 08:11:03 +000084 return (0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID
85 && ! (s_threadinfo[tid].vg_thread_exists == False
86 && s_threadinfo[tid].posix_thread_exists == False
87 && s_threadinfo[tid].detached_posix_thread == False));
sewardjaf44c822007-11-25 14:01:38 +000088}
89
90/**
91 * Convert Valgrind's ThreadId into a DrdThreadId. Report failure if
92 * Valgrind's ThreadId does not yet exist.
93 **/
94DrdThreadId VgThreadIdToDrdThreadId(const ThreadId tid)
95{
bart3772a982008-03-15 08:11:03 +000096 int i;
sewardjaf44c822007-11-25 14:01:38 +000097
bart3772a982008-03-15 08:11:03 +000098 if (tid == VG_INVALID_THREADID)
99 return DRD_INVALID_THREADID;
sewardjaf44c822007-11-25 14:01:38 +0000100
bart3772a982008-03-15 08:11:03 +0000101 for (i = 1; i < DRD_N_THREADS; i++)
102 {
103 if (s_threadinfo[i].vg_thread_exists == True
104 && s_threadinfo[i].vg_threadid == tid)
105 {
106 return i;
107 }
108 }
sewardjaf44c822007-11-25 14:01:38 +0000109
bart3772a982008-03-15 08:11:03 +0000110 return DRD_INVALID_THREADID;
sewardjaf44c822007-11-25 14:01:38 +0000111}
112
113static
114DrdThreadId VgThreadIdToNewDrdThreadId(const ThreadId tid)
115{
bart3772a982008-03-15 08:11:03 +0000116 int i;
sewardjaf44c822007-11-25 14:01:38 +0000117
bart3772a982008-03-15 08:11:03 +0000118 tl_assert(VgThreadIdToDrdThreadId(tid) == DRD_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000119
bart3772a982008-03-15 08:11:03 +0000120 for (i = 1; i < DRD_N_THREADS; i++)
121 {
122 if (s_threadinfo[i].vg_thread_exists == False
123 && s_threadinfo[i].posix_thread_exists == False
124 && s_threadinfo[i].detached_posix_thread == False)
125 {
126 s_threadinfo[i].vg_thread_exists = True;
127 s_threadinfo[i].vg_threadid = tid;
128 s_threadinfo[i].pt_threadid = INVALID_POSIX_THREADID;
bart3772a982008-03-15 08:11:03 +0000129 s_threadinfo[i].stack_min = 0;
130 s_threadinfo[i].stack_startup = 0;
131 s_threadinfo[i].stack_max = 0;
bart3772a982008-03-15 08:11:03 +0000132 s_threadinfo[i].is_recording = True;
133 s_threadinfo[i].synchr_nesting = 0;
134 if (s_threadinfo[i].first != 0)
135 VG_(printf)("drd thread id = %d\n", i);
136 tl_assert(s_threadinfo[i].first == 0);
137 tl_assert(s_threadinfo[i].last == 0);
138 return i;
139 }
140 }
sewardjaf44c822007-11-25 14:01:38 +0000141
bart3772a982008-03-15 08:11:03 +0000142 tl_assert(False);
sewardjaf44c822007-11-25 14:01:38 +0000143
bart3772a982008-03-15 08:11:03 +0000144 return DRD_INVALID_THREADID;
sewardjaf44c822007-11-25 14:01:38 +0000145}
146
147DrdThreadId PtThreadIdToDrdThreadId(const PThreadId tid)
148{
bart3772a982008-03-15 08:11:03 +0000149 int i;
sewardjaf44c822007-11-25 14:01:38 +0000150
bart3772a982008-03-15 08:11:03 +0000151 tl_assert(tid != INVALID_POSIX_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000152
bart3772a982008-03-15 08:11:03 +0000153 for (i = 1; i < DRD_N_THREADS; i++)
154 {
155 if (s_threadinfo[i].posix_thread_exists
156 && s_threadinfo[i].pt_threadid == tid)
157 {
158 return i;
159 }
160 }
161 return DRD_INVALID_THREADID;
sewardjaf44c822007-11-25 14:01:38 +0000162}
163
164ThreadId DrdThreadIdToVgThreadId(const DrdThreadId tid)
165{
bart3772a982008-03-15 08:11:03 +0000166 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
167 return (s_threadinfo[tid].vg_thread_exists
168 ? s_threadinfo[tid].vg_threadid
169 : VG_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000170}
171
bart26f73e12008-02-24 18:37:08 +0000172/** Sanity check of the doubly linked list of segments referenced by a
173 * ThreadInfo struct.
174 * @return True if sane, False if not.
sewardjaf44c822007-11-25 14:01:38 +0000175 */
176static Bool sane_ThreadInfo(const ThreadInfo* const ti)
177{
bart3772a982008-03-15 08:11:03 +0000178 Segment* p;
179 for (p = ti->first; p; p = p->next) {
180 if (p->next && p->next->prev != p)
181 return False;
182 if (p->next == 0 && p != ti->last)
183 return False;
184 }
185 for (p = ti->last; p; p = p->prev) {
186 if (p->prev && p->prev->next != p)
187 return False;
188 if (p->prev == 0 && p != ti->first)
189 return False;
190 }
191 return True;
sewardjaf44c822007-11-25 14:01:38 +0000192}
193
194DrdThreadId thread_pre_create(const DrdThreadId creator,
195 const ThreadId vg_created)
196{
bart3772a982008-03-15 08:11:03 +0000197 DrdThreadId created;
sewardjaf44c822007-11-25 14:01:38 +0000198
bart3772a982008-03-15 08:11:03 +0000199 tl_assert(VgThreadIdToDrdThreadId(vg_created) == DRD_INVALID_THREADID);
200 created = VgThreadIdToNewDrdThreadId(vg_created);
201 tl_assert(0 <= created && created < DRD_N_THREADS
202 && created != DRD_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000203
bart3772a982008-03-15 08:11:03 +0000204 tl_assert(s_threadinfo[created].first == 0);
205 tl_assert(s_threadinfo[created].last == 0);
206 thread_append_segment(created, sg_new(creator, created));
sewardjaf44c822007-11-25 14:01:38 +0000207
bart3772a982008-03-15 08:11:03 +0000208 return created;
sewardjaf44c822007-11-25 14:01:38 +0000209}
210
bart26f73e12008-02-24 18:37:08 +0000211/** Allocate the first segment for a thread. Call this just after
212 * pthread_create().
sewardjaf44c822007-11-25 14:01:38 +0000213 */
214DrdThreadId thread_post_create(const ThreadId vg_created)
215{
bart3772a982008-03-15 08:11:03 +0000216 const DrdThreadId created = VgThreadIdToDrdThreadId(vg_created);
sewardjaf44c822007-11-25 14:01:38 +0000217
bart3772a982008-03-15 08:11:03 +0000218 tl_assert(0 <= created && created < DRD_N_THREADS
219 && created != DRD_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000220
bart3772a982008-03-15 08:11:03 +0000221 s_threadinfo[created].stack_max = VG_(thread_get_stack_max)(vg_created);
222 s_threadinfo[created].stack_startup = s_threadinfo[created].stack_max;
223 s_threadinfo[created].stack_min = s_threadinfo[created].stack_max;
bart3772a982008-03-15 08:11:03 +0000224 tl_assert(s_threadinfo[created].stack_max != 0);
sewardjaf44c822007-11-25 14:01:38 +0000225
bart3772a982008-03-15 08:11:03 +0000226 return created;
sewardjaf44c822007-11-25 14:01:38 +0000227}
228
229/* NPTL hack: NPTL allocates the 'struct pthread' on top of the stack, */
230/* and accesses this data structure from multiple threads without locking. */
231/* Any conflicting accesses in the range stack_startup..stack_max will be */
232/* ignored. */
233void thread_set_stack_startup(const DrdThreadId tid, const Addr stack_startup)
234{
bart3772a982008-03-15 08:11:03 +0000235 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
236 tl_assert(s_threadinfo[tid].stack_min <= stack_startup);
237 tl_assert(stack_startup <= s_threadinfo[tid].stack_max);
238 s_threadinfo[tid].stack_startup = stack_startup;
sewardjaf44c822007-11-25 14:01:38 +0000239}
240
241Addr thread_get_stack_min(const DrdThreadId tid)
242{
bart3772a982008-03-15 08:11:03 +0000243 tl_assert(0 <= tid && tid < DRD_N_THREADS
244 && tid != DRD_INVALID_THREADID);
245 return s_threadinfo[tid].stack_min;
sewardjaf44c822007-11-25 14:01:38 +0000246}
247
bartd43f8d32008-03-16 17:29:20 +0000248Addr thread_get_stack_max(const DrdThreadId tid)
sewardjaf44c822007-11-25 14:01:38 +0000249{
bartd43f8d32008-03-16 17:29:20 +0000250 tl_assert(0 <= tid && tid < DRD_N_THREADS
251 && tid != DRD_INVALID_THREADID);
252 return s_threadinfo[tid].stack_max;
sewardjaf44c822007-11-25 14:01:38 +0000253}
254
barta2b6e1b2008-03-17 18:32:39 +0000255/** Clean up thread-specific data structures. Call this just after
256 * pthread_join().
sewardjaf44c822007-11-25 14:01:38 +0000257 */
258void thread_delete(const DrdThreadId tid)
259{
bart3772a982008-03-15 08:11:03 +0000260 Segment* sg;
261 Segment* sg_prev;
sewardjaf44c822007-11-25 14:01:38 +0000262
bart3772a982008-03-15 08:11:03 +0000263 tl_assert(0 <= tid && tid < DRD_N_THREADS
264 && tid != DRD_INVALID_THREADID);
265 tl_assert(s_threadinfo[tid].synchr_nesting == 0);
266 for (sg = s_threadinfo[tid].last; sg; sg = sg_prev)
267 {
268 sg_prev = sg->prev;
barta2b6e1b2008-03-17 18:32:39 +0000269 sg->prev = 0;
270 sg->next = 0;
271 sg_put(sg);
bart3772a982008-03-15 08:11:03 +0000272 }
273 s_threadinfo[tid].vg_thread_exists = False;
274 s_threadinfo[tid].posix_thread_exists = False;
275 tl_assert(s_threadinfo[tid].detached_posix_thread == False);
276 s_threadinfo[tid].first = 0;
277 s_threadinfo[tid].last = 0;
sewardjaf44c822007-11-25 14:01:38 +0000278}
279
280/* Called after a thread performed its last memory access and before */
281/* thread_delete() is called. Note: thread_delete() is only called for */
282/* joinable threads, not for detached threads. */
283void thread_finished(const DrdThreadId tid)
284{
bart3772a982008-03-15 08:11:03 +0000285 tl_assert(0 <= tid && tid < DRD_N_THREADS
286 && tid != DRD_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000287
bart3772a982008-03-15 08:11:03 +0000288 s_threadinfo[tid].vg_thread_exists = False;
sewardjaf44c822007-11-25 14:01:38 +0000289
bart3772a982008-03-15 08:11:03 +0000290 if (s_threadinfo[tid].detached_posix_thread)
291 {
292 /* Once a detached thread has finished, its stack is deallocated and */
293 /* should no longer be taken into account when computing the danger set*/
294 s_threadinfo[tid].stack_min = s_threadinfo[tid].stack_max;
sewardjaf44c822007-11-25 14:01:38 +0000295
bart3772a982008-03-15 08:11:03 +0000296 /* For a detached thread, calling pthread_exit() invalidates the */
297 /* POSIX thread ID associated with the detached thread. For joinable */
298 /* POSIX threads however, the POSIX thread ID remains live after the */
299 /* pthread_exit() call until pthread_join() is called. */
300 s_threadinfo[tid].posix_thread_exists = False;
301 }
sewardjaf44c822007-11-25 14:01:38 +0000302}
303
304void thread_set_pthreadid(const DrdThreadId tid, const PThreadId ptid)
305{
bart3772a982008-03-15 08:11:03 +0000306 tl_assert(0 <= tid && tid < DRD_N_THREADS
307 && tid != DRD_INVALID_THREADID);
308 tl_assert(s_threadinfo[tid].pt_threadid == INVALID_POSIX_THREADID);
309 tl_assert(ptid != INVALID_POSIX_THREADID);
310 s_threadinfo[tid].posix_thread_exists = True;
311 s_threadinfo[tid].pt_threadid = ptid;
sewardjaf44c822007-11-25 14:01:38 +0000312}
313
314Bool thread_get_joinable(const DrdThreadId tid)
315{
bart3772a982008-03-15 08:11:03 +0000316 tl_assert(0 <= tid && tid < DRD_N_THREADS
317 && tid != DRD_INVALID_THREADID);
318 return ! s_threadinfo[tid].detached_posix_thread;
sewardjaf44c822007-11-25 14:01:38 +0000319}
320
321void thread_set_joinable(const DrdThreadId tid, const Bool joinable)
322{
bart3772a982008-03-15 08:11:03 +0000323 tl_assert(0 <= tid && tid < DRD_N_THREADS
324 && tid != DRD_INVALID_THREADID);
325 tl_assert(!! joinable == joinable);
326 tl_assert(s_threadinfo[tid].pt_threadid != INVALID_POSIX_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000327#if 0
bart3772a982008-03-15 08:11:03 +0000328 VG_(message)(Vg_DebugMsg,
329 "thread_set_joinable(%d/%d, %s)",
330 tid,
331 s_threadinfo[tid].vg_threadid,
332 joinable ? "joinable" : "detached");
sewardjaf44c822007-11-25 14:01:38 +0000333#endif
bart3772a982008-03-15 08:11:03 +0000334 s_threadinfo[tid].detached_posix_thread = ! joinable;
sewardjaf44c822007-11-25 14:01:38 +0000335}
336
sewardj8b09d4f2007-12-04 21:27:18 +0000337void thread_set_vg_running_tid(const ThreadId vg_tid)
sewardjaf44c822007-11-25 14:01:38 +0000338{
bart3772a982008-03-15 08:11:03 +0000339 tl_assert(vg_tid != VG_INVALID_THREADID);
sewardj8b09d4f2007-12-04 21:27:18 +0000340
bart3772a982008-03-15 08:11:03 +0000341 if (vg_tid != s_vg_running_tid)
342 {
343 thread_set_running_tid(vg_tid, VgThreadIdToDrdThreadId(vg_tid));
344 }
sewardj8b09d4f2007-12-04 21:27:18 +0000345
bart3772a982008-03-15 08:11:03 +0000346 tl_assert(s_vg_running_tid != VG_INVALID_THREADID);
347 tl_assert(s_drd_running_tid != DRD_INVALID_THREADID);
sewardj8b09d4f2007-12-04 21:27:18 +0000348}
349
350void thread_set_running_tid(const ThreadId vg_tid, const DrdThreadId drd_tid)
351{
bart3772a982008-03-15 08:11:03 +0000352 tl_assert(vg_tid != VG_INVALID_THREADID);
353 tl_assert(drd_tid != DRD_INVALID_THREADID);
sewardj8b09d4f2007-12-04 21:27:18 +0000354
bart3772a982008-03-15 08:11:03 +0000355 if (vg_tid != s_vg_running_tid)
356 {
357 if (s_trace_context_switches
358 && s_drd_running_tid != DRD_INVALID_THREADID)
359 {
360 VG_(message)(Vg_DebugMsg,
barta2b6e1b2008-03-17 18:32:39 +0000361 "Context switch from thread %d/%d to thread %d/%d;"
362 " segments: %llu",
bartaa97a542008-03-16 17:57:01 +0000363 s_vg_running_tid, s_drd_running_tid,
barta2b6e1b2008-03-17 18:32:39 +0000364 DrdThreadIdToVgThreadId(drd_tid), drd_tid,
365 sg_get_alive_segments_count());
bart3772a982008-03-15 08:11:03 +0000366 }
367 s_vg_running_tid = vg_tid;
368 s_drd_running_tid = drd_tid;
369 thread_update_danger_set(drd_tid);
370 s_context_switch_count++;
371 }
sewardj8b09d4f2007-12-04 21:27:18 +0000372
bart3772a982008-03-15 08:11:03 +0000373 tl_assert(s_vg_running_tid != VG_INVALID_THREADID);
374 tl_assert(s_drd_running_tid != DRD_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000375}
376
bart0268dfa2008-03-11 20:10:21 +0000377int thread_enter_synchr(const DrdThreadId tid)
378{
bart3772a982008-03-15 08:11:03 +0000379 tl_assert(IsValidDrdThreadId(tid));
380 return s_threadinfo[tid].synchr_nesting++;
bart0268dfa2008-03-11 20:10:21 +0000381}
382
383int thread_leave_synchr(const DrdThreadId tid)
384{
bart3772a982008-03-15 08:11:03 +0000385 tl_assert(IsValidDrdThreadId(tid));
386 tl_assert(s_threadinfo[tid].synchr_nesting >= 1);
387 return --s_threadinfo[tid].synchr_nesting;
bart0268dfa2008-03-11 20:10:21 +0000388}
389
390int thread_get_synchr_nesting_count(const DrdThreadId tid)
391{
bart3772a982008-03-15 08:11:03 +0000392 tl_assert(IsValidDrdThreadId(tid));
393 return s_threadinfo[tid].synchr_nesting;
bart0268dfa2008-03-11 20:10:21 +0000394}
395
bart1a473c72008-03-13 19:03:38 +0000396/** Append a new segment at the end of the segment list. */
bart26f73e12008-02-24 18:37:08 +0000397static void thread_append_segment(const DrdThreadId tid, Segment* const sg)
sewardjaf44c822007-11-25 14:01:38 +0000398{
bart3772a982008-03-15 08:11:03 +0000399 tl_assert(0 <= tid && tid < DRD_N_THREADS
400 && tid != DRD_INVALID_THREADID);
401 tl_assert(sane_ThreadInfo(&s_threadinfo[tid]));
402 sg->prev = s_threadinfo[tid].last;
403 sg->next = 0;
404 if (s_threadinfo[tid].last)
405 s_threadinfo[tid].last->next = sg;
406 s_threadinfo[tid].last = sg;
407 if (s_threadinfo[tid].first == 0)
408 s_threadinfo[tid].first = sg;
409 tl_assert(sane_ThreadInfo(&s_threadinfo[tid]));
sewardjaf44c822007-11-25 14:01:38 +0000410}
411
bart26f73e12008-02-24 18:37:08 +0000412/** Remove a segment from the segment list of thread threadid, and free the
413 * associated memory.
sewardjaf44c822007-11-25 14:01:38 +0000414 */
bart26f73e12008-02-24 18:37:08 +0000415static void thread_discard_segment(const DrdThreadId tid, Segment* const sg)
sewardjaf44c822007-11-25 14:01:38 +0000416{
bart3772a982008-03-15 08:11:03 +0000417 tl_assert(0 <= tid && tid < DRD_N_THREADS
418 && tid != DRD_INVALID_THREADID);
bart3f749672008-03-22 09:49:40 +0000419 //tl_assert(sane_ThreadInfo(&s_threadinfo[tid]));
bart26f73e12008-02-24 18:37:08 +0000420
bart3772a982008-03-15 08:11:03 +0000421 if (sg->prev)
422 sg->prev->next = sg->next;
423 if (sg->next)
424 sg->next->prev = sg->prev;
425 if (sg == s_threadinfo[tid].first)
426 s_threadinfo[tid].first = sg->next;
427 if (sg == s_threadinfo[tid].last)
428 s_threadinfo[tid].last = sg->prev;
barta2b6e1b2008-03-17 18:32:39 +0000429 sg_put(sg);
bart3f749672008-03-22 09:49:40 +0000430
431 //tl_assert(sane_ThreadInfo(&s_threadinfo[tid]));
sewardjaf44c822007-11-25 14:01:38 +0000432}
433
434VectorClock* thread_get_vc(const DrdThreadId tid)
435{
barta2b6e1b2008-03-17 18:32:39 +0000436 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
bart3772a982008-03-15 08:11:03 +0000437 tl_assert(s_threadinfo[tid].last);
438 return &s_threadinfo[tid].last->vc;
sewardjaf44c822007-11-25 14:01:38 +0000439}
440
barta2b6e1b2008-03-17 18:32:39 +0000441/** Return the latest segment of thread 'tid' and increment its reference
442 * count.
443 */
444void thread_get_latest_segment(Segment** sg, const DrdThreadId tid)
445{
446 tl_assert(sg);
447 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
448 tl_assert(s_threadinfo[tid].last);
449
450 sg_put(*sg);
451 *sg = sg_get(s_threadinfo[tid].last);
452}
453
sewardjaf44c822007-11-25 14:01:38 +0000454/**
455 * Compute the minimum of all latest vector clocks of all threads
456 * (Michiel Ronsse calls this "clock snooping" in his papers about DIOTA).
457 * @param vc pointer to a vectorclock, holds result upon return.
458 */
459static void thread_compute_minimum_vc(VectorClock* vc)
460{
bart3772a982008-03-15 08:11:03 +0000461 unsigned i;
462 Bool first;
463 Segment* latest_sg;
sewardjaf44c822007-11-25 14:01:38 +0000464
bart3772a982008-03-15 08:11:03 +0000465 first = True;
466 for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
467 {
468 latest_sg = s_threadinfo[i].last;
469 if (latest_sg)
470 {
471 if (first)
472 vc_assign(vc, &latest_sg->vc);
473 else
474 vc_min(vc, &latest_sg->vc);
475 first = False;
476 }
477 }
sewardjaf44c822007-11-25 14:01:38 +0000478}
479
480static void thread_compute_maximum_vc(VectorClock* vc)
481{
bart3772a982008-03-15 08:11:03 +0000482 unsigned i;
483 Bool first;
484 Segment* latest_sg;
sewardjaf44c822007-11-25 14:01:38 +0000485
bart3772a982008-03-15 08:11:03 +0000486 first = True;
487 for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
488 {
489 latest_sg = s_threadinfo[i].last;
490 if (latest_sg)
491 {
492 if (first)
493 vc_assign(vc, &latest_sg->vc);
494 else
495 vc_combine(vc, &latest_sg->vc);
496 first = False;
497 }
498 }
sewardjaf44c822007-11-25 14:01:38 +0000499}
500
501/**
bart5bd9f2d2008-03-03 20:31:58 +0000502 * Discard all segments that have a defined order against the latest vector
sewardjaf44c822007-11-25 14:01:38 +0000503 * clock of every thread -- these segments can no longer be involved in a
504 * data race.
505 */
506static void thread_discard_ordered_segments(void)
507{
bart3772a982008-03-15 08:11:03 +0000508 unsigned i;
509 VectorClock thread_vc_min;
sewardjaf44c822007-11-25 14:01:38 +0000510
bart3772a982008-03-15 08:11:03 +0000511 s_discard_ordered_segments_count++;
sewardjaf44c822007-11-25 14:01:38 +0000512
bart3772a982008-03-15 08:11:03 +0000513 vc_init(&thread_vc_min, 0, 0);
514 thread_compute_minimum_vc(&thread_vc_min);
515 if (sg_get_trace())
516 {
517 char msg[256];
518 VectorClock thread_vc_max;
sewardjaf44c822007-11-25 14:01:38 +0000519
bart3772a982008-03-15 08:11:03 +0000520 vc_init(&thread_vc_max, 0, 0);
521 thread_compute_maximum_vc(&thread_vc_max);
522 VG_(snprintf)(msg, sizeof(msg),
523 "Discarding ordered segments -- min vc is ");
524 vc_snprint(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg),
525 &thread_vc_min);
526 VG_(snprintf)(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg),
527 ", max vc is ");
528 vc_snprint(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg),
529 &thread_vc_max);
barta2b6e1b2008-03-17 18:32:39 +0000530 VG_(message)(Vg_UserMsg, "%s", msg);
bart3772a982008-03-15 08:11:03 +0000531 vc_cleanup(&thread_vc_max);
532 }
sewardjaf44c822007-11-25 14:01:38 +0000533
bart3772a982008-03-15 08:11:03 +0000534 for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
535 {
536 Segment* sg;
537 Segment* sg_next;
538 for (sg = s_threadinfo[i].first;
539 sg && (sg_next = sg->next) && vc_lte(&sg->vc, &thread_vc_min);
540 sg = sg_next)
541 {
542 thread_discard_segment(i, sg);
543 }
544 }
545 vc_cleanup(&thread_vc_min);
sewardjaf44c822007-11-25 14:01:38 +0000546}
547
barta9c37392008-03-22 09:38:48 +0000548/** Merge all segments that may be merged without triggering false positives
549 * or discarding real data races. For the theoretical background of segment
550 * merging, see also the following paper:
551 * Mark Christiaens, Michiel Ronsse and Koen De Bosschere.
552 * Bounding the number of segment histories during data race detection.
553 * Parallel Computing archive, Volume 28, Issue 9, pp 1221-1238,
554 * September 2002.
555 */
556static void thread_merge_segments(void)
557{
558 unsigned i;
559
560 for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
561 {
562 Segment* sg;
563
564 tl_assert(sane_ThreadInfo(&s_threadinfo[i]));
565
566 for (sg = s_threadinfo[i].first; sg; sg = sg->next)
567 {
568 if (sg_get_refcnt(sg) == 1
569 && sg->next
570 && sg_get_refcnt(sg->next) == 1
571 && sg->next->next)
572 {
573 /* Merge sg and sg->next into sg. */
574 sg_merge(sg, sg->next);
575 thread_discard_segment(i, sg->next);
576 }
577 }
578
579 tl_assert(sane_ThreadInfo(&s_threadinfo[i]));
580 }
581}
582
barta2b6e1b2008-03-17 18:32:39 +0000583/** Create a new segment for the specified thread, and discard any segments
584 * that cannot cause races anymore.
sewardjaf44c822007-11-25 14:01:38 +0000585 */
586void thread_new_segment(const DrdThreadId tid)
587{
barta2b6e1b2008-03-17 18:32:39 +0000588 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000589
barta2b6e1b2008-03-17 18:32:39 +0000590 thread_append_segment(tid, sg_new(tid, tid));
sewardjaf44c822007-11-25 14:01:38 +0000591
bart3772a982008-03-15 08:11:03 +0000592 thread_discard_ordered_segments();
bart26f73e12008-02-24 18:37:08 +0000593
barta9c37392008-03-22 09:38:48 +0000594 if (s_segment_merging)
595 thread_merge_segments();
596
bart3772a982008-03-15 08:11:03 +0000597 if (tid == s_drd_running_tid)
598 {
599 /* Every change in the vector clock of the current thread may cause */
600 /* segments that were previously ordered to this thread to become */
601 /* unordered. Hence, recalculate the danger set if the vector clock */
602 /* of the current thread is updated. */
603 thread_update_danger_set(tid);
604 }
sewardjaf44c822007-11-25 14:01:38 +0000605}
606
bart26f73e12008-02-24 18:37:08 +0000607/** Call this function after thread 'joiner' joined thread 'joinee'. */
sewardjaf44c822007-11-25 14:01:38 +0000608void thread_combine_vc(DrdThreadId joiner, DrdThreadId joinee)
609{
bart3772a982008-03-15 08:11:03 +0000610 tl_assert(joiner != joinee);
611 tl_assert(0 <= joiner && joiner < DRD_N_THREADS
612 && joiner != DRD_INVALID_THREADID);
613 tl_assert(0 <= joinee && joinee < DRD_N_THREADS
614 && joinee != DRD_INVALID_THREADID);
615 tl_assert(s_threadinfo[joiner].last);
616 tl_assert(s_threadinfo[joinee].last);
617 vc_combine(&s_threadinfo[joiner].last->vc, &s_threadinfo[joinee].last->vc);
618 thread_discard_ordered_segments();
sewardjaf44c822007-11-25 14:01:38 +0000619
bart3772a982008-03-15 08:11:03 +0000620 if (joiner == s_drd_running_tid)
621 {
622 thread_update_danger_set(joiner);
623 }
sewardjaf44c822007-11-25 14:01:38 +0000624}
625
bart26f73e12008-02-24 18:37:08 +0000626/** Call this function after thread 'tid' had to wait because of thread
627 * synchronization until the memory accesses in the segment with vector clock
628 * 'vc' finished.
629 */
sewardjaf44c822007-11-25 14:01:38 +0000630void thread_combine_vc2(DrdThreadId tid, const VectorClock* const vc)
631{
bart3772a982008-03-15 08:11:03 +0000632 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
633 tl_assert(s_threadinfo[tid].last);
634 tl_assert(vc);
635 vc_combine(&s_threadinfo[tid].last->vc, vc);
636 thread_discard_ordered_segments();
sewardjaf44c822007-11-25 14:01:38 +0000637}
638
bart26f73e12008-02-24 18:37:08 +0000639/** Call this function whenever a thread is no longer using the memory
640 * [ a1, a2 [, e.g. because of a call to free() or a stack pointer
641 * increase.
642 */
sewardjaf44c822007-11-25 14:01:38 +0000643void thread_stop_using_mem(const Addr a1, const Addr a2)
644{
bartd43f8d32008-03-16 17:29:20 +0000645 DrdThreadId other_user;
646 unsigned i;
sewardjaf44c822007-11-25 14:01:38 +0000647
bart3772a982008-03-15 08:11:03 +0000648 /* For all threads, mark the range [ a1, a2 [ as no longer in use. */
bartd43f8d32008-03-16 17:29:20 +0000649 other_user = DRD_INVALID_THREADID;
bart3772a982008-03-15 08:11:03 +0000650 for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
651 {
652 Segment* p;
653 for (p = s_threadinfo[i].first; p; p = p->next)
654 {
655 if (other_user == DRD_INVALID_THREADID
656 && i != s_drd_running_tid
657 && bm_has_any_access(p->bm, a1, a2))
sewardjaf44c822007-11-25 14:01:38 +0000658 {
bart3772a982008-03-15 08:11:03 +0000659 other_user = i;
sewardjaf44c822007-11-25 14:01:38 +0000660 }
bart3772a982008-03-15 08:11:03 +0000661 bm_clear(p->bm, a1, a2);
662 }
663 }
sewardjaf44c822007-11-25 14:01:38 +0000664
bart3772a982008-03-15 08:11:03 +0000665 /* If any other thread had accessed memory in [ a1, a2 [, update the */
666 /* danger set. */
667 if (other_user != DRD_INVALID_THREADID
668 && bm_has_any_access(s_danger_set, a1, a2))
669 {
670 thread_update_danger_set(thread_get_running_tid());
671 }
sewardjaf44c822007-11-25 14:01:38 +0000672}
673
bart0268dfa2008-03-11 20:10:21 +0000674void thread_start_recording(const DrdThreadId tid)
675{
bart3772a982008-03-15 08:11:03 +0000676 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
677 tl_assert(! s_threadinfo[tid].is_recording);
678 s_threadinfo[tid].is_recording = True;
bart0268dfa2008-03-11 20:10:21 +0000679}
680
681void thread_stop_recording(const DrdThreadId tid)
682{
bart3772a982008-03-15 08:11:03 +0000683 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
684 tl_assert(s_threadinfo[tid].is_recording);
685 s_threadinfo[tid].is_recording = False;
bart0268dfa2008-03-11 20:10:21 +0000686}
687
sewardjaf44c822007-11-25 14:01:38 +0000688void thread_print_all(void)
689{
bart3772a982008-03-15 08:11:03 +0000690 unsigned i;
691 Segment* p;
sewardjaf44c822007-11-25 14:01:38 +0000692
bart3772a982008-03-15 08:11:03 +0000693 for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
694 {
695 if (s_threadinfo[i].first)
696 {
697 VG_(printf)("**************\n"
barta2b6e1b2008-03-17 18:32:39 +0000698 "* thread %3d (%d/%d/%d/0x%lx/%d) *\n"
bart3772a982008-03-15 08:11:03 +0000699 "**************\n",
700 i,
701 s_threadinfo[i].vg_thread_exists,
702 s_threadinfo[i].vg_threadid,
703 s_threadinfo[i].posix_thread_exists,
704 s_threadinfo[i].pt_threadid,
bart354009c2008-03-16 10:42:33 +0000705 s_threadinfo[i].detached_posix_thread);
bart3772a982008-03-15 08:11:03 +0000706 for (p = s_threadinfo[i].first; p; p = p->next)
sewardjaf44c822007-11-25 14:01:38 +0000707 {
bart3772a982008-03-15 08:11:03 +0000708 sg_print(p);
sewardjaf44c822007-11-25 14:01:38 +0000709 }
bart3772a982008-03-15 08:11:03 +0000710 }
711 }
sewardjaf44c822007-11-25 14:01:38 +0000712}
713
714static void show_call_stack(const DrdThreadId tid,
715 const Char* const msg,
716 ExeContext* const callstack)
717{
bart3772a982008-03-15 08:11:03 +0000718 const ThreadId vg_tid = DrdThreadIdToVgThreadId(tid);
sewardjaf44c822007-11-25 14:01:38 +0000719
bartaa97a542008-03-16 17:57:01 +0000720 VG_(message)(Vg_UserMsg, "%s (thread %d/%d)", msg, vg_tid, tid);
sewardjaf44c822007-11-25 14:01:38 +0000721
bart3772a982008-03-15 08:11:03 +0000722 if (vg_tid != VG_INVALID_THREADID)
723 {
724 if (callstack)
725 {
726 VG_(pp_ExeContext)(callstack);
727 }
728 else
729 {
730 VG_(get_and_pp_StackTrace)(vg_tid, VG_(clo_backtrace_size));
731 }
732 }
733 else
734 {
735 VG_(message)(Vg_UserMsg,
736 " (thread finished, call stack no longer available)");
737 }
sewardjaf44c822007-11-25 14:01:38 +0000738}
739
sewardjaf44c822007-11-25 14:01:38 +0000740static void
741thread_report_conflicting_segments_segment(const DrdThreadId tid,
742 const Addr addr,
743 const SizeT size,
744 const BmAccessTypeT access_type,
745 const Segment* const p)
746{
bart3772a982008-03-15 08:11:03 +0000747 unsigned i;
sewardjaf44c822007-11-25 14:01:38 +0000748
bart3772a982008-03-15 08:11:03 +0000749 tl_assert(0 <= tid && tid < DRD_N_THREADS
750 && tid != DRD_INVALID_THREADID);
751 tl_assert(p);
sewardjaf44c822007-11-25 14:01:38 +0000752
bart3772a982008-03-15 08:11:03 +0000753 for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
754 {
755 if (i != tid)
756 {
757 Segment* q;
758 for (q = s_threadinfo[i].last; q; q = q->prev)
sewardjaf44c822007-11-25 14:01:38 +0000759 {
bart3772a982008-03-15 08:11:03 +0000760 // Since q iterates over the segments of thread i in order of
761 // decreasing vector clocks, if q->vc <= p->vc, then
762 // q->next->vc <= p->vc will also hold. Hence, break out of the
763 // loop once this condition is met.
764 if (vc_lte(&q->vc, &p->vc))
765 break;
766 if (! vc_lte(&p->vc, &q->vc))
767 {
768 if (bm_has_conflict_with(q->bm, addr, addr + size, access_type))
769 {
770 tl_assert(q->stacktrace);
771 show_call_stack(i, "Other segment start",
772 q->stacktrace);
773 show_call_stack(i, "Other segment end",
774 q->next ? q->next->stacktrace : 0);
775 }
776 }
sewardjaf44c822007-11-25 14:01:38 +0000777 }
bart3772a982008-03-15 08:11:03 +0000778 }
779 }
sewardjaf44c822007-11-25 14:01:38 +0000780}
781
782void thread_report_conflicting_segments(const DrdThreadId tid,
783 const Addr addr,
784 const SizeT size,
785 const BmAccessTypeT access_type)
786{
bart3772a982008-03-15 08:11:03 +0000787 Segment* p;
sewardjaf44c822007-11-25 14:01:38 +0000788
bart3772a982008-03-15 08:11:03 +0000789 tl_assert(0 <= tid && tid < DRD_N_THREADS
790 && tid != DRD_INVALID_THREADID);
sewardjaf44c822007-11-25 14:01:38 +0000791
bart3772a982008-03-15 08:11:03 +0000792 for (p = s_threadinfo[tid].first; p; p = p->next)
793 {
794 if (bm_has(p->bm, addr, addr + size, access_type))
795 {
796 thread_report_conflicting_segments_segment(tid, addr, size,
797 access_type, p);
798 }
799 }
sewardjaf44c822007-11-25 14:01:38 +0000800}
sewardjaf44c822007-11-25 14:01:38 +0000801
bart26f73e12008-02-24 18:37:08 +0000802/** Compute a bitmap that represents the union of all memory accesses of all
803 * segments that are unordered to the current segment of the thread tid.
sewardjaf44c822007-11-25 14:01:38 +0000804 */
805static void thread_update_danger_set(const DrdThreadId tid)
806{
bart3772a982008-03-15 08:11:03 +0000807 Segment* p;
sewardjaf44c822007-11-25 14:01:38 +0000808
bart3772a982008-03-15 08:11:03 +0000809 tl_assert(0 <= tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID);
810 tl_assert(tid == s_drd_running_tid);
sewardjaf44c822007-11-25 14:01:38 +0000811
bart3772a982008-03-15 08:11:03 +0000812 s_update_danger_set_count++;
813 s_danger_set_bitmap_creation_count -= bm_get_bitmap_creation_count();
814 s_danger_set_bitmap2_creation_count -= bm_get_bitmap2_creation_count();
sewardjaf44c822007-11-25 14:01:38 +0000815
bart3772a982008-03-15 08:11:03 +0000816 if (s_danger_set)
817 {
bart1ea5fff2008-03-16 08:36:23 +0000818 bm_delete(s_danger_set);
bart3772a982008-03-15 08:11:03 +0000819 }
bart1ea5fff2008-03-16 08:36:23 +0000820 s_danger_set = bm_new();
bart26f73e12008-02-24 18:37:08 +0000821
bart3772a982008-03-15 08:11:03 +0000822 if (s_trace_danger_set)
823 {
824 char msg[256];
825
826 VG_(snprintf)(msg, sizeof(msg),
bartaa97a542008-03-16 17:57:01 +0000827 "computing danger set for thread %d/%d with vc ",
828 DrdThreadIdToVgThreadId(tid), tid);
bart3772a982008-03-15 08:11:03 +0000829 vc_snprint(msg + VG_(strlen)(msg),
830 sizeof(msg) - VG_(strlen)(msg),
831 &s_threadinfo[tid].last->vc);
barta2b6e1b2008-03-17 18:32:39 +0000832 VG_(message)(Vg_UserMsg, "%s", msg);
bart3772a982008-03-15 08:11:03 +0000833 }
834
835 p = s_threadinfo[tid].last;
836 {
837 unsigned j;
838
839 if (s_trace_danger_set)
840 {
bart26f73e12008-02-24 18:37:08 +0000841 char msg[256];
842
843 VG_(snprintf)(msg, sizeof(msg),
bart3772a982008-03-15 08:11:03 +0000844 "danger set: thread [%d] at vc ",
bart26f73e12008-02-24 18:37:08 +0000845 tid);
846 vc_snprint(msg + VG_(strlen)(msg),
847 sizeof(msg) - VG_(strlen)(msg),
bart3772a982008-03-15 08:11:03 +0000848 &p->vc);
barta2b6e1b2008-03-17 18:32:39 +0000849 VG_(message)(Vg_UserMsg, "%s", msg);
bart3772a982008-03-15 08:11:03 +0000850 }
sewardjaf44c822007-11-25 14:01:38 +0000851
bart3772a982008-03-15 08:11:03 +0000852 for (j = 0; j < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); j++)
853 {
854 if (IsValidDrdThreadId(j))
bart26f73e12008-02-24 18:37:08 +0000855 {
bart3772a982008-03-15 08:11:03 +0000856 const Segment* q;
857 for (q = s_threadinfo[j].last; q; q = q->prev)
858 if (j != tid && q != 0
859 && ! vc_lte(&q->vc, &p->vc) && ! vc_lte(&p->vc, &q->vc))
860 {
861 if (s_trace_danger_set)
862 {
863 char msg[256];
864 VG_(snprintf)(msg, sizeof(msg),
865 "danger set: [%d] merging segment ", j);
866 vc_snprint(msg + VG_(strlen)(msg),
867 sizeof(msg) - VG_(strlen)(msg),
868 &q->vc);
barta2b6e1b2008-03-17 18:32:39 +0000869 VG_(message)(Vg_UserMsg, "%s", msg);
bart3772a982008-03-15 08:11:03 +0000870 }
871 bm_merge2(s_danger_set, q->bm);
872 }
873 else
874 {
875 if (s_trace_danger_set)
876 {
877 char msg[256];
878 VG_(snprintf)(msg, sizeof(msg),
879 "danger set: [%d] ignoring segment ", j);
880 vc_snprint(msg + VG_(strlen)(msg),
881 sizeof(msg) - VG_(strlen)(msg),
882 &q->vc);
barta2b6e1b2008-03-17 18:32:39 +0000883 VG_(message)(Vg_UserMsg, "%s", msg);
bart3772a982008-03-15 08:11:03 +0000884 }
885 }
bart26f73e12008-02-24 18:37:08 +0000886 }
bart3772a982008-03-15 08:11:03 +0000887 }
bart26f73e12008-02-24 18:37:08 +0000888
bart3772a982008-03-15 08:11:03 +0000889 for (j = 0; j < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); j++)
890 {
891 if (IsValidDrdThreadId(j))
sewardjaf44c822007-11-25 14:01:38 +0000892 {
bart3772a982008-03-15 08:11:03 +0000893 // NPTL hack: don't report data races on sizeof(struct pthread)
894 // bytes at the top of the stack, since the NPTL functions access
895 // this data without locking.
896 if (s_threadinfo[j].stack_min != 0)
897 {
898 tl_assert(s_threadinfo[j].stack_startup != 0);
899 if (s_threadinfo[j].stack_min < s_threadinfo[j].stack_startup)
900 {
901 bm_clear(s_danger_set,
902 s_threadinfo[j].stack_min,
903 s_threadinfo[j].stack_startup);
904 }
905 }
sewardjaf44c822007-11-25 14:01:38 +0000906 }
bart3772a982008-03-15 08:11:03 +0000907 }
908 }
sewardjaf44c822007-11-25 14:01:38 +0000909
bart3772a982008-03-15 08:11:03 +0000910 s_danger_set_bitmap_creation_count += bm_get_bitmap_creation_count();
911 s_danger_set_bitmap2_creation_count += bm_get_bitmap2_creation_count();
sewardjaf44c822007-11-25 14:01:38 +0000912
bart3772a982008-03-15 08:11:03 +0000913 if (0 && s_trace_danger_set)
914 {
barta2b6e1b2008-03-17 18:32:39 +0000915 VG_(message)(Vg_UserMsg, "[%d] new danger set:", tid);
bart3772a982008-03-15 08:11:03 +0000916 bm_print(s_danger_set);
barta2b6e1b2008-03-17 18:32:39 +0000917 VG_(message)(Vg_UserMsg, "[%d] end of new danger set.", tid);
bart3772a982008-03-15 08:11:03 +0000918 }
sewardjaf44c822007-11-25 14:01:38 +0000919}
920
sewardjaf44c822007-11-25 14:01:38 +0000921ULong thread_get_context_switch_count(void)
922{
bart3772a982008-03-15 08:11:03 +0000923 return s_context_switch_count;
sewardjaf44c822007-11-25 14:01:38 +0000924}
925
sewardjaf44c822007-11-25 14:01:38 +0000926ULong thread_get_discard_ordered_segments_count(void)
927{
bart3772a982008-03-15 08:11:03 +0000928 return s_discard_ordered_segments_count;
sewardjaf44c822007-11-25 14:01:38 +0000929}
930
931ULong thread_get_update_danger_set_count(void)
932{
bart3772a982008-03-15 08:11:03 +0000933 return s_update_danger_set_count;
sewardjaf44c822007-11-25 14:01:38 +0000934}
935
936ULong thread_get_danger_set_bitmap_creation_count(void)
937{
bart3772a982008-03-15 08:11:03 +0000938 return s_danger_set_bitmap_creation_count;
sewardjaf44c822007-11-25 14:01:38 +0000939}
940
941ULong thread_get_danger_set_bitmap2_creation_count(void)
942{
bart3772a982008-03-15 08:11:03 +0000943 return s_danger_set_bitmap2_creation_count;
sewardjaf44c822007-11-25 14:01:38 +0000944}