aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/symbol.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-04-27 20:17:50 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-04-27 20:17:50 -0400
commit23346f21b277e3aae5e9989e711a11cbe8133a45 (patch)
tree21f11a72cf21d4eb3d824f46e274dc8f9815d749 /tools/perf/util/symbol.c
parent462b04e28a7ec1339c892117c3f20a40e55d0e83 (diff)
perf tools: Rename "kernel_info" to "machine"
struct kernel_info and kerninfo__ are too vague, what they really describe are machines, virtual ones or hosts. There are more changes to introduce helpers to shorten function calls and to make more clear what is really being done, but I left that for subsequent patches. Cc: Avi Kivity <avi@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Cc: Zhang, Yanmin <yanmin_zhang@linux.intel.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r--tools/perf/util/symbol.c132
1 files changed, 60 insertions, 72 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index e77c33a11de3..dc046368b5cf 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -485,7 +485,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
485 symbol_filter_t filter) 485 symbol_filter_t filter)
486{ 486{
487 struct map_groups *kmaps = map__kmap(map)->kmaps; 487 struct map_groups *kmaps = map__kmap(map)->kmaps;
488 struct kernel_info *kerninfo = kmaps->this_kerninfo; 488 struct machine *machine = kmaps->machine;
489 struct map *curr_map = map; 489 struct map *curr_map = map;
490 struct symbol *pos; 490 struct symbol *pos;
491 int count = 0; 491 int count = 0;
@@ -508,8 +508,8 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
508 508
509 if (strcmp(curr_map->dso->short_name, module)) { 509 if (strcmp(curr_map->dso->short_name, module)) {
510 if (curr_map != map && 510 if (curr_map != map &&
511 self->kernel == DSO_TYPE_GUEST_KERNEL && 511 self->kernel == DSO_TYPE_GUEST_KERNEL &&
512 is_default_guest(kerninfo)) { 512 machine__is_default_guest(machine)) {
513 /* 513 /*
514 * We assume all symbols of a module are 514 * We assume all symbols of a module are
515 * continuous in * kallsyms, so curr_map 515 * continuous in * kallsyms, so curr_map
@@ -527,13 +527,13 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
527 pr_err("%s/proc/{kallsyms,modules} " 527 pr_err("%s/proc/{kallsyms,modules} "
528 "inconsistency while looking " 528 "inconsistency while looking "
529 "for \"%s\" module!\n", 529 "for \"%s\" module!\n",
530 kerninfo->root_dir, module); 530 machine->root_dir, module);
531 curr_map = map; 531 curr_map = map;
532 goto discard_symbol; 532 goto discard_symbol;
533 } 533 }
534 534
535 if (curr_map->dso->loaded && 535 if (curr_map->dso->loaded &&
536 !is_default_guest(kmaps->this_kerninfo)) 536 !machine__is_default_guest(machine))
537 goto discard_symbol; 537 goto discard_symbol;
538 } 538 }
539 /* 539 /*
@@ -586,7 +586,7 @@ discard_symbol: rb_erase(&pos->rb_node, root);
586 586
587 if (curr_map != map && 587 if (curr_map != map &&
588 self->kernel == DSO_TYPE_GUEST_KERNEL && 588 self->kernel == DSO_TYPE_GUEST_KERNEL &&
589 is_default_guest(kmaps->this_kerninfo)) { 589 machine__is_default_guest(kmaps->machine)) {
590 dso__set_loaded(curr_map->dso, curr_map->type); 590 dso__set_loaded(curr_map->dso, curr_map->type);
591 } 591 }
592 592
@@ -1291,7 +1291,7 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
1291 char build_id_hex[BUILD_ID_SIZE * 2 + 1]; 1291 char build_id_hex[BUILD_ID_SIZE * 2 + 1];
1292 int ret = -1; 1292 int ret = -1;
1293 int fd; 1293 int fd;
1294 struct kernel_info *kerninfo; 1294 struct machine *machine;
1295 const char *root_dir; 1295 const char *root_dir;
1296 1296
1297 dso__set_loaded(self, map->type); 1297 dso__set_loaded(self, map->type);
@@ -1301,10 +1301,10 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
1301 else if (self->kernel == DSO_TYPE_GUEST_KERNEL) 1301 else if (self->kernel == DSO_TYPE_GUEST_KERNEL)
1302 return dso__load_guest_kernel_sym(self, map, filter); 1302 return dso__load_guest_kernel_sym(self, map, filter);
1303 1303
1304 if (map->groups && map->groups->this_kerninfo) 1304 if (map->groups && map->groups->machine)
1305 kerninfo = map->groups->this_kerninfo; 1305 machine = map->groups->machine;
1306 else 1306 else
1307 kerninfo = NULL; 1307 machine = NULL;
1308 1308
1309 name = malloc(size); 1309 name = malloc(size);
1310 if (!name) 1310 if (!name)
@@ -1359,8 +1359,8 @@ more:
1359 snprintf(name, size, "%s", self->long_name); 1359 snprintf(name, size, "%s", self->long_name);
1360 break; 1360 break;
1361 case DSO__ORIG_GUEST_KMODULE: 1361 case DSO__ORIG_GUEST_KMODULE:
1362 if (map->groups && map->groups->this_kerninfo) 1362 if (map->groups && map->groups->machine)
1363 root_dir = map->groups->this_kerninfo->root_dir; 1363 root_dir = map->groups->machine->root_dir;
1364 else 1364 else
1365 root_dir = ""; 1365 root_dir = "";
1366 snprintf(name, size, "%s%s", root_dir, self->long_name); 1366 snprintf(name, size, "%s%s", root_dir, self->long_name);
@@ -1566,12 +1566,12 @@ static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
1566 1566
1567struct map *map_groups__new_module(struct map_groups *self, u64 start, 1567struct map *map_groups__new_module(struct map_groups *self, u64 start,
1568 const char *filename, 1568 const char *filename,
1569 struct kernel_info *kerninfo) 1569 struct machine *machine)
1570{ 1570{
1571 struct map *map; 1571 struct map *map;
1572 struct dso *dso; 1572 struct dso *dso;
1573 1573
1574 dso = __dsos__findnew(&kerninfo->dsos__kernel, filename); 1574 dso = __dsos__findnew(&machine->kernel_dsos, filename);
1575 if (dso == NULL) 1575 if (dso == NULL)
1576 return NULL; 1576 return NULL;
1577 1577
@@ -1579,7 +1579,7 @@ struct map *map_groups__new_module(struct map_groups *self, u64 start,
1579 if (map == NULL) 1579 if (map == NULL)
1580 return NULL; 1580 return NULL;
1581 1581
1582 if (is_host_kernel(kerninfo)) 1582 if (machine__is_host(machine))
1583 dso->origin = DSO__ORIG_KMODULE; 1583 dso->origin = DSO__ORIG_KMODULE;
1584 else 1584 else
1585 dso->origin = DSO__ORIG_GUEST_KMODULE; 1585 dso->origin = DSO__ORIG_GUEST_KMODULE;
@@ -1587,7 +1587,7 @@ struct map *map_groups__new_module(struct map_groups *self, u64 start,
1587 return map; 1587 return map;
1588} 1588}
1589 1589
1590static int map_groups__create_modules(struct kernel_info *kerninfo) 1590static int map_groups__create_modules(struct machine *machine)
1591{ 1591{
1592 char *line = NULL; 1592 char *line = NULL;
1593 size_t n; 1593 size_t n;
@@ -1597,10 +1597,10 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1597 const char *modules; 1597 const char *modules;
1598 char path[PATH_MAX]; 1598 char path[PATH_MAX];
1599 1599
1600 if (is_default_guest(kerninfo)) 1600 if (machine__is_default_guest(machine))
1601 modules = symbol_conf.default_guest_modules; 1601 modules = symbol_conf.default_guest_modules;
1602 else { 1602 else {
1603 sprintf(path, "%s/proc/modules", kerninfo->root_dir); 1603 sprintf(path, "%s/proc/modules", machine->root_dir);
1604 modules = path; 1604 modules = path;
1605 } 1605 }
1606 1606
@@ -1608,7 +1608,7 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1608 if (file == NULL) 1608 if (file == NULL)
1609 return -1; 1609 return -1;
1610 1610
1611 root_dir = kerninfo->root_dir; 1611 root_dir = machine->root_dir;
1612 1612
1613 while (!feof(file)) { 1613 while (!feof(file)) {
1614 char name[PATH_MAX]; 1614 char name[PATH_MAX];
@@ -1638,8 +1638,8 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1638 *sep = '\0'; 1638 *sep = '\0';
1639 1639
1640 snprintf(name, sizeof(name), "[%s]", line); 1640 snprintf(name, sizeof(name), "[%s]", line);
1641 map = map_groups__new_module(&kerninfo->kmaps, 1641 map = map_groups__new_module(&machine->kmaps, start,
1642 start, name, kerninfo); 1642 name, machine);
1643 if (map == NULL) 1643 if (map == NULL)
1644 goto out_delete_line; 1644 goto out_delete_line;
1645 dso__kernel_module_get_build_id(map->dso, root_dir); 1645 dso__kernel_module_get_build_id(map->dso, root_dir);
@@ -1648,7 +1648,7 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1648 free(line); 1648 free(line);
1649 fclose(file); 1649 fclose(file);
1650 1650
1651 return map_groups__set_modules_path(&kerninfo->kmaps, root_dir); 1651 return map_groups__set_modules_path(&machine->kmaps, root_dir);
1652 1652
1653out_delete_line: 1653out_delete_line:
1654 free(line); 1654 free(line);
@@ -1820,16 +1820,16 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
1820{ 1820{
1821 int err; 1821 int err;
1822 const char *kallsyms_filename = NULL; 1822 const char *kallsyms_filename = NULL;
1823 struct kernel_info *kerninfo; 1823 struct machine *machine;
1824 char path[PATH_MAX]; 1824 char path[PATH_MAX];
1825 1825
1826 if (!map->groups) { 1826 if (!map->groups) {
1827 pr_debug("Guest kernel map hasn't the point to groups\n"); 1827 pr_debug("Guest kernel map hasn't the point to groups\n");
1828 return -1; 1828 return -1;
1829 } 1829 }
1830 kerninfo = map->groups->this_kerninfo; 1830 machine = map->groups->machine;
1831 1831
1832 if (is_default_guest(kerninfo)) { 1832 if (machine__is_default_guest(machine)) {
1833 /* 1833 /*
1834 * if the user specified a vmlinux filename, use it and only 1834 * if the user specified a vmlinux filename, use it and only
1835 * it, reporting errors to the user if it cannot be used. 1835 * it, reporting errors to the user if it cannot be used.
@@ -1845,7 +1845,7 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
1845 if (!kallsyms_filename) 1845 if (!kallsyms_filename)
1846 return -1; 1846 return -1;
1847 } else { 1847 } else {
1848 sprintf(path, "%s/proc/kallsyms", kerninfo->root_dir); 1848 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
1849 kallsyms_filename = path; 1849 kallsyms_filename = path;
1850 } 1850 }
1851 1851
@@ -1856,9 +1856,8 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
1856out_try_fixup: 1856out_try_fixup:
1857 if (err > 0) { 1857 if (err > 0) {
1858 if (kallsyms_filename != NULL) { 1858 if (kallsyms_filename != NULL) {
1859 kern_mmap_name(kerninfo, path); 1859 machine__mmap_name(machine, path);
1860 dso__set_long_name(self, 1860 dso__set_long_name(self, strdup(path));
1861 strdup(path));
1862 } 1861 }
1863 map__fixup_start(map); 1862 map__fixup_start(map);
1864 map__fixup_end(map); 1863 map__fixup_end(map);
@@ -1908,15 +1907,14 @@ static void __dsos__fprintf(struct list_head *head, FILE *fp)
1908 } 1907 }
1909} 1908}
1910 1909
1911void dsos__fprintf(struct rb_root *kerninfo_root, FILE *fp) 1910void dsos__fprintf(struct rb_root *machines, FILE *fp)
1912{ 1911{
1913 struct rb_node *nd; 1912 struct rb_node *nd;
1914 1913
1915 for (nd = rb_first(kerninfo_root); nd; nd = rb_next(nd)) { 1914 for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
1916 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 1915 struct machine *pos = rb_entry(nd, struct machine, rb_node);
1917 rb_node); 1916 __dsos__fprintf(&pos->kernel_dsos, fp);
1918 __dsos__fprintf(&pos->dsos__kernel, fp); 1917 __dsos__fprintf(&pos->user_dsos, fp);
1919 __dsos__fprintf(&pos->dsos__user, fp);
1920 } 1918 }
1921} 1919}
1922 1920
@@ -1935,19 +1933,15 @@ static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
1935 return ret; 1933 return ret;
1936} 1934}
1937 1935
1938size_t dsos__fprintf_buildid(struct rb_root *kerninfo_root, 1936size_t dsos__fprintf_buildid(struct rb_root *machines, FILE *fp, bool with_hits)
1939 FILE *fp, bool with_hits)
1940{ 1937{
1941 struct rb_node *nd; 1938 struct rb_node *nd;
1942 size_t ret = 0; 1939 size_t ret = 0;
1943 1940
1944 for (nd = rb_first(kerninfo_root); nd; nd = rb_next(nd)) { 1941 for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
1945 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 1942 struct machine *pos = rb_entry(nd, struct machine, rb_node);
1946 rb_node); 1943 ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits);
1947 ret += __dsos__fprintf_buildid(&pos->dsos__kernel, 1944 ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits);
1948 fp, with_hits);
1949 ret += __dsos__fprintf_buildid(&pos->dsos__user,
1950 fp, with_hits);
1951 } 1945 }
1952 return ret; 1946 return ret;
1953} 1947}
@@ -1964,14 +1958,12 @@ struct dso *dso__new_kernel(const char *name)
1964 return self; 1958 return self;
1965} 1959}
1966 1960
1967static struct dso *dso__new_guest_kernel(struct kernel_info *kerninfo, 1961static struct dso *dso__new_guest_kernel(struct machine *machine,
1968 const char *name) 1962 const char *name)
1969{ 1963{
1970 char buff[PATH_MAX]; 1964 char buff[PATH_MAX];
1971 struct dso *self; 1965 struct dso *self = dso__new(name ?: machine__mmap_name(machine, buff));
1972 1966
1973 kern_mmap_name(kerninfo, buff);
1974 self = dso__new(name ?: buff);
1975 if (self != NULL) { 1967 if (self != NULL) {
1976 dso__set_short_name(self, "[guest.kernel]"); 1968 dso__set_short_name(self, "[guest.kernel]");
1977 self->kernel = DSO_TYPE_GUEST_KERNEL; 1969 self->kernel = DSO_TYPE_GUEST_KERNEL;
@@ -1980,36 +1972,35 @@ static struct dso *dso__new_guest_kernel(struct kernel_info *kerninfo,
1980 return self; 1972 return self;
1981} 1973}
1982 1974
1983void dso__read_running_kernel_build_id(struct dso *self, 1975void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine)
1984 struct kernel_info *kerninfo)
1985{ 1976{
1986 char path[PATH_MAX]; 1977 char path[PATH_MAX];
1987 1978
1988 if (is_default_guest(kerninfo)) 1979 if (machine__is_default_guest(machine))
1989 return; 1980 return;
1990 sprintf(path, "%s/sys/kernel/notes", kerninfo->root_dir); 1981 sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
1991 if (sysfs__read_build_id(path, self->build_id, 1982 if (sysfs__read_build_id(path, self->build_id,
1992 sizeof(self->build_id)) == 0) 1983 sizeof(self->build_id)) == 0)
1993 self->has_build_id = true; 1984 self->has_build_id = true;
1994} 1985}
1995 1986
1996static struct dso *dsos__create_kernel(struct kernel_info *kerninfo) 1987static struct dso *dsos__create_kernel(struct machine *machine)
1997{ 1988{
1998 const char *vmlinux_name = NULL; 1989 const char *vmlinux_name = NULL;
1999 struct dso *kernel; 1990 struct dso *kernel;
2000 1991
2001 if (is_host_kernel(kerninfo)) { 1992 if (machine__is_host(machine)) {
2002 vmlinux_name = symbol_conf.vmlinux_name; 1993 vmlinux_name = symbol_conf.vmlinux_name;
2003 kernel = dso__new_kernel(vmlinux_name); 1994 kernel = dso__new_kernel(vmlinux_name);
2004 } else { 1995 } else {
2005 if (is_default_guest(kerninfo)) 1996 if (machine__is_default_guest(machine))
2006 vmlinux_name = symbol_conf.default_guest_vmlinux_name; 1997 vmlinux_name = symbol_conf.default_guest_vmlinux_name;
2007 kernel = dso__new_guest_kernel(kerninfo, vmlinux_name); 1998 kernel = dso__new_guest_kernel(machine, vmlinux_name);
2008 } 1999 }
2009 2000
2010 if (kernel != NULL) { 2001 if (kernel != NULL) {
2011 dso__read_running_kernel_build_id(kernel, kerninfo); 2002 dso__read_running_kernel_build_id(kernel, machine);
2012 dsos__add(&kerninfo->dsos__kernel, kernel); 2003 dsos__add(&machine->kernel_dsos, kernel);
2013 } 2004 }
2014 return kernel; 2005 return kernel;
2015} 2006}
@@ -2154,29 +2145,28 @@ out_free_comm_list:
2154 return -1; 2145 return -1;
2155} 2146}
2156 2147
2157int map_groups__create_kernel_maps(struct rb_root *kerninfo_root, pid_t pid) 2148int map_groups__create_kernel_maps(struct rb_root *machines, pid_t pid)
2158{ 2149{
2159 struct kernel_info *kerninfo;
2160 struct dso *kernel; 2150 struct dso *kernel;
2151 struct machine *machine = machines__findnew(machines, pid);
2161 2152
2162 kerninfo = kerninfo__findnew(kerninfo_root, pid); 2153 if (machine == NULL)
2163 if (kerninfo == NULL)
2164 return -1; 2154 return -1;
2165 kernel = dsos__create_kernel(kerninfo); 2155 kernel = dsos__create_kernel(machine);
2166 if (kernel == NULL) 2156 if (kernel == NULL)
2167 return -1; 2157 return -1;
2168 2158
2169 if (__map_groups__create_kernel_maps(&kerninfo->kmaps, 2159 if (__map_groups__create_kernel_maps(&machine->kmaps,
2170 kerninfo->vmlinux_maps, kernel) < 0) 2160 machine->vmlinux_maps, kernel) < 0)
2171 return -1; 2161 return -1;
2172 2162
2173 if (symbol_conf.use_modules && 2163 if (symbol_conf.use_modules &&
2174 map_groups__create_modules(kerninfo) < 0) 2164 map_groups__create_modules(machine) < 0)
2175 pr_debug("Problems creating module maps, continuing anyway...\n"); 2165 pr_debug("Problems creating module maps, continuing anyway...\n");
2176 /* 2166 /*
2177 * Now that we have all the maps created, just set the ->end of them: 2167 * Now that we have all the maps created, just set the ->end of them:
2178 */ 2168 */
2179 map_groups__fixup_end(&kerninfo->kmaps); 2169 map_groups__fixup_end(&machine->kmaps);
2180 return 0; 2170 return 0;
2181} 2171}
2182 2172
@@ -2223,7 +2213,7 @@ char *strxfrchar(char *s, char from, char to)
2223 return s; 2213 return s;
2224} 2214}
2225 2215
2226int map_groups__create_guest_kernel_maps(struct rb_root *kerninfo_root) 2216int map_groups__create_guest_kernel_maps(struct rb_root *machines)
2227{ 2217{
2228 int ret = 0; 2218 int ret = 0;
2229 struct dirent **namelist = NULL; 2219 struct dirent **namelist = NULL;
@@ -2234,8 +2224,7 @@ int map_groups__create_guest_kernel_maps(struct rb_root *kerninfo_root)
2234 if (symbol_conf.default_guest_vmlinux_name || 2224 if (symbol_conf.default_guest_vmlinux_name ||
2235 symbol_conf.default_guest_modules || 2225 symbol_conf.default_guest_modules ||
2236 symbol_conf.default_guest_kallsyms) { 2226 symbol_conf.default_guest_kallsyms) {
2237 map_groups__create_kernel_maps(kerninfo_root, 2227 map_groups__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
2238 DEFAULT_GUEST_KERNEL_ID);
2239 } 2228 }
2240 2229
2241 if (symbol_conf.guestmount) { 2230 if (symbol_conf.guestmount) {
@@ -2256,8 +2245,7 @@ int map_groups__create_guest_kernel_maps(struct rb_root *kerninfo_root)
2256 pr_debug("Can't access file %s\n", path); 2245 pr_debug("Can't access file %s\n", path);
2257 goto failure; 2246 goto failure;
2258 } 2247 }
2259 map_groups__create_kernel_maps(kerninfo_root, 2248 map_groups__create_kernel_maps(machines, pid);
2260 pid);
2261 } 2249 }
2262failure: 2250failure:
2263 free(namelist); 2251 free(namelist);