tsan_trace.h revision d698edc4f74a17048eef3342a9fa42b3ebba802a
16fbecdd97512bd7d9ccef130e99650d446b50444Alexey Samsonov//===-- tsan_trace.h --------------------------------------------*- C++ -*-===// 27ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 37ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// The LLVM Compiler Infrastructure 47ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 57ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file is distributed under the University of Illinois Open Source 67ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// License. See LICENSE.TXT for details. 77ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 87ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===// 97ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file is a part of ThreadSanitizer (TSan), a race detector. 117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===// 137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#ifndef TSAN_TRACE_H 147ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#define TSAN_TRACE_H 157ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "tsan_defs.h" 177ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "tsan_mutex.h" 187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "tsan_sync.h" 197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanynamespace __tsan { 217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 22d698edc4f74a17048eef3342a9fa42b3ebba802aDmitry Vyukovconst int kTracePartSizeBits = 14; 23d698edc4f74a17048eef3342a9fa42b3ebba802aDmitry Vyukovconst int kTracePartSize = 1 << kTracePartSizeBits; 24d698edc4f74a17048eef3342a9fa42b3ebba802aDmitry Vyukovconst int kTraceParts = 4 * 1024 * 1024 / kTracePartSize; 25ffad0c4bc88056f5c9360af792ef2e6c1e8259bfDmitry Vyukovconst int kTraceSize = kTracePartSize * kTraceParts; 267ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// Must fit into 3 bits. 287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum EventType { 297ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany EventTypeMop, 307ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany EventTypeFuncEnter, 317ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany EventTypeFuncExit, 327ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany EventTypeLock, 337ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany EventTypeUnlock, 347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany EventTypeRLock, 352135d8a7f4ba30fe35ed02d5e6ffd59a95b26219Alexey Samsonov EventTypeRUnlock 367ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}; 377ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// Represents a thread event (from most significant bit): 397ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// u64 typ : 3; // EventType. 407ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// u64 addr : 61; // Associated pc. 417ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanytypedef u64 Event; 427ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 437ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct TraceHeader { 447ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany StackTrace stack0; // Start stack for the trace. 459ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov u64 epoch0; // Start epoch for the trace. 4625d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#ifndef TSAN_GO 470ab628c61594eb80612e5389d9c33da0e0d70c66Dmitry Vyukov uptr stack0buf[kTraceStackSize]; 4825d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#endif 499ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov 509ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov TraceHeader() 5125d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#ifndef TSAN_GO 520ab628c61594eb80612e5389d9c33da0e0d70c66Dmitry Vyukov : stack0(stack0buf, kTraceStackSize) 5325d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#else 5425d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov : stack0() 5525d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#endif 569ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov , epoch0() { 579ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov } 587ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}; 597ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 607ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct Trace { 617ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany TraceHeader headers[kTraceParts]; 627ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany Mutex mtx; 637ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 647ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany Trace() 657ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany : mtx(MutexTypeTrace, StatMtxTrace) { 667ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany } 677ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}; 687ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 697ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany} // namespace __tsan 707ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 717ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#endif // TSAN_TRACE_H 72