Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2734591pxu; Mon, 14 Dec 2020 09:37:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5a5NSaVqBosLHVhaHIJkPl9i6fmbb497ac+cth4WFyyC4T6im5r/PeJMiFX24KDqiA3Uo X-Received: by 2002:aa7:c1c6:: with SMTP id d6mr12208881edp.275.1607967458257; Mon, 14 Dec 2020 09:37:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607967458; cv=none; d=google.com; s=arc-20160816; b=eAjIUbH0ilGXcXjxK7tfJMgPhv6FfqTSBRLNxJ2afct555BdH1KPakWaW2TomNF8Fn L6lO8D56fGXDWbgXeMf+uxYeOzls1RVRA6lSUudYmc/iN69cM6eIopVMrkDsMn7WKevt N/uWTy2CCECT9WBP468DFhh9xSgi7AeOfMNgP2OBkk9wNA2hsJMUT2sfMltVGv9Jvq6H quKiKMkg0VH9iUyxfvn9PhnGlwjJZ/lALxgVXbYqyluuirqFy5xTpDlnMCc+p6vkBbwc nlm1NyylGPhmfdmQiC/+sHwRma6wk1792r8kI98yH1eqwitq0l6H2a2SX8mv/r4GERqN d7GA== 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=6GnKJkiZFzHAlG69VjSlZNfXeDn2tU2LG9o9GmLRtfM=; b=YYLl70kjK8uFIqLmcNh3lIReJ5aYe15k+kpddaEYf7JGvs1k0GF7B+TwS6v5CWdf/6 5E+W0pewd/IK8EEY6DfRSxbldv1oJRI+DRFjRlMbHy9pUh6YANvrUUdlCrWQNxdvu/7a r3d/3XyAc7h9CNaNirFq+u+q/p/vu1yr6/G3+mt4LNMrurUCZLs9CyaCzmRqqdNrHm0w AV40qwPbFfITmQuy5WJakOR+lId25ATQGuR5FHLNGNYMjoGpkidPhraHdF3vduENJrWX k5GR20EG9Z5mEXBlWq8gKr0+3bQH4yArcJtXZbatSW7ksrYgS1ryWZ97WS97l7FlQASM b7mg== 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 y9si9990725eju.43.2020.12.14.09.37.14; Mon, 14 Dec 2020 09:37:38 -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 S2407384AbgLNK5q convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 Dec 2020 05:57:46 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:50956 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407341AbgLNK47 (ORCPT ); Mon, 14 Dec 2020 05:56:59 -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-503-ZFDL1PJBOT-wmxSeNwi8Rg-1; Mon, 14 Dec 2020 05:56:02 -0500 X-MC-Unique: ZFDL1PJBOT-wmxSeNwi8Rg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4B74800D53; Mon, 14 Dec 2020 10:55:59 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.194.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C2E77047D; Mon, 14 Dec 2020 10:55:52 +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 , Alexei Budankov , Andi Kleen , Adrian Hunter Subject: [PATCH 09/15] perf tools: Allow mmap2 event to synthesize modules Date: Mon, 14 Dec 2020 11:54:51 +0100 Message-Id: <20201214105457.543111-10-jolsa@kernel.org> In-Reply-To: <20201214105457.543111-1-jolsa@kernel.org> References: <20201214105457.543111-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 a5f271fa2ae4..c209377106f5 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -596,16 +596,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 @@ -616,23 +617,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