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 updates from Ingo Molnar:
 "Mostly tooling fixes and some late tooling updates, plus two perf
  related printk message fixes"

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  perf tests bpf: Use SyS_epoll_wait alias
  perf tests: objdump output can contain multi byte chunks
  perf record: Add --sample-cpu option
  perf hists: Introduce output_resort_cb method
  perf tools: Move config/Makefile into Makefile.config
  perf tests: Add test for bitmap_scnprintf function
  tools lib: Add bitmap_and function
  tools lib: Add bitmap_scnprintf function
  tools lib: Add bitmap_alloc function
  tools lib traceevent: Ignore generated library files
  perf tools: Fix build failure on perl script context
  perf/core: Change log level for duration warning to KERN_INFO
  perf annotate: Plug filename string leak
  perf annotate: Introduce strerror for handling symbol__disassemble() errors
  perf annotate: Rename symbol__annotate() to symbol__disassemble()
  perf/x86: Modify error message in virtualized environment
  perf target: str_error_r() always returns the buffer it receives
  perf annotate: Use pipe + fork instead of popen
  perf evsel: Introduce constructor for cycles event
  • Loading branch information
torvalds committed Aug 6, 2016
2 parents c98f582 + f282f7a commit db82627
Show file tree
Hide file tree
Showing 28 changed files with 402 additions and 111 deletions.
11 changes: 7 additions & 4 deletions arch/x86/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,13 @@ static bool check_hw_exists(void)
return true;

msr_fail:
pr_cont("Broken PMU hardware detected, using software events only.\n");
printk("%sFailed to access perfctr msr (MSR %x is %Lx)\n",
boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR,
reg, val_new);
if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
pr_cont("PMU not available due to virtualization, using software events only.\n");
} else {
pr_cont("Broken PMU hardware detected, using software events only.\n");
pr_err("Failed to access perfctr msr (MSR %x is %Lx)\n",
reg, val_new);
}

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static u64 __report_allowed;

static void perf_duration_warn(struct irq_work *w)
{
printk_ratelimited(KERN_WARNING
printk_ratelimited(KERN_INFO
"perf: interrupt took too long (%lld > %lld), lowering "
"kernel.perf_event_max_sample_rate to %d\n",
__report_avg, __report_allowed,
Expand Down
37 changes: 37 additions & 0 deletions tools/include/linux/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

#include <string.h>
#include <linux/bitops.h>
#include <stdlib.h>

#define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)]

int __bitmap_weight(const unsigned long *bitmap, int bits);
void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, int bits);
int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits);

#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))

Expand Down Expand Up @@ -65,4 +68,38 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
return (old & mask) != 0;
}

/**
* bitmap_alloc - Allocate bitmap
* @nr: Bit to set
*/
static inline unsigned long *bitmap_alloc(int nbits)
{
return calloc(1, BITS_TO_LONGS(nbits) * sizeof(unsigned long));
}

/*
* bitmap_scnprintf - print bitmap list into buffer
* @bitmap: bitmap
* @nbits: size of bitmap
* @buf: buffer to store output
* @size: size of @buf
*/
size_t bitmap_scnprintf(unsigned long *bitmap, int nbits,
char *buf, size_t size);

/**
* bitmap_and - Do logical and on bitmaps
* @dst: resulting bitmap
* @src1: operand 1
* @src2: operand 2
* @nbits: size of bitmap
*/
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0;
return __bitmap_and(dst, src1, src2, nbits);
}

#endif /* _PERF_BITOPS_H */
44 changes: 44 additions & 0 deletions tools/lib/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,47 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
for (k = 0; k < nr; k++)
dst[k] = bitmap1[k] | bitmap2[k];
}

size_t bitmap_scnprintf(unsigned long *bitmap, int nbits,
char *buf, size_t size)
{
/* current bit is 'cur', most recently seen range is [rbot, rtop] */
int cur, rbot, rtop;
bool first = true;
size_t ret = 0;

rbot = cur = find_first_bit(bitmap, nbits);
while (cur < nbits) {
rtop = cur;
cur = find_next_bit(bitmap, nbits, cur + 1);
if (cur < nbits && cur <= rtop + 1)
continue;

if (!first)
ret += scnprintf(buf + ret, size - ret, ",");

first = false;

ret += scnprintf(buf + ret, size - ret, "%d", rbot);
if (rbot < rtop)
ret += scnprintf(buf + ret, size - ret, "-%d", rtop);

rbot = cur;
}
return ret;
}

int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
unsigned int k;
unsigned int lim = bits/BITS_PER_LONG;
unsigned long result = 0;

for (k = 0; k < lim; k++)
result |= (dst[k] = bitmap1[k] & bitmap2[k]);
if (bits % BITS_PER_LONG)
result |= (dst[k] = bitmap1[k] & bitmap2[k] &
BITMAP_LAST_WORD_MASK(bits));
return result != 0;
}
1 change: 1 addition & 0 deletions tools/lib/traceevent/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TRACEEVENT-CFLAGS
libtraceevent-dynamic-list
libtraceevent.so.*
3 changes: 3 additions & 0 deletions tools/perf/Documentation/perf-record.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ OPTIONS
--period::
Record the sample period.

--sample-cpu::
Record the sample cpu.

-n::
--no-samples::
Don't sample.
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions tools/perf/Makefile.perf
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
BPF_DIR = $(srctree)/tools/lib/bpf/
SUBCMD_DIR = $(srctree)/tools/lib/subcmd/

# include config/Makefile by default and rule out
# include Makefile.config by default and rule out
# non-config cases
config := 1

Expand All @@ -183,7 +183,7 @@ ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-dump)
FEATURE_TESTS := all
endif
endif
include config/Makefile
include Makefile.config
endif

ifeq ($(config),0)
Expand Down Expand Up @@ -706,7 +706,7 @@ $(INSTALL_DOC_TARGETS):
### Cleaning rules

#
# This is here, not in config/Makefile, because config/Makefile does
# This is here, not in Makefile.config, because Makefile.config does
# not get included for the clean target:
#
config-clean:
Expand Down
1 change: 1 addition & 0 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,7 @@ struct option __record_options[] = {
OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat,
"per thread counts"),
OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),
OPT_BOOLEAN(0, "sample-cpu", &record.opts.sample_cpu, "Record the sample cpu"),
OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
&record.opts.sample_time_set,
"Record the sample timestamps"),
Expand Down
6 changes: 5 additions & 1 deletion tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
return err;
}

err = symbol__annotate(sym, map, 0);
err = symbol__disassemble(sym, map, 0);
if (err == 0) {
out_assign:
top->sym_filter_entry = he;
} else {
char msg[BUFSIZ];
symbol__strerror_disassemble(sym, map, err, msg, sizeof(msg));
pr_err("Couldn't annotate %s: %s\n", sym->name, msg);
}

pthread_mutex_unlock(&notes->lock);
Expand Down
1 change: 1 addition & 0 deletions tools/perf/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct record_opts {
bool sample_weight;
bool sample_time;
bool sample_time_set;
bool sample_cpu;
bool period;
bool running_time;
bool full_auxtrace;
Expand Down
4 changes: 3 additions & 1 deletion tools/perf/scripts/perl/Perf-Trace-Util/Build
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
libperf-y += Context.o

CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs -Wno-undef -Wno-switch-default
CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes
CFLAGS_Context.o += -Wno-unused-parameter -Wno-nested-externs -Wno-undef
CFLAGS_Context.o += -Wno-switch-default -Wno-shadow
1 change: 1 addition & 0 deletions tools/perf/tests/Build
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ perf-y += event-times.o
perf-y += backward-ring-buffer.o
perf-y += sdt.o
perf-y += is_printable_array.o
perf-y += bitmap.o

$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
$(call rule_mkdir)
Expand Down
53 changes: 53 additions & 0 deletions tools/perf/tests/bitmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <linux/compiler.h>
#include <linux/bitmap.h>
#include "tests.h"
#include "cpumap.h"
#include "debug.h"

#define NBITS 100

static unsigned long *get_bitmap(const char *str, int nbits)
{
struct cpu_map *map = cpu_map__new(str);
unsigned long *bm = NULL;
int i;

bm = bitmap_alloc(nbits);

if (map && bm) {
bitmap_zero(bm, nbits);

for (i = 0; i < map->nr; i++)
set_bit(map->map[i], bm);
}

if (map)
cpu_map__put(map);
return bm;
}

static int test_bitmap(const char *str)
{
unsigned long *bm = get_bitmap(str, NBITS);
char buf[100];
int ret;

bitmap_scnprintf(bm, NBITS, buf, sizeof(buf));
pr_debug("bitmap: %s\n", buf);

ret = !strcmp(buf, str);
free(bm);
return ret;
}

int test__bitmap_print(int subtest __maybe_unused)
{
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1"));
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,5"));
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3,5,7,9,11,13,15,17,19,21-40"));
TEST_ASSERT_VAL("failed to convert map", test_bitmap("2-5"));
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1-10,12-20,22-30,32-40"));
return 0;
}
4 changes: 2 additions & 2 deletions tools/perf/tests/bpf-script-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ struct bpf_map_def SEC("maps") flip_table = {
.max_entries = 1,
};

SEC("func=sys_epoll_wait")
int bpf_func__sys_epoll_wait(void *ctx)
SEC("func=SyS_epoll_wait")
int bpf_func__SyS_epoll_wait(void *ctx)
{
int ind =0;
int *flag = bpf_map_lookup_elem(&flip_table, &ind);
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/tests/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ static struct test generic_tests[] = {
.desc = "Test is_printable_array function",
.func = test__is_printable_array,
},
{
.desc = "Test bitmap print",
.func = test__bitmap_print,
},
{
.func = NULL,
},
Expand Down
Loading

0 comments on commit db82627

Please sign in to comment.