Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3537205pxb; Mon, 9 Nov 2020 14:00:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuj8h+OkJ+8qw1tIQFznvOiOLDmXG3tQoukjzAXJP2oSxvd2nTfetPya687tREGBXWn9fj X-Received: by 2002:aa7:ccd2:: with SMTP id y18mr17993198edt.11.1604959244172; Mon, 09 Nov 2020 14:00:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604959244; cv=none; d=google.com; s=arc-20160816; b=cuZzjuosRJXsoy0cVGn7WmTSVq4nsRmAbqAkbJgGaY1lEwEmVEiaq0OhG0CEpOZ9SZ nxum4khOU5ZZKdLUr/CgI2HnxbbnlDTecCZ5Leq/ScxFjk0SP8a5hCS9DhMhD0v6dx5q j5AwD/KdBFQ9xMREq//loIxUi50WtmdNLoQayYwf9HlRbS/d2ytDrAw6Gnb2sAfy6f1O kmatld3gKODIyzo0QvPf21yUI+cua0mjLcBb+SKoGYwSFb2caN2aPwO2nP7T321psbbL IX0BqWnAvD7w4jSDFBRDIaOFk04pyDZK1Td9gPU6Bnzw5LtIFauvF0vORCSXlV584DRl hIew== 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=rTF4ELtfxMG4Iz7Bl5ZuMS6x92XC4uaiX+3Snwv/GsU=; b=z5cc4Tge/EG9nh7h1mHbki2/vFg8N/dKZlWoWuYXfRxvq8CBz6KyODJxwq8FNiYysY qldYWJ7beIpW0uW0JKSTFZ19cwn2v6PU6jYAX1CBRDhvDwZMGxOTX6+00iseE4Ivve2y kvRTeZCN0g4Ya6rCJSuSA4cd2jUgxeMGrYPf2aVS0zfkAl1GFQzLO3jX/n20egzZZe9/ 2/T9LzULHo7zZrVYJMiIW3tgKnXiCIQPYp4jjAWO2wAhu0g0as0YGKQTHI5iZSbCdfRw kV/hMQxW2kTCG6rDsPq8rGaTLKA9x8aa1JYvT91L4Amy+H8q6Q8YojUjDbL5miKz1HUS VLow== 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 qq25si7649622ejb.546.2020.11.09.14.00.21; Mon, 09 Nov 2020 14:00:44 -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 S1731754AbgKIV4N convert rfc822-to-8bit (ORCPT + 99 others); Mon, 9 Nov 2020 16:56:13 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:57670 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731599AbgKIVzU (ORCPT ); Mon, 9 Nov 2020 16:55:20 -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-185-6PxACxz3N-ymhUCDduRCGQ-1; Mon, 09 Nov 2020 16:55:15 -0500 X-MC-Unique: 6PxACxz3N-ymhUCDduRCGQ-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 7770A186DD4C; Mon, 9 Nov 2020 21:55:12 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7237A6EF46; Mon, 9 Nov 2020 21:55:09 +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 14/24] perf tools: Allow mmap2 event to synthesize modules Date: Mon, 9 Nov 2020 22:54:05 +0100 Message-Id: <20201109215415.400153-15-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 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. 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