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

perf maps: Rename 'mg' variables to 'maps'

Continuing the merge of 'struct maps' with 'struct map_groups'.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-z8d14wrw393a0fbvmnk1bqd9@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f2eaea09
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ static int check_maps(struct map_def *merged, unsigned int size, struct maps *ma

int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __maybe_unused)
{
	struct maps mg;
	struct maps maps;
	unsigned int i;
	struct map_def bpf_progs[] = {
		{ "bpf_prog_1", 200, 300 },
@@ -64,7 +64,7 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __mayb
	struct map *map_kcore1, *map_kcore2, *map_kcore3;
	int ret;

	maps__init(&mg, NULL);
	maps__init(&maps, NULL);

	for (i = 0; i < ARRAY_SIZE(bpf_progs); i++) {
		struct map *map;
@@ -74,7 +74,7 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __mayb

		map->start = bpf_progs[i].start;
		map->end   = bpf_progs[i].end;
		maps__insert(&mg, map);
		maps__insert(&maps, map);
		map__put(map);
	}

@@ -99,22 +99,22 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __mayb
	map_kcore3->start = 880;
	map_kcore3->end   = 1100;

	ret = maps__merge_in(&mg, map_kcore1);
	ret = maps__merge_in(&maps, map_kcore1);
	TEST_ASSERT_VAL("failed to merge map", !ret);

	ret = check_maps(merged12, ARRAY_SIZE(merged12), &mg);
	ret = check_maps(merged12, ARRAY_SIZE(merged12), &maps);
	TEST_ASSERT_VAL("merge check failed", !ret);

	ret = maps__merge_in(&mg, map_kcore2);
	ret = maps__merge_in(&maps, map_kcore2);
	TEST_ASSERT_VAL("failed to merge map", !ret);

	ret = check_maps(merged12, ARRAY_SIZE(merged12), &mg);
	ret = check_maps(merged12, ARRAY_SIZE(merged12), &maps);
	TEST_ASSERT_VAL("merge check failed", !ret);

	ret = maps__merge_in(&mg, map_kcore3);
	ret = maps__merge_in(&maps, map_kcore3);
	TEST_ASSERT_VAL("failed to merge map", !ret);

	ret = check_maps(merged3, ARRAY_SIZE(merged3), &mg);
	ret = check_maps(merged3, ARRAY_SIZE(merged3), &maps);
	TEST_ASSERT_VAL("merge check failed", !ret);
	return TEST_OK;
}
+9 −9
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ int test__thread_mg_share(struct test *test __maybe_unused, int subtest __maybe_
	/* thread group */
	struct thread *leader;
	struct thread *t1, *t2, *t3;
	struct maps *mg;
	struct maps *maps;

	/* other process */
	struct thread *other, *other_leader;
@@ -42,13 +42,13 @@ int test__thread_mg_share(struct test *test __maybe_unused, int subtest __maybe_
	TEST_ASSERT_VAL("failed to create threads",
			leader && t1 && t2 && t3 && other);

	mg = leader->maps;
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 4);
	maps = leader->maps;
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&maps->refcnt), 4);

	/* test the map groups pointer is shared */
	TEST_ASSERT_VAL("map groups don't match", mg == t1->maps);
	TEST_ASSERT_VAL("map groups don't match", mg == t2->maps);
	TEST_ASSERT_VAL("map groups don't match", mg == t3->maps);
	TEST_ASSERT_VAL("map groups don't match", maps == t1->maps);
	TEST_ASSERT_VAL("map groups don't match", maps == t2->maps);
	TEST_ASSERT_VAL("map groups don't match", maps == t3->maps);

	/*
	 * Verify the other leader was created by previous call.
@@ -77,13 +77,13 @@ int test__thread_mg_share(struct test *test __maybe_unused, int subtest __maybe_

	/* release thread group */
	thread__put(leader);
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 3);
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&maps->refcnt), 3);

	thread__put(t1);
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 2);
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&maps->refcnt), 2);

	thread__put(t2);
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 1);
	TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&maps->refcnt), 1);

	thread__put(t3);

+6 −6
Original line number Diff line number Diff line
@@ -457,11 +457,11 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
			     struct addr_location *al)
{
	struct maps *mg = thread->maps;
	struct machine *machine = mg->machine;
	struct maps *maps = thread->maps;
	struct machine *machine = maps->machine;
	bool load_map = false;

	al->maps = mg;
	al->maps = maps;
	al->thread = thread;
	al->addr = addr;
	al->cpumode = cpumode;
@@ -474,13 +474,13 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,

	if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
		al->level = 'k';
		al->maps = mg = &machine->kmaps;
		al->maps = maps = &machine->kmaps;
		load_map = true;
	} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
		al->level = '.';
	} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
		al->level = 'g';
		al->maps = mg = &machine->kmaps;
		al->maps = maps = &machine->kmaps;
		load_map = true;
	} else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) {
		al->level = 'u';
@@ -500,7 +500,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
		return NULL;
	}

	al->map = maps__find(mg, al->addr);
	al->map = maps__find(maps, al->addr);
	if (al->map != NULL) {
		/*
		 * Kernel maps might be changed when loading symbols so loading
+5 −5
Original line number Diff line number Diff line
@@ -1259,10 +1259,10 @@ static bool is_kmod_dso(struct dso *dso)
	       dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE;
}

static int maps__set_module_path(struct maps *mg, const char *path, struct kmod_path *m)
static int maps__set_module_path(struct maps *maps, const char *path, struct kmod_path *m)
{
	char *long_name;
	struct map *map = maps__find_by_name(mg, m->name);
	struct map *map = maps__find_by_name(maps, m->name);

	if (map == NULL)
		return 0;
@@ -1286,7 +1286,7 @@ static int maps__set_module_path(struct maps *mg, const char *path, struct kmod_
	return 0;
}

static int maps__set_modules_path_dir(struct maps *mg, const char *dir_name, int depth)
static int maps__set_modules_path_dir(struct maps *maps, const char *dir_name, int depth)
{
	struct dirent *dent;
	DIR *dir = opendir(dir_name);
@@ -1318,7 +1318,7 @@ static int maps__set_modules_path_dir(struct maps *mg, const char *dir_name, int
					continue;
			}

			ret = maps__set_modules_path_dir(mg, path, depth + 1);
			ret = maps__set_modules_path_dir(maps, path, depth + 1);
			if (ret < 0)
				goto out;
		} else {
@@ -1329,7 +1329,7 @@ static int maps__set_modules_path_dir(struct maps *mg, const char *dir_name, int
				goto out;

			if (m.kmod)
				ret = maps__set_module_path(mg, path, &m);
				ret = maps__set_module_path(maps, path, &m);

			zfree(&m.name);

+43 −46
Original line number Diff line number Diff line
@@ -512,52 +512,50 @@ u64 map__objdump_2mem(struct map *map, u64 ip)
	return ip + map->reloc;
}

void maps__init(struct maps *mg, struct machine *machine)
void maps__init(struct maps *maps, struct machine *machine)
{
	mg->entries = RB_ROOT;
	init_rwsem(&mg->lock);
	mg->machine = machine;
	mg->last_search_by_name = NULL;
	mg->nr_maps = 0;
	mg->maps_by_name = NULL;
	refcount_set(&mg->refcnt, 1);
	maps->entries = RB_ROOT;
	init_rwsem(&maps->lock);
	maps->machine = machine;
	maps->last_search_by_name = NULL;
	maps->nr_maps = 0;
	maps->maps_by_name = NULL;
	refcount_set(&maps->refcnt, 1);
}

static void __maps__free_maps_by_name(struct maps *mg)
static void __maps__free_maps_by_name(struct maps *maps)
{
	/*
	 * Free everything to try to do it from the rbtree in the next search
	 */
	zfree(&mg->maps_by_name);
	mg->nr_maps_allocated = 0;
	zfree(&maps->maps_by_name);
	maps->nr_maps_allocated = 0;
}

void maps__insert(struct maps *mg, struct map *map)
void maps__insert(struct maps *maps, struct map *map)
{
	struct maps *maps = mg;

	down_write(&maps->lock);
	__maps__insert(maps, map);
	++mg->nr_maps;
	++maps->nr_maps;

	/*
	 * If we already performed some search by name, then we need to add the just
	 * inserted map and resort.
	 */
	if (mg->maps_by_name) {
		if (mg->nr_maps > mg->nr_maps_allocated) {
			int nr_allocate = mg->nr_maps * 2;
			struct map **maps_by_name = realloc(mg->maps_by_name, nr_allocate * sizeof(map));
	if (maps->maps_by_name) {
		if (maps->nr_maps > maps->nr_maps_allocated) {
			int nr_allocate = maps->nr_maps * 2;
			struct map **maps_by_name = realloc(maps->maps_by_name, nr_allocate * sizeof(map));

			if (maps_by_name == NULL) {
				__maps__free_maps_by_name(maps);
				return;
			}

			mg->maps_by_name = maps_by_name;
			mg->nr_maps_allocated = nr_allocate;
			maps->maps_by_name = maps_by_name;
			maps->nr_maps_allocated = nr_allocate;
		}
		mg->maps_by_name[mg->nr_maps - 1] = map;
		maps->maps_by_name[maps->nr_maps - 1] = map;
		__maps__sort_by_name(maps);
	}
	up_write(&maps->lock);
@@ -569,16 +567,15 @@ static void __maps__remove(struct maps *maps, struct map *map)
	map__put(map);
}

void maps__remove(struct maps *mg, struct map *map)
void maps__remove(struct maps *maps, struct map *map)
{
	struct maps *maps = mg;
	down_write(&maps->lock);
	if (mg->last_search_by_name == map)
		mg->last_search_by_name = NULL;
	if (maps->last_search_by_name == map)
		maps->last_search_by_name = NULL;

	__maps__remove(maps, map);
	--mg->nr_maps;
	if (mg->maps_by_name)
	--maps->nr_maps;
	if (maps->maps_by_name)
		__maps__free_maps_by_name(maps);
	up_write(&maps->lock);
}
@@ -607,30 +604,30 @@ bool maps__empty(struct maps *maps)

struct maps *maps__new(struct machine *machine)
{
	struct maps *mg = zalloc(sizeof(*mg)), *maps = mg;
	struct maps *maps = zalloc(sizeof(*maps));

	if (mg != NULL)
	if (maps != NULL)
		maps__init(maps, machine);

	return mg;
	return maps;
}

void maps__delete(struct maps *mg)
void maps__delete(struct maps *maps)
{
	maps__exit(mg);
	unwind__finish_access(mg);
	free(mg);
	maps__exit(maps);
	unwind__finish_access(maps);
	free(maps);
}

void maps__put(struct maps *mg)
void maps__put(struct maps *maps)
{
	if (mg && refcount_dec_and_test(&mg->refcnt))
		maps__delete(mg);
	if (maps && refcount_dec_and_test(&maps->refcnt))
		maps__delete(maps);
}

struct symbol *maps__find_symbol(struct maps *mg, u64 addr, struct map **mapp)
struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
{
	struct map *map = maps__find(mg, addr);
	struct map *map = maps__find(maps, addr);

	/* Ensure map is loaded before using map->map_ip */
	if (map != NULL && map__load(map) >= 0) {
@@ -676,12 +673,12 @@ out:
	return sym;
}

int maps__find_ams(struct maps *mg, struct addr_map_symbol *ams)
int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
{
	if (ams->addr < ams->ms.map->start || ams->addr >= ams->ms.map->end) {
		if (mg == NULL)
		if (maps == NULL)
			return -1;
		ams->ms.map = maps__find(mg, ams->addr);
		ams->ms.map = maps__find(maps, ams->addr);
		if (ams->ms.map == NULL)
			return -1;
	}
@@ -819,7 +816,7 @@ out:
 */
int maps__clone(struct thread *thread, struct maps *parent)
{
	struct maps *mg = thread->maps;
	struct maps *maps = thread->maps;
	int err = -ENOMEM;
	struct map *map;

@@ -830,11 +827,11 @@ int maps__clone(struct thread *thread, struct maps *parent)
		if (new == NULL)
			goto out_unlock;

		err = unwind__prepare_access(mg, new, NULL);
		err = unwind__prepare_access(maps, new, NULL);
		if (err)
			goto out_unlock;

		maps__insert(mg, new);
		maps__insert(maps, new);
		map__put(new);
	}

Loading