update header version
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 11 Oct 2008 17:09:03 +0000 (17:09 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 11 Oct 2008 17:09:03 +0000 (17:09 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@3100 04897980-b3bd-0310-b5e0-8ef037075253

trunk/lttv/ltt/ltt-private.h
trunk/lttv/ltt/tracefile.c

index 1233b8fe8afa9d06e6602206e0ea682c40042506..24e82f291e25949da8a6ae7b3dd76fb1e6157b3b 100644 (file)
   (((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 };
 
index 64830859cfdf4d6df870c9742d4b86cb18ab63bb..d30dc51188b0470327cbb212253614fd1c99d536 100644 (file)
@@ -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);
   }
This page took 0.030636 seconds and 4 git commands to generate.