Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5750834pxv; Wed, 7 Jul 2021 10:54:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyn7XeLccOhFM8sTp8CpOaSICxDKUd9C7isLgGZjQJ0+MEfjuxCY3qMcjREkaWNO/AuZJJM X-Received: by 2002:a17:907:1c0a:: with SMTP id nc10mr14404310ejc.488.1625680471021; Wed, 07 Jul 2021 10:54:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625680471; cv=none; d=google.com; s=arc-20160816; b=dPE++njMOAgK4NJ8TQFuMXYCeMqF+rvKAdjRPlgW9WQVTkgR0aOkIDzsWYMjamnAhy U4uKpprV7XAWbuVg/yxoTFgB8ej7b7IMTLGCOHe5OrEDn1tiUrbfF/aB3jNnEMeT6pwa ORw01WhcMQFdPRmaAsB8uGFpUjWNq/FKKXEZyGRu860WRIBBC1O/84aX5scRgatgXhbo eehVlTwB2XwBEx4xfMJskFtBp5Olj6tIMYwpOe3KIzP2n9/6z7/R98rbntTg+Pya8JiM y/+KtS9eypulHn9eMtDYnVNSpBOyoegLKp8gjeHB9YZvS1jSkxb2NNOH1T2CWMHm3O1Z +yEw== 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=KulQMwJ202bs4ka0WsHc8bnpejfI623tG6wovxQ8tcc=; b=NISMA7PIbQLCPNKoe1wU503HilrXoq+JF0YU3FtoZYoTjY8SZiixRofcGSOp6oI8/O ZLMMBTaGuRjF8acBYV8eAkIqgAunCEnp9I2eLyOKpcX9I9FvwSqnremKNViqLm6tvsWn aevGJM7vTeOQQTVuVVGeCkpQdjJxAS3GqA2GClA3/AFTbg9GHh7prC8fhVJKfKH5lJKV GCD3eW6dkhkAcC0NclJFviBTlb8r9Dezxlp9fNfFqRvTTSjszF6uQmHF4XKuYg1SsyUx eNfa9oM+bKp8xfeAvpXpOdHhBK3LOqWt2k5L6LodaKx2ZwWVjsRhqUM3VI8WtcgOco9u 6Z5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Sl+08+zS; 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 h6si3501321ejq.666.2021.07.07.10.53.59; Wed, 07 Jul 2021 10:54:31 -0700 (PDT) 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=k20201202 header.b=Sl+08+zS; 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 S230416AbhGGRpv (ORCPT + 99 others); Wed, 7 Jul 2021 13:45:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:48328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbhGGRpu (ORCPT ); Wed, 7 Jul 2021 13:45:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2200D61CC8; Wed, 7 Jul 2021 17:43:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625679790; bh=hd+YlzFsLb6/d/lU/DpcxgXWDZRboDxqk3+K2iuZQ2I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Sl+08+zSFaA02gl6tj0xFIYHgODbhKkuqKmATlDoEEyIyPQ/UprMr12cjPYLH1oQ+ ee8IP0/y7m0sY+u2jKI81a8xvqYH/kI1hNyUEcdpi61Ygl/6XmXhciPeYqO1ZHA1ov IXzlCc1xYoEHFEJuLbT10Gp7MSZGpukjNjWUGS2NIHIoLOZcb6/GNc0ibEHQeHGgLW 3wHKzYW3AMts8e1Wagv4BRv3sOycF4XFj8JEsJLYCDYhVkkpcOOyLvxrKAp6vbD0Eo 0VmxseXgZz5C9lBI4l7L3vofWStlOtGmRod7pzm6szoz2CI8XEm59x3Ay6bflEhSN5 S6dZW4ZeLLmeg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 3C8C140B1A; Wed, 7 Jul 2021 14:43:07 -0300 (-03) Date: Wed, 7 Jul 2021 14:43:07 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , nakamura.shun@fujitsu.com, linux-perf-users@vger.kernel.org Subject: Re: [PATCH 6/7] libperF: Add group support to perf_evsel__open Message-ID: References: <20210706151704.73662-1-jolsa@kernel.org> <20210706151704.73662-7-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210706151704.73662-7-jolsa@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Jul 06, 2021 at 05:17:03PM +0200, Jiri Olsa escreveu: > Adding support to set group_fd in perf_evsel__open > call and make it to follow the group setup. > > Signed-off-by: Jiri Olsa > --- > tools/lib/perf/evsel.c | 26 ++++++++++++++++++++++++-- > 1 file changed, 24 insertions(+), 2 deletions(-) > > diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c > index 3e6638d27c45..9ebf7122d476 100644 > --- a/tools/lib/perf/evsel.c > +++ b/tools/lib/perf/evsel.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > > void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, > int idx) > @@ -76,6 +77,25 @@ sys_perf_event_open(struct perf_event_attr *attr, > return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); > } > > +static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread) > +{ > + struct perf_evsel *leader = evsel->leader; > + int fd; > + > + if (evsel == leader) > + return -1; > + > + /* > + * Leader must be already processed/open, > + * if not it's a bug. > + */ > + BUG_ON(!leader->fd); Humm, having panics in library code looks ugly, why can't we just return some errno and let the whatever is using the library to fail gracefully? I applied the patches so far, will make them available at tmp.perf/core now. - Arnaldo > + fd = FD(leader, cpu, thread); > + BUG_ON(fd == -1); > + return fd; > +} > + > int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, > struct perf_thread_map *threads) > { > @@ -111,11 +131,13 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, > > for (cpu = 0; cpu < cpus->nr; cpu++) { > for (thread = 0; thread < threads->nr; thread++) { > - int fd; > + int fd, group_fd; > + > + group_fd = get_group_fd(evsel, cpu, thread); > > fd = sys_perf_event_open(&evsel->attr, > threads->map[thread].pid, > - cpus->map[cpu], -1, 0); > + cpus->map[cpu], group_fd, 0); > > if (fd < 0) > return -errno; > -- > 2.31.1 > -- - Arnaldo