Commit 4da7e90e 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: Fix task_struct reference leak
  perf: Fix task context scheduling
  perf: mmap 512 kiB by default
  perf: Rebase max unprivileged mlock threshold on top of page size
  perf tools: Fix NO_NEWT=1 python build error
  perf symbols: Properly align symbol_conf.priv_size
  perf tools: Emit clearer message for sys_perf_event_open ENOENT return
  perf tools: Fixup exit path when not able to open events
  perf symbols: Fix vsyscall symbol lookup
  oprofile, x86: Allow setting EDGE/INV/CMASK for counter events
parents fb9a7d76 fd1edb3a
...@@ -49,6 +49,10 @@ u64 op_x86_get_ctrl(struct op_x86_model_spec const *model, ...@@ -49,6 +49,10 @@ u64 op_x86_get_ctrl(struct op_x86_model_spec const *model,
val |= counter_config->user ? ARCH_PERFMON_EVENTSEL_USR : 0; val |= counter_config->user ? ARCH_PERFMON_EVENTSEL_USR : 0;
val |= counter_config->kernel ? ARCH_PERFMON_EVENTSEL_OS : 0; val |= counter_config->kernel ? ARCH_PERFMON_EVENTSEL_OS : 0;
val |= (counter_config->unit_mask & 0xFF) << 8; val |= (counter_config->unit_mask & 0xFF) << 8;
counter_config->extra &= (ARCH_PERFMON_EVENTSEL_INV |
ARCH_PERFMON_EVENTSEL_EDGE |
ARCH_PERFMON_EVENTSEL_CMASK);
val |= counter_config->extra;
event &= model->event_mask ? model->event_mask : 0xFF; event &= model->event_mask ? model->event_mask : 0xFF;
val |= event & 0xFF; val |= event & 0xFF;
val |= (event & 0x0F00) << 24; val |= (event & 0x0F00) << 24;
...@@ -440,6 +444,7 @@ static int nmi_create_files(struct super_block *sb, struct dentry *root) ...@@ -440,6 +444,7 @@ static int nmi_create_files(struct super_block *sb, struct dentry *root)
oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask); oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel); oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user); oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
oprofilefs_create_ulong(sb, dir, "extra", &counter_config[i].extra);
} }
return 0; return 0;
......
...@@ -22,6 +22,7 @@ struct op_counter_config { ...@@ -22,6 +22,7 @@ struct op_counter_config {
unsigned long kernel; unsigned long kernel;
unsigned long user; unsigned long user;
unsigned long unit_mask; unsigned long unit_mask;
unsigned long extra;
}; };
extern struct op_counter_config counter_config[]; extern struct op_counter_config counter_config[];
......
...@@ -1086,7 +1086,7 @@ void perf_event_task_sched_out(struct task_struct *task, struct task_struct *nex ...@@ -1086,7 +1086,7 @@ void perf_event_task_sched_out(struct task_struct *task, struct task_struct *nex
{ {
perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0); perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0);
COND_STMT(&perf_sched_events, __perf_event_task_sched_out(task, next)); __perf_event_task_sched_out(task, next);
} }
extern void perf_event_mmap(struct vm_area_struct *vma); extern void perf_event_mmap(struct vm_area_struct *vma);
......
...@@ -145,8 +145,8 @@ static struct srcu_struct pmus_srcu; ...@@ -145,8 +145,8 @@ static struct srcu_struct pmus_srcu;
*/ */
int sysctl_perf_event_paranoid __read_mostly = 1; int sysctl_perf_event_paranoid __read_mostly = 1;
/* Minimum for 128 pages + 1 for the user control page */ /* Minimum for 512 kiB + 1 user control page */
int sysctl_perf_event_mlock __read_mostly = 516; /* 'free' kb per user */ int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
/* /*
* max perf event sample rate * max perf event sample rate
...@@ -6531,6 +6531,11 @@ SYSCALL_DEFINE5(perf_event_open, ...@@ -6531,6 +6531,11 @@ SYSCALL_DEFINE5(perf_event_open,
goto err_alloc; goto err_alloc;
} }
if (task) {
put_task_struct(task);
task = NULL;
}
/* /*
* Look up the group leader (we will attach this event to it): * Look up the group leader (we will attach this event to it):
*/ */
......
...@@ -165,8 +165,12 @@ grep-libs = $(filter -l%,$(1)) ...@@ -165,8 +165,12 @@ grep-libs = $(filter -l%,$(1))
strip-libs = $(filter-out -l%,$(1)) strip-libs = $(filter-out -l%,$(1))
$(OUTPUT)python/perf.so: $(PYRF_OBJS) $(OUTPUT)python/perf.so: $(PYRF_OBJS)
$(QUIET_GEN)python util/setup.py --quiet build_ext --build-lib='$(OUTPUT)python' \ $(QUIET_GEN)( \
--build-temp='$(OUTPUT)python/temp' export CFLAGS="$(BASIC_CFLAGS)"; \
python util/setup.py --quiet build_ext --build-lib='$(OUTPUT)python' \
--build-temp='$(OUTPUT)python/temp' \
)
# #
# No Perl scripts right now: # No Perl scripts right now:
# #
......
...@@ -41,7 +41,7 @@ static u64 user_interval = ULLONG_MAX; ...@@ -41,7 +41,7 @@ static u64 user_interval = ULLONG_MAX;
static u64 default_interval = 0; static u64 default_interval = 0;
static unsigned int page_size; static unsigned int page_size;
static unsigned int mmap_pages = 128; static unsigned int mmap_pages = UINT_MAX;
static unsigned int user_freq = UINT_MAX; static unsigned int user_freq = UINT_MAX;
static int freq = 1000; static int freq = 1000;
static int output; static int output;
...@@ -275,11 +275,10 @@ static void open_counters(struct perf_evlist *evlist) ...@@ -275,11 +275,10 @@ static void open_counters(struct perf_evlist *evlist)
!no_inherit) < 0) { !no_inherit) < 0) {
int err = errno; int err = errno;
if (err == EPERM || err == EACCES) if (err == EPERM || err == EACCES) {
die("Permission error - are you root?\n" ui__warning_paranoid();
"\t Consider tweaking" exit(EXIT_FAILURE);
" /proc/sys/kernel/perf_event_paranoid.\n"); } else if (err == ENODEV && cpu_list) {
else if (err == ENODEV && cpu_list) {
die("No such device - did you specify" die("No such device - did you specify"
" an out-of-range profile CPU?\n"); " an out-of-range profile CPU?\n");
} else if (err == EINVAL && sample_id_all_avail) { } else if (err == EINVAL && sample_id_all_avail) {
...@@ -302,11 +301,19 @@ static void open_counters(struct perf_evlist *evlist) ...@@ -302,11 +301,19 @@ static void open_counters(struct perf_evlist *evlist)
&& attr->config == PERF_COUNT_HW_CPU_CYCLES) { && attr->config == PERF_COUNT_HW_CPU_CYCLES) {
if (verbose) if (verbose)
warning(" ... trying to fall back to cpu-clock-ticks\n"); ui__warning("The cycles event is not supported, "
"trying to fall back to cpu-clock-ticks\n");
attr->type = PERF_TYPE_SOFTWARE; attr->type = PERF_TYPE_SOFTWARE;
attr->config = PERF_COUNT_SW_CPU_CLOCK; attr->config = PERF_COUNT_SW_CPU_CLOCK;
goto try_again; goto try_again;
} }
if (err == ENOENT) {
ui__warning("The %s event is not supported.\n",
event_name(pos));
exit(EXIT_FAILURE);
}
printf("\n"); printf("\n");
error("sys_perf_event_open() syscall returned with %d (%s). /bin/dmesg may provide additional information.\n", error("sys_perf_event_open() syscall returned with %d (%s). /bin/dmesg may provide additional information.\n",
err, strerror(err)); err, strerror(err));
...@@ -506,6 +513,10 @@ static int __cmd_record(int argc, const char **argv) ...@@ -506,6 +513,10 @@ static int __cmd_record(int argc, const char **argv)
if (have_tracepoints(&evsel_list->entries)) if (have_tracepoints(&evsel_list->entries))
perf_header__set_feat(&session->header, HEADER_TRACE_INFO); perf_header__set_feat(&session->header, HEADER_TRACE_INFO);
/* 512 kiB: default amount of unprivileged mlocked memory */
if (mmap_pages == UINT_MAX)
mmap_pages = (512 * 1024) / page_size;
if (forks) { if (forks) {
child_pid = fork(); child_pid = fork();
if (child_pid < 0) { if (child_pid < 0) {
......
...@@ -850,10 +850,10 @@ static void start_counters(struct perf_evlist *evlist) ...@@ -850,10 +850,10 @@ static void start_counters(struct perf_evlist *evlist)
top.evlist->threads, group, inherit) < 0) { top.evlist->threads, group, inherit) < 0) {
int err = errno; int err = errno;
if (err == EPERM || err == EACCES) if (err == EPERM || err == EACCES) {
die("Permission error - are you root?\n" ui__warning_paranoid();
"\t Consider tweaking" goto out_err;
" /proc/sys/kernel/perf_event_paranoid.\n"); }
/* /*
* If it's cycles then fall back to hrtimer * If it's cycles then fall back to hrtimer
* based cpu-clock-tick sw counter, which * based cpu-clock-tick sw counter, which
...@@ -861,25 +861,41 @@ static void start_counters(struct perf_evlist *evlist) ...@@ -861,25 +861,41 @@ static void start_counters(struct perf_evlist *evlist)
*/ */
if (attr->type == PERF_TYPE_HARDWARE && if (attr->type == PERF_TYPE_HARDWARE &&
attr->config == PERF_COUNT_HW_CPU_CYCLES) { attr->config == PERF_COUNT_HW_CPU_CYCLES) {
if (verbose) if (verbose)
warning(" ... trying to fall back to cpu-clock-ticks\n"); ui__warning("Cycles event not supported,\n"
"trying to fall back to cpu-clock-ticks\n");
attr->type = PERF_TYPE_SOFTWARE; attr->type = PERF_TYPE_SOFTWARE;
attr->config = PERF_COUNT_SW_CPU_CLOCK; attr->config = PERF_COUNT_SW_CPU_CLOCK;
goto try_again; goto try_again;
} }
printf("\n");
error("sys_perf_event_open() syscall returned with %d " if (err == ENOENT) {
"(%s). /bin/dmesg may provide additional information.\n", ui__warning("The %s event is not supported.\n",
err, strerror(err)); event_name(counter));
die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); goto out_err;
exit(-1); }
ui__warning("The sys_perf_event_open() syscall "
"returned with %d (%s). /bin/dmesg "
"may provide additional information.\n"
"No CONFIG_PERF_EVENTS=y kernel support "
"configured?\n", err, strerror(err));
goto out_err;
} }
} }
if (perf_evlist__mmap(evlist, mmap_pages, false) < 0) if (perf_evlist__mmap(evlist, mmap_pages, false) < 0) {
die("failed to mmap with %d (%s)\n", errno, strerror(errno)); ui__warning("Failed to mmap with %d (%s)\n",
errno, strerror(errno));
goto out_err;
}
return;
out_err:
exit_browser(0);
exit(0);
} }
static int __cmd_top(void) static int __cmd_top(void)
......
...@@ -57,6 +57,16 @@ void ui__warning(const char *format, ...) ...@@ -57,6 +57,16 @@ void ui__warning(const char *format, ...)
} }
#endif #endif
void ui__warning_paranoid(void)
{
ui__warning("Permission error - are you root?\n"
"Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
" -1 - Not paranoid at all\n"
" 0 - Disallow raw tracepoint access for unpriv\n"
" 1 - Disallow cpu events for unpriv\n"
" 2 - Disallow kernel profiling for unpriv\n");
}
void trace_event(union perf_event *event) void trace_event(union perf_event *event)
{ {
unsigned char *raw_event = (void *)event; unsigned char *raw_event = (void *)event;
......
...@@ -36,5 +36,6 @@ int ui_helpline__show_help(const char *format, va_list ap); ...@@ -36,5 +36,6 @@ int ui_helpline__show_help(const char *format, va_list ap);
#endif #endif
void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); void ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
void ui__warning_paranoid(void);
#endif /* __PERF_DEBUG_H */ #endif /* __PERF_DEBUG_H */
...@@ -710,7 +710,7 @@ void thread__find_addr_map(struct thread *self, ...@@ -710,7 +710,7 @@ void thread__find_addr_map(struct thread *self,
* in the whole kernel symbol list. * in the whole kernel symbol list.
*/ */
if ((long long)al->addr < 0 && if ((long long)al->addr < 0 &&
cpumode == PERF_RECORD_MISC_KERNEL && cpumode == PERF_RECORD_MISC_USER &&
machine && mg != &machine->kmaps) { machine && mg != &machine->kmaps) {
mg = &machine->kmaps; mg = &machine->kmaps;
goto try_again; goto try_again;
......
#!/usr/bin/python2 #!/usr/bin/python2
from distutils.core import setup, Extension from distutils.core import setup, Extension
from os import getenv
cflags = ['-fno-strict-aliasing', '-Wno-write-strings']
cflags += getenv('CFLAGS', '').split()
perf = Extension('perf', perf = Extension('perf',
sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c', sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c',
'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c', 'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c',
'util/util.c', 'util/xyarray.c', 'util/cgroup.c'], 'util/util.c', 'util/xyarray.c', 'util/cgroup.c'],
include_dirs = ['util/include'], include_dirs = ['util/include'],
extra_compile_args = ['-fno-strict-aliasing', '-Wno-write-strings']) extra_compile_args = cflags,
)
setup(name='perf', setup(name='perf',
version='0.1', version='0.1',
......
...@@ -1196,6 +1196,8 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, ...@@ -1196,6 +1196,8 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
if (curr_dso == NULL) if (curr_dso == NULL)
goto out_elf_end; goto out_elf_end;
curr_dso->kernel = self->kernel; curr_dso->kernel = self->kernel;
curr_dso->long_name = self->long_name;
curr_dso->long_name_len = self->long_name_len;
curr_map = map__new2(start, curr_dso, curr_map = map__new2(start, curr_dso,
map->type); map->type);
if (curr_map == NULL) { if (curr_map == NULL) {
...@@ -1842,6 +1844,7 @@ int dso__load_vmlinux(struct dso *self, struct map *map, ...@@ -1842,6 +1844,7 @@ int dso__load_vmlinux(struct dso *self, struct map *map,
if (fd < 0) if (fd < 0)
return -1; return -1;
dso__set_long_name(self, (char *)vmlinux);
dso__set_loaded(self, map->type); dso__set_loaded(self, map->type);
err = dso__load_sym(self, map, symfs_vmlinux, fd, filter, 0, 0); err = dso__load_sym(self, map, symfs_vmlinux, fd, filter, 0, 0);
close(fd); close(fd);
...@@ -2403,6 +2406,8 @@ int symbol__init(void) ...@@ -2403,6 +2406,8 @@ int symbol__init(void)
if (symbol_conf.initialized) if (symbol_conf.initialized)
return 0; return 0;
symbol_conf.priv_size = ALIGN(symbol_conf.priv_size, sizeof(u64));
elf_version(EV_CURRENT); elf_version(EV_CURRENT);
if (symbol_conf.sort_by_name) if (symbol_conf.sort_by_name)
symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) - symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
......
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