(((t)->float_word_order == __BYTE_ORDER) ? 0 : 1)
#define SEQUENCE_AVG_ELEMENTS 1000
-
+
+/*
+ * offsetof taken from Linux kernel.
+ */
+#undef offsetof
+#ifdef __compiler_offsetof
+#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
+#else
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
typedef guint8 uint8_t;
typedef guint16 uint16_t;
typedef guint32 uint32_t;
typedef guint64 uint64_t;
/* Subbuffer header */
-struct ltt_subbuffer_header_2_0 {
+struct ltt_subbuffer_header_2_1 {
uint64_t cycle_count_begin; /* Cycle count at subbuffer start */
uint64_t cycle_count_end; /* Cycle count at subbuffer end */
- uint32_t magic_number; /* Trace magic number.
+ uint32_t magic_number; /*
+ * Trace magic number.
* contains endianness information.
*/
uint8_t major_version;
uint32_t freq_scale; /* Frequency scaling */
uint32_t lost_size; /* Size unused at end of subbuffer */
uint32_t buf_size; /* Size of this subbuffer */
+ char header_end[0]; /* End of header */
};
-typedef struct ltt_subbuffer_header_2_0 ltt_subbuffer_header_t;
+typedef struct ltt_subbuffer_header_2_1 ltt_subbuffer_header_t;
+
+/*
+ * Return header size without padding after the structure. Don't use packed
+ * structure because gcc generates inefficient code on some architectures
+ * (powerpc, mips..)
+ */
+static inline size_t ltt_subbuffer_header_size(void)
+{
+ return offsetof(ltt_subbuffer_header_t, header_end);
+}
enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
break;
case 2:
switch(header->minor_version) {
- case 0:
+ case 1:
{
- struct ltt_subbuffer_header_2_0 *vheader = header;
- tf->buffer_header_size = sizeof(struct ltt_subbuffer_header_2_0) ;
+ struct ltt_subbuffer_header_2_1 *vheader = header;
+ tf->buffer_header_size = ltt_subbuffer_header_size();
tf->tscbits = 27;
tf->eventbits = 5;
tf->tsc_mask = ((1ULL << tf->tscbits) - 1);
// Is the file large enough to contain a trace
if(lTDFStat.st_size <
- (off_t)(sizeof(ltt_subbuffer_header_t))){
+ (off_t)(ltt_subbuffer_header_size())){
g_print("The input data file %s does not contain a trace\n", fileName);
goto close_file;
}
/* Temporarily map the buffer start header to get trace information */
/* Multiple of pages aligned head */
tf->buffer.head = mmap(0,
- PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)), PROT_READ,
+ PAGE_ALIGN(ltt_subbuffer_header_size()), PROT_READ,
MAP_PRIVATE, tf->fd, 0);
if(tf->buffer.head == MAP_FAILED) {
perror("Error in allocating memory for buffer of tracefile");
tf->num_blocks = tf->file_size / tf->buf_size;
if(munmap(tf->buffer.head,
- PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)))) {
+ PAGE_ALIGN(ltt_subbuffer_header_size()))) {
g_warning("unmap size : %u\n",
- PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)));
+ PAGE_ALIGN(ltt_subbuffer_header_size()));
perror("munmap error");
g_assert(0);
}
/* Error */
unmap_file:
if(munmap(tf->buffer.head,
- PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)))) {
+ PAGE_ALIGN(ltt_subbuffer_header_size()))) {
g_warning("unmap size : %u\n",
- PAGE_ALIGN(sizeof(ltt_subbuffer_header_t)));
+ PAGE_ALIGN(ltt_subbuffer_header_size()));
perror("munmap error");
g_assert(0);
}