From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA218C3DA4B for ; Mon, 15 Jul 2024 21:49:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CCF66B0092; Mon, 15 Jul 2024 17:49:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 156C56B0093; Mon, 15 Jul 2024 17:49:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F11596B0095; Mon, 15 Jul 2024 17:49:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CEB5A6B0092 for ; Mon, 15 Jul 2024 17:49:10 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4120E8087D for ; Mon, 15 Jul 2024 21:49:10 +0000 (UTC) X-FDA: 82343328060.30.F5DA31B Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf19.hostedemail.com (Postfix) with ESMTP id 6FB901A001C for ; Mon, 15 Jul 2024 21:49:08 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UjOJTDz5; spf=pass (imf19.hostedemail.com: domain of irogers@google.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=irogers@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721080129; a=rsa-sha256; cv=none; b=ZVn/XXqQEBRteJzPyYSRfhXYdtlj1FMk3NsVUjzg7vLZccrhhZwmnUy9NxT3mH53mHfarV 2DAqBmEV18IPFwWq2zKNzhl1YUO8W6K42i5dQ6Z9cuVm0/yb4PPSUr7W+2wJfGp0lhBCPU LL3cBCn+JgGJXF+PXzQPzflhyMTBi0Q= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UjOJTDz5; spf=pass (imf19.hostedemail.com: domain of irogers@google.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=irogers@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721080129; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wB6SC4uGgu6orZ7uUyB+Wip/qnu3DTiRnxdXUaHY4wE=; b=kV83VizbODxbb0nvNFGd295x4ewYn3bijOVPeqxf4Fje93B39SxHNVfaLxKDiqxhwAiL07 u2ZfsUn8uo6PyPQvQaZ1LgT6GVneXXMjUnuilZy2HFCzDYyezw3TXAMGXDZcxzYKRb1yUD XJGK/4HY6nb8q/vWNJ2wPMIB4dtVpWg= Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-447f8aa87bfso134181cf.0 for ; Mon, 15 Jul 2024 14:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721080147; x=1721684947; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wB6SC4uGgu6orZ7uUyB+Wip/qnu3DTiRnxdXUaHY4wE=; b=UjOJTDz5rHrEtcJZRdAtlqs/y/xwbXt0oDsSdF0kWJ/BPjAZv09kjgW85qxehofad5 9T644dLrgKX6D8BBxqpmKGfdUUTh7QSA+0HlV/umnoWC3clVbunUtUBDOrEMiH5W5BQ5 W6M9LaDThDZ3iw6Mj0hUUuqMTGA63PHjnruOXlgKZJCWgnxjJ3H/RlDorugHhUfY0yAL mvd3Lw0W1A0p15X5qZyofgv12Fe5S3EQ7rrZRvbb5iPpJTLT/ybfiZm/2Ikcn+yFweEI HN5mXtPn0ouzRL8/KV0e9n2BdcvjqFOIRdHaTaggLZ4Tn57h/NbNmnkkXwwA9ARgKSnc JmqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721080147; x=1721684947; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wB6SC4uGgu6orZ7uUyB+Wip/qnu3DTiRnxdXUaHY4wE=; b=ZtXpop9M9/ly+5KXDix/4VFOhtP1Le8if8B29qZgKr/oQtSlQV5nA/Uz2lLgfraP64 634C7CzBsVKLWTmFZQHQChlLE5tGPNaCw2LfOXDKPuVFsSJTZAwyXVyN/5xUESAztepr ViXQ13/2Yi+8ZeOqE0Q/vI6BGt1bejOMBz9djCSwcDmAajsyQGJbXSQn9nbZ4IbrLZua iFQyD/j1NU3q6OOuGFoaTsUZF0n0A6VPDDs14FgHRhlAQKbsle0AnA13KOIRZrRJs/H4 aTOjMNMJObUdrjQk42Ck33W9IsCN9zvirMv08N9ffbSbofN7N9ysssc8fx0Ja6EcBFaz RoQQ== X-Forwarded-Encrypted: i=1; AJvYcCWRL6IU0kWgaZATQq21b0PB8CscF6Q+2yqP9bwED/QifeutgSSlVxL2t72Zert9DpwgzBOnuMzvDHATTR+NmKMBDMw= X-Gm-Message-State: AOJu0YzJjwqzgrFsUmDiMwP90jBip2qAbrYLf3PVZuX/ktKi9uBVyCD9 u86RcrajfFdpfWka+b8VUuU7M6WSmFoaN2zCXW2hE1VCVRXK9eFI84M6is80tBRH0w2xNsQRa+A lfoCWMbNSOTm0Bmru7Jgkam77XDFYIHZa7rTX X-Google-Smtp-Source: AGHT+IGhwTiqL6/IuPxIfPGI2o8M8T5jSY2UEJVTwdFThGzYdC8Wi2wU6umxV/eEeTZynx4KCQZgI14aR/KG4ZKDSW0= X-Received: by 2002:a05:622a:6113:b0:447:e153:66e0 with SMTP id d75a77b69052e-44f7a64d44bmr943591cf.2.1721080147286; Mon, 15 Jul 2024 14:49:07 -0700 (PDT) MIME-Version: 1.0 References: <202407101021.2c8baddb-oliver.sang@intel.com> <48b4bfb0-d0c7-4d1f-9e52-06e873646366@linux.intel.com> In-Reply-To: <48b4bfb0-d0c7-4d1f-9e52-06e873646366@linux.intel.com> From: Ian Rogers Date: Mon, 15 Jul 2024 14:48:55 -0700 Message-ID: Subject: Re: [linux-next:master] [perf vendor events] e2641db83f: perf-sanity-tests.perf_all_PMU_test.fail To: "Liang, Kan" Cc: kernel test robot , oe-lkp@lists.linux.dev, lkp@intel.com, Linux Memory Management List , Namhyung Kim , Weilin Wang , Caleb Biggers , Alexandre Torgue , Maxime Coquelin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: 7tybd6gdohwoys8ex3pz7hb6rhhj3fpc X-Rspamd-Queue-Id: 6FB901A001C X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721080148-404726 X-HE-Meta: U2FsdGVkX1++8NfxJCfBgayMuCdOz0x5TZOnZAxWw9lHX8s+iERzW9w9X43IPAQ7w7Xr9RAv0jtcZkKH1kNIeZ4LKDUR50pNqxz/tH0aoNasxOJe6OnMuiVMhGWHIRfURiBiM3PPnRvohRirhpjkiogVq7zXZRY7EDNUW7U9j6FbReQIaiL4OI20DMNeQHG4S6BCPjbiMKHxBjJz5iNaWIPVi5t3GcgTjO3NTT9emf5PvNaPj1eb0751CpUmGPFVmRgYV94mbXXXluzo9fjRMCkqkgT8WrtSk0urc2xfmHvi2ManpuG1NC8F5Vzh+tyfXP64Ihu5LvIj9yT+tUxj83mYK8kKyqgLmbjRWY+O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ner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jul 15, 2024 at 2:41=E2=80=AFPM Liang, Kan wrote: > > > > On 2024-07-15 4:11 p.m., Ian Rogers wrote: > > On Mon, Jul 15, 2024 at 1:05=E2=80=AFPM Liang, Kan wrote: > >> > >> Hi Ian, > >> > >> On 2024-07-10 12:59 a.m., kernel test robot wrote: > >>> > >>> > >>> Hello, > >>> > >>> kernel test robot noticed "perf-sanity-tests.perf_all_PMU_test.fail" = on: > >>> > >>> commit: e2641db83f18782f57a0e107c50d2d1731960fb8 ("perf vendor events= : Add/update skylake events/metrics") > >>> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git mast= er > >>> > >>> [test failed on linux-next/master 82d01fe6ee52086035b201cfa1410a3b043= 84257] > >>> > >>> in testcase: perf-sanity-tests > >>> version: > >>> with following parameters: > >>> > >>> perf_compiler: gcc > >>> > >>> > >>> > >>> compiler: gcc-13 > >>> test machine: 16 threads 1 sockets Intel(R) Xeon(R) E-2278G CPU @ 3.4= 0GHz (Coffee Lake) with 32G memory > >>> > >>> (please refer to attached dmesg/kmsg for entire log/backtrace) > >>> > >>> > >>> we also observed two cases which also failed on parent can pass on th= is commit. > >>> FYI. > >>> > >>> > >>> caccae3ce7b988b6 e2641db83f18782f57a0e107c50 > >>> ---------------- --------------------------- > >>> fail:runs %reproduction fail:runs > >>> | | | > >>> :6 100% 6:6 perf-sanity-tests.perf_= all_PMU_test.fail > >>> :6 100% 6:6 perf-sanity-tests.perf_= all_metricgroups_test.pass > >>> :6 100% 6:6 perf-sanity-tests.perf_= all_metrics_test.pass > >>> > >>> > >>> > >>> > >>> > >>> If you fix the issue in a separate patch/commit (i.e. not just a new = version of > >>> the same patch/commit), kindly add following tags > >>> | Reported-by: kernel test robot > >>> | Closes: https://lore.kernel.org/oe-lkp/202407101021.2c8baddb-oliver= .sang@intel.com > >>> > >>> > >>> > >>> 2024-07-09 07:09:53 sudo /usr/src/linux-perf-x86_64-rhel-8.3-bpf-e264= 1db83f18782f57a0e107c50d2d1731960fb8/tools/perf/perf test 105 > >>> 105: perf all metricgroups test = : Ok > >>> 2024-07-09 07:10:11 sudo /usr/src/linux-perf-x86_64-rhel-8.3-bpf-e264= 1db83f18782f57a0e107c50d2d1731960fb8/tools/perf/perf test 106 > >>> 106: perf all metrics test = : Ok > >>> 2024-07-09 07:10:23 sudo /usr/src/linux-perf-x86_64-rhel-8.3-bpf-e264= 1db83f18782f57a0e107c50d2d1731960fb8/tools/perf/perf test 107 > >>> 107: perf all libpfm4 events test = : Ok > >>> 2024-07-09 07:10:47 sudo /usr/src/linux-perf-x86_64-rhel-8.3-bpf-e264= 1db83f18782f57a0e107c50d2d1731960fb8/tools/perf/perf test 108 > >>> 108: perf all PMU test = : FAILED! > >>> > >> > >> The failure is caused by the below change in the e2641db83f18. > >> > >> + { > >> + "BriefDescription": "This 48-bit fixed counter counts the UCL= K > >> cycles", > >> + "Counter": "FIXED", > >> + "EventCode": "0xff", > >> + "EventName": "UNC_CLOCK.SOCKET", > >> + "PerPkg": "1", > >> + "PublicDescription": "This 48-bit fixed counter counts the UC= LK > >> cycles.", > >> + "Unit": "cbox_0" > >> } > >> > >> The other cbox events have the unit name "CBOX", while the fixed count= er > >> has a unit name "cbox_0". So the events_table will maintain separate > >> entries for cbox and cbox_0. > >> > >> The perf_pmus__print_pmu_events() calculate the total number of events= , > >> allocate an aliases buffer, store all the events into the buffer, sort= , > >> and print all the aliases one by one. > >> > >> The problem is that the calculated total number of events doesn't matc= h > >> the stored events on the SKL machine. > >> > >> The perf_pmu__num_events() is used to calculate the number of events. = It > >> invokes the pmu_events_table__num_events() to go through the entire > >> events_table to find all events. Because of the > >> pmu_uncore_alias_match(), the suffix of uncore PMU will be ignored. So > >> the events for cbox and cbox_0 are all counted. > >> > >> When storing events into the aliases buffer, the > >> perf_pmu__for_each_event() only process the events for cbox. > >> > >> Since a bigger buffer was allocated, the last entry are all 0. > >> When printing all the aliases, null will be outputed. > >> > >> $ perf list pmu > >> > >> List of pre-defined events (to be used in -e or -M): > >> > >> (null) [Kernel PMU event= ] > >> branch-instructions OR cpu/branch-instructions/ [Kernel PMU event= ] > >> branch-misses OR cpu/branch-misses/ [Kernel PMU event= ] > >> > >> > >> I'm thinking of two ways to address it. > >> One is to only print all the stored events. The below patch can fix it= . > >> > >> diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c > >> index 3fcabfd8fca1..2b2f5117ff84 100644 > >> --- a/tools/perf/util/pmus.c > >> +++ b/tools/perf/util/pmus.c > >> @@ -485,6 +485,7 @@ void perf_pmus__print_pmu_events(const struct > >> print_callbacks *print_cb, void *p > >> perf_pmu__for_each_event(pmu, skip_duplicate_pmus, &st= ate, > >> perf_pmus__print_pmu_events__c= allback); > >> } > >> + len =3D state.index; > >> qsort(aliases, len, sizeof(struct sevent), cmp_sevent); > >> for (int j =3D 0; j < len; j++) { > >> /* Skip duplicates */ > >> > >> The only drawback is that perf list will not show the new cbox_0 event= . > >> (But the event name still works. Users can still apply perf stat -e > >> unc_clock.socket.) > >> > >> Since the cbox_0 event is only available on old machines (SKL and > >> earlier), people should already use the equivalent kernel event. It > >> doesn't sounds a big issue for me. I prefer this simple fix. > >> > >> I think the other way would be to modify the perf_pmu__for_each_event(= ) > >> to go through all the possible PMUs. > >> It seems complicated and may impact others ARCHs (e.g., S390). I haven= 't > >> tried it yet. > >> > >> What do you think? > >> Do you see any other ways to address the issue? > > > > Ugh. It seems the sizing and then iterating approach is just prone to > > keep breaking. Perhaps we can switch to realloc-ed arrays to avoid the > > need for perf_pmu__num_events, which seems to be the source of the > > problems. > > > > I think a realloc-ed array should have the same drawback as the first > way, but bad performance. > Because the pmu_add_cpu_aliases() in the perf_pmu__for_each_event() only > add the events from the first matched PMU. If we don't fix it, the > UNC_CLOCK.SOCKET of cbox_0 will never be displayed. Ok, but I don't think we need to optimize `perf list` for speed. Fwiw, I think this was the fix for the last bug in this code: https://lore.kernel.org/r/20240511003601.2666907-1-irogers@google.com Thanks, Ian