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

Commit d28c6223 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf machine: Adopt some map_groups functions



Those functions operated on members now grouped in 'struct machine', so
move those methods to this new class.

The changes made to 'perf probe' shows that using this abstraction
inserting probes on guests almost got supported for free.

Cc: Avi Kivity <avi@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zhang, Yanmin <yanmin_zhang@linux.intel.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 48ea8f54
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -370,7 +370,6 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
		struct alloc_stat *data = rb_entry(next, struct alloc_stat,
						   node);
		struct symbol *sym = NULL;
		struct map_groups *kmaps = &machine->kmaps;
		struct map *map;
		char buf[BUFSIZ];
		u64 addr;
@@ -378,8 +377,7 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
		if (is_caller) {
			addr = data->call_site;
			if (!raw_ip)
				sym = map_groups__find_function(kmaps, addr,
								&map, NULL);
				sym = machine__find_function(machine, addr, &map, NULL);
		} else
			addr = data->ptr;

+3 −6
Original line number Diff line number Diff line
@@ -429,9 +429,8 @@ static int event__process_kernel_mmap(event_t *self,
		} else
			strcpy(short_module_name, self->mmap.filename);

		map = map_groups__new_module(&machine->kmaps,
					     self->mmap.start,
					     self->mmap.filename, machine);
		map = machine__new_module(machine, self->mmap.start,
					  self->mmap.filename);
		if (map == NULL)
			goto out_problem;

@@ -454,9 +453,7 @@ static int event__process_kernel_mmap(event_t *self,
			goto out_problem;

		kernel->kernel = kernel_type;
		if (__map_groups__create_kernel_maps(&machine->kmaps,
						     machine->vmlinux_maps,
						     kernel) < 0)
		if (__machine__create_kernel_maps(machine, kernel) < 0)
			goto out_problem;

		event_set_kernel_mmap_len(machine->vmlinux_maps, self);
+17 −7
Original line number Diff line number Diff line
@@ -513,6 +513,19 @@ struct map *maps__find(struct rb_root *maps, u64 ip)
	return NULL;
}

int machine__init(struct machine *self, const char *root_dir, pid_t pid)
{
	map_groups__init(&self->kmaps);
	RB_CLEAR_NODE(&self->rb_node);
	INIT_LIST_HEAD(&self->user_dsos);
	INIT_LIST_HEAD(&self->kernel_dsos);

	self->kmaps.machine = self;
	self->pid	    = pid;
	self->root_dir      = strdup(root_dir);
	return self->root_dir == NULL ? -ENOMEM : 0;
}

struct machine *machines__add(struct rb_root *self, pid_t pid,
			      const char *root_dir)
{
@@ -523,13 +536,10 @@ struct machine *machines__add(struct rb_root *self, pid_t pid,
	if (!machine)
		return NULL;

	machine->pid = pid;
	map_groups__init(&machine->kmaps);
	machine->root_dir = strdup(root_dir);
	RB_CLEAR_NODE(&machine->rb_node);
	INIT_LIST_HEAD(&machine->user_dsos);
	INIT_LIST_HEAD(&machine->kernel_dsos);
	machine->kmaps.machine = machine;
	if (machine__init(machine, root_dir, pid) != 0) {
		free(machine);
		return NULL;
	}

	while (*p != NULL) {
		parent = *p;
+6 −6
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ struct machine *machines__find_host(struct rb_root *self);
struct machine *machines__find(struct rb_root *self, pid_t pid);
struct machine *machines__findnew(struct rb_root *self, pid_t pid);
char *machine__mmap_name(struct machine *self, char *bf, size_t size);
int machine__init(struct machine *self, const char *root_dir, pid_t pid);

/*
 * Default guest kernel is defined by parameter --guestkallsyms
@@ -172,11 +173,11 @@ struct symbol *map_groups__find_symbol_by_name(struct map_groups *self,
					       struct map **mapp,
					       symbol_filter_t filter);

static inline
struct symbol *map_groups__find_function(struct map_groups *self, u64 addr,
					 struct map **mapp, symbol_filter_t filter)
static inline struct symbol *machine__find_function(struct machine *self,
						    u64 addr, struct map **mapp,
						    symbol_filter_t filter)
{
	return map_groups__find_symbol(self, MAP__FUNCTION, addr, mapp, filter);
	return map_groups__find_symbol(&self->kmaps, MAP__FUNCTION, addr, mapp, filter);
}

static inline
@@ -192,8 +193,7 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,

struct map *map_groups__find_by_name(struct map_groups *self,
				     enum map_type type, const char *name);
struct map *map_groups__new_module(struct map_groups *self, u64 start,
				   const char *filename, struct machine *machine);
struct map *machine__new_module(struct machine *self, u64 start, const char *filename);

void map_groups__flush(struct map_groups *self);

+11 −9
Original line number Diff line number Diff line
@@ -72,8 +72,7 @@ static int e_snprintf(char *str, size_t size, const char *format, ...)
}

static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
static struct map_groups kmap_groups;
static struct map *kmaps[MAP__NR_TYPES];
static struct machine machine;

/* Initialize symbol maps and path of vmlinux */
static int init_vmlinux(void)
@@ -92,12 +91,15 @@ static int init_vmlinux(void)
		goto out;
	}

	ret = machine__init(&machine, "/", 0);
	if (ret < 0)
		goto out;

	kernel = dso__new_kernel(symbol_conf.vmlinux_name);
	if (kernel == NULL)
		die("Failed to create kernel dso.");

	map_groups__init(&kmap_groups);
	ret = __map_groups__create_kernel_maps(&kmap_groups, kmaps, kernel);
	ret = __machine__create_kernel_maps(&machine, kernel);
	if (ret < 0)
		pr_debug("Failed to create kernel maps.\n");

@@ -110,12 +112,12 @@ static int init_vmlinux(void)
#ifdef DWARF_SUPPORT
static int open_vmlinux(void)
{
	if (map__load(kmaps[MAP__FUNCTION], NULL) < 0) {
	if (map__load(machine.vmlinux_maps[MAP__FUNCTION], NULL) < 0) {
		pr_debug("Failed to load kernel map.\n");
		return -EINVAL;
	}
	pr_debug("Try to open %s\n", kmaps[MAP__FUNCTION]->dso->long_name);
	return open(kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY);
	pr_debug("Try to open %s\n", machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name);
	return open(machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name, O_RDONLY);
}

/* Convert trace point to probe point with debuginfo */
@@ -125,7 +127,7 @@ static int convert_to_perf_probe_point(struct kprobe_trace_point *tp,
	struct symbol *sym;
	int fd, ret = -ENOENT;

	sym = map__find_symbol_by_name(kmaps[MAP__FUNCTION],
	sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION],
				       tp->symbol, NULL);
	if (sym) {
		fd = open_vmlinux();
@@ -1466,7 +1468,7 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
	}

	/* Currently just checking function name from symbol map */
	sym = map__find_symbol_by_name(kmaps[MAP__FUNCTION],
	sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION],
				       tev->point.symbol, NULL);
	if (!sym) {
		pr_warning("Kernel symbol \'%s\' not found.\n",
Loading