aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-07-17 19:35:14 -0400
committerSteven Rostedt <srostedt@redhat.com>2009-07-17 19:37:19 -0400
commitd52dd1f4601dc2c1de730b52c3e00267740b79c5 (patch)
tree0f09bd55e0dc501410117b77b6678fb900a4e853
parent4de0b9baa56cb9e7164b5cfc6ead489c0d1c8e53 (diff)
Use arch page size instead of hard coded 4096
Archs may use different page sizes. We must use the target arch page size for this instead of just hard coding 4096. This must also be saved in the data file so that it can be read by the host data. Also fixed the bigendian routine on the recording side. Signed-off-by: Steven Rostedt <srostedt@redhat.com>
-rw-r--r--parse-events.h8
-rw-r--r--trace-cmd.c24
-rw-r--r--trace-read.c43
3 files changed, 43 insertions, 32 deletions
diff --git a/parse-events.h b/parse-events.h
index 9ba633f..c11139d 100644
--- a/parse-events.h
+++ b/parse-events.h
@@ -1,12 +1,10 @@
1#ifndef _PARSE_EVENTS_H 1#ifndef _PARSE_EVENTS_H
2#define _PARSE_EVENTS_H 2#define _PARSE_EVENTS_H
3 3
4#ifndef PAGE_SIZE 4extern unsigned int page_size;
5#define PAGE_SIZE 4096ULL
6#endif
7 5
8#ifndef PAGE_MASK 6#ifndef PAGE_MASK
9#define PAGE_MASK (PAGE_SIZE - 1) 7#define PAGE_MASK (page_size - 1)
10#endif 8#endif
11 9
12enum { 10enum {
@@ -171,6 +169,8 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs);
171extern int file_bigendian; 169extern int file_bigendian;
172extern int host_bigendian; 170extern int host_bigendian;
173 171
172int bigendian(void);
173
174static inline unsigned short __data2host2(unsigned short data) 174static inline unsigned short __data2host2(unsigned short data)
175{ 175{
176 unsigned short swap; 176 unsigned short swap;
diff --git a/trace-cmd.c b/trace-cmd.c
index 72f070b..12581bc 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -49,6 +49,8 @@
49#define ITER_CTRL "trace_options" 49#define ITER_CTRL "trace_options"
50#define MAX_LATENCY "tracing_max_latency" 50#define MAX_LATENCY "tracing_max_latency"
51 51
52unsigned int page_size;
53
52static const char *output_file = "trace.dat"; 54static const char *output_file = "trace.dat";
53static int output_fd; 55static int output_fd;
54 56
@@ -513,7 +515,7 @@ static int create_recorder(int cpu)
513 int brass[2]; 515 int brass[2];
514 int pid; 516 int pid;
515 int ret; 517 int ret;
516 char buf[PAGE_SIZE]; 518 char buf[page_size];
517 519
518 pid = fork(); 520 pid = fork();
519 if (pid < 0) 521 if (pid < 0)
@@ -547,13 +549,13 @@ static int create_recorder(int cpu)
547 die("can not create pipe"); 549 die("can not create pipe");
548 550
549 do { 551 do {
550 ret = splice(in_fd, NULL, brass[1], NULL, PAGE_SIZE, 1 /* SPLICE_F_MOVE */); 552 ret = splice(in_fd, NULL, brass[1], NULL, page_size, 1 /* SPLICE_F_MOVE */);
551 if (ret < 0) { 553 if (ret < 0) {
552 perror("in"); 554 perror("in");
553 printf("errno=%d\n", errno); 555 printf("errno=%d\n", errno);
554 die("splice in"); 556 die("splice in");
555 } 557 }
556 ret = splice(brass[0], NULL, out_fd, NULL, PAGE_SIZE, 3 /* and NON_BLOCK */); 558 ret = splice(brass[0], NULL, out_fd, NULL, page_size, 3 /* and NON_BLOCK */);
557 if (ret < 0 && errno != EAGAIN) { 559 if (ret < 0 && errno != EAGAIN) {
558 perror("in"); 560 perror("in");
559 printf("errno=%d\n", errno); 561 printf("errno=%d\n", errno);
@@ -563,7 +565,7 @@ static int create_recorder(int cpu)
563 565
564 /* splice only reads full pages */ 566 /* splice only reads full pages */
565 do { 567 do {
566 ret = read(in_fd, buf, PAGE_SIZE); 568 ret = read(in_fd, buf, page_size);
567 if (ret > 0) 569 if (ret > 0)
568 write(out_fd, buf, ret); 570 write(out_fd, buf, ret);
569 } while (ret > 0); 571 } while (ret > 0);
@@ -601,13 +603,13 @@ static ssize_t write_or_die(const void *buf, size_t len)
601 return ret; 603 return ret;
602} 604}
603 605
604static int bigendian(void) 606int bigendian(void)
605{ 607{
606 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 }; 608 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
607 unsigned int *ptr; 609 unsigned int *ptr;
608 610
609 ptr = (unsigned int *)str; 611 ptr = (unsigned int *)str;
610 return *ptr == 0x1234; 612 return *ptr == 0x01020304;
611} 613}
612 614
613static unsigned long long copy_file_fd(int fd) 615static unsigned long long copy_file_fd(int fd)
@@ -864,6 +866,7 @@ static void read_tracing_data(void)
864 866
865 write_or_die(VERSION, strlen(VERSION) + 1); 867 write_or_die(VERSION, strlen(VERSION) + 1);
866 868
869 /* save endian */
867 if (bigendian()) 870 if (bigendian())
868 buf[0] = 1; 871 buf[0] = 1;
869 else 872 else
@@ -871,9 +874,14 @@ static void read_tracing_data(void)
871 874
872 write_or_die(buf, 1); 875 write_or_die(buf, 1);
873 876
877 /* save size of long */
874 buf[0] = sizeof(long); 878 buf[0] = sizeof(long);
875 write_or_die(buf, 1); 879 write_or_die(buf, 1);
876 880
881 /* save page_size */
882 page_size = getpagesize();
883 write_or_die(&page_size, 4);
884
877 read_header_files(); 885 read_header_files();
878 read_ftrace_files(); 886 read_ftrace_files();
879 read_event_files(); 887 read_event_files();
@@ -947,7 +955,7 @@ static void read_thread_data(void)
947 955
948 /* hold any extra data for data */ 956 /* hold any extra data for data */
949 offset += cpu_count * (16); 957 offset += cpu_count * (16);
950 offset = (offset + (PAGE_SIZE - 1)) & ~(PAGE_MASK); 958 offset = (offset + (page_size - 1)) & ~(PAGE_MASK);
951 959
952 for (i = 0; i < cpu_count; i++) { 960 for (i = 0; i < cpu_count; i++) {
953 file = malloc_or_die(strlen(output_file) + 20); 961 file = malloc_or_die(strlen(output_file) + 20);
@@ -959,7 +967,7 @@ static void read_thread_data(void)
959 offsets[i] = offset; 967 offsets[i] = offset;
960 sizes[i] = st.st_size; 968 sizes[i] = st.st_size;
961 offset += st.st_size; 969 offset += st.st_size;
962 offset = (offset + (PAGE_SIZE - 1)) & ~(PAGE_MASK); 970 offset = (offset + (page_size - 1)) & ~(PAGE_MASK);
963 971
964 write_or_die(&offsets[i], 8); 972 write_or_die(&offsets[i], 8);
965 write_or_die(&sizes[i], 8); 973 write_or_die(&sizes[i], 8);
diff --git a/trace-read.c b/trace-read.c
index ffb1374..91054b8 100644
--- a/trace-read.c
+++ b/trace-read.c
@@ -48,15 +48,6 @@ static int long_size;
48 48
49static int filter_cpu = -1; 49static int filter_cpu = -1;
50 50
51static int bigendian(void)
52{
53 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
54 unsigned int *ptr;
55
56 ptr = (unsigned int *)str;
57 return *ptr == 0x01020304;
58}
59
60static int read_or_die(void *data, int size) 51static int read_or_die(void *data, int size)
61{ 52{
62 int r; 53 int r;
@@ -257,7 +248,7 @@ static void init_read(int cpu)
257 off64_t ret; 248 off64_t ret;
258 off64_t save_seek; 249 off64_t save_seek;
259 250
260 cpu_data[cpu].page = malloc_or_die(PAGE_SIZE); 251 cpu_data[cpu].page = malloc_or_die(page_size);
261 252
262 /* other parts of the code may expect the pointer to not move */ 253 /* other parts of the code may expect the pointer to not move */
263 save_seek = lseek64(input_fd, 0, SEEK_CUR); 254 save_seek = lseek64(input_fd, 0, SEEK_CUR);
@@ -265,7 +256,7 @@ static void init_read(int cpu)
265 ret = lseek64(input_fd, (off64_t)cpu_data[cpu].offset, SEEK_SET); 256 ret = lseek64(input_fd, (off64_t)cpu_data[cpu].offset, SEEK_SET);
266 if (ret < 0) 257 if (ret < 0)
267 die("failed to lseek"); 258 die("failed to lseek");
268 ret = read(input_fd, cpu_data[cpu].page, PAGE_SIZE); 259 ret = read(input_fd, cpu_data[cpu].page, page_size);
269 if (ret < 0) 260 if (ret < 0)
270 die("failed to read page"); 261 die("failed to read page");
271 262
@@ -285,7 +276,7 @@ static void init_cpu(int cpu)
285 return; 276 return;
286 } 277 }
287 278
288 cpu_data[cpu].page = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, 279 cpu_data[cpu].page = mmap(NULL, page_size, PROT_READ, MAP_PRIVATE,
289 input_fd, cpu_data[cpu].offset); 280 input_fd, cpu_data[cpu].offset);
290 if (cpu_data[cpu].page == MAP_FAILED) { 281 if (cpu_data[cpu].page == MAP_FAILED) {
291 /* fall back to just reading pages */ 282 /* fall back to just reading pages */
@@ -298,8 +289,8 @@ static void init_cpu(int cpu)
298 289
299static void update_cpu_data_index(int cpu) 290static void update_cpu_data_index(int cpu)
300{ 291{
301 cpu_data[cpu].offset += PAGE_SIZE; 292 cpu_data[cpu].offset += page_size;
302 cpu_data[cpu].size -= PAGE_SIZE; 293 cpu_data[cpu].size -= page_size;
303 cpu_data[cpu].index = 0; 294 cpu_data[cpu].index = 0;
304} 295}
305 296
@@ -312,7 +303,7 @@ static void get_next_page(int cpu)
312 return; 303 return;
313 304
314 if (read_page) { 305 if (read_page) {
315 if (cpu_data[cpu].size <= PAGE_SIZE) { 306 if (cpu_data[cpu].size <= page_size) {
316 free(cpu_data[cpu].page); 307 free(cpu_data[cpu].page);
317 cpu_data[cpu].page = NULL; 308 cpu_data[cpu].page = NULL;
318 return; 309 return;
@@ -326,7 +317,7 @@ static void get_next_page(int cpu)
326 ret = lseek64(input_fd, cpu_data[cpu].offset, SEEK_SET); 317 ret = lseek64(input_fd, cpu_data[cpu].offset, SEEK_SET);
327 if (ret < 0) 318 if (ret < 0)
328 die("failed to lseek"); 319 die("failed to lseek");
329 ret = read(input_fd, cpu_data[cpu].page, PAGE_SIZE); 320 ret = read(input_fd, cpu_data[cpu].page, page_size);
330 if (ret < 0) 321 if (ret < 0)
331 die("failed to read page"); 322 die("failed to read page");
332 323
@@ -336,15 +327,15 @@ static void get_next_page(int cpu)
336 return; 327 return;
337 } 328 }
338 329
339 munmap(cpu_data[cpu].page, PAGE_SIZE); 330 munmap(cpu_data[cpu].page, page_size);
340 cpu_data[cpu].page = NULL; 331 cpu_data[cpu].page = NULL;
341 332
342 if (cpu_data[cpu].size <= PAGE_SIZE) 333 if (cpu_data[cpu].size <= page_size)
343 return; 334 return;
344 335
345 update_cpu_data_index(cpu); 336 update_cpu_data_index(cpu);
346 337
347 cpu_data[cpu].page = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, 338 cpu_data[cpu].page = mmap(NULL, page_size, PROT_READ, MAP_PRIVATE,
348 input_fd, cpu_data[cpu].offset); 339 input_fd, cpu_data[cpu].offset);
349 if (cpu_data[cpu].page == MAP_FAILED) 340 if (cpu_data[cpu].page == MAP_FAILED)
350 die("failed to mmap cpu %d at offset 0x%llx", 341 die("failed to mmap cpu %d at offset 0x%llx",
@@ -571,6 +562,7 @@ void trace_report (int argc, char **argv)
571 char *version; 562 char *version;
572 int show_funcs = 0; 563 int show_funcs = 0;
573 int show_endian = 0; 564 int show_endian = 0;
565 int show_page_size = 0;
574 int c; 566 int c;
575 567
576 if (argc < 2) 568 if (argc < 2)
@@ -587,7 +579,7 @@ void trace_report (int argc, char **argv)
587 {NULL, 0, NULL, 0} 579 {NULL, 0, NULL, 0}
588 }; 580 };
589 581
590 c = getopt_long (argc-1, argv+1, "+hi:fe", 582 c = getopt_long (argc-1, argv+1, "+hi:fep",
591 long_options, &option_index); 583 long_options, &option_index);
592 if (c == -1) 584 if (c == -1)
593 break; 585 break;
@@ -604,6 +596,9 @@ void trace_report (int argc, char **argv)
604 case 'e': 596 case 'e':
605 show_endian = 1; 597 show_endian = 1;
606 break; 598 break;
599 case 'p':
600 show_page_size = 1;
601 break;
607 case 0: 602 case 0:
608 switch(option_index) { 603 switch(option_index) {
609 case 0: 604 case 0:
@@ -641,6 +636,14 @@ void trace_report (int argc, char **argv)
641 read_or_die(buf, 1); 636 read_or_die(buf, 1);
642 long_size = buf[0]; 637 long_size = buf[0];
643 638
639 page_size = read4();
640 if (show_page_size) {
641 printf("file page size is %d, and host page size is %d\n",
642 page_size,
643 getpagesize());
644 return;
645 }
646
644 if (show_endian) { 647 if (show_endian) {
645 printf("file is %s endian and host is %s endian\n", 648 printf("file is %s endian and host is %s endian\n",
646 file_bigendian ? "big" : "little", 649 file_bigendian ? "big" : "little",