Commit 49e70dda authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'perf-fixes-for-linus' of...

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
parents 179b9145 725b1368
...@@ -1790,6 +1790,9 @@ void smp_perf_pending_interrupt(struct pt_regs *regs) ...@@ -1790,6 +1790,9 @@ void smp_perf_pending_interrupt(struct pt_regs *regs)
void set_perf_event_pending(void) void set_perf_event_pending(void)
{ {
#ifdef CONFIG_X86_LOCAL_APIC #ifdef CONFIG_X86_LOCAL_APIC
if (!x86_pmu.apic || !x86_pmu_initialized())
return;
apic->send_IPI_self(LOCAL_PENDING_VECTOR); apic->send_IPI_self(LOCAL_PENDING_VECTOR);
#endif #endif
} }
......
...@@ -361,7 +361,7 @@ enum perf_event_type { ...@@ -361,7 +361,7 @@ enum perf_event_type {
* struct perf_event_header header; * struct perf_event_header header;
* u32 pid, ppid; * u32 pid, ppid;
* u32 tid, ptid; * u32 tid, ptid;
* { u64 time; } && PERF_SAMPLE_TIME * u64 time;
* }; * };
*/ */
PERF_EVENT_FORK = 7, PERF_EVENT_FORK = 7,
......
...@@ -357,7 +357,7 @@ enum perf_event_type { ...@@ -357,7 +357,7 @@ enum perf_event_type {
* struct perf_event_header header; * struct perf_event_header header;
* u32 pid, ppid; * u32 pid, ppid;
* u32 tid, ptid; * u32 tid, ptid;
* { u64 time; } && PERF_SAMPLE_TIME * u64 time;
* }; * };
*/ */
PERF_RECORD_FORK = 7, PERF_RECORD_FORK = 7,
......
...@@ -10,6 +10,7 @@ perf-stat ...@@ -10,6 +10,7 @@ perf-stat
perf-top perf-top
perf*.1 perf*.1
perf*.xml perf*.xml
perf*.html
common-cmds.h common-cmds.h
tags tags
TAGS TAGS
......
...@@ -338,14 +338,24 @@ static void nsec_printout(int counter, double avg) ...@@ -338,14 +338,24 @@ static void nsec_printout(int counter, double avg)
static void abs_printout(int counter, double avg) static void abs_printout(int counter, double avg)
{ {
double total, ratio = 0.0;
fprintf(stderr, " %14.0f %-24s", avg, event_name(counter)); fprintf(stderr, " %14.0f %-24s", avg, event_name(counter));
if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) {
fprintf(stderr, " # %10.3f IPC ", total = avg_stats(&runtime_cycles_stats);
avg / avg_stats(&runtime_cycles_stats));
if (total)
ratio = avg / total;
fprintf(stderr, " # %10.3f IPC ", ratio);
} else { } else {
fprintf(stderr, " # %10.3f M/sec", total = avg_stats(&runtime_nsecs_stats);
1000.0 * avg / avg_stats(&runtime_nsecs_stats));
if (total)
ratio = 1000.0 * avg / total;
fprintf(stderr, " # %10.3f M/sec", ratio);
} }
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "module.h" #include "module.h"
#include <libelf.h> #include <libelf.h>
#include <libgen.h>
#include <gelf.h> #include <gelf.h>
#include <elf.h> #include <elf.h>
#include <dirent.h> #include <dirent.h>
...@@ -409,35 +410,40 @@ static int mod_dso__load_sections(struct module *mod) ...@@ -409,35 +410,40 @@ static int mod_dso__load_sections(struct module *mod)
static int mod_dso__load_module_paths(struct mod_dso *self) static int mod_dso__load_module_paths(struct mod_dso *self)
{ {
struct utsname uts; struct utsname uts;
int count = 0, len; int count = 0, len, err = -1;
char *line = NULL; char *line = NULL;
FILE *file; FILE *file;
char *path; char *dpath, *dir;
size_t n; size_t n;
if (uname(&uts) < 0) if (uname(&uts) < 0)
goto out_failure; return err;
len = strlen("/lib/modules/"); len = strlen("/lib/modules/");
len += strlen(uts.release); len += strlen(uts.release);
len += strlen("/modules.dep"); len += strlen("/modules.dep");
path = calloc(1, len); dpath = calloc(1, len + 1);
if (path == NULL) if (dpath == NULL)
goto out_failure; return err;
strcat(path, "/lib/modules/"); strcat(dpath, "/lib/modules/");
strcat(path, uts.release); strcat(dpath, uts.release);
strcat(path, "/modules.dep"); strcat(dpath, "/modules.dep");
file = fopen(path, "r"); file = fopen(dpath, "r");
free(path);
if (file == NULL) if (file == NULL)
goto out_failure; goto out_failure;
dir = dirname(dpath);
if (!dir)
goto out_failure;
strcat(dir, "/");
while (!feof(file)) { while (!feof(file)) {
char *name, *tmp;
struct module *module; struct module *module;
char *name, *path, *tmp;
FILE *modfile;
int line_len; int line_len;
line_len = getline(&line, &n, file); line_len = getline(&line, &n, file);
...@@ -445,17 +451,41 @@ static int mod_dso__load_module_paths(struct mod_dso *self) ...@@ -445,17 +451,41 @@ static int mod_dso__load_module_paths(struct mod_dso *self)
break; break;
if (!line) if (!line)
goto out_failure; break;
line[--line_len] = '\0'; /* \n */ line[--line_len] = '\0'; /* \n */
path = strtok(line, ":"); path = strchr(line, ':');
if (!path)
break;
*path = '\0';
path = strdup(line);
if (!path) if (!path)
goto out_failure; break;
if (!strstr(path, dir)) {
if (strncmp(path, "kernel/", 7))
break;
free(path);
path = calloc(1, strlen(dir) + strlen(line) + 1);
if (!path)
break;
strcat(path, dir);
strcat(path, line);
}
modfile = fopen(path, "r");
if (modfile == NULL)
break;
fclose(modfile);
name = strdup(path); name = strdup(path);
name = strtok(name, "/"); if (!name)
break;
name = strtok(name, "/");
tmp = name; tmp = name;
while (tmp) { while (tmp) {
...@@ -463,26 +493,25 @@ static int mod_dso__load_module_paths(struct mod_dso *self) ...@@ -463,26 +493,25 @@ static int mod_dso__load_module_paths(struct mod_dso *self)
if (tmp) if (tmp)
name = tmp; name = tmp;
} }
name = strsep(&name, "."); name = strsep(&name, ".");
if (!name)
break;
/* Quirk: replace '-' with '_' in sound modules */ /* Quirk: replace '-' with '_' in all modules */
for (len = strlen(name); len; len--) { for (len = strlen(name); len; len--) {
if (*(name+len) == '-') if (*(name+len) == '-')
*(name+len) = '_'; *(name+len) = '_';
} }
module = module__new(name, path); module = module__new(name, path);
if (!module) { if (!module)
fprintf(stderr, "load_module_paths: allocation error\n"); break;
goto out_failure;
}
mod_dso__insert_module(self, module); mod_dso__insert_module(self, module);
module->sections = sec_dso__new_dso("sections"); module->sections = sec_dso__new_dso("sections");
if (!module->sections) { if (!module->sections)
fprintf(stderr, "load_module_paths: allocation error\n"); break;
goto out_failure;
}
module->active = mod_dso__load_sections(module); module->active = mod_dso__load_sections(module);
...@@ -490,13 +519,20 @@ static int mod_dso__load_module_paths(struct mod_dso *self) ...@@ -490,13 +519,20 @@ static int mod_dso__load_module_paths(struct mod_dso *self)
count++; count++;
} }
free(line); if (feof(file))
fclose(file); err = count;
else
return count; fprintf(stderr, "load_module_paths: modules.dep parsing failure!\n");
out_failure: out_failure:
return -1; if (dpath)
free(dpath);
if (file)
fclose(file);
if (line)
free(line);
return err;
} }
int mod_dso__load_modules(struct mod_dso *dso) int mod_dso__load_modules(struct mod_dso *dso)
......
...@@ -165,33 +165,31 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -165,33 +165,31 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
char id_buf[4]; char id_buf[4];
int sys_dir_fd, fd; int fd;
u64 id; u64 id;
char evt_path[MAXPATHLEN]; char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];
if (valid_debugfs_mount(debugfs_path)) if (valid_debugfs_mount(debugfs_path))
return NULL; return NULL;
sys_dir = opendir(debugfs_path); sys_dir = opendir(debugfs_path);
if (!sys_dir) if (!sys_dir)
goto cleanup; return NULL;
sys_dir_fd = dirfd(sys_dir);
for_each_subsystem(sys_dir, sys_dirent, sys_next) { for_each_subsystem(sys_dir, sys_dirent, sys_next) {
int dfd = openat(sys_dir_fd, sys_dirent.d_name,
O_RDONLY|O_DIRECTORY), evt_dir_fd; snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
if (dfd == -1) sys_dirent.d_name);
continue; evt_dir = opendir(dir_path);
evt_dir = fdopendir(dfd); if (!evt_dir)
if (!evt_dir) {
close(dfd);
continue; continue;
}
evt_dir_fd = dirfd(evt_dir);
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
snprintf(evt_path, MAXPATHLEN, "%s/id",
snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
evt_dirent.d_name); evt_dirent.d_name);
fd = openat(evt_dir_fd, evt_path, O_RDONLY); fd = open(evt_path, O_RDONLY);
if (fd < 0) if (fd < 0)
continue; continue;
if (read(fd, id_buf, sizeof(id_buf)) < 0) { if (read(fd, id_buf, sizeof(id_buf)) < 0) {
...@@ -225,7 +223,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -225,7 +223,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
closedir(evt_dir); closedir(evt_dir);
} }
cleanup:
closedir(sys_dir); closedir(sys_dir);
return NULL; return NULL;
} }
...@@ -761,28 +758,24 @@ static void print_tracepoint_events(void) ...@@ -761,28 +758,24 @@ static void print_tracepoint_events(void)
{ {
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
int sys_dir_fd;
char evt_path[MAXPATHLEN]; char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];
if (valid_debugfs_mount(debugfs_path)) if (valid_debugfs_mount(debugfs_path))
return; return;
sys_dir = opendir(debugfs_path); sys_dir = opendir(debugfs_path);
if (!sys_dir) if (!sys_dir)
goto cleanup; return;
sys_dir_fd = dirfd(sys_dir);
for_each_subsystem(sys_dir, sys_dirent, sys_next) { for_each_subsystem(sys_dir, sys_dirent, sys_next) {
int dfd = openat(sys_dir_fd, sys_dirent.d_name,
O_RDONLY|O_DIRECTORY), evt_dir_fd; snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
if (dfd == -1) sys_dirent.d_name);
continue; evt_dir = opendir(dir_path);
evt_dir = fdopendir(dfd); if (!evt_dir)
if (!evt_dir) {
close(dfd);
continue; continue;
}
evt_dir_fd = dirfd(evt_dir);
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
snprintf(evt_path, MAXPATHLEN, "%s:%s", snprintf(evt_path, MAXPATHLEN, "%s:%s",
sys_dirent.d_name, evt_dirent.d_name); sys_dirent.d_name, evt_dirent.d_name);
...@@ -791,8 +784,6 @@ static void print_tracepoint_events(void) ...@@ -791,8 +784,6 @@ static void print_tracepoint_events(void)
} }
closedir(evt_dir); closedir(evt_dir);
} }
cleanup:
closedir(sys_dir); closedir(sys_dir);
} }
......
...@@ -833,7 +833,7 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int v) ...@@ -833,7 +833,7 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int v)
struct mod_dso *mods = mod_dso__new_dso("modules"); struct mod_dso *mods = mod_dso__new_dso("modules");
struct module *pos; struct module *pos;
struct rb_node *next; struct rb_node *next;
int err; int err, count = 0;
err = mod_dso__load_modules(mods); err = mod_dso__load_modules(mods);
...@@ -852,14 +852,16 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int v) ...@@ -852,14 +852,16 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int v)
break; break;
next = rb_next(&pos->rb_node); next = rb_next(&pos->rb_node);
count += err;
} }
if (err < 0) { if (err < 0) {
mod_dso__delete_modules(mods); mod_dso__delete_modules(mods);
mod_dso__delete_self(mods); mod_dso__delete_self(mods);
return err;
} }
return err; return count;
} }
static inline void dso__fill_symbol_holes(struct dso *self) static inline void dso__fill_symbol_holes(struct dso *self)
...@@ -913,8 +915,15 @@ int dso__load_kernel(struct dso *self, const char *vmlinux, ...@@ -913,8 +915,15 @@ int dso__load_kernel(struct dso *self, const char *vmlinux,
if (vmlinux) { if (vmlinux) {
err = dso__load_vmlinux(self, vmlinux, filter, v); err = dso__load_vmlinux(self, vmlinux, filter, v);
if (err > 0 && use_modules) if (err > 0 && use_modules) {
err = dso__load_modules(self, filter, v); int syms = dso__load_modules(self, filter, v);
if (syms < 0) {
fprintf(stderr, "dso__load_modules failed!\n");
return syms;
}
err += syms;
}
} }
if (err <= 0) if (err <= 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment