struct maps is reference counted, using a pointer is more idiomatic. Committer notes: Delay: maps = machine__kernel_maps(&vmlinux); To after: machine__init(&vmlinux, "", HOST_KERNEL_ID); To avoid this on f34: In file included from /var/home/acme/git/perf/tools/perf/util/build-id.h:10, from /var/home/acme/git/perf/tools/perf/util/dso.h:13, from tests/vmlinux-kallsyms.c:8: In function ‘machine__kernel_maps’, inlined from ‘test__vmlinux_matches_kallsyms’ at tests/vmlinux-kallsyms.c:122:22: /var/home/acme/git/perf/tools/perf/util/machine.h:86:23: error: ‘vmlinux.kmaps’ is used uninitialized [-Werror=uninitialized] 86 | return machine->kmaps; | ~~~~~~~^~~~~~~ tests/vmlinux-kallsyms.c: In function ‘test__vmlinux_matches_kallsyms’: tests/vmlinux-kallsyms.c:121:34: note: ‘vmlinux’ declared here 121 | struct machine kallsyms, vmlinux; | ^~~~~~~ cc1: all warnings being treated as errors Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: André Almeida <andrealmeid@collabora.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Eric Dumazet <edumazet@google.com> Cc: German Gomez <german.gomez@arm.com> Cc: Hao Luo <haoluo@google.com> Cc: James Clark <james.clark@arm.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.garry@huawei.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Miaoqian Lin <linmq006@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Riccardo Mancini <rickyman7@gmail.com> Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com> Cc: Song Liu <song@kernel.org> Cc: Stephane Eranian <eranian@google.com> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Yury Norov <yury.norov@gmail.com> Link: http://lore.kernel.org/lkml/20220211103415.2737789-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
102 lines
2.3 KiB
C
102 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/types.h>
|
|
#include <linux/string.h>
|
|
#include <linux/zalloc.h>
|
|
|
|
#include "../../../util/event.h"
|
|
#include "../../../util/synthetic-events.h"
|
|
#include "../../../util/machine.h"
|
|
#include "../../../util/tool.h"
|
|
#include "../../../util/map.h"
|
|
#include "../../../util/debug.h"
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
|
|
perf_event__handler_t process,
|
|
struct machine *machine)
|
|
{
|
|
int rc = 0;
|
|
struct map *pos;
|
|
struct maps *kmaps = machine__kernel_maps(machine);
|
|
union perf_event *event = zalloc(sizeof(event->mmap) +
|
|
machine->id_hdr_size);
|
|
|
|
if (!event) {
|
|
pr_debug("Not enough memory synthesizing mmap event "
|
|
"for extra kernel maps\n");
|
|
return -1;
|
|
}
|
|
|
|
maps__for_each_entry(kmaps, pos) {
|
|
struct kmap *kmap;
|
|
size_t size;
|
|
|
|
if (!__map__is_extra_kernel_map(pos))
|
|
continue;
|
|
|
|
kmap = map__kmap(pos);
|
|
|
|
size = sizeof(event->mmap) - sizeof(event->mmap.filename) +
|
|
PERF_ALIGN(strlen(kmap->name) + 1, sizeof(u64)) +
|
|
machine->id_hdr_size;
|
|
|
|
memset(event, 0, size);
|
|
|
|
event->mmap.header.type = PERF_RECORD_MMAP;
|
|
|
|
/*
|
|
* kernel uses 0 for user space maps, see kernel/perf_event.c
|
|
* __perf_event_mmap
|
|
*/
|
|
if (machine__is_host(machine))
|
|
event->header.misc = PERF_RECORD_MISC_KERNEL;
|
|
else
|
|
event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
|
|
|
|
event->mmap.header.size = size;
|
|
|
|
event->mmap.start = pos->start;
|
|
event->mmap.len = pos->end - pos->start;
|
|
event->mmap.pgoff = pos->pgoff;
|
|
event->mmap.pid = machine->pid;
|
|
|
|
strlcpy(event->mmap.filename, kmap->name, PATH_MAX);
|
|
|
|
if (perf_tool__process_synth_event(tool, event, machine,
|
|
process) != 0) {
|
|
rc = -1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
free(event);
|
|
return rc;
|
|
}
|
|
|
|
#endif
|
|
|
|
void arch_perf_parse_sample_weight(struct perf_sample *data,
|
|
const __u64 *array, u64 type)
|
|
{
|
|
union perf_sample_weight weight;
|
|
|
|
weight.full = *array;
|
|
if (type & PERF_SAMPLE_WEIGHT)
|
|
data->weight = weight.full;
|
|
else {
|
|
data->weight = weight.var1_dw;
|
|
data->ins_lat = weight.var2_w;
|
|
}
|
|
}
|
|
|
|
void arch_perf_synthesize_sample_weight(const struct perf_sample *data,
|
|
__u64 *array, u64 type)
|
|
{
|
|
*array = data->weight;
|
|
|
|
if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
|
|
*array &= 0xffffffff;
|
|
*array |= ((u64)data->ins_lat << 32);
|
|
}
|
|
}
|