Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp600645ybm; Wed, 27 May 2020 03:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw66AnwiXQlOCwzoGKGP/l83uWMa6EbFFH01S+pje4/iBGQBf2fD42QNgUqw+nbSrzVYz5k X-Received: by 2002:a05:6402:1c94:: with SMTP id cy20mr23083872edb.270.1590575325255; Wed, 27 May 2020 03:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590575325; cv=none; d=google.com; s=arc-20160816; b=FshIoviUtfwPkM80bTlkb6OFh56R+EKrwLludPKnLIUjaZIGbfwx4Yd8e+mMdTypoL sUyV/uUljVcuVojXEVoTtmqvtRr1c4uQINfj3BMq+Xz5CwkiHit/IgkKz2RR9G2rOL7g C6CY3XBmX/ZRwXoFyoND2HjCYvUXTaiaMEmKfKFzvgbXColsJvyK/7Fpr4CyoR4mR2Vz S/tsH/ZT9lVnQ2nsAsCKcf2g/0y6jRCOWLANvMWG57esoCI8TE1WQXRJzwZdX96bDj85 5WycXf6XFiTM47pnzfUYD4pZWJVUfb8F87mGbK0dcLA3SeqHU9KuZzZInUQxzJmNRaNA +zsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:ironport-sdr:ironport-sdr; bh=Br6eCkg+hJmxS2XeV7Wn1c12D1OjkmySu7IwW+Tg2so=; b=L+6keG/FwjZTwH3MHPu1lpEK72PhfE6WcA7x9ccwwEQsghBpDA0OSiE1EwY9RzVNZv +6qfP0e24Cw2xsYd2yymWLDjhlD5j1tC8VV66sxlqShnc5hUyk0io3sU6pB0PnAPvrtv cpoi+PzDkW8qimxSV4/N2M5NO65F5raWXIA80NrT5TseSyWCbPH7gbSMiq3EZTrc9vm6 JTojDzKXQPIYkJ+6n6OnNdN97yULaTOOj5AzftmPaor65uujENTNBrGPYw6x2NVzwwt7 +6OM0mAS8oJw2Z9tosXU9998WaTjmXAV2Ozrq9vA2+qkwxoOZj4I+Pi/4s+hPy1lnj/5 FH/g== 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si1607467ejq.732.2020.05.27.03.28.21; Wed, 27 May 2020 03:28:45 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbgE0H0n (ORCPT + 99 others); Wed, 27 May 2020 03:26:43 -0400 Received: from mga05.intel.com ([192.55.52.43]:7186 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728303AbgE0H0m (ORCPT ); Wed, 27 May 2020 03:26:42 -0400 IronPort-SDR: ekH/x4lUwyqbArEUHhH0Ex2IFsymaQxlE/fiOmNQS3t/Yxh6dcpHPzXDnfPXaQ+pEvGpip4LXr nzCZ1puij4Cw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 00:26:41 -0700 IronPort-SDR: 9V7ogVoTODyRT2Nq47Vo9K+mkTl/APvqOomugdaO5MZ3zwoy42G2FST+8zRegV7NEDWgcFMSgW bFuKueoAis1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,440,1583222400"; d="scan'208";a="375946941" Received: from yjin15-mobl1.ccr.corp.intel.com (HELO [10.238.5.239]) ([10.238.5.239]) by fmsmga001.fm.intel.com with ESMTP; 27 May 2020 00:26:39 -0700 Subject: Re: [PATCH v2 1/2] perf evlist: Ensure grouped events with same cpu map From: "Jin, Yao" To: Jiri Olsa 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 References: <20200525065559.6422-1-yao.jin@linux.intel.com> <20200526115155.GE333164@krava> <32c4663a-6934-2a2d-79e2-7a335e3629a2@linux.intel.com> Message-ID: <4c670bf6-c0e4-1f9d-455c-a4bf9fd005fc@linux.intel.com> Date: Wed, 27 May 2020 15:26:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiri, On 5/27/2020 2:31 PM, Jin, Yao wrote: > Hi Jiri, > > On 5/27/2020 11:20 AM, Jin, Yao wrote: >> Hi Jiri, >> >> On 5/26/2020 7:51 PM, Jiri Olsa wrote: >>> On Mon, May 25, 2020 at 02:55:58PM +0800, Jin Yao wrote: >>> >>> SNIP >>> >>>> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c >>>> index 2a9de6491700..1161cffc0688 100644 >>>> --- a/tools/perf/util/evlist.c >>>> +++ b/tools/perf/util/evlist.c >>>> @@ -1704,3 +1704,52 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list, >>>>       } >>>>       return leader; >>>>   } >>>> + >>>> +static bool cpus_map_matched(struct evsel *prev, struct evsel *evsel) >>>> +{ >>>> +    if (evsel->core.cpus->nr != prev->core.cpus->nr) >>>> +        return false; >>>> + >>>> +    for (int i = 0; i < evsel->core.cpus->nr; i++) { >>>> +        if (evsel->core.cpus->map[i] != prev->core.cpus->map[i]) >>>> +            return false; >>>> +    } >>>> + >>>> +    return true; >>>> +} >>>> + >>>> +bool evlist__cpus_map_matched(struct evlist *evlist) >>>> +{ >>>> +    struct evsel *prev = evlist__first(evlist), *evsel = prev; >>>> +    int nr_members = prev->core.nr_members; >>>> + >>>> +    evlist__for_each_entry_continue(evlist, evsel) { >>>> +        if (nr_members <= 1) { >>>> +            prev = evsel; >>>> +            nr_members = evsel->core.nr_members; >>>> +            continue; >>>> +        } >>>> + >>>> +        nr_members--; >>>> + >>>> +        if (!cpus_map_matched(prev, evsel)) >>>> +            return false; >>>> + >>>> +        prev = evsel; >>>> +    } >>>> + >>>> +    return true; >>>> +} >>>> + >>>> +void evlist__force_disable_group(struct evlist *evlist) >>>> +{ >>>> +    struct evsel *evsel; >>>> + >>>> +    pr_warning("WARNING: event cpu maps are not fully matched, " >>>> +           "stop event grouping\n"); >>>> + >>>> +    evlist__for_each_entry(evlist, evsel) { >>>> +        evsel->leader = evsel; >>>> +        evsel->core.nr_members = 0; >>>> +    } >>>> +} >>> >>> I think this is too much, we need to disable only groups with not >>> matching cpus, not all of them, how about something like this >>> >> >> Yes, that's too much. >> >>> >>>          struct evsel *pos; >>> >>>          evlist__for_each_entry(evlist, evsel) { >>>                  if (evsel->leader == evsel) >>>                          continue; >>>                  if (!cpus_map_matched(evsel->leader, evsel)) >>>                          continue; >>>                  pr_warn("Disabling group... >>> >>>                  for_each_group_member(pos, evsel->leader) { >>>                          pos->leader = pos; >>>                          evsel->core.nr_members = 0; >>>                  } >>>          } >>> >>> jirka >>> >> >> Hmm, change "!cpus_map_matched()" to "cpus_map_matched()"? and use for_each_group_evsel() to >> replace for_each_group_member()? >> >> How about something like following? >> >> void evlist__check_cpu_maps(struct evlist *evlist) >> { >>      struct evsel *evsel, *pos; >> >>      evlist__for_each_entry(evlist, evsel) { >>          if (evsel->leader == evsel) >>              continue; >> >>          if (cpu_maps_matched(evsel->leader, evsel)) >>              continue; >> >>          pr_warning("WARNING: event cpu maps are not fully matched, " >>                 "disable group\n"); >> >>          for_each_group_evsel(pos, evsel->leader) { >>              pos->leader = pos; >>              pos->core.nr_members = 0; >>          } >> >>          /* >>           * For core & uncore mixed event group, for example, >>           * '{cycles,unc_cbo_cache_lookup.any_i}', >>           * In evlist: >>           * cycles, >>           * unc_cbo_cache_lookup.any_i, >>           * unc_cbo_cache_lookup.any_i, >>           * unc_cbo_cache_lookup.any_i, >>           * unc_cbo_cache_lookup.any_i, >>           * >>           * cycles is leader and all unc_cbo_cache_lookup.any_i >>           * point to this leader. But for_each_group_evsel can't >>           * iterate all members from cycles. It only iterates >>           * cycles and one unc_cbo_cache_lookup.any_i. So we >>           * set extra evsel here. >>           */ >>          evsel->leader = evsel; >>          evsel->core.nr_members = 0; >>      } >> } >> >> Thanks >> Jin Yao > > Issue is found! > > It looks we can't set "pos->leader = pos" in either for_each_group_member() or in > for_each_group_evsel() because it may exit the iteration immediately. > >     evlist__for_each_entry(evlist, evsel) { >         if (evsel->leader == evsel) >             continue; > >         if (cpu_maps_matched(evsel->leader, evsel)) >             continue; > >         pr_warning("WARNING: event cpu maps are not fully matched, " >                "disable group\n"); > >         for_each_group_member(pos, evsel->leader) { >             pos->leader = pos; >             pos->core.nr_members = 0; >         } > > Let me use the example of '{cycles,unc_cbo_cache_lookup.any_i}' again. > > In evlist: > cycles, > unc_cbo_cache_lookup.any_i, > unc_cbo_cache_lookup.any_i, > unc_cbo_cache_lookup.any_i, > unc_cbo_cache_lookup.any_i, > > When we reach the for_each_group_member at first time, evsel is the first unc_cbo_cache_lookup.any_i > and evsel->leader is cycles. pos is same as the evsel (the first unc_cbo_cache_lookup.any_i). > > Once we execute "pos->leader = pos;", it's actually "evsel->leader = evsel". So now evsel->leader is > changed to the first unc_cbo_cache_lookup.any_i. > > In next iteration, pos is the second unc_cbo_cache_lookup.any_i. pos->leader is cycles but > unfortunately evsel->leader has been changed to the first unc_cbo_cache_lookup.any_i. So iteration > stops immediately. > > I'm now thinking if we can solve this issue by an easy way. > > Thanks > Jin Yao How about this fix? void evlist__check_cpu_maps(struct evlist *evlist) { struct evsel *evsel, *pos, *tmp; evlist__for_each_entry(evlist, evsel) { if (evsel->leader == evsel) continue; if (cpu_maps_matched(evsel->leader, evsel)) continue; pr_warning("WARNING: event cpu maps are not fully matched, " "disable group\n"); for_each_group_member(pos, evsel->leader) { if (pos != evsel) { pos->leader = pos; pos->core.nr_members = 0; } } tmp = evsel->leader; tmp->leader = tmp; tmp->core.nr_members = 0; evsel->leader = evsel; evsel->core.nr_members = 0; } } Thanks Jin Yao