+/*
+ * TRACE file formats...
+ *
+ * RAW_VERSION0
+ *
+ * uint32_t #threadmaps
+ * kd_threadmap[]
+ * kd_buf[]
+ *
+ * RAW_VERSION1
+ *
+ * RAW_header, with version_no set to RAW_VERSION1
+ * kd_threadmap[]
+ * Empty space to pad alignment to the nearest page boundary.
+ * kd_buf[]
+ *
+ * RAW_VERSION1+
+ *
+ * RAW_header, with version_no set to RAW_VERSION1
+ * kd_threadmap[]
+ * kd_cpumap_header, with version_no set to RAW_VERSION1
+ * kd_cpumap[]
+ * Empty space to pad alignment to the nearest page boundary.
+ * kd_buf[]
+ *
+ * V1+ implementation details...
+ *
+ * It would have been nice to add the cpumap data "correctly", but there were
+ * several obstacles. Existing code attempts to parse both V1 and V0 files.
+ * Due to the fact that V0 has no versioning or header, the test looks like
+ * this:
+ *
+ * // Read header
+ * if (header.version_no != RAW_VERSION1) { // Assume V0 }
+ *
+ * If we add a VERSION2 file format, all existing code is going to treat that
+ * as a VERSION0 file when reading it, and crash terribly when trying to read
+ * RAW_VERSION2 threadmap entries.
+ *
+ * To differentiate between a V1 and V1+ file, read as V1 until you reach
+ * the padding bytes. Then:
+ *
+ * boolean_t is_v1plus = FALSE;
+ * if (padding_bytes >= sizeof(kd_cpumap_header)) {
+ * kd_cpumap_header header = // read header;
+ * if (header.version_no == RAW_VERSION1) {
+ * is_v1plus = TRUE;
+ * }
+ * }
+ *
+ */
+
+#define RAW_VERSION3 0x00001000
+
+// Version 3 header
+// The header chunk has the tag 0x00001000 which also serves as a magic word
+// that identifies the file as a version 3 trace file. The header payload is
+// a set of fixed fields followed by a variable number of sub-chunks:
+/*
+ * ____________________________________________________________________________
+ | Offset | Size | Field |
+ | ----------------------------------------------------------------------------
+ | 0 | 4 | Tag (0x00001000) |
+ | 4 | 4 | Sub-tag. Represents the version of the header. |
+ | 8 | 8 | Length of header payload (40+8x) |
+ | 16 | 8 | Time base info. Two 32-bit numbers, numer/denom, |
+ | | | for converting timestamps to nanoseconds. |
+ | 24 | 8 | Timestamp of trace start. |
+ | 32 | 8 | Wall time seconds since Unix epoch. |
+ | | | As returned by gettimeofday(). |
+ | 40 | 4 | Wall time microseconds. As returned by gettimeofday(). |
+ | 44 | 4 | Local time zone offset in minutes. ( " ) |
+ | 48 | 4 | Type of daylight savings time correction to apply. ( " ) |
+ | 52 | 4 | Flags. 1 = 64-bit. Remaining bits should be written |
+ | | | as 0 and ignored when reading. |
+ | 56 | 8x | Variable number of sub-chunks. None are required. |
+ | | | Ignore unknown chunks. |
+ | ----------------------------------------------------------------------------
+ */
+// NOTE: The header sub-chunks are considered part of the header chunk,
+// so they must be included in the header chunk’s length field.
+// The CPU map is an optional sub-chunk of the header chunk. It provides
+// information about the CPUs that are referenced from the trace events.
+typedef struct {
+ uint32_t tag;
+ uint32_t sub_tag;
+ uint64_t length;
+ uint32_t timebase_numer;
+ uint32_t timebase_denom;
+ uint64_t timestamp;
+ uint64_t walltime_secs;
+ uint32_t walltime_usecs;
+ uint32_t timezone_minuteswest;
+ uint32_t timezone_dst;
+ uint32_t flags;
+} __attribute__((packed)) kd_header_v3;
+
+typedef struct {
+ uint32_t tag;
+ uint32_t sub_tag;
+ uint64_t length;
+} __attribute__((packed)) kd_chunk_header_v3;
+
+#define V3_CONFIG 0x00001b00
+#define V3_CPU_MAP 0x00001c00
+#define V3_THREAD_MAP 0x00001d00
+#define V3_RAW_EVENTS 0x00001e00
+#define V3_NULL_CHUNK 0x00002000
+
+// The current version of all kernel managed chunks is 1. The
+// V3_CURRENT_CHUNK_VERSION is added to ease the simple case
+// when most/all the kernel managed chunks have the same version.
+
+#define V3_CURRENT_CHUNK_VERSION 1
+#define V3_HEADER_VERSION V3_CURRENT_CHUNK_VERSION
+#define V3_CPUMAP_VERSION V3_CURRENT_CHUNK_VERSION
+#define V3_THRMAP_VERSION V3_CURRENT_CHUNK_VERSION
+#define V3_EVENT_DATA_VERSION V3_CURRENT_CHUNK_VERSION
+