Commit f7f4d43b authored by Linus Torvalds's avatar Linus Torvalds

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

Pull perf fixes from Ingo Molnar:
 "An uncharacteristically large number of bugs popped up in the last
  week:

   - various tooling fixes, two crashes and build problems
   - two Intel PT fixes
   - an KNL uncore driver fix
   - an Intel PMU driver fix"

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  perf stat: Fallback to user only counters when perf_event_paranoid > 1
  perf evsel: Handle EACCESS + perf_event_paranoid=2 in fallback()
  perf evsel: Improve EPERM error handling in open_strerror()
  tools lib traceevent: Do not reassign parg after collapse_tree()
  perf probe: Check if dwarf_getlocations() is available
  perf dwarf: Guard !x86_64 definitions under #ifdef else clause
  perf tools: Use readdir() instead of deprecated readdir_r()
  perf thread_map: Use readdir() instead of deprecated readdir_r()
  perf script: Use readdir() instead of deprecated readdir_r()
  perf tools: Use readdir() instead of deprecated readdir_r()
  perf/core: Disable the event on a truncated AUX record
  perf/x86/intel/pt: Generate PMI in the STOP region as well
  perf/x86: Fix undefined shift on 32-bit kernels
  perf/x86/msr: Fix SMI overflow
  perf/x86/intel/uncore: Fix CHA registers configuration procedure for Knights Landing platform
  perf diff: Fix duplicated output column
parents 18759462 636fa4a7
...@@ -3708,7 +3708,7 @@ __init int intel_pmu_init(void) ...@@ -3708,7 +3708,7 @@ __init int intel_pmu_init(void)
c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1; c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1;
} }
c->idxmsk64 &= c->idxmsk64 &=
~(~0UL << (INTEL_PMC_IDX_FIXED + x86_pmu.num_counters_fixed)); ~(~0ULL << (INTEL_PMC_IDX_FIXED + x86_pmu.num_counters_fixed));
c->weight = hweight64(c->idxmsk64); c->weight = hweight64(c->idxmsk64);
} }
} }
......
...@@ -709,6 +709,7 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf, ...@@ -709,6 +709,7 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf,
/* clear STOP and INT from current entry */ /* clear STOP and INT from current entry */
buf->topa_index[buf->stop_pos]->stop = 0; buf->topa_index[buf->stop_pos]->stop = 0;
buf->topa_index[buf->stop_pos]->intr = 0;
buf->topa_index[buf->intr_pos]->intr = 0; buf->topa_index[buf->intr_pos]->intr = 0;
/* how many pages till the STOP marker */ /* how many pages till the STOP marker */
...@@ -733,6 +734,7 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf, ...@@ -733,6 +734,7 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf,
buf->intr_pos = idx; buf->intr_pos = idx;
buf->topa_index[buf->stop_pos]->stop = 1; buf->topa_index[buf->stop_pos]->stop = 1;
buf->topa_index[buf->stop_pos]->intr = 1;
buf->topa_index[buf->intr_pos]->intr = 1; buf->topa_index[buf->intr_pos]->intr = 1;
return 0; return 0;
......
...@@ -219,6 +219,9 @@ ...@@ -219,6 +219,9 @@
#define KNL_CHA_MSR_PMON_BOX_FILTER_TID 0x1ff #define KNL_CHA_MSR_PMON_BOX_FILTER_TID 0x1ff
#define KNL_CHA_MSR_PMON_BOX_FILTER_STATE (7 << 18) #define KNL_CHA_MSR_PMON_BOX_FILTER_STATE (7 << 18)
#define KNL_CHA_MSR_PMON_BOX_FILTER_OP (0xfffffe2aULL << 32) #define KNL_CHA_MSR_PMON_BOX_FILTER_OP (0xfffffe2aULL << 32)
#define KNL_CHA_MSR_PMON_BOX_FILTER_REMOTE_NODE (0x1ULL << 32)
#define KNL_CHA_MSR_PMON_BOX_FILTER_LOCAL_NODE (0x1ULL << 33)
#define KNL_CHA_MSR_PMON_BOX_FILTER_NNC (0x1ULL << 37)
/* KNL EDC/MC UCLK */ /* KNL EDC/MC UCLK */
#define KNL_UCLK_MSR_PMON_CTR0_LOW 0x400 #define KNL_UCLK_MSR_PMON_CTR0_LOW 0x400
...@@ -1902,6 +1905,10 @@ static int knl_cha_hw_config(struct intel_uncore_box *box, ...@@ -1902,6 +1905,10 @@ static int knl_cha_hw_config(struct intel_uncore_box *box,
reg1->reg = HSWEP_C0_MSR_PMON_BOX_FILTER0 + reg1->reg = HSWEP_C0_MSR_PMON_BOX_FILTER0 +
KNL_CHA_MSR_OFFSET * box->pmu->pmu_idx; KNL_CHA_MSR_OFFSET * box->pmu->pmu_idx;
reg1->config = event->attr.config1 & knl_cha_filter_mask(idx); reg1->config = event->attr.config1 & knl_cha_filter_mask(idx);
reg1->config |= KNL_CHA_MSR_PMON_BOX_FILTER_REMOTE_NODE;
reg1->config |= KNL_CHA_MSR_PMON_BOX_FILTER_LOCAL_NODE;
reg1->config |= KNL_CHA_MSR_PMON_BOX_FILTER_NNC;
reg1->idx = idx; reg1->idx = idx;
} }
return 0; return 0;
......
...@@ -166,7 +166,7 @@ static void msr_event_update(struct perf_event *event) ...@@ -166,7 +166,7 @@ static void msr_event_update(struct perf_event *event)
if (unlikely(event->hw.event_base == MSR_SMI_COUNT)) if (unlikely(event->hw.event_base == MSR_SMI_COUNT))
delta = sign_extend64(delta, 31); delta = sign_extend64(delta, 31);
local64_add(now - prev, &event->count); local64_add(delta, &event->count);
} }
static void msr_event_start(struct perf_event *event, int flags) static void msr_event_start(struct perf_event *event, int flags)
......
...@@ -347,6 +347,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size, ...@@ -347,6 +347,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
bool truncated) bool truncated)
{ {
struct ring_buffer *rb = handle->rb; struct ring_buffer *rb = handle->rb;
bool wakeup = truncated;
unsigned long aux_head; unsigned long aux_head;
u64 flags = 0; u64 flags = 0;
...@@ -375,9 +376,16 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size, ...@@ -375,9 +376,16 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
aux_head = rb->user_page->aux_head = local_read(&rb->aux_head); aux_head = rb->user_page->aux_head = local_read(&rb->aux_head);
if (aux_head - local_read(&rb->aux_wakeup) >= rb->aux_watermark) { if (aux_head - local_read(&rb->aux_wakeup) >= rb->aux_watermark) {
perf_output_wakeup(handle); wakeup = true;
local_add(rb->aux_watermark, &rb->aux_wakeup); local_add(rb->aux_watermark, &rb->aux_wakeup);
} }
if (wakeup) {
if (truncated)
handle->event->pending_disable = 1;
perf_output_wakeup(handle);
}
handle->event = NULL; handle->event = NULL;
local_set(&rb->aux_nest, 0); local_set(&rb->aux_nest, 0);
......
...@@ -30,6 +30,7 @@ endef ...@@ -30,6 +30,7 @@ endef
FEATURE_TESTS_BASIC := \ FEATURE_TESTS_BASIC := \
backtrace \ backtrace \
dwarf \ dwarf \
dwarf_getlocations \
fortify-source \ fortify-source \
sync-compare-and-swap \ sync-compare-and-swap \
glibc \ glibc \
...@@ -78,6 +79,7 @@ endif ...@@ -78,6 +79,7 @@ endif
FEATURE_DISPLAY ?= \ FEATURE_DISPLAY ?= \
dwarf \ dwarf \
dwarf_getlocations \
glibc \ glibc \
gtk2 \ gtk2 \
libaudit \ libaudit \
......
...@@ -3,6 +3,7 @@ FILES= \ ...@@ -3,6 +3,7 @@ FILES= \
test-backtrace.bin \ test-backtrace.bin \
test-bionic.bin \ test-bionic.bin \
test-dwarf.bin \ test-dwarf.bin \
test-dwarf_getlocations.bin \
test-fortify-source.bin \ test-fortify-source.bin \
test-sync-compare-and-swap.bin \ test-sync-compare-and-swap.bin \
test-glibc.bin \ test-glibc.bin \
...@@ -82,6 +83,9 @@ endif ...@@ -82,6 +83,9 @@ endif
$(OUTPUT)test-dwarf.bin: $(OUTPUT)test-dwarf.bin:
$(BUILD) $(DWARFLIBS) $(BUILD) $(DWARFLIBS)
$(OUTPUT)test-dwarf_getlocations.bin:
$(BUILD) $(DWARFLIBS)
$(OUTPUT)test-libelf-mmap.bin: $(OUTPUT)test-libelf-mmap.bin:
$(BUILD) -lelf $(BUILD) -lelf
......
...@@ -41,6 +41,10 @@ ...@@ -41,6 +41,10 @@
# include "test-dwarf.c" # include "test-dwarf.c"
#undef main #undef main
#define main main_test_dwarf_getlocations
# include "test-dwarf_getlocations.c"
#undef main
#define main main_test_libelf_getphdrnum #define main main_test_libelf_getphdrnum
# include "test-libelf-getphdrnum.c" # include "test-libelf-getphdrnum.c"
#undef main #undef main
...@@ -143,6 +147,7 @@ int main(int argc, char *argv[]) ...@@ -143,6 +147,7 @@ int main(int argc, char *argv[])
main_test_libelf_mmap(); main_test_libelf_mmap();
main_test_glibc(); main_test_glibc();
main_test_dwarf(); main_test_dwarf();
main_test_dwarf_getlocations();
main_test_libelf_getphdrnum(); main_test_libelf_getphdrnum();
main_test_libunwind(); main_test_libunwind();
main_test_libaudit(); main_test_libaudit();
......
#include <stdlib.h>
#include <elfutils/libdw.h>
int main(void)
{
Dwarf_Addr base, start, end;
Dwarf_Attribute attr;
Dwarf_Op *op;
size_t nops;
ptrdiff_t offset = 0;
return (int)dwarf_getlocations(&attr, offset, &base, &start, &end, &op, &nops);
}
...@@ -1164,11 +1164,11 @@ process_filter(struct event_format *event, struct filter_arg **parg, ...@@ -1164,11 +1164,11 @@ process_filter(struct event_format *event, struct filter_arg **parg,
current_op = current_exp; current_op = current_exp;
ret = collapse_tree(current_op, parg, error_str); ret = collapse_tree(current_op, parg, error_str);
/* collapse_tree() may free current_op, and updates parg accordingly */
current_op = NULL;
if (ret < 0) if (ret < 0)
goto fail; goto fail;
*parg = current_op;
free(token); free(token);
return 0; return 0;
......
...@@ -63,6 +63,8 @@ struct pt_regs_offset { ...@@ -63,6 +63,8 @@ struct pt_regs_offset {
# define REG_OFFSET_NAME_32(n, r) {.name = n, .offset = offsetof(struct pt_regs, r)} # define REG_OFFSET_NAME_32(n, r) {.name = n, .offset = offsetof(struct pt_regs, r)}
#endif #endif
/* TODO: switching by dwarf address size */
#ifndef __x86_64__
static const struct pt_regs_offset x86_32_regoffset_table[] = { static const struct pt_regs_offset x86_32_regoffset_table[] = {
REG_OFFSET_NAME_32("%ax", eax), REG_OFFSET_NAME_32("%ax", eax),
REG_OFFSET_NAME_32("%cx", ecx), REG_OFFSET_NAME_32("%cx", ecx),
...@@ -75,6 +77,8 @@ static const struct pt_regs_offset x86_32_regoffset_table[] = { ...@@ -75,6 +77,8 @@ static const struct pt_regs_offset x86_32_regoffset_table[] = {
REG_OFFSET_END, REG_OFFSET_END,
}; };
#define regoffset_table x86_32_regoffset_table
#else
static const struct pt_regs_offset x86_64_regoffset_table[] = { static const struct pt_regs_offset x86_64_regoffset_table[] = {
REG_OFFSET_NAME_64("%ax", rax), REG_OFFSET_NAME_64("%ax", rax),
REG_OFFSET_NAME_64("%dx", rdx), REG_OFFSET_NAME_64("%dx", rdx),
...@@ -95,11 +99,7 @@ static const struct pt_regs_offset x86_64_regoffset_table[] = { ...@@ -95,11 +99,7 @@ static const struct pt_regs_offset x86_64_regoffset_table[] = {
REG_OFFSET_END, REG_OFFSET_END,
}; };
/* TODO: switching by dwarf address size */
#ifdef __x86_64__
#define regoffset_table x86_64_regoffset_table #define regoffset_table x86_64_regoffset_table
#else
#define regoffset_table x86_32_regoffset_table
#endif #endif
/* Minus 1 for the ending REG_OFFSET_END */ /* Minus 1 for the ending REG_OFFSET_END */
......
...@@ -1415,21 +1415,19 @@ static int is_directory(const char *base_path, const struct dirent *dent) ...@@ -1415,21 +1415,19 @@ static int is_directory(const char *base_path, const struct dirent *dent)
return S_ISDIR(st.st_mode); return S_ISDIR(st.st_mode);
} }
#define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\ #define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \ while ((lang_dirent = readdir(scripts_dir)) != NULL) \
lang_next) \ if ((lang_dirent->d_type == DT_DIR || \
if ((lang_dirent.d_type == DT_DIR || \ (lang_dirent->d_type == DT_UNKNOWN && \
(lang_dirent.d_type == DT_UNKNOWN && \ is_directory(scripts_path, lang_dirent))) && \
is_directory(scripts_path, &lang_dirent))) && \ (strcmp(lang_dirent->d_name, ".")) && \
(strcmp(lang_dirent.d_name, ".")) && \ (strcmp(lang_dirent->d_name, "..")))
(strcmp(lang_dirent.d_name, "..")))
#define for_each_script(lang_path, lang_dir, script_dirent) \
#define for_each_script(lang_path, lang_dir, script_dirent, script_next)\ while ((script_dirent = readdir(lang_dir)) != NULL) \
while (!readdir_r(lang_dir, &script_dirent, &script_next) && \ if (script_dirent->d_type != DT_DIR && \
script_next) \ (script_dirent->d_type != DT_UNKNOWN || \
if (script_dirent.d_type != DT_DIR && \ !is_directory(lang_path, script_dirent)))
(script_dirent.d_type != DT_UNKNOWN || \
!is_directory(lang_path, &script_dirent)))
#define RECORD_SUFFIX "-record" #define RECORD_SUFFIX "-record"
...@@ -1575,7 +1573,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused, ...@@ -1575,7 +1573,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
const char *s __maybe_unused, const char *s __maybe_unused,
int unset __maybe_unused) int unset __maybe_unused)
{ {
struct dirent *script_next, *lang_next, script_dirent, lang_dirent; struct dirent *script_dirent, *lang_dirent;
char scripts_path[MAXPATHLEN]; char scripts_path[MAXPATHLEN];
DIR *scripts_dir, *lang_dir; DIR *scripts_dir, *lang_dir;
char script_path[MAXPATHLEN]; char script_path[MAXPATHLEN];
...@@ -1590,19 +1588,19 @@ static int list_available_scripts(const struct option *opt __maybe_unused, ...@@ -1590,19 +1588,19 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
if (!scripts_dir) if (!scripts_dir)
return -1; return -1;
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { for_each_lang(scripts_path, scripts_dir, lang_dirent) {
snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
lang_dirent.d_name); lang_dirent->d_name);
lang_dir = opendir(lang_path); lang_dir = opendir(lang_path);
if (!lang_dir) if (!lang_dir)
continue; continue;
for_each_script(lang_path, lang_dir, script_dirent, script_next) { for_each_script(lang_path, lang_dir, script_dirent) {
script_root = get_script_root(&script_dirent, REPORT_SUFFIX); script_root = get_script_root(script_dirent, REPORT_SUFFIX);
if (script_root) { if (script_root) {
desc = script_desc__findnew(script_root); desc = script_desc__findnew(script_root);
snprintf(script_path, MAXPATHLEN, "%s/%s", snprintf(script_path, MAXPATHLEN, "%s/%s",
lang_path, script_dirent.d_name); lang_path, script_dirent->d_name);
read_script_info(desc, script_path); read_script_info(desc, script_path);
free(script_root); free(script_root);
} }
...@@ -1690,7 +1688,7 @@ static int check_ev_match(char *dir_name, char *scriptname, ...@@ -1690,7 +1688,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
*/ */
int find_scripts(char **scripts_array, char **scripts_path_array) int find_scripts(char **scripts_array, char **scripts_path_array)
{ {
struct dirent *script_next, *lang_next, script_dirent, lang_dirent; struct dirent *script_dirent, *lang_dirent;
char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
DIR *scripts_dir, *lang_dir; DIR *scripts_dir, *lang_dir;
struct perf_session *session; struct perf_session *session;
...@@ -1713,9 +1711,9 @@ int find_scripts(char **scripts_array, char **scripts_path_array) ...@@ -1713,9 +1711,9 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
return -1; return -1;
} }
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { for_each_lang(scripts_path, scripts_dir, lang_dirent) {
snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
lang_dirent.d_name); lang_dirent->d_name);
#ifdef NO_LIBPERL #ifdef NO_LIBPERL
if (strstr(lang_path, "perl")) if (strstr(lang_path, "perl"))
continue; continue;
...@@ -1729,16 +1727,16 @@ int find_scripts(char **scripts_array, char **scripts_path_array) ...@@ -1729,16 +1727,16 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
if (!lang_dir) if (!lang_dir)
continue; continue;
for_each_script(lang_path, lang_dir, script_dirent, script_next) { for_each_script(lang_path, lang_dir, script_dirent) {
/* Skip those real time scripts: xxxtop.p[yl] */ /* Skip those real time scripts: xxxtop.p[yl] */
if (strstr(script_dirent.d_name, "top.")) if (strstr(script_dirent->d_name, "top."))
continue; continue;
sprintf(scripts_path_array[i], "%s/%s", lang_path, sprintf(scripts_path_array[i], "%s/%s", lang_path,
script_dirent.d_name); script_dirent->d_name);
temp = strchr(script_dirent.d_name, '.'); temp = strchr(script_dirent->d_name, '.');
snprintf(scripts_array[i], snprintf(scripts_array[i],
(temp - script_dirent.d_name) + 1, (temp - script_dirent->d_name) + 1,
"%s", script_dirent.d_name); "%s", script_dirent->d_name);
if (check_ev_match(lang_path, if (check_ev_match(lang_path,
scripts_array[i], session)) scripts_array[i], session))
...@@ -1756,7 +1754,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array) ...@@ -1756,7 +1754,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
static char *get_script_path(const char *script_root, const char *suffix) static char *get_script_path(const char *script_root, const char *suffix)
{ {
struct dirent *script_next, *lang_next, script_dirent, lang_dirent; struct dirent *script_dirent, *lang_dirent;
char scripts_path[MAXPATHLEN]; char scripts_path[MAXPATHLEN];
char script_path[MAXPATHLEN]; char script_path[MAXPATHLEN];
DIR *scripts_dir, *lang_dir; DIR *scripts_dir, *lang_dir;
...@@ -1769,21 +1767,21 @@ static char *get_script_path(const char *script_root, const char *suffix) ...@@ -1769,21 +1767,21 @@ static char *get_script_path(const char *script_root, const char *suffix)
if (!scripts_dir) if (!scripts_dir)
return NULL; return NULL;
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { for_each_lang(scripts_path, scripts_dir, lang_dirent) {
snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
lang_dirent.d_name); lang_dirent->d_name);
lang_dir = opendir(lang_path); lang_dir = opendir(lang_path);
if (!lang_dir) if (!lang_dir)
continue; continue;
for_each_script(lang_path, lang_dir, script_dirent, script_next) { for_each_script(lang_path, lang_dir, script_dirent) {
__script_root = get_script_root(&script_dirent, suffix); __script_root = get_script_root(script_dirent, suffix);
if (__script_root && !strcmp(script_root, __script_root)) { if (__script_root && !strcmp(script_root, __script_root)) {
free(__script_root); free(__script_root);
closedir(lang_dir); closedir(lang_dir);
closedir(scripts_dir); closedir(scripts_dir);
snprintf(script_path, MAXPATHLEN, "%s/%s", snprintf(script_path, MAXPATHLEN, "%s/%s",
lang_path, script_dirent.d_name); lang_path, script_dirent->d_name);
return strdup(script_path); return strdup(script_path);
} }
free(__script_root); free(__script_root);
......
...@@ -528,6 +528,7 @@ static int __run_perf_stat(int argc, const char **argv) ...@@ -528,6 +528,7 @@ static int __run_perf_stat(int argc, const char **argv)
perf_evlist__set_leader(evsel_list); perf_evlist__set_leader(evsel_list);
evlist__for_each(evsel_list, counter) { evlist__for_each(evsel_list, counter) {
try_again:
if (create_perf_stat_counter(counter) < 0) { if (create_perf_stat_counter(counter) < 0) {
/* /*
* PPC returns ENXIO for HW counters until 2.6.37 * PPC returns ENXIO for HW counters until 2.6.37
...@@ -544,6 +545,10 @@ static int __run_perf_stat(int argc, const char **argv) ...@@ -544,6 +545,10 @@ static int __run_perf_stat(int argc, const char **argv)
if ((counter->leader != counter) || if ((counter->leader != counter) ||
!(counter->leader->nr_members > 1)) !(counter->leader->nr_members > 1))
continue; continue;
} else if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) {
if (verbose)
ui__warning("%s\n", msg);
goto try_again;
} }
perf_evsel__open_strerror(counter, &target, perf_evsel__open_strerror(counter, &target,
......
...@@ -268,6 +268,12 @@ else ...@@ -268,6 +268,12 @@ else
ifneq ($(feature-dwarf), 1) ifneq ($(feature-dwarf), 1)
msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev); msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
NO_DWARF := 1 NO_DWARF := 1
else
ifneq ($(feature-dwarf_getlocations), 1)
msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
else
CFLAGS += -DHAVE_DWARF_GETLOCATIONS
endif # dwarf_getlocations
endif # Dwarf support endif # Dwarf support
endif # libelf support endif # libelf support
endif # NO_LIBELF endif # NO_LIBELF
......
...@@ -959,6 +959,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf) ...@@ -959,6 +959,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
return 0; return 0;
} }
#ifdef HAVE_DWARF_GETLOCATIONS
/** /**
* die_get_var_innermost_scope - Get innermost scope range of given variable DIE * die_get_var_innermost_scope - Get innermost scope range of given variable DIE
* @sp_die: a subprogram DIE * @sp_die: a subprogram DIE
...@@ -1080,3 +1081,11 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) ...@@ -1080,3 +1081,11 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)
return ret; return ret;
} }
#else
int die_get_var_range(Dwarf_Die *sp_die __maybe_unused,
Dwarf_Die *vr_die __maybe_unused,
struct strbuf *buf __maybe_unused)
{
return -ENOTSUP;
}
#endif
...@@ -433,7 +433,7 @@ static int __event__synthesize_thread(union perf_event *comm_event, ...@@ -433,7 +433,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
{ {
char filename[PATH_MAX]; char filename[PATH_MAX];
DIR *tasks; DIR *tasks;
struct dirent dirent, *next; struct dirent *dirent;
pid_t tgid, ppid; pid_t tgid, ppid;
int rc = 0; int rc = 0;
...@@ -462,11 +462,11 @@ static int __event__synthesize_thread(union perf_event *comm_event, ...@@ -462,11 +462,11 @@ static int __event__synthesize_thread(union perf_event *comm_event,
return 0; return 0;
} }
while (!readdir_r(tasks, &dirent, &next) && next) { while ((dirent = readdir(tasks)) != NULL) {
char *end; char *end;
pid_t _pid; pid_t _pid;
_pid = strtol(dirent.d_name, &end, 10); _pid = strtol(dirent->d_name, &end, 10);
if (*end) if (*end)
continue; continue;
...@@ -575,7 +575,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool, ...@@ -575,7 +575,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
{ {
DIR *proc; DIR *proc;
char proc_path[PATH_MAX]; char proc_path[PATH_MAX];
struct dirent dirent, *next; struct dirent *dirent;
union perf_event *comm_event, *mmap_event, *fork_event; union perf_event *comm_event, *mmap_event, *fork_event;
int err = -1; int err = -1;
...@@ -600,9 +600,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool, ...@@ -600,9 +600,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
if (proc == NULL) if (proc == NULL)
goto out_free_fork; goto out_free_fork;
while (!readdir_r(proc, &dirent, &next) && next) { while ((dirent = readdir(proc)) != NULL) {
char *end; char *end;
pid_t pid = strtol(dirent.d_name, &end, 10); pid_t pid = strtol(dirent->d_name, &end, 10);
if (*end) /* only interested in proper numerical dirents */ if (*end) /* only interested in proper numerical dirents */
continue; continue;
......
...@@ -2345,6 +2345,8 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, ...@@ -2345,6 +2345,8 @@ int perf_evsel__fprintf(struct perf_evsel *evsel,
bool perf_evsel__fallback(struct perf_evsel *evsel, int err, bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
char *msg, size_t msgsize) char *msg, size_t msgsize)
{ {
int paranoid;
if ((err == ENOENT || err == ENXIO || err == ENODEV) && if ((err == ENOENT || err == ENXIO || err == ENODEV) &&
evsel->attr.type == PERF_TYPE_HARDWARE && evsel->attr.type == PERF_TYPE_HARDWARE &&
evsel->attr.config == PERF_COUNT_HW_CPU_CYCLES) { evsel->attr.config == PERF_COUNT_HW_CPU_CYCLES) {
...@@ -2363,6 +2365,22 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err, ...@@ -2363,6 +2365,22 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
evsel->attr.config = PERF_COUNT_SW_CPU_CLOCK; evsel->attr.config = PERF_COUNT_SW_CPU_CLOCK;
zfree(&evsel->name); zfree(&evsel->name);
return true;
} else if (err == EACCES && !evsel->attr.exclude_kernel &&
(paranoid = perf_event_paranoid()) > 1) {
const char *name = perf_evsel__name(evsel);
char *new_name;
if (asprintf(&new_name, "%s%su", name, strchr(name, ':') ? "" : ":") < 0)
return false;
if (evsel->name)
free(evsel->name);
evsel->name = new_name;
scnprintf(msg, msgsize,
"kernel.perf_event_paranoid=%d, trying to fall back to excluding kernel samples", paranoid);
evsel->attr.exclude_kernel = 1;
return true; return true;
} }
...@@ -2382,12 +2400,13 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, ...@@ -2382,12 +2400,13 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
"Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n" "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n"
"which controls use of the performance events system by\n" "which controls use of the performance events system by\n"
"unprivileged users (without CAP_SYS_ADMIN).\n\n" "unprivileged users (without CAP_SYS_ADMIN).\n\n"
"The default value is 1:\n\n" "The current value is %d:\n\n"
" -1: Allow use of (almost) all events by all users\n" " -1: Allow use of (almost) all events by all users\n"
">= 0: Disallow raw tracepoint access by users without CAP_IOC_LOCK\n" ">= 0: Disallow raw tracepoint access by users without CAP_IOC_LOCK\n"
">= 1: Disallow CPU event access by users without CAP_SYS_ADMIN\n" ">= 1: Disallow CPU event access by users without CAP_SYS_ADMIN\n"
">= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN", ">= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN",
target->system_wide ? "system-wide " : ""); target->system_wide ? "system-wide " : "",
perf_event_paranoid());
case ENOENT: case ENOENT:
return scnprintf(msg, size, "The %s event is not supported.", return scnprintf(msg, size, "The %s event is not supported.",
perf_evsel__name(evsel)); perf_evsel__name(evsel));
......
...@@ -138,11 +138,11 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { ...@@ -138,11 +138,11 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
#define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE)
#define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT)
#define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ #define for_each_subsystem(sys_dir, sys_dirent) \
while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ while ((sys_dirent = readdir(sys_dir)) != NULL) \
if (sys_dirent.d_type == DT_DIR && \ if (sys_dirent->d_type == DT_DIR && \
(strcmp(sys_dirent.d_name, ".")) && \ (strcmp(sys_dirent->d_name, ".")) && \
(strcmp(sys_dirent.d_name, ".."))) (strcmp(sys_dirent->d_name, "..")))
static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
{ {
...@@ -159,12 +159,12 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) ...@@ -159,12 +159,12 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
return 0; return 0;
} }
#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ #define for_each_event(sys_dirent, evt_dir, evt_dirent) \
while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ while ((evt_dirent = readdir(evt_dir)) != NULL) \
if (evt_dirent.d_type == DT_DIR && \ if (evt_dirent->d_type == DT_DIR && \
(strcmp(evt_dirent.d_name, ".")) && \ (strcmp(evt_dirent->d_name, ".")) && \
(strcmp(evt_dirent.d_name, "..")) && \ (strcmp(evt_dirent->d_name, "..")) && \
(!tp_event_has_id(&sys_dirent, &evt_dirent))) (!tp_event_has_id(sys_dirent, evt_dirent)))
#define MAX_EVENT_LENGTH 512 #define MAX_EVENT_LENGTH 512
...@@ -173,7 +173,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -173,7 +173,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
{ {
struct tracepoint_path *path = NULL; struct tracepoint_path *path = NULL;
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; struct dirent *sys_dirent, *evt_dirent;
char id_buf[24]; char id_buf[24];
int fd; int fd;
u64 id; u64 id;
...@@ -184,18 +184,18 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -184,18 +184,18 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
if (!sys_dir) if (!sys_dir)
return NULL; return NULL;
for_each_subsystem(sys_dir, sys_dirent, sys_next) { for_each_subsystem(sys_dir, sys_dirent) {
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
sys_dirent.d_name); sys_dirent->d_name);
evt_dir = opendir(dir_path); evt_dir = opendir(dir_path);
if (!evt_dir) if (!evt_dir)
continue; continue;
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { for_each_event(sys_dirent, evt_dir, evt_dirent) {
snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
evt_dirent.d_name); evt_dirent->d_name);
fd = open(evt_path, O_RDONLY); fd = open(evt_path, O_RDONLY);
if (fd < 0) if (fd < 0)
continue; continue;
...@@ -220,9 +220,9 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -220,9 +220,9 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
free(path); free(path);
return NULL; return NULL;
} }
strncpy(path->system, sys_dirent.d_name, strncpy(path->system, sys_dirent->d_name,
MAX_EVENT_LENGTH); MAX_EVENT_LENGTH);
strncpy(path->name, evt_dirent.d_name, strncpy(path->name, evt_dirent->d_name,
MAX_EVENT_LENGTH); MAX_EVENT_LENGTH);
return path; return path;
} }
...@@ -1812,7 +1812,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob, ...@@ -1812,7 +1812,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
bool name_only) bool name_only)
{ {
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; struct dirent *sys_dirent, *evt_dirent;
char evt_path[MAXPATHLEN]; char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN]; char dir_path[MAXPATHLEN];
char **evt_list = NULL; char **evt_list = NULL;
...@@ -1830,20 +1830,20 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob, ...@@ -1830,20 +1830,20 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
goto out_close_sys_dir; goto out_close_sys_dir;
} }
for_each_subsystem(sys_dir, sys_dirent, sys_next) { for_each_subsystem(sys_dir, sys_dirent) {
if (subsys_glob != NULL && if (subsys_glob != NULL &&
!strglobmatch(sys_dirent.d_name, subsys_glob)) !strglobmatch(sys_dirent->d_name, subsys_glob))
continue; continue;
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
sys_dirent.d_name); sys_dirent->d_name);
evt_dir = opendir(dir_path); evt_dir = opendir(dir_path);
if (!evt_dir) if (!evt_dir)
continue; continue;
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { for_each_event(sys_dirent, evt_dir, evt_dirent) {
if (event_glob != NULL && if (event_glob != NULL &&
!strglobmatch(evt_dirent.d_name, event_glob)) !strglobmatch(evt_dirent->d_name, event_glob))
continue; continue;
if (!evt_num_known) { if (!evt_num_known) {
...@@ -1852,7 +1852,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob, ...@@ -1852,7 +1852,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
} }
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);
evt_list[evt_i] = strdup(evt_path); evt_list[evt_i] = strdup(evt_path);
if (evt_list[evt_i] == NULL) if (evt_list[evt_i] == NULL)
...@@ -1905,7 +1905,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob, ...@@ -1905,7 +1905,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
int is_valid_tracepoint(const char *event_string) int is_valid_tracepoint(const char *event_string)
{ {
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; struct dirent *sys_dirent, *evt_dirent;
char evt_path[MAXPATHLEN]; char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN]; char dir_path[MAXPATHLEN];
...@@ -1913,17 +1913,17 @@ int is_valid_tracepoint(const char *event_string) ...@@ -1913,17 +1913,17 @@ int is_valid_tracepoint(const char *event_string)
if (!sys_dir) if (!sys_dir)
return 0; return 0;
for_each_subsystem(sys_dir, sys_dirent, sys_next) { for_each_subsystem(sys_dir, sys_dirent) {
snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
sys_dirent.d_name); sys_dirent->d_name);
evt_dir = opendir(dir_path); evt_dir = opendir(dir_path);
if (!evt_dir) if (!evt_dir)
continue; continue;
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { for_each_event(sys_dirent, evt_dir, evt_dirent) {
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);
if (!strcmp(evt_path, event_string)) { if (!strcmp(evt_path, event_string)) {
closedir(evt_dir); closedir(evt_dir);
closedir(sys_dir); closedir(sys_dir);
......
...@@ -2445,6 +2445,9 @@ static char *prefix_if_not_in(const char *pre, char *str) ...@@ -2445,6 +2445,9 @@ static char *prefix_if_not_in(const char *pre, char *str)
static char *setup_overhead(char *keys) static char *setup_overhead(char *keys)
{ {
if (sort__mode == SORT_MODE__DIFF)
return keys;
keys = prefix_if_not_in("overhead", keys); keys = prefix_if_not_in("overhead", keys);
if (symbol_conf.cumulate_callchain) if (symbol_conf.cumulate_callchain)
......
...@@ -94,7 +94,7 @@ struct thread_map *thread_map__new_by_uid(uid_t uid) ...@@ -94,7 +94,7 @@ struct thread_map *thread_map__new_by_uid(uid_t uid)
DIR *proc; DIR *proc;
int max_threads = 32, items, i; int max_threads = 32, items, i;
char path[256]; char path[256];
struct dirent dirent, *next, **namelist = NULL; struct dirent *dirent, **namelist = NULL;
struct thread_map *threads = thread_map__alloc(max_threads); struct thread_map *threads = thread_map__alloc(max_threads);
if (threads == NULL) if (threads == NULL)
...@@ -107,16 +107,16 @@ struct thread_map *thread_map__new_by_uid(uid_t uid) ...@@ -107,16 +107,16 @@ struct thread_map *thread_map__new_by_uid(uid_t uid)
threads->nr = 0; threads->nr = 0;
atomic_set(&threads->refcnt, 1); atomic_set(&threads->refcnt, 1);
while (!readdir_r(proc, &dirent, &next) && next) { while ((dirent = readdir(proc)) != NULL) {
char *end; char *end;
bool grow = false; bool grow = false;
struct stat st; struct stat st;
pid_t pid = strtol(dirent.d_name, &end, 10); pid_t pid = strtol(dirent->d_name, &end, 10);
if (*end) /* only interested in proper numerical dirents */ if (*end) /* only interested in proper numerical dirents */
continue; continue;
snprintf(path, sizeof(path), "/proc/%s", dirent.d_name); snprintf(path, sizeof(path), "/proc/%s", dirent->d_name);
if (stat(path, &st) != 0) if (stat(path, &st) != 0)
continue; continue;
......
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