Merge branch 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
perf tools: Dont use openat()
perf tools: Fix buffer allocation
perf tools: .gitignore += perf*.html
perf tools: Handle relative paths while loading module symbols
perf tools: Fix module symbol loading bug
perf_event, x86: Fix 'perf sched record' crashing the machine
perf_event: Update PERF_EVENT_FORK header definition
perf stat: Fix zero total printouts

+120 -70
+3
arch/x86/kernel/cpu/perf_event.c
··· 1790 void set_perf_event_pending(void) 1791 { 1792 #ifdef CONFIG_X86_LOCAL_APIC 1793 apic->send_IPI_self(LOCAL_PENDING_VECTOR); 1794 #endif 1795 }
··· 1790 void set_perf_event_pending(void) 1791 { 1792 #ifdef CONFIG_X86_LOCAL_APIC 1793 + if (!x86_pmu.apic || !x86_pmu_initialized()) 1794 + return; 1795 + 1796 apic->send_IPI_self(LOCAL_PENDING_VECTOR); 1797 #endif 1798 }
+1 -1
include/linux/perf_counter.h
··· 361 * struct perf_event_header header; 362 * u32 pid, ppid; 363 * u32 tid, ptid; 364 - * { u64 time; } && PERF_SAMPLE_TIME 365 * }; 366 */ 367 PERF_EVENT_FORK = 7,
··· 361 * struct perf_event_header header; 362 * u32 pid, ppid; 363 * u32 tid, ptid; 364 + * u64 time; 365 * }; 366 */ 367 PERF_EVENT_FORK = 7,
+1 -1
include/linux/perf_event.h
··· 357 * struct perf_event_header header; 358 * u32 pid, ppid; 359 * u32 tid, ptid; 360 - * { u64 time; } && PERF_SAMPLE_TIME 361 * }; 362 */ 363 PERF_RECORD_FORK = 7,
··· 357 * struct perf_event_header header; 358 * u32 pid, ppid; 359 * u32 tid, ptid; 360 + * u64 time; 361 * }; 362 */ 363 PERF_RECORD_FORK = 7,
+1
tools/perf/.gitignore
··· 10 perf-top 11 perf*.1 12 perf*.xml 13 common-cmds.h 14 tags 15 TAGS
··· 10 perf-top 11 perf*.1 12 perf*.xml 13 + perf*.html 14 common-cmds.h 15 tags 16 TAGS
+14 -4
tools/perf/builtin-stat.c
··· 338 339 static void abs_printout(int counter, double avg) 340 { 341 fprintf(stderr, " %14.0f %-24s", avg, event_name(counter)); 342 343 if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { 344 - fprintf(stderr, " # %10.3f IPC ", 345 - avg / avg_stats(&runtime_cycles_stats)); 346 } else { 347 - fprintf(stderr, " # %10.3f M/sec", 348 - 1000.0 * avg / avg_stats(&runtime_nsecs_stats)); 349 } 350 } 351
··· 338 339 static void abs_printout(int counter, double avg) 340 { 341 + double total, ratio = 0.0; 342 + 343 fprintf(stderr, " %14.0f %-24s", avg, event_name(counter)); 344 345 if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { 346 + total = avg_stats(&runtime_cycles_stats); 347 + 348 + if (total) 349 + ratio = avg / total; 350 + 351 + fprintf(stderr, " # %10.3f IPC ", ratio); 352 } else { 353 + total = avg_stats(&runtime_nsecs_stats); 354 + 355 + if (total) 356 + ratio = 1000.0 * avg / total; 357 + 358 + fprintf(stderr, " # %10.3f M/sec", ratio); 359 } 360 } 361
+67 -31
tools/perf/util/module.c
··· 4 #include "module.h" 5 6 #include <libelf.h> 7 #include <gelf.h> 8 #include <elf.h> 9 #include <dirent.h> ··· 410 static int mod_dso__load_module_paths(struct mod_dso *self) 411 { 412 struct utsname uts; 413 - int count = 0, len; 414 char *line = NULL; 415 FILE *file; 416 - char *path; 417 size_t n; 418 419 if (uname(&uts) < 0) 420 - goto out_failure; 421 422 len = strlen("/lib/modules/"); 423 len += strlen(uts.release); 424 len += strlen("/modules.dep"); 425 426 - path = calloc(1, len); 427 - if (path == NULL) 428 - goto out_failure; 429 430 - strcat(path, "/lib/modules/"); 431 - strcat(path, uts.release); 432 - strcat(path, "/modules.dep"); 433 434 - file = fopen(path, "r"); 435 - free(path); 436 if (file == NULL) 437 goto out_failure; 438 439 while (!feof(file)) { 440 - char *name, *tmp; 441 struct module *module; 442 int line_len; 443 444 line_len = getline(&line, &n, file); ··· 451 break; 452 453 if (!line) 454 - goto out_failure; 455 456 line[--line_len] = '\0'; /* \n */ 457 458 - path = strtok(line, ":"); 459 if (!path) 460 - goto out_failure; 461 462 name = strdup(path); 463 - name = strtok(name, "/"); 464 465 tmp = name; 466 467 while (tmp) { ··· 493 if (tmp) 494 name = tmp; 495 } 496 - name = strsep(&name, "."); 497 498 - /* Quirk: replace '-' with '_' in sound modules */ 499 for (len = strlen(name); len; len--) { 500 if (*(name+len) == '-') 501 *(name+len) = '_'; 502 } 503 504 module = module__new(name, path); 505 - if (!module) { 506 - fprintf(stderr, "load_module_paths: allocation error\n"); 507 - goto out_failure; 508 - } 509 mod_dso__insert_module(self, module); 510 511 module->sections = sec_dso__new_dso("sections"); 512 - if (!module->sections) { 513 - fprintf(stderr, "load_module_paths: allocation error\n"); 514 - goto out_failure; 515 - } 516 517 module->active = mod_dso__load_sections(module); 518 ··· 519 count++; 520 } 521 522 - free(line); 523 - fclose(file); 524 - 525 - return count; 526 527 out_failure: 528 - return -1; 529 } 530 531 int mod_dso__load_modules(struct mod_dso *dso)
··· 4 #include "module.h" 5 6 #include <libelf.h> 7 + #include <libgen.h> 8 #include <gelf.h> 9 #include <elf.h> 10 #include <dirent.h> ··· 409 static int mod_dso__load_module_paths(struct mod_dso *self) 410 { 411 struct utsname uts; 412 + int count = 0, len, err = -1; 413 char *line = NULL; 414 FILE *file; 415 + char *dpath, *dir; 416 size_t n; 417 418 if (uname(&uts) < 0) 419 + return err; 420 421 len = strlen("/lib/modules/"); 422 len += strlen(uts.release); 423 len += strlen("/modules.dep"); 424 425 + dpath = calloc(1, len + 1); 426 + if (dpath == NULL) 427 + return err; 428 429 + strcat(dpath, "/lib/modules/"); 430 + strcat(dpath, uts.release); 431 + strcat(dpath, "/modules.dep"); 432 433 + file = fopen(dpath, "r"); 434 if (file == NULL) 435 goto out_failure; 436 437 + dir = dirname(dpath); 438 + if (!dir) 439 + goto out_failure; 440 + strcat(dir, "/"); 441 + 442 while (!feof(file)) { 443 struct module *module; 444 + char *name, *path, *tmp; 445 + FILE *modfile; 446 int line_len; 447 448 line_len = getline(&line, &n, file); ··· 445 break; 446 447 if (!line) 448 + break; 449 450 line[--line_len] = '\0'; /* \n */ 451 452 + path = strchr(line, ':'); 453 if (!path) 454 + break; 455 + *path = '\0'; 456 + 457 + path = strdup(line); 458 + if (!path) 459 + break; 460 + 461 + if (!strstr(path, dir)) { 462 + if (strncmp(path, "kernel/", 7)) 463 + break; 464 + 465 + free(path); 466 + path = calloc(1, strlen(dir) + strlen(line) + 1); 467 + if (!path) 468 + break; 469 + strcat(path, dir); 470 + strcat(path, line); 471 + } 472 + 473 + modfile = fopen(path, "r"); 474 + if (modfile == NULL) 475 + break; 476 + fclose(modfile); 477 478 name = strdup(path); 479 + if (!name) 480 + break; 481 482 + name = strtok(name, "/"); 483 tmp = name; 484 485 while (tmp) { ··· 463 if (tmp) 464 name = tmp; 465 } 466 467 + name = strsep(&name, "."); 468 + if (!name) 469 + break; 470 + 471 + /* Quirk: replace '-' with '_' in all modules */ 472 for (len = strlen(name); len; len--) { 473 if (*(name+len) == '-') 474 *(name+len) = '_'; 475 } 476 477 module = module__new(name, path); 478 + if (!module) 479 + break; 480 mod_dso__insert_module(self, module); 481 482 module->sections = sec_dso__new_dso("sections"); 483 + if (!module->sections) 484 + break; 485 486 module->active = mod_dso__load_sections(module); 487 ··· 490 count++; 491 } 492 493 + if (feof(file)) 494 + err = count; 495 + else 496 + fprintf(stderr, "load_module_paths: modules.dep parsing failure!\n"); 497 498 out_failure: 499 + if (dpath) 500 + free(dpath); 501 + if (file) 502 + fclose(file); 503 + if (line) 504 + free(line); 505 + 506 + return err; 507 } 508 509 int mod_dso__load_modules(struct mod_dso *dso)
+20 -29
tools/perf/util/parse-events.c
··· 165 DIR *sys_dir, *evt_dir; 166 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 167 char id_buf[4]; 168 - int sys_dir_fd, fd; 169 u64 id; 170 char evt_path[MAXPATHLEN]; 171 172 if (valid_debugfs_mount(debugfs_path)) 173 return NULL; 174 175 sys_dir = opendir(debugfs_path); 176 if (!sys_dir) 177 - goto cleanup; 178 - sys_dir_fd = dirfd(sys_dir); 179 180 for_each_subsystem(sys_dir, sys_dirent, sys_next) { 181 - int dfd = openat(sys_dir_fd, sys_dirent.d_name, 182 - O_RDONLY|O_DIRECTORY), evt_dir_fd; 183 - if (dfd == -1) 184 continue; 185 - evt_dir = fdopendir(dfd); 186 - if (!evt_dir) { 187 - close(dfd); 188 - continue; 189 - } 190 - evt_dir_fd = dirfd(evt_dir); 191 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { 192 - snprintf(evt_path, MAXPATHLEN, "%s/id", 193 evt_dirent.d_name); 194 - fd = openat(evt_dir_fd, evt_path, O_RDONLY); 195 if (fd < 0) 196 continue; 197 if (read(fd, id_buf, sizeof(id_buf)) < 0) { ··· 223 closedir(evt_dir); 224 } 225 226 - cleanup: 227 closedir(sys_dir); 228 return NULL; 229 } ··· 758 { 759 DIR *sys_dir, *evt_dir; 760 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 761 - int sys_dir_fd; 762 char evt_path[MAXPATHLEN]; 763 764 if (valid_debugfs_mount(debugfs_path)) 765 return; 766 767 sys_dir = opendir(debugfs_path); 768 if (!sys_dir) 769 - goto cleanup; 770 - sys_dir_fd = dirfd(sys_dir); 771 772 for_each_subsystem(sys_dir, sys_dirent, sys_next) { 773 - int dfd = openat(sys_dir_fd, sys_dirent.d_name, 774 - O_RDONLY|O_DIRECTORY), evt_dir_fd; 775 - if (dfd == -1) 776 continue; 777 - evt_dir = fdopendir(dfd); 778 - if (!evt_dir) { 779 - close(dfd); 780 - continue; 781 - } 782 - evt_dir_fd = dirfd(evt_dir); 783 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { 784 snprintf(evt_path, MAXPATHLEN, "%s:%s", 785 sys_dirent.d_name, evt_dirent.d_name); ··· 784 } 785 closedir(evt_dir); 786 } 787 - 788 - cleanup: 789 closedir(sys_dir); 790 } 791
··· 165 DIR *sys_dir, *evt_dir; 166 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 167 char id_buf[4]; 168 + int fd; 169 u64 id; 170 char evt_path[MAXPATHLEN]; 171 + char dir_path[MAXPATHLEN]; 172 173 if (valid_debugfs_mount(debugfs_path)) 174 return NULL; 175 176 sys_dir = opendir(debugfs_path); 177 if (!sys_dir) 178 + return NULL; 179 180 for_each_subsystem(sys_dir, sys_dirent, sys_next) { 181 + 182 + snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, 183 + sys_dirent.d_name); 184 + evt_dir = opendir(dir_path); 185 + if (!evt_dir) 186 continue; 187 + 188 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { 189 + 190 + snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, 191 evt_dirent.d_name); 192 + fd = open(evt_path, O_RDONLY); 193 if (fd < 0) 194 continue; 195 if (read(fd, id_buf, sizeof(id_buf)) < 0) { ··· 225 closedir(evt_dir); 226 } 227 228 closedir(sys_dir); 229 return NULL; 230 } ··· 761 { 762 DIR *sys_dir, *evt_dir; 763 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 764 char evt_path[MAXPATHLEN]; 765 + char dir_path[MAXPATHLEN]; 766 767 if (valid_debugfs_mount(debugfs_path)) 768 return; 769 770 sys_dir = opendir(debugfs_path); 771 if (!sys_dir) 772 + return; 773 774 for_each_subsystem(sys_dir, sys_dirent, sys_next) { 775 + 776 + snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, 777 + sys_dirent.d_name); 778 + evt_dir = opendir(dir_path); 779 + if (!evt_dir) 780 continue; 781 + 782 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { 783 snprintf(evt_path, MAXPATHLEN, "%s:%s", 784 sys_dirent.d_name, evt_dirent.d_name); ··· 791 } 792 closedir(evt_dir); 793 } 794 closedir(sys_dir); 795 } 796
+13 -4
tools/perf/util/symbol.c
··· 833 struct mod_dso *mods = mod_dso__new_dso("modules"); 834 struct module *pos; 835 struct rb_node *next; 836 - int err; 837 838 err = mod_dso__load_modules(mods); 839 ··· 852 break; 853 854 next = rb_next(&pos->rb_node); 855 } 856 857 if (err < 0) { 858 mod_dso__delete_modules(mods); 859 mod_dso__delete_self(mods); 860 } 861 862 - return err; 863 } 864 865 static inline void dso__fill_symbol_holes(struct dso *self) ··· 915 916 if (vmlinux) { 917 err = dso__load_vmlinux(self, vmlinux, filter, v); 918 - if (err > 0 && use_modules) 919 - err = dso__load_modules(self, filter, v); 920 } 921 922 if (err <= 0)
··· 833 struct mod_dso *mods = mod_dso__new_dso("modules"); 834 struct module *pos; 835 struct rb_node *next; 836 + int err, count = 0; 837 838 err = mod_dso__load_modules(mods); 839 ··· 852 break; 853 854 next = rb_next(&pos->rb_node); 855 + count += err; 856 } 857 858 if (err < 0) { 859 mod_dso__delete_modules(mods); 860 mod_dso__delete_self(mods); 861 + return err; 862 } 863 864 + return count; 865 } 866 867 static inline void dso__fill_symbol_holes(struct dso *self) ··· 913 914 if (vmlinux) { 915 err = dso__load_vmlinux(self, vmlinux, filter, v); 916 + if (err > 0 && use_modules) { 917 + int syms = dso__load_modules(self, filter, v); 918 + 919 + if (syms < 0) { 920 + fprintf(stderr, "dso__load_modules failed!\n"); 921 + return syms; 922 + } 923 + err += syms; 924 + } 925 } 926 927 if (err <= 0)