Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp687299pxu; Thu, 26 Nov 2020 09:05:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeo4TjfwIt3R3RUh1c7DS62VF3tdufxbM7jpm7VDEkASw1UexLbYV5eVdNRX0Y1ir0oGNK X-Received: by 2002:aa7:c30d:: with SMTP id l13mr3381462edq.280.1606410309964; Thu, 26 Nov 2020 09:05:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606410309; cv=none; d=google.com; s=arc-20160816; b=DCmtmSLr5MenCqWRyNtpJq6j2aWlBTuY9TKW5omo/DbYmgGH+TxGd4/3iZod1mSfx3 7RPlIloKqVBGsbXp2nOxc5yhOvnl67lu7JXyW8k1HCTY69ez/25QXjbGzH6cZ12qRemw Yi5k6Qb/2LIvZ+jJG4nyoORBbvMULuGbxskI2uXc2dAqylI07t9lPR1BuX3ZxU8BHoHo kT7ruoYu3fyx2BqchlnB6D33Qo4Xuw8JaYP5Xd9yxkzk/qSbx+jWBPSVvs1Kr6Qf1htq OuG4QnWMKgwDkiWKFH6PXTW6PEKtZnFWvX4jyICDRhGahtD7qQ+5TEVk2kExCvD+3gt3 z7UQ== 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=tU5KsaL9akdwN7D5kdAkod331CxAI1oWR3uUu96TyRr2cTnb/H/0JYx+ylusDQ51Xc TWy36Y73bg+gcblS1O/XXbbX/xM/+pSBE19IFDpyAe7Ee1l9/BRsVPQVKmlPIqEcAvnT dTFSk0i4zQgViCYrsclF0pRPeHgotJ0IIyBicRnfzh+LadRbT6BFS4ZMMopCjgJBsUZt MiMUSBfWMWP3VsWowsiu3OZpu1536fB7vB42JXEQinKdiEcDWJ82Bqb4rkyh1COdzozP 9wlAqaTdnOdwRO6/uDfJGqlPxBOzJRYl3wRjuzeVIE3yYDnAFYJax0a/GkNtYHSV6tLN XoQw== 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 q13si3399785ejx.705.2020.11.26.09.04.42; Thu, 26 Nov 2020 09:05:09 -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 S2404088AbgKZRBk convert rfc822-to-8bit (ORCPT + 99 others); Thu, 26 Nov 2020 12:01:40 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:53489 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404106AbgKZRBj (ORCPT ); Thu, 26 Nov 2020 12:01:39 -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-161-kf1UvtuiM960HCs8zq_GJw-1; Thu, 26 Nov 2020 12:01:34 -0500 X-MC-Unique: kf1UvtuiM960HCs8zq_GJw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6836918C89DE; Thu, 26 Nov 2020 17:01:32 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71F8460BFA; Thu, 26 Nov 2020 17:01:29 +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: Thu, 26 Nov 2020 18:00:16 +0100 Message-Id: <20201126170026.2619053-16-jolsa@kernel.org> In-Reply-To: <20201126170026.2619053-1-jolsa@kernel.org> References: <20201126170026.2619053-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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