Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3536492pxb; Mon, 9 Nov 2020 13:59:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxe1IlWhQolLQE69jCTFbY09zw2lG0H2jdaheE3p8RRSxkRNWSYJBpThkaidQRM4cIEy3O5 X-Received: by 2002:a50:b761:: with SMTP id g88mr17960376ede.387.1604959172256; Mon, 09 Nov 2020 13:59:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604959172; cv=none; d=google.com; s=arc-20160816; b=VGahUdkE0fAitC0LLMQj/5Ow5+bRx+WATUFSxh0084RkQ56QF9ywZdyEIuOqCVpy+J wupIieePJpDX9JM5gbPOQ1NtuXJkvrbXOk03BE7VeH2n7dmrXHPQwNcoiq0iU9m6oJ+x uPMGvPFwmK/vLE+T73TH4oGYIW+BcvDNqKRGlMQ+ctMlTh6DQn9T0Ckn+T1qTFharMPG zfYRnGecot6NVE4rkwznC2S0+80zgZ42W9jg+u7OJ09Qpf0Y5O6g8QWqvGGitFgZx7kf iuMXUa85KDq9/vI+p1tJ9u/hgt9R9Ds8JhO8G92aMZJaFP2idWRer/YJip1Fvk2hqczJ Iubg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=KbJbm8xewvhHfXQc0vEBAKcoP4+IbM+ytBxhHERDI1A=; b=wk+M4HSEeYYk9PDEPRIHjBSW6aGiJQh2NlIfcM0B0Me7ISTdcoXBxAA70KMmf7cHj9 ovK1In+NW5fx70D0r2zR8CHFRo9eQK+s6yv7vCrrBTiCSEycCS6dfd3PRHmrU7KTR0/D ZV5Df3nPzzk7zwnMEw3I58v5PPm2izo3rHwJYNMdokZSI3bAmBax3CjXOXYHv58wl9Rl x4FFoN+i1BLVHwai1Pn6VAaQu8qAnUMaaxQAwaho21UC4hYTnh2nvD+CiwJ0Fgl66njZ oXLvOO2bkjcXxecSx8e8ibobJ4J7PzPZDLWhr3XoxjApoQMC/SM2hgC85iZXgBd0r1ll wGBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si8291853edt.581.2020.11.09.13.59.10; Mon, 09 Nov 2020 13:59:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731961AbgKIV4O convert rfc822-to-8bit (ORCPT + 99 others); Mon, 9 Nov 2020 16:56:14 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:58213 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731521AbgKIVzS (ORCPT ); Mon, 9 Nov 2020 16:55:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-9pZAIlKNOgy-LVFTue6x5w-1; Mon, 09 Nov 2020 16:55:11 -0500 X-MC-Unique: 9pZAIlKNOgy-LVFTue6x5w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA2421074655; Mon, 9 Nov 2020 21:55:08 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB7D06EF46; Mon, 9 Nov 2020 21:55:05 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Song Liu , Ian Rogers , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: [PATCH 13/24] perf tools: Allow mmap2 event to synthesize kernel image Date: Mon, 9 Nov 2020 22:54:04 +0100 Message-Id: <20201109215415.400153-14-jolsa@kernel.org> In-Reply-To: <20201109215415.400153-1-jolsa@kernel.org> References: <20201109215415.400153-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow mmap2 event to synthesize kernel image, so we can synthesize kernel build id data in following changes. It's enabled by new symbol_conf.buildid_mmap2 bool, which will be switched in following changes. Signed-off-by: Jiri Olsa --- tools/perf/util/symbol_conf.h | 3 ++- tools/perf/util/synthetic-events.c | 40 ++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h index b916afb95ec5..b18f9c8dbb75 100644 --- a/tools/perf/util/symbol_conf.h +++ b/tools/perf/util/symbol_conf.h @@ -42,7 +42,8 @@ struct symbol_conf { report_block, report_individual_block, inline_name, - disable_add2line_warn; + disable_add2line_warn, + buildid_mmap2; const char *vmlinux_name, *kallsyms_name, *source_prefix, diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index 8a23391558cf..872df6d6dbef 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -988,11 +988,12 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine) { - size_t size; + union perf_event *event; + size_t size = symbol_conf.buildid_mmap2 ? + sizeof(event->mmap2) : sizeof(event->mmap); struct map *map = machine__kernel_map(machine); struct kmap *kmap; int err; - union perf_event *event; if (map == NULL) return -1; @@ -1006,7 +1007,7 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool, * available use this, and after it is use this as a fallback for older * kernels. */ - event = zalloc((sizeof(event->mmap) + machine->id_hdr_size)); + event = zalloc(size + machine->id_hdr_size); if (event == NULL) { pr_debug("Not enough memory synthesizing mmap event " "for kernel modules\n"); @@ -1023,16 +1024,29 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool, event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL; } - size = snprintf(event->mmap.filename, sizeof(event->mmap.filename), - "%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1; - size = PERF_ALIGN(size, sizeof(u64)); - event->mmap.header.type = PERF_RECORD_MMAP; - event->mmap.header.size = (sizeof(event->mmap) - - (sizeof(event->mmap.filename) - size) + machine->id_hdr_size); - event->mmap.pgoff = kmap->ref_reloc_sym->addr; - event->mmap.start = map->start; - event->mmap.len = map->end - event->mmap.start; - event->mmap.pid = machine->pid; + if (symbol_conf.buildid_mmap2) { + size = snprintf(event->mmap2.filename, sizeof(event->mmap2.filename), + "%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1; + size = PERF_ALIGN(size, sizeof(u64)); + event->mmap2.header.type = PERF_RECORD_MMAP2; + event->mmap2.header.size = (sizeof(event->mmap2) - + (sizeof(event->mmap2.filename) - size) + machine->id_hdr_size); + event->mmap2.pgoff = kmap->ref_reloc_sym->addr; + event->mmap2.start = map->start; + event->mmap2.len = map->end - event->mmap.start; + event->mmap2.pid = machine->pid; + } else { + size = snprintf(event->mmap.filename, sizeof(event->mmap.filename), + "%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1; + size = PERF_ALIGN(size, sizeof(u64)); + event->mmap.header.type = PERF_RECORD_MMAP; + event->mmap.header.size = (sizeof(event->mmap) - + (sizeof(event->mmap.filename) - size) + machine->id_hdr_size); + event->mmap.pgoff = kmap->ref_reloc_sym->addr; + event->mmap.start = map->start; + event->mmap.len = map->end - event->mmap.start; + event->mmap.pid = machine->pid; + } err = perf_tool__process_synth_event(tool, event, machine, process); free(event); -- 2.26.2