tsan_trace.h revision 25d1c799087af5757ab6efc4a77558565fb1744a
17ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===-- 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
227ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyconst int kTraceParts = 8;
239d2ffc2ee08216f8fad9b1bd267d1f112e0d2f01Dmitry Vyukovconst int kTraceSize = 128*1024;
247ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyconst int kTracePartSize = kTraceSize / kTraceParts;
257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
267ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// Must fit into 3 bits.
277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum EventType {
287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  EventTypeMop,
297ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  EventTypeFuncEnter,
307ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  EventTypeFuncExit,
317ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  EventTypeLock,
327ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  EventTypeUnlock,
337ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  EventTypeRLock,
347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  EventTypeRUnlock,
357ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
367ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
377ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// Represents a thread event (from most significant bit):
387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// u64 typ  : 3;   // EventType.
397ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// u64 addr : 61;  // Associated pc.
407ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanytypedef u64 Event;
417ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
427ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct TraceHeader {
437ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  StackTrace stack0;  // Start stack for the trace.
449ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov  u64        epoch0;  // Start epoch for the trace.
4525d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#ifndef TSAN_GO
469ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov  uptr       stack0buf[kShadowStackSize];
4725d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#endif
489ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov
499ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov  TraceHeader()
5025d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#ifndef TSAN_GO
519ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov      : stack0(stack0buf, kShadowStackSize)
5225d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#else
5325d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov      : stack0()
5425d1c799087af5757ab6efc4a77558565fb1744aDmitry Vyukov#endif
559ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov      , epoch0() {
569ad7c32720dfa1287f8cfd481e5d583435178caeDmitry Vyukov  }
577ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
587ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
597ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct Trace {
607ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Event events[kTraceSize];
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