Skip to content

Commit b4503cd

Browse files
ahunter6acmel
authored andcommitted
perf kcore_copy: Get rid of kernel_map
In preparation to add more program headers, get rid of kernel_map and modules_map by moving ->kernel_map and ->modules_map to newly allocated entries in the ->phdrs list. Signed-off-by: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Dave Hansen <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d2c9598 commit b4503cd

File tree

1 file changed

+52
-18
lines changed

1 file changed

+52
-18
lines changed

tools/perf/util/symbol-elf.c

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,14 +1400,47 @@ struct kcore_copy_info {
14001400
u64 first_module;
14011401
u64 last_module_symbol;
14021402
size_t phnum;
1403-
struct phdr_data kernel_map;
1404-
struct phdr_data modules_map;
14051403
struct list_head phdrs;
14061404
};
14071405

14081406
#define kcore_copy__for_each_phdr(k, p) \
14091407
list_for_each_entry((p), &(k)->phdrs, node)
14101408

1409+
static struct phdr_data *phdr_data__new(u64 addr, u64 len, off_t offset)
1410+
{
1411+
struct phdr_data *p = zalloc(sizeof(*p));
1412+
1413+
if (p) {
1414+
p->addr = addr;
1415+
p->len = len;
1416+
p->offset = offset;
1417+
}
1418+
1419+
return p;
1420+
}
1421+
1422+
static struct phdr_data *kcore_copy_info__addnew(struct kcore_copy_info *kci,
1423+
u64 addr, u64 len,
1424+
off_t offset)
1425+
{
1426+
struct phdr_data *p = phdr_data__new(addr, len, offset);
1427+
1428+
if (p)
1429+
list_add_tail(&p->node, &kci->phdrs);
1430+
1431+
return p;
1432+
}
1433+
1434+
static void kcore_copy__free_phdrs(struct kcore_copy_info *kci)
1435+
{
1436+
struct phdr_data *p, *tmp;
1437+
1438+
list_for_each_entry_safe(p, tmp, &kci->phdrs, node) {
1439+
list_del(&p->node);
1440+
free(p);
1441+
}
1442+
}
1443+
14111444
static int kcore_copy__process_kallsyms(void *arg, const char *name, char type,
14121445
u64 start)
14131446
{
@@ -1487,27 +1520,31 @@ static int kcore_copy__parse_modules(struct kcore_copy_info *kci,
14871520
return 0;
14881521
}
14891522

1490-
static void kcore_copy__map(struct phdr_data *p, u64 start, u64 end, u64 pgoff,
1491-
u64 s, u64 e)
1523+
static int kcore_copy__map(struct kcore_copy_info *kci, u64 start, u64 end,
1524+
u64 pgoff, u64 s, u64 e)
14921525
{
1493-
if (p->addr || s < start || s >= end)
1494-
return;
1526+
u64 len, offset;
1527+
1528+
if (s < start || s >= end)
1529+
return 0;
14951530

1496-
p->addr = s;
1497-
p->offset = (s - start) + pgoff;
1498-
p->len = e < end ? e - s : end - s;
1531+
offset = (s - start) + pgoff;
1532+
len = e < end ? e - s : end - s;
1533+
1534+
return kcore_copy_info__addnew(kci, s, len, offset) ? 0 : -1;
14991535
}
15001536

15011537
static int kcore_copy__read_map(u64 start, u64 len, u64 pgoff, void *data)
15021538
{
15031539
struct kcore_copy_info *kci = data;
15041540
u64 end = start + len;
15051541

1506-
kcore_copy__map(&kci->kernel_map, start, end, pgoff, kci->stext,
1507-
kci->etext);
1542+
if (kcore_copy__map(kci, start, end, pgoff, kci->stext, kci->etext))
1543+
return -1;
15081544

1509-
kcore_copy__map(&kci->modules_map, start, end, pgoff, kci->first_module,
1510-
kci->last_module_symbol);
1545+
if (kcore_copy__map(kci, start, end, pgoff, kci->first_module,
1546+
kci->last_module_symbol))
1547+
return -1;
15111548

15121549
return 0;
15131550
}
@@ -1517,11 +1554,6 @@ static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf)
15171554
if (elf_read_maps(elf, true, kcore_copy__read_map, kci) < 0)
15181555
return -1;
15191556

1520-
if (kci->kernel_map.len)
1521-
list_add_tail(&kci->kernel_map.node, &kci->phdrs);
1522-
if (kci->modules_map.len)
1523-
list_add_tail(&kci->modules_map.node, &kci->phdrs);
1524-
15251557
return 0;
15261558
}
15271559

@@ -1773,6 +1805,8 @@ int kcore_copy(const char *from_dir, const char *to_dir)
17731805
if (err)
17741806
kcore_copy__unlink(to_dir, "kallsyms");
17751807

1808+
kcore_copy__free_phdrs(&kci);
1809+
17761810
return err;
17771811
}
17781812

0 commit comments

Comments
 (0)