Skip to content

Commit

Permalink
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
torvalds committed May 13, 2016
2 parents 1875946 + 636fa4a commit f7f4d43
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 88 deletions.
2 changes: 1 addition & 1 deletion arch/x86/events/intel/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@ __init int intel_pmu_init(void)
c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1;
}
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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/events/intel/pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf,

/* clear STOP and INT from current entry */
buf->topa_index[buf->stop_pos]->stop = 0;
buf->topa_index[buf->stop_pos]->intr = 0;
buf->topa_index[buf->intr_pos]->intr = 0;

/* how many pages till the STOP marker */
Expand All @@ -733,6 +734,7 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf,
buf->intr_pos = idx;

buf->topa_index[buf->stop_pos]->stop = 1;
buf->topa_index[buf->stop_pos]->intr = 1;
buf->topa_index[buf->intr_pos]->intr = 1;

return 0;
Expand Down
7 changes: 7 additions & 0 deletions arch/x86/events/intel/uncore_snbep.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
#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_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 */
#define KNL_UCLK_MSR_PMON_CTR0_LOW 0x400
Expand Down Expand Up @@ -1902,6 +1905,10 @@ static int knl_cha_hw_config(struct intel_uncore_box *box,
reg1->reg = HSWEP_C0_MSR_PMON_BOX_FILTER0 +
KNL_CHA_MSR_OFFSET * box->pmu->pmu_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;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/events/msr.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static void msr_event_update(struct perf_event *event)
if (unlikely(event->hw.event_base == MSR_SMI_COUNT))
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)
Expand Down
10 changes: 9 additions & 1 deletion kernel/events/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
bool truncated)
{
struct ring_buffer *rb = handle->rb;
bool wakeup = truncated;
unsigned long aux_head;
u64 flags = 0;

Expand Down Expand Up @@ -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);

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);
}

if (wakeup) {
if (truncated)
handle->event->pending_disable = 1;
perf_output_wakeup(handle);
}

handle->event = NULL;

local_set(&rb->aux_nest, 0);
Expand Down
2 changes: 2 additions & 0 deletions tools/build/Makefile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ endef
FEATURE_TESTS_BASIC := \
backtrace \
dwarf \
dwarf_getlocations \
fortify-source \
sync-compare-and-swap \
glibc \
Expand Down Expand Up @@ -78,6 +79,7 @@ endif

FEATURE_DISPLAY ?= \
dwarf \
dwarf_getlocations \
glibc \
gtk2 \
libaudit \
Expand Down
4 changes: 4 additions & 0 deletions tools/build/feature/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FILES= \
test-backtrace.bin \
test-bionic.bin \
test-dwarf.bin \
test-dwarf_getlocations.bin \
test-fortify-source.bin \
test-sync-compare-and-swap.bin \
test-glibc.bin \
Expand Down Expand Up @@ -82,6 +83,9 @@ endif
$(OUTPUT)test-dwarf.bin:
$(BUILD) $(DWARFLIBS)

$(OUTPUT)test-dwarf_getlocations.bin:
$(BUILD) $(DWARFLIBS)

$(OUTPUT)test-libelf-mmap.bin:
$(BUILD) -lelf

Expand Down
5 changes: 5 additions & 0 deletions tools/build/feature/test-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
# include "test-dwarf.c"
#undef main

#define main main_test_dwarf_getlocations
# include "test-dwarf_getlocations.c"
#undef main

#define main main_test_libelf_getphdrnum
# include "test-libelf-getphdrnum.c"
#undef main
Expand Down Expand Up @@ -143,6 +147,7 @@ int main(int argc, char *argv[])
main_test_libelf_mmap();
main_test_glibc();
main_test_dwarf();
main_test_dwarf_getlocations();
main_test_libelf_getphdrnum();
main_test_libunwind();
main_test_libaudit();
Expand Down
12 changes: 12 additions & 0 deletions tools/build/feature/test-dwarf_getlocations.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#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);
}
4 changes: 2 additions & 2 deletions tools/lib/traceevent/parse-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,11 +1164,11 @@ process_filter(struct event_format *event, struct filter_arg **parg,
current_op = current_exp;

ret = collapse_tree(current_op, parg, error_str);
/* collapse_tree() may free current_op, and updates parg accordingly */
current_op = NULL;
if (ret < 0)
goto fail;

*parg = current_op;

free(token);
return 0;

Expand Down
8 changes: 4 additions & 4 deletions tools/perf/arch/x86/util/dwarf-regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct pt_regs_offset {
# define REG_OFFSET_NAME_32(n, r) {.name = n, .offset = offsetof(struct pt_regs, r)}
#endif

/* TODO: switching by dwarf address size */
#ifndef __x86_64__
static const struct pt_regs_offset x86_32_regoffset_table[] = {
REG_OFFSET_NAME_32("%ax", eax),
REG_OFFSET_NAME_32("%cx", ecx),
Expand All @@ -75,6 +77,8 @@ static const struct pt_regs_offset x86_32_regoffset_table[] = {
REG_OFFSET_END,
};

#define regoffset_table x86_32_regoffset_table
#else
static const struct pt_regs_offset x86_64_regoffset_table[] = {
REG_OFFSET_NAME_64("%ax", rax),
REG_OFFSET_NAME_64("%dx", rdx),
Expand All @@ -95,11 +99,7 @@ static const struct pt_regs_offset x86_64_regoffset_table[] = {
REG_OFFSET_END,
};

/* TODO: switching by dwarf address size */
#ifdef __x86_64__
#define regoffset_table x86_64_regoffset_table
#else
#define regoffset_table x86_32_regoffset_table
#endif

/* Minus 1 for the ending REG_OFFSET_END */
Expand Down
70 changes: 34 additions & 36 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -1415,21 +1415,19 @@ static int is_directory(const char *base_path, const struct dirent *dent)
return S_ISDIR(st.st_mode);
}

#define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\
while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
lang_next) \
if ((lang_dirent.d_type == DT_DIR || \
(lang_dirent.d_type == DT_UNKNOWN && \
is_directory(scripts_path, &lang_dirent))) && \
(strcmp(lang_dirent.d_name, ".")) && \
(strcmp(lang_dirent.d_name, "..")))

#define for_each_script(lang_path, lang_dir, script_dirent, script_next)\
while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
script_next) \
if (script_dirent.d_type != DT_DIR && \
(script_dirent.d_type != DT_UNKNOWN || \
!is_directory(lang_path, &script_dirent)))
#define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
while ((lang_dirent = readdir(scripts_dir)) != NULL) \
if ((lang_dirent->d_type == DT_DIR || \
(lang_dirent->d_type == DT_UNKNOWN && \
is_directory(scripts_path, lang_dirent))) && \
(strcmp(lang_dirent->d_name, ".")) && \
(strcmp(lang_dirent->d_name, "..")))

#define for_each_script(lang_path, lang_dir, script_dirent) \
while ((script_dirent = readdir(lang_dir)) != NULL) \
if (script_dirent->d_type != DT_DIR && \
(script_dirent->d_type != DT_UNKNOWN || \
!is_directory(lang_path, script_dirent)))


#define RECORD_SUFFIX "-record"
Expand Down Expand Up @@ -1575,7 +1573,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
const char *s __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];
DIR *scripts_dir, *lang_dir;
char script_path[MAXPATHLEN];
Expand All @@ -1590,19 +1588,19 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
if (!scripts_dir)
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,
lang_dirent.d_name);
lang_dirent->d_name);
lang_dir = opendir(lang_path);
if (!lang_dir)
continue;

for_each_script(lang_path, lang_dir, script_dirent, script_next) {
script_root = get_script_root(&script_dirent, REPORT_SUFFIX);
for_each_script(lang_path, lang_dir, script_dirent) {
script_root = get_script_root(script_dirent, REPORT_SUFFIX);
if (script_root) {
desc = script_desc__findnew(script_root);
snprintf(script_path, MAXPATHLEN, "%s/%s",
lang_path, script_dirent.d_name);
lang_path, script_dirent->d_name);
read_script_info(desc, script_path);
free(script_root);
}
Expand Down Expand Up @@ -1690,7 +1688,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
*/
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];
DIR *scripts_dir, *lang_dir;
struct perf_session *session;
Expand All @@ -1713,9 +1711,9 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
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,
lang_dirent.d_name);
lang_dirent->d_name);
#ifdef NO_LIBPERL
if (strstr(lang_path, "perl"))
continue;
Expand All @@ -1729,16 +1727,16 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
if (!lang_dir)
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] */
if (strstr(script_dirent.d_name, "top."))
if (strstr(script_dirent->d_name, "top."))
continue;
sprintf(scripts_path_array[i], "%s/%s", lang_path,
script_dirent.d_name);
temp = strchr(script_dirent.d_name, '.');
script_dirent->d_name);
temp = strchr(script_dirent->d_name, '.');
snprintf(scripts_array[i],
(temp - script_dirent.d_name) + 1,
"%s", script_dirent.d_name);
(temp - script_dirent->d_name) + 1,
"%s", script_dirent->d_name);

if (check_ev_match(lang_path,
scripts_array[i], session))
Expand All @@ -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)
{
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
struct dirent *script_dirent, *lang_dirent;
char scripts_path[MAXPATHLEN];
char script_path[MAXPATHLEN];
DIR *scripts_dir, *lang_dir;
Expand All @@ -1769,21 +1767,21 @@ static char *get_script_path(const char *script_root, const char *suffix)
if (!scripts_dir)
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,
lang_dirent.d_name);
lang_dirent->d_name);
lang_dir = opendir(lang_path);
if (!lang_dir)
continue;

for_each_script(lang_path, lang_dir, script_dirent, script_next) {
__script_root = get_script_root(&script_dirent, suffix);
for_each_script(lang_path, lang_dir, script_dirent) {
__script_root = get_script_root(script_dirent, suffix);
if (__script_root && !strcmp(script_root, __script_root)) {
free(__script_root);
closedir(lang_dir);
closedir(scripts_dir);
snprintf(script_path, MAXPATHLEN, "%s/%s",
lang_path, script_dirent.d_name);
lang_path, script_dirent->d_name);
return strdup(script_path);
}
free(__script_root);
Expand Down
7 changes: 6 additions & 1 deletion tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ static int __run_perf_stat(int argc, const char **argv)
perf_evlist__set_leader(evsel_list);

evlist__for_each(evsel_list, counter) {
try_again:
if (create_perf_stat_counter(counter) < 0) {
/*
* PPC returns ENXIO for HW counters until 2.6.37
Expand All @@ -544,7 +545,11 @@ static int __run_perf_stat(int argc, const char **argv)
if ((counter->leader != counter) ||
!(counter->leader->nr_members > 1))
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,
errno, msg, sizeof(msg));
Expand Down
6 changes: 6 additions & 0 deletions tools/perf/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ else
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);
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 # libelf support
endif # NO_LIBELF
Expand Down
9 changes: 9 additions & 0 deletions tools/perf/util/dwarf-aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
return 0;
}

#ifdef HAVE_DWARF_GETLOCATIONS
/**
* die_get_var_innermost_scope - Get innermost scope range of given variable DIE
* @sp_die: a subprogram DIE
Expand Down Expand Up @@ -1080,3 +1081,11 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)

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
Loading

0 comments on commit f7f4d43

Please sign in to comment.