Skip to content

Commit

Permalink
Merge branch 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/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
  • Loading branch information
torvalds committed Sep 26, 2009
2 parents 179b914 + 725b136 commit 49e70dd
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 69 deletions.
3 changes: 3 additions & 0 deletions arch/x86/kernel/cpu/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,9 @@ void smp_perf_pending_interrupt(struct pt_regs *regs)
void set_perf_event_pending(void)
{
#ifdef CONFIG_X86_LOCAL_APIC
if (!x86_pmu.apic || !x86_pmu_initialized())
return;

apic->send_IPI_self(LOCAL_PENDING_VECTOR);
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ enum perf_event_type {
* struct perf_event_header header;
* u32 pid, ppid;
* u32 tid, ptid;
* { u64 time; } && PERF_SAMPLE_TIME
* u64 time;
* };
*/
PERF_EVENT_FORK = 7,
Expand Down
2 changes: 1 addition & 1 deletion include/linux/perf_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ enum perf_event_type {
* struct perf_event_header header;
* u32 pid, ppid;
* u32 tid, ptid;
* { u64 time; } && PERF_SAMPLE_TIME
* u64 time;
* };
*/
PERF_RECORD_FORK = 7,
Expand Down
1 change: 1 addition & 0 deletions tools/perf/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ perf-stat
perf-top
perf*.1
perf*.xml
perf*.html
common-cmds.h
tags
TAGS
Expand Down
18 changes: 14 additions & 4 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,24 @@ static void nsec_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));

if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) {
fprintf(stderr, " # %10.3f IPC ",
avg / avg_stats(&runtime_cycles_stats));
total = avg_stats(&runtime_cycles_stats);

if (total)
ratio = avg / total;

fprintf(stderr, " # %10.3f IPC ", ratio);
} else {
fprintf(stderr, " # %10.3f M/sec",
1000.0 * avg / avg_stats(&runtime_nsecs_stats));
total = avg_stats(&runtime_nsecs_stats);

if (total)
ratio = 1000.0 * avg / total;

fprintf(stderr, " # %10.3f M/sec", ratio);
}
}

Expand Down
96 changes: 66 additions & 30 deletions tools/perf/util/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "module.h"

#include <libelf.h>
#include <libgen.h>
#include <gelf.h>
#include <elf.h>
#include <dirent.h>
Expand Down Expand Up @@ -409,94 +410,129 @@ static int mod_dso__load_sections(struct module *mod)
static int mod_dso__load_module_paths(struct mod_dso *self)
{
struct utsname uts;
int count = 0, len;
int count = 0, len, err = -1;
char *line = NULL;
FILE *file;
char *path;
char *dpath, *dir;
size_t n;

if (uname(&uts) < 0)
goto out_failure;
return err;

len = strlen("/lib/modules/");
len += strlen(uts.release);
len += strlen("/modules.dep");

path = calloc(1, len);
if (path == NULL)
goto out_failure;
dpath = calloc(1, len + 1);
if (dpath == NULL)
return err;

strcat(path, "/lib/modules/");
strcat(path, uts.release);
strcat(path, "/modules.dep");
strcat(dpath, "/lib/modules/");
strcat(dpath, uts.release);
strcat(dpath, "/modules.dep");

file = fopen(path, "r");
free(path);
file = fopen(dpath, "r");
if (file == NULL)
goto out_failure;

dir = dirname(dpath);
if (!dir)
goto out_failure;
strcat(dir, "/");

while (!feof(file)) {
char *name, *tmp;
struct module *module;
char *name, *path, *tmp;
FILE *modfile;
int line_len;

line_len = getline(&line, &n, file);
if (line_len < 0)
break;

if (!line)
goto out_failure;
break;

line[--line_len] = '\0'; /* \n */

path = strtok(line, ":");
path = strchr(line, ':');
if (!path)
break;
*path = '\0';

path = strdup(line);
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 = strtok(name, "/");
if (!name)
break;

name = strtok(name, "/");
tmp = name;

while (tmp) {
tmp = strtok(NULL, "/");
if (tmp)
name = tmp;
}

name = strsep(&name, ".");
if (!name)
break;

/* Quirk: replace '-' with '_' in sound modules */
/* Quirk: replace '-' with '_' in all modules */
for (len = strlen(name); len; len--) {
if (*(name+len) == '-')
*(name+len) = '_';
}

module = module__new(name, path);
if (!module) {
fprintf(stderr, "load_module_paths: allocation error\n");
goto out_failure;
}
if (!module)
break;
mod_dso__insert_module(self, module);

module->sections = sec_dso__new_dso("sections");
if (!module->sections) {
fprintf(stderr, "load_module_paths: allocation error\n");
goto out_failure;
}
if (!module->sections)
break;

module->active = mod_dso__load_sections(module);

if (module->active > 0)
count++;
}

free(line);
fclose(file);

return count;
if (feof(file))
err = count;
else
fprintf(stderr, "load_module_paths: modules.dep parsing failure!\n");

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)
Expand Down
49 changes: 20 additions & 29 deletions tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,31 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
char id_buf[4];
int sys_dir_fd, fd;
int fd;
u64 id;
char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];

if (valid_debugfs_mount(debugfs_path))
return NULL;

sys_dir = opendir(debugfs_path);
if (!sys_dir)
goto cleanup;
sys_dir_fd = dirfd(sys_dir);
return NULL;

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;
if (dfd == -1)
continue;
evt_dir = fdopendir(dfd);
if (!evt_dir) {
close(dfd);

snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
sys_dirent.d_name);
evt_dir = opendir(dir_path);
if (!evt_dir)
continue;
}
evt_dir_fd = dirfd(evt_dir);

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);
fd = openat(evt_dir_fd, evt_path, O_RDONLY);
fd = open(evt_path, O_RDONLY);
if (fd < 0)
continue;
if (read(fd, id_buf, sizeof(id_buf)) < 0) {
Expand Down Expand Up @@ -225,7 +223,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
closedir(evt_dir);
}

cleanup:
closedir(sys_dir);
return NULL;
}
Expand Down Expand Up @@ -761,28 +758,24 @@ static void print_tracepoint_events(void)
{
DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
int sys_dir_fd;
char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];

if (valid_debugfs_mount(debugfs_path))
return;

sys_dir = opendir(debugfs_path);
if (!sys_dir)
goto cleanup;
sys_dir_fd = dirfd(sys_dir);
return;

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;
if (dfd == -1)
continue;
evt_dir = fdopendir(dfd);
if (!evt_dir) {
close(dfd);

snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
sys_dirent.d_name);
evt_dir = opendir(dir_path);
if (!evt_dir)
continue;
}
evt_dir_fd = dirfd(evt_dir);

for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
snprintf(evt_path, MAXPATHLEN, "%s:%s",
sys_dirent.d_name, evt_dirent.d_name);
Expand All @@ -791,8 +784,6 @@ static void print_tracepoint_events(void)
}
closedir(evt_dir);
}

cleanup:
closedir(sys_dir);
}

Expand Down
17 changes: 13 additions & 4 deletions tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 module *pos;
struct rb_node *next;
int err;
int err, count = 0;

err = mod_dso__load_modules(mods);

Expand All @@ -852,14 +852,16 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int v)
break;

next = rb_next(&pos->rb_node);
count += err;
}

if (err < 0) {
mod_dso__delete_modules(mods);
mod_dso__delete_self(mods);
return err;
}

return err;
return count;
}

static inline void dso__fill_symbol_holes(struct dso *self)
Expand Down Expand Up @@ -913,8 +915,15 @@ int dso__load_kernel(struct dso *self, const char *vmlinux,

if (vmlinux) {
err = dso__load_vmlinux(self, vmlinux, filter, v);
if (err > 0 && use_modules)
err = dso__load_modules(self, filter, v);
if (err > 0 && use_modules) {
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)
Expand Down

0 comments on commit 49e70dd

Please sign in to comment.