From 1550fba68437fc32b4f0ee82d82553c0fddb6d8a Mon Sep 17 00:00:00 2001 From: compudj Date: Sat, 11 Oct 2008 17:09:03 +0000 Subject: [PATCH] update header version git-svn-id: http://ltt.polymtl.ca/svn@3100 04897980-b3bd-0310-b5e0-8ef037075253 --- trunk/lttv/ltt/ltt-private.h | 30 ++++++++++++++++++++++++++---- trunk/lttv/ltt/tracefile.c | 18 +++++++++--------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/trunk/lttv/ltt/ltt-private.h b/trunk/lttv/ltt/ltt-private.h index 1233b8fe..24e82f29 100644 --- a/trunk/lttv/ltt/ltt-private.h +++ b/trunk/lttv/ltt/ltt-private.h @@ -49,17 +49,28 @@ (((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; @@ -75,9 +86,20 @@ struct ltt_subbuffer_header_2_0 { 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 }; diff --git a/trunk/lttv/ltt/tracefile.c b/trunk/lttv/ltt/tracefile.c index 64830859..d30dc511 100644 --- a/trunk/lttv/ltt/tracefile.c +++ b/trunk/lttv/ltt/tracefile.c @@ -152,10 +152,10 @@ static int parse_trace_header(ltt_subbuffer_header_t *header, 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); @@ -238,7 +238,7 @@ static gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) // 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; } @@ -246,7 +246,7 @@ static gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) /* 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"); @@ -267,9 +267,9 @@ static gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) 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); } @@ -286,9 +286,9 @@ static gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf) /* 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); } -- 2.34.1