Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3768595pxb; Tue, 17 Nov 2020 03:06:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeYv6gI6pesrZdVR7W0pJdHimcLpaYCQv2TPoaGCnWmWUqmOiE7Z9qpeU3r/YXQMEd+iQW X-Received: by 2002:a17:906:40c9:: with SMTP id a9mr18136433ejk.518.1605611175439; Tue, 17 Nov 2020 03:06:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605611175; cv=none; d=google.com; s=arc-20160816; b=awfuxqCwVT/gR3+Es2F1McIQ2tNo91TDfUts3motkAiOqQNqDukXWzb+nASFJCgGG2 Waff3wseeia9mbwsNlmqMGxD32EIfJoFkVIBWD6cwozPR4K4P02P3eXpYbIVHDMPivMz qPqYfv2YcI6FVJRAoHwrU9nlSnMltBWbwUuqfCdyBNSOlvtsbu+axO4OgEn40/H8y+k9 7tnN2ppxGpmuoDAeNgQ57AXL9t2gZtZUjOqkBh4A9ppcK8ltVveav+7EJB+l+gh8QYho onzSzfuvV8btKYQNX0Y1FGDxF3Xw/T+6jUqVLFnU5cYKmw5ygHEd/iKRS7xbK/xelr1/ SQKw== 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=j8+pm2U1dK/+3idfgitZqwKqb0G9bAVADkJ02ZrP1/9tPVbxEF8K4Nd8OyCKHIbGQ+ +NqgMLvHuku2dfrsC4UeidjpoiC3zf7/kwihuDuezrRZVz3M8o60SDiRTTZkOzKxgh8e AOv0EnUi8YSUFXxbnHixTfis3SpNhp7mLOvUbKVTdFs0ZVMypUNHLtMmS22HHzzDvAVR p8NDN0zZ4q/TlZ0a0EGWhs6WqmJ+NtmtZ7Dial4b8V9C3+I+RMV76imTNMy41oMXKXCg 7OsZbYgRAb9MH5D9JoKQEUTTaPikiJ7YwdNDD4DAZAaxGaSoDjG83Zx2SlD8AoXWm8ow lmLA== 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 ds16si600442ejc.666.2020.11.17.03.05.51; Tue, 17 Nov 2020 03:06:15 -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 S1728362AbgKQLBz convert rfc822-to-8bit (ORCPT + 99 others); Tue, 17 Nov 2020 06:01:55 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:47971 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727526AbgKQLBy (ORCPT ); Tue, 17 Nov 2020 06:01:54 -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-462-ISR6eNfnP7iFy4ChFrhOmA-1; Tue, 17 Nov 2020 06:01:49 -0500 X-MC-Unique: ISR6eNfnP7iFy4ChFrhOmA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDFE664166; Tue, 17 Nov 2020 11:01:47 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id C088E5C1CF; Tue, 17 Nov 2020 11:01:44 +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: Tue, 17 Nov 2020 12:00:42 +0100 Message-Id: <20201117110053.1303113-14-jolsa@kernel.org> In-Reply-To: <20201117110053.1303113-1-jolsa@kernel.org> References: <20201117110053.1303113-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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