Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d76ded5 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

Merge tag 'perf-core-for-mingo' of...

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

 into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

User visible changes:

  - Fix 'perf top' annotation in --stdio (Namhyung Kim)

  - Support hw breakpoint events (mem:0xAddress) in the default output mode in
    'perf script' (Wang Nan)

Infrastructure changes:

  - Do not hold the hists lock while emitting one specific warning (Namhyung Kim)

  - Fetch map names from correct strtab, worked so far because llvm/clang
    uses just one string table (Wang Nan)

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents 057032e4 93b0ba3c
Loading
Loading
Loading
Loading
+18 −6
Original line number Original line Diff line number Diff line
@@ -195,6 +195,7 @@ struct bpf_object {
		Elf *elf;
		Elf *elf;
		GElf_Ehdr ehdr;
		GElf_Ehdr ehdr;
		Elf_Data *symbols;
		Elf_Data *symbols;
		size_t strtabidx;
		struct {
		struct {
			GElf_Shdr shdr;
			GElf_Shdr shdr;
			Elf_Data *data;
			Elf_Data *data;
@@ -527,14 +528,14 @@ bpf_object__init_maps(struct bpf_object *obj, void *data,
	return 0;
	return 0;
}
}


static void
static int
bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
{
{
	int i;
	int i;
	Elf_Data *symbols = obj->efile.symbols;
	Elf_Data *symbols = obj->efile.symbols;


	if (!symbols || maps_shndx < 0)
	if (!symbols || maps_shndx < 0)
		return;
		return -EINVAL;


	for (i = 0; i < symbols->d_size / sizeof(GElf_Sym); i++) {
	for (i = 0; i < symbols->d_size / sizeof(GElf_Sym); i++) {
		GElf_Sym sym;
		GElf_Sym sym;
@@ -547,7 +548,7 @@ bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
			continue;
			continue;


		map_name = elf_strptr(obj->efile.elf,
		map_name = elf_strptr(obj->efile.elf,
				      obj->efile.ehdr.e_shstrndx,
				      obj->efile.strtabidx,
				      sym.st_name);
				      sym.st_name);
		map_idx = sym.st_value / sizeof(struct bpf_map_def);
		map_idx = sym.st_value / sizeof(struct bpf_map_def);
		if (map_idx >= obj->nr_maps) {
		if (map_idx >= obj->nr_maps) {
@@ -556,9 +557,14 @@ bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
			continue;
			continue;
		}
		}
		obj->maps[map_idx].name = strdup(map_name);
		obj->maps[map_idx].name = strdup(map_name);
		if (!obj->maps[map_idx].name) {
			pr_warning("failed to alloc map name\n");
			return -ENOMEM;
		}
		pr_debug("map %zu is \"%s\"\n", map_idx,
		pr_debug("map %zu is \"%s\"\n", map_idx,
			 obj->maps[map_idx].name);
			 obj->maps[map_idx].name);
	}
	}
	return 0;
}
}


static int bpf_object__elf_collect(struct bpf_object *obj)
static int bpf_object__elf_collect(struct bpf_object *obj)
@@ -625,8 +631,10 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
				pr_warning("bpf: multiple SYMTAB in %s\n",
				pr_warning("bpf: multiple SYMTAB in %s\n",
					   obj->path);
					   obj->path);
				err = -LIBBPF_ERRNO__FORMAT;
				err = -LIBBPF_ERRNO__FORMAT;
			} else
			} else {
				obj->efile.symbols = data;
				obj->efile.symbols = data;
				obj->efile.strtabidx = sh.sh_link;
			}
		} else if ((sh.sh_type == SHT_PROGBITS) &&
		} else if ((sh.sh_type == SHT_PROGBITS) &&
			   (sh.sh_flags & SHF_EXECINSTR) &&
			   (sh.sh_flags & SHF_EXECINSTR) &&
			   (data->d_size > 0)) {
			   (data->d_size > 0)) {
@@ -662,8 +670,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
			goto out;
			goto out;
	}
	}


	if (!obj->efile.strtabidx || obj->efile.strtabidx >= idx) {
		pr_warning("Corrupted ELF file: index of strtab invalid\n");
		return LIBBPF_ERRNO__FORMAT;
	}
	if (maps_shndx >= 0)
	if (maps_shndx >= 0)
		bpf_object__init_maps_name(obj, maps_shndx);
		err = bpf_object__init_maps_name(obj, maps_shndx);
out:
out:
	return err;
	return err;
}
}
@@ -1372,7 +1384,7 @@ bpf_object__get_map_by_name(struct bpf_object *obj, const char *name)
	struct bpf_map *pos;
	struct bpf_map *pos;


	bpf_map__for_each(pos, obj) {
	bpf_map__for_each(pos, obj) {
		if (strcmp(pos->name, name) == 0)
		if (pos->name && !strcmp(pos->name, name))
			return pos;
			return pos;
	}
	}
	return NULL;
	return NULL;
+14 −0
Original line number Original line Diff line number Diff line
@@ -130,6 +130,18 @@ static struct {


		.invalid_fields = PERF_OUTPUT_TRACE,
		.invalid_fields = PERF_OUTPUT_TRACE,
	},
	},

	[PERF_TYPE_BREAKPOINT] = {
		.user_set = false,

		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
			      PERF_OUTPUT_PERIOD,

		.invalid_fields = PERF_OUTPUT_TRACE,
	},
};
};


static bool output_set_by_user(void)
static bool output_set_by_user(void)
@@ -1129,6 +1141,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
			type = PERF_TYPE_TRACEPOINT;
			type = PERF_TYPE_TRACEPOINT;
		else if (!strcmp(str, "raw"))
		else if (!strcmp(str, "raw"))
			type = PERF_TYPE_RAW;
			type = PERF_TYPE_RAW;
		else if (!strcmp(str, "break"))
			type = PERF_TYPE_BREAKPOINT;
		else {
		else {
			fprintf(stderr, "Invalid event type in field string.\n");
			fprintf(stderr, "Invalid event type in field string.\n");
			rc = -EINVAL;
			rc = -EINVAL;
+22 −30
Original line number Original line Diff line number Diff line
@@ -175,27 +175,24 @@ static void perf_top__record_precise_ip(struct perf_top *top,
					int counter, u64 ip)
					int counter, u64 ip)
{
{
	struct annotation *notes;
	struct annotation *notes;
	struct symbol *sym;
	struct symbol *sym = he->ms.sym;
	int err = 0;
	int err = 0;


	if (he == NULL || he->ms.sym == NULL ||
	if (sym == NULL || (use_browser == 0 &&
	    ((top->sym_filter_entry == NULL ||
			    (top->sym_filter_entry == NULL ||
	      top->sym_filter_entry->ms.sym != he->ms.sym) && use_browser != 1))
			     top->sym_filter_entry->ms.sym != sym)))
		return;
		return;


	sym = he->ms.sym;
	notes = symbol__annotation(sym);
	notes = symbol__annotation(sym);


	if (pthread_mutex_trylock(&notes->lock))
	if (pthread_mutex_trylock(&notes->lock))
		return;
		return;


	ip = he->ms.map->map_ip(he->ms.map, ip);

	if (ui__has_annotation())
	err = hist_entry__inc_addr_samples(he, counter, ip);
	err = hist_entry__inc_addr_samples(he, counter, ip);


	pthread_mutex_unlock(&notes->lock);
	pthread_mutex_unlock(&notes->lock);


	if (unlikely(err)) {
		/*
		/*
		 * This function is now called with he->hists->lock held.
		 * This function is now called with he->hists->lock held.
		 * Release it before going to sleep.
		 * Release it before going to sleep.
@@ -212,6 +209,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,


		pthread_mutex_lock(&he->hists->lock);
		pthread_mutex_lock(&he->hists->lock);
	}
	}
}


static void perf_top__show_details(struct perf_top *top)
static void perf_top__show_details(struct perf_top *top)
{
{
@@ -687,14 +685,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,
	struct hist_entry *he = iter->he;
	struct hist_entry *he = iter->he;
	struct perf_evsel *evsel = iter->evsel;
	struct perf_evsel *evsel = iter->evsel;


	if (sort__has_sym && single) {
	if (sort__has_sym && single)
		u64 ip = al->addr;
		perf_top__record_precise_ip(top, he, evsel->idx, al->addr);

		if (al->map)
			ip = al->map->unmap_ip(al->map, ip);

		perf_top__record_precise_ip(top, he, evsel->idx, ip);
	}


	hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
	hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
		     !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));
		     !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));
+2 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ struct ctf_writer {
			struct bt_ctf_field_type	*s32;
			struct bt_ctf_field_type	*s32;
			struct bt_ctf_field_type	*u32;
			struct bt_ctf_field_type	*u32;
			struct bt_ctf_field_type	*string;
			struct bt_ctf_field_type	*string;
			struct bt_ctf_field_type	*u32_hex;
			struct bt_ctf_field_type	*u64_hex;
			struct bt_ctf_field_type	*u64_hex;
		};
		};
		struct bt_ctf_field_type *array[6];
		struct bt_ctf_field_type *array[6];
@@ -982,6 +983,7 @@ do { \
	CREATE_INT_TYPE(cw->data.u64, 64, false, false);
	CREATE_INT_TYPE(cw->data.u64, 64, false, false);
	CREATE_INT_TYPE(cw->data.s32, 32, true,  false);
	CREATE_INT_TYPE(cw->data.s32, 32, true,  false);
	CREATE_INT_TYPE(cw->data.u32, 32, false, false);
	CREATE_INT_TYPE(cw->data.u32, 32, false, false);
	CREATE_INT_TYPE(cw->data.u32_hex, 32, false, true);
	CREATE_INT_TYPE(cw->data.u64_hex, 64, false, true);
	CREATE_INT_TYPE(cw->data.u64_hex, 64, false, true);


	cw->data.string  = bt_ctf_field_type_string_create();
	cw->data.string  = bt_ctf_field_type_string_create();
+1 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ static void dsos__init(struct dsos *dsos)


int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
{
{
	memset(machine, 0, sizeof(*machine));
	map_groups__init(&machine->kmaps, machine);
	map_groups__init(&machine->kmaps, machine);
	RB_CLEAR_NODE(&machine->rb_node);
	RB_CLEAR_NODE(&machine->rb_node);
	dsos__init(&machine->dsos);
	dsos__init(&machine->dsos);