diff options
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r-- | tools/perf/util/symbol.c | 71 |
1 files changed, 30 insertions, 41 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index c9c0bdd667ac..12359c37240c 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -1528,21 +1528,20 @@ static char *get_kernel_version(const char *root_dir) | |||
1528 | return strdup(name); | 1528 | return strdup(name); |
1529 | } | 1529 | } |
1530 | 1530 | ||
1531 | static int map_groups__set_modules_path(struct map_groups *self, | 1531 | static int machine__set_modules_path(struct machine *self) |
1532 | const char *root_dir) | ||
1533 | { | 1532 | { |
1534 | char *version; | 1533 | char *version; |
1535 | char modules_path[PATH_MAX]; | 1534 | char modules_path[PATH_MAX]; |
1536 | 1535 | ||
1537 | version = get_kernel_version(root_dir); | 1536 | version = get_kernel_version(self->root_dir); |
1538 | if (!version) | 1537 | if (!version) |
1539 | return -1; | 1538 | return -1; |
1540 | 1539 | ||
1541 | snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel", | 1540 | snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel", |
1542 | root_dir, version); | 1541 | self->root_dir, version); |
1543 | free(version); | 1542 | free(version); |
1544 | 1543 | ||
1545 | return map_groups__set_modules_path_dir(self, modules_path); | 1544 | return map_groups__set_modules_path_dir(&self->kmaps, modules_path); |
1546 | } | 1545 | } |
1547 | 1546 | ||
1548 | /* | 1547 | /* |
@@ -1564,14 +1563,12 @@ static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) | |||
1564 | return self; | 1563 | return self; |
1565 | } | 1564 | } |
1566 | 1565 | ||
1567 | struct map *map_groups__new_module(struct map_groups *self, u64 start, | 1566 | struct map *machine__new_module(struct machine *self, u64 start, |
1568 | const char *filename, | 1567 | const char *filename) |
1569 | struct machine *machine) | ||
1570 | { | 1568 | { |
1571 | struct map *map; | 1569 | struct map *map; |
1572 | struct dso *dso; | 1570 | struct dso *dso = __dsos__findnew(&self->kernel_dsos, filename); |
1573 | 1571 | ||
1574 | dso = __dsos__findnew(&machine->kernel_dsos, filename); | ||
1575 | if (dso == NULL) | 1572 | if (dso == NULL) |
1576 | return NULL; | 1573 | return NULL; |
1577 | 1574 | ||
@@ -1579,28 +1576,27 @@ struct map *map_groups__new_module(struct map_groups *self, u64 start, | |||
1579 | if (map == NULL) | 1576 | if (map == NULL) |
1580 | return NULL; | 1577 | return NULL; |
1581 | 1578 | ||
1582 | if (machine__is_host(machine)) | 1579 | if (machine__is_host(self)) |
1583 | dso->origin = DSO__ORIG_KMODULE; | 1580 | dso->origin = DSO__ORIG_KMODULE; |
1584 | else | 1581 | else |
1585 | dso->origin = DSO__ORIG_GUEST_KMODULE; | 1582 | dso->origin = DSO__ORIG_GUEST_KMODULE; |
1586 | map_groups__insert(self, map); | 1583 | map_groups__insert(&self->kmaps, map); |
1587 | return map; | 1584 | return map; |
1588 | } | 1585 | } |
1589 | 1586 | ||
1590 | static int map_groups__create_modules(struct machine *machine) | 1587 | static int machine__create_modules(struct machine *self) |
1591 | { | 1588 | { |
1592 | char *line = NULL; | 1589 | char *line = NULL; |
1593 | size_t n; | 1590 | size_t n; |
1594 | FILE *file; | 1591 | FILE *file; |
1595 | struct map *map; | 1592 | struct map *map; |
1596 | const char *root_dir; | ||
1597 | const char *modules; | 1593 | const char *modules; |
1598 | char path[PATH_MAX]; | 1594 | char path[PATH_MAX]; |
1599 | 1595 | ||
1600 | if (machine__is_default_guest(machine)) | 1596 | if (machine__is_default_guest(self)) |
1601 | modules = symbol_conf.default_guest_modules; | 1597 | modules = symbol_conf.default_guest_modules; |
1602 | else { | 1598 | else { |
1603 | sprintf(path, "%s/proc/modules", machine->root_dir); | 1599 | sprintf(path, "%s/proc/modules", self->root_dir); |
1604 | modules = path; | 1600 | modules = path; |
1605 | } | 1601 | } |
1606 | 1602 | ||
@@ -1608,8 +1604,6 @@ static int map_groups__create_modules(struct machine *machine) | |||
1608 | if (file == NULL) | 1604 | if (file == NULL) |
1609 | return -1; | 1605 | return -1; |
1610 | 1606 | ||
1611 | root_dir = machine->root_dir; | ||
1612 | |||
1613 | while (!feof(file)) { | 1607 | while (!feof(file)) { |
1614 | char name[PATH_MAX]; | 1608 | char name[PATH_MAX]; |
1615 | u64 start; | 1609 | u64 start; |
@@ -1638,17 +1632,16 @@ static int map_groups__create_modules(struct machine *machine) | |||
1638 | *sep = '\0'; | 1632 | *sep = '\0'; |
1639 | 1633 | ||
1640 | snprintf(name, sizeof(name), "[%s]", line); | 1634 | snprintf(name, sizeof(name), "[%s]", line); |
1641 | map = map_groups__new_module(&machine->kmaps, start, | 1635 | map = machine__new_module(self, start, name); |
1642 | name, machine); | ||
1643 | if (map == NULL) | 1636 | if (map == NULL) |
1644 | goto out_delete_line; | 1637 | goto out_delete_line; |
1645 | dso__kernel_module_get_build_id(map->dso, root_dir); | 1638 | dso__kernel_module_get_build_id(map->dso, self->root_dir); |
1646 | } | 1639 | } |
1647 | 1640 | ||
1648 | free(line); | 1641 | free(line); |
1649 | fclose(file); | 1642 | fclose(file); |
1650 | 1643 | ||
1651 | return map_groups__set_modules_path(&machine->kmaps, root_dir); | 1644 | return machine__set_modules_path(self); |
1652 | 1645 | ||
1653 | out_delete_line: | 1646 | out_delete_line: |
1654 | free(line); | 1647 | free(line); |
@@ -2005,25 +1998,23 @@ static struct dso *dsos__create_kernel(struct machine *machine) | |||
2005 | return kernel; | 1998 | return kernel; |
2006 | } | 1999 | } |
2007 | 2000 | ||
2008 | int __map_groups__create_kernel_maps(struct map_groups *self, | 2001 | int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) |
2009 | struct map *vmlinux_maps[MAP__NR_TYPES], | ||
2010 | struct dso *kernel) | ||
2011 | { | 2002 | { |
2012 | enum map_type type; | 2003 | enum map_type type; |
2013 | 2004 | ||
2014 | for (type = 0; type < MAP__NR_TYPES; ++type) { | 2005 | for (type = 0; type < MAP__NR_TYPES; ++type) { |
2015 | struct kmap *kmap; | 2006 | struct kmap *kmap; |
2016 | 2007 | ||
2017 | vmlinux_maps[type] = map__new2(0, kernel, type); | 2008 | self->vmlinux_maps[type] = map__new2(0, kernel, type); |
2018 | if (vmlinux_maps[type] == NULL) | 2009 | if (self->vmlinux_maps[type] == NULL) |
2019 | return -1; | 2010 | return -1; |
2020 | 2011 | ||
2021 | vmlinux_maps[type]->map_ip = | 2012 | self->vmlinux_maps[type]->map_ip = |
2022 | vmlinux_maps[type]->unmap_ip = identity__map_ip; | 2013 | self->vmlinux_maps[type]->unmap_ip = identity__map_ip; |
2023 | 2014 | ||
2024 | kmap = map__kmap(vmlinux_maps[type]); | 2015 | kmap = map__kmap(self->vmlinux_maps[type]); |
2025 | kmap->kmaps = self; | 2016 | kmap->kmaps = &self->kmaps; |
2026 | map_groups__insert(self, vmlinux_maps[type]); | 2017 | map_groups__insert(&self->kmaps, self->vmlinux_maps[type]); |
2027 | } | 2018 | } |
2028 | 2019 | ||
2029 | return 0; | 2020 | return 0; |
@@ -2145,10 +2136,10 @@ out_free_comm_list: | |||
2145 | return -1; | 2136 | return -1; |
2146 | } | 2137 | } |
2147 | 2138 | ||
2148 | int map_groups__create_kernel_maps(struct rb_root *machines, pid_t pid) | 2139 | int machines__create_kernel_maps(struct rb_root *self, pid_t pid) |
2149 | { | 2140 | { |
2150 | struct dso *kernel; | 2141 | struct dso *kernel; |
2151 | struct machine *machine = machines__findnew(machines, pid); | 2142 | struct machine *machine = machines__findnew(self, pid); |
2152 | 2143 | ||
2153 | if (machine == NULL) | 2144 | if (machine == NULL) |
2154 | return -1; | 2145 | return -1; |
@@ -2156,12 +2147,10 @@ int map_groups__create_kernel_maps(struct rb_root *machines, pid_t pid) | |||
2156 | if (kernel == NULL) | 2147 | if (kernel == NULL) |
2157 | return -1; | 2148 | return -1; |
2158 | 2149 | ||
2159 | if (__map_groups__create_kernel_maps(&machine->kmaps, | 2150 | if (__machine__create_kernel_maps(machine, kernel) < 0) |
2160 | machine->vmlinux_maps, kernel) < 0) | ||
2161 | return -1; | 2151 | return -1; |
2162 | 2152 | ||
2163 | if (symbol_conf.use_modules && | 2153 | if (symbol_conf.use_modules && machine__create_modules(machine) < 0) |
2164 | map_groups__create_modules(machine) < 0) | ||
2165 | pr_debug("Problems creating module maps, continuing anyway...\n"); | 2154 | pr_debug("Problems creating module maps, continuing anyway...\n"); |
2166 | /* | 2155 | /* |
2167 | * Now that we have all the maps created, just set the ->end of them: | 2156 | * Now that we have all the maps created, just set the ->end of them: |
@@ -2213,7 +2202,7 @@ char *strxfrchar(char *s, char from, char to) | |||
2213 | return s; | 2202 | return s; |
2214 | } | 2203 | } |
2215 | 2204 | ||
2216 | int map_groups__create_guest_kernel_maps(struct rb_root *machines) | 2205 | int machines__create_guest_kernel_maps(struct rb_root *self) |
2217 | { | 2206 | { |
2218 | int ret = 0; | 2207 | int ret = 0; |
2219 | struct dirent **namelist = NULL; | 2208 | struct dirent **namelist = NULL; |
@@ -2224,7 +2213,7 @@ int map_groups__create_guest_kernel_maps(struct rb_root *machines) | |||
2224 | if (symbol_conf.default_guest_vmlinux_name || | 2213 | if (symbol_conf.default_guest_vmlinux_name || |
2225 | symbol_conf.default_guest_modules || | 2214 | symbol_conf.default_guest_modules || |
2226 | symbol_conf.default_guest_kallsyms) { | 2215 | symbol_conf.default_guest_kallsyms) { |
2227 | map_groups__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID); | 2216 | machines__create_kernel_maps(self, DEFAULT_GUEST_KERNEL_ID); |
2228 | } | 2217 | } |
2229 | 2218 | ||
2230 | if (symbol_conf.guestmount) { | 2219 | if (symbol_conf.guestmount) { |
@@ -2245,7 +2234,7 @@ int map_groups__create_guest_kernel_maps(struct rb_root *machines) | |||
2245 | pr_debug("Can't access file %s\n", path); | 2234 | pr_debug("Can't access file %s\n", path); |
2246 | goto failure; | 2235 | goto failure; |
2247 | } | 2236 | } |
2248 | map_groups__create_kernel_maps(machines, pid); | 2237 | machines__create_kernel_maps(self, pid); |
2249 | } | 2238 | } |
2250 | failure: | 2239 | failure: |
2251 | free(namelist); | 2240 | free(namelist); |