Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3829770pxb; Tue, 17 Nov 2020 04:51:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwXa40Ph9hPuo7Xp08bfHxEfIdVihuBosNtMJexMMln8hGBeLWG8MYQRjEvp5S5A/qxeG2 X-Received: by 2002:a17:906:b312:: with SMTP id n18mr19849964ejz.353.1605617503881; Tue, 17 Nov 2020 04:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605617503; cv=none; d=google.com; s=arc-20160816; b=id1TUdC7/z6t/oJOMfQDoh+Z2cE8VWTzAg9eSFq7q4Fr8MEyFIx7sC8S2WdJBgFgPH dQG/M1Q6odZ+VhdidgKJWa9sE4djoARWDmy5XFoJ4SjkEfw17b73kCbaNbR5fBRSTfgm BJxf1hba/GFAH7PZgY5MjUCOLicMCGVWUZbWmD4lWVFb5Rw9+YO+4mrGDVct6CEtZsoC fkdetGqasJcHGgFvOGXf045TT0I/CWm6MR7N+oR0ZvL06dNGbWwZxw20z4rdXGoNxdYw m0pOIkduwDDLAGptoRVTdopEEMKjSBbYGdYcXbz66vtyRluB6lHZZyUrVbbRSdZl8FA4 oIvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=AB6B6kfsUAXCJMAu0gNiK64R/YYQG4+LoPnARYxzzTM=; b=gz4uEX2/n4w9j2K2Dyz9o+jqcYmVMw+tBmk/LX2Cr8QO/WgEA16Vl3B76ECI5GyQtM t8eRLfMj1xP0QXo2guc7mX3cjGt/ufqYCNQ7FwU/iyMmFqNKsKBDslEzaHqyVWIg4rAd JklHXMd1uOPGasFhrlVWjKPzMbri5yzOSHaoCOjbm3GpzQTrwTgThfLTO5TOAVEfHLyD UT5jsVCEZHs81nJywzgz/a99cKMipJ84uCDis6nhkMqlCHW+Jt6sNBdTp7Gk0GdTYxQY qRtEnF2hf5nCuYQYtBaILlMiCFjXZjN+9J2R8igaBXOnsWy3j8QsIiVivxFeqiQIC8GU BO2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QPXygCEQ; 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 a10si14688130edq.316.2020.11.17.04.51.21; Tue, 17 Nov 2020 04:51:43 -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; dkim=pass header.i=@kernel.org header.s=default header.b=QPXygCEQ; 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 S1728293AbgKQMq4 (ORCPT + 99 others); Tue, 17 Nov 2020 07:46:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:49830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbgKQMqz (ORCPT ); Tue, 17 Nov 2020 07:46:55 -0500 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5CD462222A; Tue, 17 Nov 2020 12:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605617214; bh=w2JRgA1Ne8LerPp1nVhszfic7yCVQyHfDY/SgatFze8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QPXygCEQ7JuNIx+1R6rEVW2osfuZBDkuWBAsgBTkKvy62cviNGS1CnRur1YkeQYQ1 LxQc9BUQHiqeM9HOVm1rCv4rsqqDTio6UhZz3ZtHF3PRErpLjRtClv21VUF0OytTyK d3e3H4ZP8QAmgMsN35GK+WLlWwVcHHXIQ7/iRmzg= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 3AFB140E29; Tue, 17 Nov 2020 09:46:52 -0300 (-03) Date: Tue, 17 Nov 2020 09:46:52 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa 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: Re: [PATCH 14/24] perf tools: Allow mmap2 event to synthesize modules Message-ID: <20201117124652.GP614220@kernel.org> References: <20201117110053.1303113-1-jolsa@kernel.org> <20201117110053.1303113-15-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201117110053.1303113-15-jolsa@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Nov 17, 2020 at 12:00:43PM +0100, Jiri Olsa escreveu: > 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. Ditto as for the kernel mmap event, don't we do this probing before generating the synthetic events? If not perhaps we should, to avoid synthesizing things and then failing on creating the events? If we do it that way, we can switch from symbol_conf.buildid_mmap2 to !perf_missing_features.mmap2. - Arnaldo > 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 > -- - Arnaldo