Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1225043pxu; Mon, 23 Nov 2020 15:12:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5/6Epwpc4oz3wdGUyQnZB3TOA17qFXjHTlH07vh6CGhDktjN+HSSm2uHaKINkkO05mOiV X-Received: by 2002:a50:8f06:: with SMTP id 6mr1478254edy.39.1606173135574; Mon, 23 Nov 2020 15:12:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606173135; cv=none; d=google.com; s=arc-20160816; b=GYrueure7+4m6DlmF7ae8xOhdToa8lP5hpTnCv8gZzJGLIEqy/ds5iTh+M7fRdTzEY HrMn1g9d+qUW+bo3qbIU8rN1NvNa/7ixNcIh/Ez7jYnQSd7ErLYG5dt4Aw58s/3Rz/Ie wHOp7yHTbfZUJniDciqwH7LYKBYDvO0M1xqPL6H5x/8y7M4RB+jQmuY3zbVBwqACgMZj Oy6+k2q28F+JfsIB/0SD0ys8q8dXOjGt5U8dg7Hn23Ec9Nw3l1fqyBApN9bTCPJYgVPw sv707R+NQFbl4MAOm0lB+dOj/8AWovpsS0YJ96KgQ1icTiFwacHP/0Wx/lypGw/VXQH8 tvMg== 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=k8WoQUjMcsI9mkD6OltIkiZtJqpxDW58rubhYmRkHBM=; b=zT2DbrUNFtlkdI0/5oK8EkOvCab08s5UdsBUq++CEmPHtC8HTVP3Y1CWb5ICewNtwv iaaM3SqjIfpJCakKSaxgSJwRApGZAX4ms5mwgrGY+y86k/F02M4MocISPUetgiiJYGc4 qP3YfH2TgCRbFvH4y7WmYYrUjzc443D9YBUDdoZzIeTwaYk4o7L0LhzYJgmYrBvuTv8T FTOuzIJFFL+RuRy7BWTJcrylwjNSnUzPCtTW1Yu0KUStbq651hBJjbYQMz8IH7fiSqjj 2G2X5wLA3f9cPxsgnHLkKyDcfzCltw5ZIjTXS2FZm7rKqw8oZVsY0a9vxCGzJYDavqP8 zemw== 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 t17si7413932ejj.562.2020.11.23.15.11.52; Mon, 23 Nov 2020 15:12: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 S1732365AbgKWXGj convert rfc822-to-8bit (ORCPT + 99 others); Mon, 23 Nov 2020 18:06:39 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:22735 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388141AbgKWXGX (ORCPT ); Mon, 23 Nov 2020 18:06:23 -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-255-7XgDLdpPOR-VDzCLxLo1Rw-1; Mon, 23 Nov 2020 18:06:18 -0500 X-MC-Unique: 7XgDLdpPOR-VDzCLxLo1Rw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 41E2710866A5; Mon, 23 Nov 2020 23:06:16 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.195.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4304B5D9CA; Mon, 23 Nov 2020 23:06:13 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Ian Rogers , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Song Liu , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: [PATCH 15/25] perf tools: Allow mmap2 event to synthesize modules Date: Tue, 24 Nov 2020 00:05:02 +0100 Message-Id: <20201123230512.2097312-16-jolsa@kernel.org> In-Reply-To: <20201123230512.2097312-1-jolsa@kernel.org> References: <20201123230512.2097312-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 modules, so we can synthesize module's build id data in following changes. It's enabled by new symbol_conf.buildid_mmap2 bool, which will be switched in following changes. Acked-by: Ian Rogers Signed-off-by: Jiri Olsa --- tools/perf/util/synthetic-events.c | 49 +++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index 872df6d6dbef..a18ae502d765 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -593,16 +593,17 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t int rc = 0; struct map *pos; struct maps *maps = machine__kernel_maps(machine); - union perf_event *event = zalloc((sizeof(event->mmap) + - machine->id_hdr_size)); + union perf_event *event; + size_t size = symbol_conf.buildid_mmap2 ? + sizeof(event->mmap2) : sizeof(event->mmap); + + event = zalloc(size + machine->id_hdr_size); if (event == NULL) { pr_debug("Not enough memory synthesizing mmap event " "for kernel modules\n"); return -1; } - event->header.type = PERF_RECORD_MMAP; - /* * kernel uses 0 for user space maps, see kernel/perf_event.c * __perf_event_mmap @@ -613,23 +614,37 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL; maps__for_each_entry(maps, pos) { - size_t size; - if (!__map__is_kmodule(pos)) continue; - size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); - event->mmap.header.type = PERF_RECORD_MMAP; - event->mmap.header.size = (sizeof(event->mmap) - - (sizeof(event->mmap.filename) - size)); - memset(event->mmap.filename + size, 0, machine->id_hdr_size); - event->mmap.header.size += machine->id_hdr_size; - event->mmap.start = pos->start; - event->mmap.len = pos->end - pos->start; - event->mmap.pid = machine->pid; + if (symbol_conf.buildid_mmap2) { + size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); + event->mmap2.header.type = PERF_RECORD_MMAP2; + event->mmap2.header.size = (sizeof(event->mmap2) - + (sizeof(event->mmap2.filename) - size)); + memset(event->mmap2.filename + size, 0, machine->id_hdr_size); + event->mmap2.header.size += machine->id_hdr_size; + event->mmap2.start = pos->start; + event->mmap2.len = pos->end - pos->start; + event->mmap2.pid = machine->pid; + + memcpy(event->mmap2.filename, pos->dso->long_name, + pos->dso->long_name_len + 1); + } else { + size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); + event->mmap.header.type = PERF_RECORD_MMAP; + event->mmap.header.size = (sizeof(event->mmap) - + (sizeof(event->mmap.filename) - size)); + memset(event->mmap.filename + size, 0, machine->id_hdr_size); + event->mmap.header.size += machine->id_hdr_size; + event->mmap.start = pos->start; + event->mmap.len = pos->end - pos->start; + event->mmap.pid = machine->pid; + + memcpy(event->mmap.filename, pos->dso->long_name, + pos->dso->long_name_len + 1); + } - memcpy(event->mmap.filename, pos->dso->long_name, - pos->dso->long_name_len + 1); if (perf_tool__process_synth_event(tool, event, machine, process) != 0) { rc = -1; break; -- 2.26.2