Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5269447pxj; Wed, 9 Jun 2021 13:20:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK8ayZHGfT8kLUGNhiF50m8+IJQ16/0+z+OHWErpryeEHoM/dtAMSIExO722LZ7B9uuiuy X-Received: by 2002:aa7:c3ce:: with SMTP id l14mr1124523edr.99.1623270031963; Wed, 09 Jun 2021 13:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623270031; cv=none; d=google.com; s=arc-20160816; b=u/dVRuR9IGnErqqq0L8fN9jlFP2qIITHNp3tOn/iNbTidK4B4d4itgOV5rq/CPHAPu FOFDph7mdwH0imqr9AF7Dr/2xEFD5RLTZHRijid+YcXhP8Mq5xDmHREdU2aFo5RmBa0i bInDnbh6kTV9CAyN112TFMXczjYQVzsCfNexX3gVE7pl3pOv3WUMz6uMmN2f32XQe+a2 tXdhxom0FxmsBg835KMRwHn0ftXOb++eIqjX7f7zvYDnh2aYMHAlxUb+9j/li/Do732K i19QuUDsjlL5sehkb/fOvXfpp9ftoHobyLHXYgH0ZZLSagm415fdJ+UKfaWNT59Qzp5x A9dQ== 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=2jcNr0v+NDTjKgDg0kRNxIjhwVlOX9/eMThTuNOtXDw=; b=dHgOV1bL1wzxklNRPyAQaMvpGKi6IIxWtsbykK9JIWmEdhNw4b0Xy16rxKOXFwHY3Q 3+QXgsaYcW32vKQ8sm8K5L/jSuGbXk6NtJb5iVWC27lxK2gV3TqjYqAO1v6Y5hfgLk7L qmmxw6XqG+Hkv8v4NjY6UuAr+WnjWPncrPgTbNN9JAriHUyqOnVQr5PuGwbiv4VDDirD mJzKk9UATbbOKCDaY9ZGYm9Pq65GwYELp/sDXWHjeka2TPlQK4u/7QvPxCfbOZUug3CT eV1DHajy1qwynIfCgtQOPhx4eoirnFE/s8GTq9PuTn8HtwUI7QwJA5xdtL3RnQDj2jq0 l6KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M23R6OyU; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si683387ejm.619.2021.06.09.13.19.51; Wed, 09 Jun 2021 13:20: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=@redhat.com header.s=mimecast20190719 header.b=M23R6OyU; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229527AbhFIURh (ORCPT + 99 others); Wed, 9 Jun 2021 16:17:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36258 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbhFIURg (ORCPT ); Wed, 9 Jun 2021 16:17:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623269740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2jcNr0v+NDTjKgDg0kRNxIjhwVlOX9/eMThTuNOtXDw=; b=M23R6OyU88jiT4iUjILnH3FwjwxBvr2Hp6JqkhfB+bUWM0MYamvnlfYCOBhdLE3V7rN9sM KYteyXqiP2la4A9bVDjw2OWFrvbW/zZ+8Rk2FjiTOXt5VKvyp8+APz+G0HXHWP/BTQrAir pEnF7ihsPYGyeiQoW7POOfjx/rxSnuo= 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-501-KcLN-hayPP-5QliIFumRXg-1; Wed, 09 Jun 2021 16:15:37 -0400 X-MC-Unique: KcLN-hayPP-5QliIFumRXg-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 533908015A4; Wed, 9 Jun 2021 20:15:35 +0000 (UTC) Received: from krava (unknown [10.40.195.97]) by smtp.corp.redhat.com (Postfix) with SMTP id 5403C60853; Wed, 9 Jun 2021 20:15:29 +0000 (UTC) Date: Wed, 9 Jun 2021 22:15:29 +0200 From: Jiri Olsa To: Jin Yao Cc: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com Subject: Re: [PATCH v2] perf evsel: Adjust hybrid event and global event mixed group Message-ID: References: <20210609044555.27180-1-yao.jin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210609044555.27180-1-yao.jin@linux.intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 09, 2021 at 12:45:55PM +0800, Jin Yao wrote: > A group mixed with hybrid event and global event is allowed. For example, > group leader is 'intel_pt//' and the group member is 'cpu_atom/cycles/'. > > e.g. > perf record --aux-sample -e '{intel_pt//,cpu_atom/cycles/}:u' > > The challenge is their available cpus are not fully matched. For example, > 'intel_pt//' is available on CPU0-CPU23, but 'cpu_atom/cycles/' is > available on CPU16-CPU23. > > When getting the group id for group member, we must be very careful. > Because the cpu for 'intel_pt//' is not equal to the cpu for > 'cpu_atom/cycles/'. Actually the cpu here is the index of evsel->core.cpus, > not the real CPU ID. > > e.g. cpu0 for 'intel_pt//' is CPU0, but cpu0 for 'cpu_atom/cycles/' is CPU16. > > Before: > > # perf record --aux-sample -e '{intel_pt//,cpu_atom/cycles/}:u' -vv uname > ... > ------------------------------------------------------------ > perf_event_attr: > type 10 > size 128 > config 0xe601 > { sample_period, sample_freq } 1 > sample_type IP|TID|TIME|CPU|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > exclude_kernel 1 > exclude_hv 1 > enable_on_exec 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid 4084 cpu 0 group_fd -1 flags 0x8 = 5 > sys_perf_event_open: pid 4084 cpu 1 group_fd -1 flags 0x8 = 6 > sys_perf_event_open: pid 4084 cpu 2 group_fd -1 flags 0x8 = 7 > sys_perf_event_open: pid 4084 cpu 3 group_fd -1 flags 0x8 = 9 > sys_perf_event_open: pid 4084 cpu 4 group_fd -1 flags 0x8 = 10 > sys_perf_event_open: pid 4084 cpu 5 group_fd -1 flags 0x8 = 11 > sys_perf_event_open: pid 4084 cpu 6 group_fd -1 flags 0x8 = 12 > sys_perf_event_open: pid 4084 cpu 7 group_fd -1 flags 0x8 = 13 > sys_perf_event_open: pid 4084 cpu 8 group_fd -1 flags 0x8 = 14 > sys_perf_event_open: pid 4084 cpu 9 group_fd -1 flags 0x8 = 15 > sys_perf_event_open: pid 4084 cpu 10 group_fd -1 flags 0x8 = 16 > sys_perf_event_open: pid 4084 cpu 11 group_fd -1 flags 0x8 = 17 > sys_perf_event_open: pid 4084 cpu 12 group_fd -1 flags 0x8 = 18 > sys_perf_event_open: pid 4084 cpu 13 group_fd -1 flags 0x8 = 19 > sys_perf_event_open: pid 4084 cpu 14 group_fd -1 flags 0x8 = 20 > sys_perf_event_open: pid 4084 cpu 15 group_fd -1 flags 0x8 = 21 > sys_perf_event_open: pid 4084 cpu 16 group_fd -1 flags 0x8 = 22 > sys_perf_event_open: pid 4084 cpu 17 group_fd -1 flags 0x8 = 23 > sys_perf_event_open: pid 4084 cpu 18 group_fd -1 flags 0x8 = 24 > sys_perf_event_open: pid 4084 cpu 19 group_fd -1 flags 0x8 = 25 > sys_perf_event_open: pid 4084 cpu 20 group_fd -1 flags 0x8 = 26 > sys_perf_event_open: pid 4084 cpu 21 group_fd -1 flags 0x8 = 27 > sys_perf_event_open: pid 4084 cpu 22 group_fd -1 flags 0x8 = 28 > sys_perf_event_open: pid 4084 cpu 23 group_fd -1 flags 0x8 = 29 > ------------------------------------------------------------ > perf_event_attr: > size 128 > config 0x800000000 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|PERIOD|IDENTIFIER|AUX > read_format ID > inherit 1 > exclude_kernel 1 > exclude_hv 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > aux_sample_size 4096 > ------------------------------------------------------------ > sys_perf_event_open: pid 4084 cpu 16 group_fd 5 flags 0x8 > sys_perf_event_open failed, error -22 > > The group_fd 5 is not correct. It should be 22 (the fd of > 'intel_pt' on CPU16). > > After: > > # perf record --aux-sample -e '{intel_pt//,cpu_atom/cycles/}:u' -vv uname > ... > ------------------------------------------------------------ > perf_event_attr: > type 10 > size 128 > config 0xe601 > { sample_period, sample_freq } 1 > sample_type IP|TID|TIME|CPU|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > exclude_kernel 1 > exclude_hv 1 > enable_on_exec 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid 5162 cpu 0 group_fd -1 flags 0x8 = 5 > sys_perf_event_open: pid 5162 cpu 1 group_fd -1 flags 0x8 = 6 > sys_perf_event_open: pid 5162 cpu 2 group_fd -1 flags 0x8 = 7 > sys_perf_event_open: pid 5162 cpu 3 group_fd -1 flags 0x8 = 9 > sys_perf_event_open: pid 5162 cpu 4 group_fd -1 flags 0x8 = 10 > sys_perf_event_open: pid 5162 cpu 5 group_fd -1 flags 0x8 = 11 > sys_perf_event_open: pid 5162 cpu 6 group_fd -1 flags 0x8 = 12 > sys_perf_event_open: pid 5162 cpu 7 group_fd -1 flags 0x8 = 13 > sys_perf_event_open: pid 5162 cpu 8 group_fd -1 flags 0x8 = 14 > sys_perf_event_open: pid 5162 cpu 9 group_fd -1 flags 0x8 = 15 > sys_perf_event_open: pid 5162 cpu 10 group_fd -1 flags 0x8 = 16 > sys_perf_event_open: pid 5162 cpu 11 group_fd -1 flags 0x8 = 17 > sys_perf_event_open: pid 5162 cpu 12 group_fd -1 flags 0x8 = 18 > sys_perf_event_open: pid 5162 cpu 13 group_fd -1 flags 0x8 = 19 > sys_perf_event_open: pid 5162 cpu 14 group_fd -1 flags 0x8 = 20 > sys_perf_event_open: pid 5162 cpu 15 group_fd -1 flags 0x8 = 21 > sys_perf_event_open: pid 5162 cpu 16 group_fd -1 flags 0x8 = 22 > sys_perf_event_open: pid 5162 cpu 17 group_fd -1 flags 0x8 = 23 > sys_perf_event_open: pid 5162 cpu 18 group_fd -1 flags 0x8 = 24 > sys_perf_event_open: pid 5162 cpu 19 group_fd -1 flags 0x8 = 25 > sys_perf_event_open: pid 5162 cpu 20 group_fd -1 flags 0x8 = 26 > sys_perf_event_open: pid 5162 cpu 21 group_fd -1 flags 0x8 = 27 > sys_perf_event_open: pid 5162 cpu 22 group_fd -1 flags 0x8 = 28 > sys_perf_event_open: pid 5162 cpu 23 group_fd -1 flags 0x8 = 29 > ------------------------------------------------------------ > perf_event_attr: > size 128 > config 0x800000000 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|PERIOD|IDENTIFIER|AUX > read_format ID > inherit 1 > exclude_kernel 1 > exclude_hv 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > aux_sample_size 4096 > ------------------------------------------------------------ > sys_perf_event_open: pid 5162 cpu 16 group_fd 22 flags 0x8 = 30 > sys_perf_event_open: pid 5162 cpu 17 group_fd 23 flags 0x8 = 31 > sys_perf_event_open: pid 5162 cpu 18 group_fd 24 flags 0x8 = 32 > sys_perf_event_open: pid 5162 cpu 19 group_fd 25 flags 0x8 = 33 > sys_perf_event_open: pid 5162 cpu 20 group_fd 26 flags 0x8 = 34 > sys_perf_event_open: pid 5162 cpu 21 group_fd 27 flags 0x8 = 35 > sys_perf_event_open: pid 5162 cpu 22 group_fd 28 flags 0x8 = 36 > sys_perf_event_open: pid 5162 cpu 23 group_fd 29 flags 0x8 = 37 > ------------------------------------------------------------ > ... > > Signed-off-by: Jin Yao looks good to me Acked-by: Jiri Olsa thanks, jirka > --- > tools/perf/util/evsel.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index 4a3cd1b5bb33..f81ac6962aec 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -1581,6 +1581,27 @@ int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale) > return 0; > } > > +static int evsel__match_other_cpu(struct evsel *evsel, struct evsel *other, > + int cpu) > +{ > + int cpuid; > + > + cpuid = perf_cpu_map__cpu(evsel->core.cpus, cpu); > + return perf_cpu_map__idx(other->core.cpus, cpuid); > +} > + > +static int evsel__hybrid_group_cpu(struct evsel *evsel, int cpu) > +{ > + struct evsel *leader = evsel->leader; > + > + if ((evsel__is_hybrid(evsel) && !evsel__is_hybrid(leader)) || > + (!evsel__is_hybrid(evsel) && evsel__is_hybrid(leader))) { > + return evsel__match_other_cpu(evsel, leader, cpu); > + } > + > + return cpu; > +} > + > static int get_group_fd(struct evsel *evsel, int cpu, int thread) > { > struct evsel *leader = evsel->leader; > @@ -1595,6 +1616,10 @@ static int get_group_fd(struct evsel *evsel, int cpu, int thread) > */ > BUG_ON(!leader->core.fd); > > + cpu = evsel__hybrid_group_cpu(evsel, cpu); > + if (cpu == -1) > + return -1; > + > fd = FD(leader, cpu, thread); > BUG_ON(fd == -1); > > -- > 2.17.1 >