From nobody Fri Apr 4 12:31:42 2025 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 623561F5832 for ; Wed, 2 Apr 2025 22:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743634064; cv=none; b=XNCBX0QsTGZMau99id5cer/S95qAqBycKAseWEsWY/ZQG1rxCkvMx8JafXZ/wDVkERZbRoAuNPiCHqJBhPUVC5Y+2YDY5U03F7hVvQ/C7W6lD8FEY9/l44iuP5Ht8ivzGFDg4vTfjEN3XfdC40f9J5E/hMG3UDtv1PXiKx6mMeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743634064; c=relaxed/simple; bh=iPx8nikC+FuJSk+ldq09sm3wLWoporp6/awl0PQSuhA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=YXLGS8q/N66JJQ0fobd2JXluq0nYP3RMjj6ZnLW0FmkL0BwbbW67t3An4bxeGH047zQaaI3x2Kmk9Xp4bfpZdRYlX0cFCFZfC1wof7Yyjma/GGkvLvWlsJIDHTG2kx9yhWNPYanuxAWKoOLvqb/AIQ+dKbklFZYToqaKPlvQxw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OEJ5Qt7X; arc=none smtp.client-ip=209.85.160.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OEJ5Qt7X" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2c6eb3e0b2aso76052fac.0 for ; Wed, 02 Apr 2025 15:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743634061; x=1744238861; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=68/tmXqoVz/h69wPliFMFDaCp2yoUaIFTM/ZDFqAtoE=; b=OEJ5Qt7Xzjkhunr49BGIkvdmbnpSZqAus1+Yi4ul5Zk+cNlsHC5J2TsVys4F0skXZO /Ui1CMe2RWF2Ci/5KIG7J6A3jGZJOmzw8FnlNaB+TuQg0MEbMD5IpB6F/r8c/JLqccK2 zNIo6KCbny3i+BhDmZJ6A36zOS3iipZKa3Z6A11Iqj/VqGOzLkJoxkiJsQRszDJgExDn d7epXoSdc7I5rQjBj9nXCtRXgvsowrKJNSLDqD/u4qHvc30QK+79vJhrIzHXRsgTg9th 5Xp9npKEOhLp+NXoy4ty3E/QwJy5yLoVRVHYUrb2u1ElSrIqtEcb/C2IADrjOAZhO0Fy MsYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743634061; x=1744238861; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=68/tmXqoVz/h69wPliFMFDaCp2yoUaIFTM/ZDFqAtoE=; b=np6t3MBr+/MhIZBvCaUed3V+bhqkIc2/umeaRe1uKK9BXIF3/FFOBmAB/7NOQTq00j EnBVIDy2ufLqH5qOoqr4JGnGvB4h3PkF0odkD0+dYMkx37CD+ApeDHxVX7tepZGspQ4t IzJGD40pFtlLqRVsyZDg5KcU3FtjB6mvmYMRvuq2K6Vl9y3te6ThYQMI2bIDiYvui3Hw ol02mGZ3gzjPU1V4BVAj7uTuSMmqDaNrlyAraNR/Ue4aBKW10uNicFDTKEe8lotpMwXO s/13puZTDSjIIkpt3hjjWcKXdRcXGpw/D4zdM4sWyq1zlaDauNKXcb7cQcBEnFNLsVNY +nZA== X-Forwarded-Encrypted: i=1; AJvYcCVZ/HH9D7KpsMYMOl6WYhY1l0HTnaXYhR/bbnwTFhoKsAs0uD8fButsC/U+YH8gQkWzNnCRaAIoQdtJFTI=@vger.kernel.org X-Gm-Message-State: AOJu0YzXmFvhG6Yr4iWC5q8rDvajgWkeolcEtgCXt4XD/BfhjxQtwWMs OmF6bTMreu8qeZEVdFBrZyBM2NfnS3aoA5yTwfVNipg6cyBdxvNWHpQysAiMt123fcgWAjp70mZ WkL7d4w== X-Google-Smtp-Source: AGHT+IGA0Ci0HBl+mfOaNd2vBxQdSnwZe4pR80XRoe96Pa3B/vXeQYX4GJOxK+O8NWh4Y6U0EUfY6HM9sqwT X-Received: from oabvs20.prod.google.com ([2002:a05:6871:a114:b0:2c1:5dcb:42ac]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:a106:b0:29e:5e83:150e with SMTP id 586e51a60fabf-2cc60d4f0f7mr2390203fac.27.1743634061447; Wed, 02 Apr 2025 15:47:41 -0700 (PDT) Date: Wed, 2 Apr 2025 15:47:21 -0700 In-Reply-To: <20250402224722.88740-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250402224722.88740-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250402224722.88740-2-irogers@google.com> Subject: [PATCH v7 1/2] perf record: Skip don't fail for events that don't open From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Ze Gao , Weilin Wang , Dominique Martinet , Jean-Philippe Romain , Junhao He , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Aditya Bodkhe , Leo Yan , Thomas Falcon , Atish Patra Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Whilst for many tools it is an expected behavior that failure to open a perf event is a failure, ARM decided to name PMU events the same as legacy events and then failed to rename such events on a server uncore SLC PMU. As perf's default behavior when no PMU is specified is to open the event on all PMUs that advertise/"have" the event, this yielded failures when trying to make the priority of legacy and sysfs/json events uniform - something requested by RISC-V and ARM. A legacy event user on ARM hardware may find their event opened on an uncore PMU which for perf record will fail. Arnaldo suggested skipping such events which this patch implements. Rather than have the skipping conditional on running on ARM, the skipping is done on all architectures as such a fundamental behavioral difference could lead to problems with tools built/depending on perf. An example of perf record failing to open events on x86 is: ``` $ perf record -e data_read,cycles,LLC-prefetch-read -a sleep 0.1 Error: Failure to open event 'data_read' on PMU 'uncore_imc_free_running_0' which = will be removed. The sys_perf_event_open() syscall returned with 22 (Invalid argument) for e= vent (data_read). "dmesg | grep -i perf" may provide additional information. Error: Failure to open event 'data_read' on PMU 'uncore_imc_free_running_1' which = will be removed. The sys_perf_event_open() syscall returned with 22 (Invalid argument) for e= vent (data_read). "dmesg | grep -i perf" may provide additional information. Error: Failure to open event 'LLC-prefetch-read' on PMU 'cpu' which will be remove= d. The LLC-prefetch-read event is not supported. [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.188 MB perf.data (87 samples) ] $ perf report --stats Aggregated stats: TOTAL events: 17255 MMAP events: 284 ( 1.6%) COMM events: 1961 (11.4%) EXIT events: 1 ( 0.0%) FORK events: 1960 (11.4%) SAMPLE events: 87 ( 0.5%) MMAP2 events: 12836 (74.4%) KSYMBOL events: 83 ( 0.5%) BPF_EVENT events: 36 ( 0.2%) FINISHED_ROUND events: 2 ( 0.0%) ID_INDEX events: 1 ( 0.0%) THREAD_MAP events: 1 ( 0.0%) CPU_MAP events: 1 ( 0.0%) TIME_CONV events: 1 ( 0.0%) FINISHED_INIT events: 1 ( 0.0%) cycles stats: SAMPLE events: 87 ``` If all events fail to open then the perf record will fail: ``` $ perf record -e LLC-prefetch-read true Error: Failure to open event 'LLC-prefetch-read' on PMU 'cpu' which will be remove= d. The LLC-prefetch-read event is not supported. Error: Failure to open any events for recording ``` As an evlist may have dummy events that open when all command line events fail we ignore dummy events when detecting if at least some events open. This still permits the dummy event on its own to be used as a permission check: ``` $ perf record -e dummy true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.046 MB perf.data ] ``` but allows failure when a dummy event is implicilty inserted or when there are insufficient permissions to open it: ``` $ perf record -e LLC-prefetch-read -a true Error: Failure to open event 'LLC-prefetch-read' on PMU 'cpu' which will be remove= d. The LLC-prefetch-read event is not supported. Error: Failure to open any events for recording ``` The issue with legacy events is that on RISC-V they want the driver to not have mappings from legacy to non-legacy config encodings for each vendor/model due to size, complexity and difficulty to update. It was reported that on ARM Apple-M? CPUs the legacy mapping in the driver was broken and the sysfs/json events should always take precedent, however, it isn't clear this is still the case. It is the case that without working around this issue a legacy event like cycles without a PMU can encode differently than when specified with a PMU - the non-PMU version favoring legacy encodings, the PMU one avoiding legacy encodings. The patch removes events and then adjusts the idx value for each evsel. This is done so that the dense xyarrays used for file descriptors, etc. don't contain broken entries. As event opening happens relatively late in the record process, use of the idx value before the open will have become corrupted, so it is expected there are latent bugs hidden behind this change - the change is best effort. As the only vendor that has broken event names is ARM, this will principally effect ARM users. They will also experience warning messages like those above because of the uncore PMU advertising legacy event names. Suggested-by: Arnaldo Carvalho de Melo Signed-off-by: Ian Rogers Tested-by: James Clark Tested-by: Leo Yan Tested-by: Atish Patra --- tools/perf/builtin-record.c | 47 ++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ba20bf7c011d..00f6a1c23254 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -962,7 +962,6 @@ static int record__config_tracking_events(struct record= *rec) */ if (opts->target.initial_delay || target__has_cpu(&opts->target) || perf_pmus__num_core_pmus() > 1) { - /* * User space tasks can migrate between CPUs, so when tracing * selected CPUs, sideband for all CPUs is still needed. @@ -1367,6 +1366,7 @@ static int record__open(struct record *rec) struct perf_session *session =3D rec->session; struct record_opts *opts =3D &rec->opts; int rc =3D 0; + bool skipped =3D false; =20 evlist__for_each_entry(evlist, pos) { try_again: @@ -1382,15 +1382,50 @@ static int record__open(struct record *rec) pos =3D evlist__reset_weak_group(evlist, pos, true); goto try_again; } - rc =3D -errno; evsel__open_strerror(pos, &opts->target, errno, msg, sizeof(msg)); - ui__error("%s\n", msg); - goto out; + ui__error("Failure to open event '%s' on PMU '%s' which will be removed= .\n%s\n", + evsel__name(pos), evsel__pmu_name(pos), msg); + pos->skippable =3D true; + skipped =3D true; + } else { + pos->supported =3D true; } - - pos->supported =3D true; } =20 + if (skipped) { + struct evsel *tmp; + int idx =3D 0; + bool evlist_empty =3D true; + + /* Remove evsels that failed to open and update indices. */ + evlist__for_each_entry_safe(evlist, tmp, pos) { + if (pos->skippable) { + evlist__remove(evlist, pos); + continue; + } + + /* + * Note, dummy events may be command line parsed or + * added by the tool. We care about supporting `perf + * record -e dummy` which may be used as a permission + * check. Dummy events that are added to the command + * line and opened along with other events that fail, + * will still fail as if the dummy events were tool + * added events for the sake of code simplicity. + */ + if (!evsel__is_dummy_event(pos)) + evlist_empty =3D false; + } + evlist__for_each_entry(evlist, pos) { + pos->core.idx =3D idx++; + } + /* If list is empty then fail. */ + if (evlist_empty) { + ui__error("Failure to open any events for recording.\n"); + rc =3D -1; + goto out; + } + } if (symbol_conf.kptr_restrict && !evlist__exclude_kernel(evlist)) { pr_warning( "WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,\n" --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Apr 4 12:31:42 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D4861F585E for ; Wed, 2 Apr 2025 22:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743634066; cv=none; b=En1pYQ+nr7IxZO8Ym8m/M+0oz++drUWQS9g9Ndr3+OyhDLUSG101hPt1ZKUK0X+SYVAhqmuyrB93uRWGE30P+Tsq/zS5PUeCnLI8nQ56j1Ra1HCcJLycZELRiooAwXYB8qRStbTdhvfqmvXMQVn6dHQeZuV4YNbKF8T4ZKzKX58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743634066; c=relaxed/simple; bh=GgWj+fQeAvPcu8cN1/Pm6FPr+NyoKyAJy6sRaAN26j4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VdRXNPXOfqTyOkx9id+jYrzw4vz9jmEov/sPG6iDIDA6YROaTCTECaC7bg/tIGHe3KepBNolu/wHeRNH5F9kP1m5lLzFaqsyOJxZwIrvjSTSJkjIXA1MGoRwFbmG7/YuXLIN/BPgtW8888sSEmg2p0W3tSOs1n0Yq6ML8kDtSNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=V3v92yqt; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="V3v92yqt" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2254e500a73so2416035ad.0 for ; Wed, 02 Apr 2025 15:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743634063; x=1744238863; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yVS32r6P7HhM3YCVDZgLF/iwv9cjL6Vhe6YAQ3BUrjk=; b=V3v92yqtaSQbXmV0N/70a06rGIqZq17VPUAkFXujsgN4miVPDn6DTqaVuu+AGQO1N3 FrkLnn/B8QGbrQb1+1xL/Bfx/zE5SPufjEvZYmWyFzcrTd7Cxwm5ZDzgm3NLJC0SPQRS 0UBYvmZ9uGoa3qRQh5CNjdmOAuIqxJ79Obslle5unQcjW2vpCBdyhEyvNiSdaC8mgdV4 MRMpclpPS3jl4gFmqGvsVbfl17NZsO74YQ1ceA2OGU19/8rEQKv1CU7wZMr2K4n5y8vS l59pBIr52wBJGW08Osv332n9xAYLmqDcvwU76u/KZd7683mZW7CfaEr3hv9Onz1JLcE4 8y1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743634063; x=1744238863; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yVS32r6P7HhM3YCVDZgLF/iwv9cjL6Vhe6YAQ3BUrjk=; b=sFU4hAurBQgkTZLDmKEmmt10JFsvYSymBeytROtVrZA4EPZxK/AzSBhtc3m9wfl0x4 r8ZosVzvlc7qUHAyvyLEVrEdjKryo1oB/obctPTwUOyy1QGcvTmdQOhYBmBtF0vybxOb 2y3MStOhrD6rNPtia42y6YSGzmH/nnTw1m2oROQzOxObv7jmg1xhnJd1D/ctScVfw4uH kUST7mtRrH/a4RPO4kFpTeKjK22NjsHV8yIo+lxu1FcfJTV0/+DJgc8THqUZXGNrsAY/ Ts9wf9fw5lEJCmS2ieyf5iMi8c2csWTM/uEf6Ct41gbZlANs1PznqvSylnm/s6SomTXD nBmQ== X-Forwarded-Encrypted: i=1; AJvYcCW0C77K70cc+Ksxa9oBbfhA/xU8MALxRw4FOyz8bdWpTwUdlX3V83oN659LcGDkvoX4kcYFC3gtKdQ+WYc=@vger.kernel.org X-Gm-Message-State: AOJu0Yzm/DykTeTYJmB+sTcmX/Yf6VofY4p7kuguJHMEFYsNrPzSHwFW pCQDSuY8AriUYkKPWzoXCScH2+7jKMNUakW+d3T4VO5Xk+p7PaxAGg3JqBYWHeLRl1p12xaPDx5 i8y2QrQ== X-Google-Smtp-Source: AGHT+IHAWTDU70xnWeDxi1VwzW8XRkOwWLHCWFL5cxcgsPSayHsP950evCbJDRlL82R6WiS4GzOnS3KCojyx X-Received: from plqg24.prod.google.com ([2002:a17:902:9f98:b0:21f:429a:36b5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d543:b0:225:abd2:5e4b with SMTP id d9443c01a7336-2295be65eb7mr120694595ad.16.1743634063547; Wed, 02 Apr 2025 15:47:43 -0700 (PDT) Date: Wed, 2 Apr 2025 15:47:22 -0700 In-Reply-To: <20250402224722.88740-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250402224722.88740-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250402224722.88740-3-irogers@google.com> Subject: [PATCH v7 2/2] perf parse-events: Reapply "Prefer sysfs/JSON hardware events over legacy" From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Ze Gao , Weilin Wang , Dominique Martinet , Jean-Philippe Romain , Junhao He , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Aditya Bodkhe , Leo Yan , Thomas Falcon , Atish Patra Cc: Beeman Strong , Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Originally posted and merged from: https://lore.kernel.org/r/20240416061533.921723-10-irogers@google.com This reverts commit 4f1b067359ac8364cdb7f9fda41085fa85789d0f although the patch is now smaller due to related fixes being applied in commit 22a4db3c3603 ("perf evsel: Add alternate_hw_config and use in evsel__match"). The original commit message was: It was requested that RISC-V be able to add events to the perf tool so the PMU driver didn't need to map legacy events to config encodings: https://lore.kernel.org/lkml/20240217005738.3744121-1-atishp@rivosinc.com/ This change makes the priority of events specified without a PMU the same as those specified with a PMU, namely sysfs and JSON events are checked first before using the legacy encoding. The hw_term is made more generic as a hardware_event that encodes a pair of string and int value, allowing parse_events_multi_pmu_add to fall back on a known encoding when the sysfs/JSON adding fails for core events. As this covers PE_VALUE_SYM_HW, that token is removed and related code simplified. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang Tested-by: Atish Patra Tested-by: James Clark Tested-by: Leo Yan Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Beeman Strong Cc: Ingo Molnar Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 27 +++++++++--- tools/perf/util/parse-events.l | 76 +++++++++++++++++----------------- tools/perf/util/parse-events.y | 60 ++++++++++++++++++--------- 3 files changed, 99 insertions(+), 64 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5152fd5a6ead..f4236570aa4c 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1551,8 +1551,8 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, struct list_head *list =3D NULL; struct perf_pmu *pmu =3D NULL; YYLTYPE *loc =3D loc_; - int ok =3D 0; - const char *config; + int ok =3D 0, core_ok =3D 0; + const char *tmp; struct parse_events_terms parsed_terms; =20 *listp =3D NULL; @@ -1565,15 +1565,15 @@ int parse_events_multi_pmu_add(struct parse_events_= state *parse_state, return ret; } =20 - config =3D strdup(event_name); - if (!config) + tmp =3D strdup(event_name); + if (!tmp) goto out_err; =20 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - config, /*num=3D*/1, /*novalue=3D*/true, + tmp, /*num=3D*/1, /*novalue=3D*/true, loc, /*loc_val=3D*/NULL) < 0) { - zfree(&config); + zfree(&tmp); goto out_err; } list_add_tail(&term->list, &parsed_terms.terms); @@ -1604,6 +1604,8 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, pr_debug("%s -> %s/%s/\n", event_name, pmu->name, sb.buf); strbuf_release(&sb); ok++; + if (pmu->is_core) + core_ok++; } } =20 @@ -1617,9 +1619,22 @@ int parse_events_multi_pmu_add(struct parse_events_s= tate *parse_state, pr_debug("%s -> fake/%s/\n", event_name, sb.buf); strbuf_release(&sb); ok++; + core_ok++; } } =20 + if (hw_config !=3D PERF_COUNT_HW_MAX && !core_ok) { + /* + * The event wasn't found on core PMUs but it has a hardware + * config version to try. + */ + if (!parse_events_add_numeric(parse_state, list, + PERF_TYPE_HARDWARE, hw_config, + const_parsed_terms, + /*wildcard=3D*/true)) + ok++; + } + out_err: parse_events_terms__exit(&parsed_terms); if (ok) diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 7ed86e3e34e3..324b7dc8a0d3 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -117,12 +117,12 @@ do { \ yyless(0); \ } while (0) =20 -static int sym(yyscan_t scanner, int type, int config) +static int sym(yyscan_t scanner, int config) { YYSTYPE *yylval =3D parse_events_get_lval(scanner); =20 - yylval->num =3D (type << 16) + config; - return type =3D=3D PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; + yylval->num =3D config; + return PE_VALUE_SYM_SW; } =20 static int term(yyscan_t scanner, enum parse_events__term_type type) @@ -133,13 +133,13 @@ static int term(yyscan_t scanner, enum parse_events__= term_type type) return PE_TERM; } =20 -static int hw_term(yyscan_t scanner, int config) +static int hw(yyscan_t scanner, int config) { YYSTYPE *yylval =3D parse_events_get_lval(scanner); char *text =3D parse_events_get_text(scanner); =20 - yylval->hardware_term.str =3D strdup(text); - yylval->hardware_term.num =3D PERF_TYPE_HARDWARE + config; + yylval->hardware_event.str =3D strdup(text); + yylval->hardware_event.num =3D config; return PE_TERM_HW; } =20 @@ -335,16 +335,16 @@ aux-output { return term(yyscanner, PARSE_EVENTS__TE= RM_TYPE_AUX_OUTPUT); } aux-action { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_ACTION); } aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMP= LE_SIZE); } metric-id { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_METRIC_ID); } -cpu-cycles|cycles { return hw_term(yyscanner, PERF_COUNT_HW_CPU_CYCLES)= ; } -stalled-cycles-frontend|idle-cycles-frontend { return hw_term(yyscanner, P= ERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return hw_term(yyscanner, PER= F_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return hw_term(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } -cache-references { return hw_term(yyscanner, PERF_COUNT_HW_CACHE_REFERE= NCES); } -cache-misses { return hw_term(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } -branch-instructions|branches { return hw_term(yyscanner, PERF_COUNT_HW_B= RANCH_INSTRUCTIONS); } -branch-misses { return hw_term(yyscanner, PERF_COUNT_HW_BRANCH_MISSES)= ; } -bus-cycles { return hw_term(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } -ref-cycles { return hw_term(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } +cpu-cycles|cycles { return hw(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return hw(yyscanner, PERF_C= OUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return hw(yyscanner, PERF_COU= NT_HW_STALLED_CYCLES_BACKEND); } +instructions { return hw(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return hw(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES)= ; } +cache-misses { return hw(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return hw(yyscanner, PERF_COUNT_HW_BRANCH= _INSTRUCTIONS); } +branch-misses { return hw(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return hw(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return hw(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } r{num_raw_hex} { return str(yyscanner, PE_RAW); } r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } , { return ','; } @@ -390,28 +390,28 @@ r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } <> { BEGIN(INITIAL); } } =20 -cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUN= T_HW_CPU_CYCLES); } -stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_= TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TY= PE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW= _INSTRUCTIONS); } -cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT= _HW_CACHE_REFERENCES); } -cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW= _CACHE_MISSES); } -branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE,= PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } -branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_H= W_BRANCH_MISSES); } -bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_B= US_CYCLES); } -ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_R= EF_CPU_CYCLES); } -cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CP= U_CLOCK); } -task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_T= ASK_CLOCK); } -page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COU= NT_SW_PAGE_FAULTS); } -minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW= _PAGE_FAULTS_MIN); } -major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW= _PAGE_FAULTS_MAJ); } -context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_CO= UNT_SW_CONTEXT_SWITCHES); } -cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PE= RF_COUNT_SW_CPU_MIGRATIONS); } -alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_ALIGNMENT_FAULTS); } -emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_EMULATION_FAULTS); } -dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY= ); } -bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_B= PF_OUTPUT); } -cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_CGROUP_SWITCHES); } +cpu-cycles|cycles { return hw(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return hw(yyscanner, PERF_C= OUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return hw(yyscanner, PERF_COU= NT_HW_STALLED_CYCLES_BACKEND); } +instructions { return hw(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return hw(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES)= ; } +cache-misses { return hw(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return hw(yyscanner, PERF_COUNT_HW_BRANCH= _INSTRUCTIONS); } +branch-misses { return hw(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return hw(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return hw(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } +cpu-clock { return sym(yyscanner, PERF_COUNT_SW_CPU_CLOCK); } +task-clock { return sym(yyscanner, PERF_COUNT_SW_TASK_CLOCK); } +page-faults|faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS); } +minor-faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS_MIN); } +major-faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } +context-switches|cs { return sym(yyscanner, PERF_COUNT_SW_CONTEXT_SWITC= HES); } +cpu-migrations|migrations { return sym(yyscanner, PERF_COUNT_SW_CPU_MIGR= ATIONS); } +alignment-faults { return sym(yyscanner, PERF_COUNT_SW_ALIGNMENT_FAULTS= ); } +emulation-faults { return sym(yyscanner, PERF_COUNT_SW_EMULATION_FAULTS= ); } +dummy { return sym(yyscanner, PERF_COUNT_SW_DUMMY); } +bpf-output { return sym(yyscanner, PERF_COUNT_SW_BPF_OUTPUT); } +cgroup-switches { return sym(yyscanner, PERF_COUNT_SW_CGROUP_SWITCHES)= ; } =20 {lc_type} { return str(yyscanner, PE_LEGACY_CACHE); } {lc_type}-{lc_op_result} { return str(yyscanner, PE_LEGACY_CACHE); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index f888cbb076d6..d2ef1890007e 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -55,7 +55,7 @@ static void free_list_evsel(struct list_head* list_evsel) %} =20 %token PE_START_EVENTS PE_START_TERMS -%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM +%token PE_VALUE PE_VALUE_SYM_SW PE_TERM %token PE_EVENT_NAME %token PE_RAW PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH @@ -65,11 +65,9 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_DRV_CFG_TERM %token PE_TERM_HW %type PE_VALUE -%type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW %type PE_MODIFIER_EVENT %type PE_TERM -%type value_sym %type PE_RAW %type PE_NAME %type PE_LEGACY_CACHE @@ -85,6 +83,7 @@ static void free_list_evsel(struct list_head* list_evsel) %type opt_pmu_config %destructor { parse_events_terms__delete ($$); } %type event_pmu +%type event_legacy_hardware %type event_legacy_symbol %type event_legacy_cache %type event_legacy_mem @@ -102,8 +101,8 @@ static void free_list_evsel(struct list_head* list_evse= l) %destructor { free_list_evsel ($$); } %type tracepoint_name %destructor { free ($$.sys); free ($$.event); } -%type PE_TERM_HW -%destructor { free ($$.str); } +%type PE_TERM_HW +%destructor { free ($$.str); } =20 %union { @@ -118,10 +117,10 @@ static void free_list_evsel(struct list_head* list_ev= sel) char *sys; char *event; } tracepoint_name; - struct hardware_term { + struct hardware_event { char *str; u64 num; - } hardware_term; + } hardware_event; } %% =20 @@ -264,6 +263,7 @@ PE_EVENT_NAME event_def event_def =20 event_def: event_pmu | + event_legacy_hardware | event_legacy_symbol | event_legacy_cache sep_dc | event_legacy_mem sep_dc | @@ -306,24 +306,45 @@ PE_NAME sep_dc $$ =3D list; } =20 -value_sym: -PE_VALUE_SYM_HW +event_legacy_hardware: +PE_TERM_HW opt_pmu_config +{ + /* List of created evsels. */ + struct list_head *list =3D NULL; + int err =3D parse_events_multi_pmu_add(_parse_state, $1.str, $1.num, $2, = &list, &@1); + + free($1.str); + parse_events_terms__delete($2); + if (err) + PE_ABORT(err); + + $$ =3D list; +} | -PE_VALUE_SYM_SW +PE_TERM_HW sep_dc +{ + struct list_head *list; + int err; + + err =3D parse_events_multi_pmu_add(_parse_state, $1.str, $1.num, NULL, &l= ist, &@1); + free($1.str); + if (err) + PE_ABORT(err); + $$ =3D list; +} =20 event_legacy_symbol: -value_sym '/' event_config '/' +PE_VALUE_SYM_SW '/' event_config '/' { struct list_head *list; - int type =3D $1 >> 16; - int config =3D $1 & 255; int err; - bool wildcard =3D (type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYP= E_HW_CACHE); =20 list =3D alloc_list(); if (!list) YYNOMEM; - err =3D parse_events_add_numeric(_parse_state, list, type, config, $3, wi= ldcard); + err =3D parse_events_add_numeric(_parse_state, list, + /*type=3D*/PERF_TYPE_SOFTWARE, /*config=3D*/$1, + $3, /*wildcard=3D*/false); parse_events_terms__delete($3); if (err) { free_list_evsel(list); @@ -332,18 +353,17 @@ value_sym '/' event_config '/' $$ =3D list; } | -value_sym sep_slash_slash_dc +PE_VALUE_SYM_SW sep_slash_slash_dc { struct list_head *list; - int type =3D $1 >> 16; - int config =3D $1 & 255; - bool wildcard =3D (type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYP= E_HW_CACHE); int err; =20 list =3D alloc_list(); if (!list) YYNOMEM; - err =3D parse_events_add_numeric(_parse_state, list, type, config, /*head= _config=3D*/NULL, wildcard); + err =3D parse_events_add_numeric(_parse_state, list, + /*type=3D*/PERF_TYPE_SOFTWARE, /*config=3D*/$1, + /*head_config=3D*/NULL, /*wildcard=3D*/false); if (err) PE_ABORT(err); $$ =3D list; --=20 2.49.0.504.g3bcea36a83-goog