From nobody Tue Dec 23 18:06:12 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 78F163EA94 for ; Wed, 31 Jan 2024 20:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706732082; cv=none; b=ou2/gCPrwegnGiqF15tMhaUbBZ5YtiXfo6UO4JJk/1j9dyi2vSAaMACViaFf7bXzaA7p0Y22jnLgcrE7TQjQVUa/1m/O33jLYzm2Fx1eKIMNLMHuT+den/b40jujYeDFwQxRKh4E7DaHtIsDzBMCaTS6SDf9vbL6nUub5ncttPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706732082; c=relaxed/simple; bh=Ax5JEIPjw4jWPtHEm7pQrjMLSrDe/wM672XsGNmMJ/0=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=jDJcWexvJiQaJj8QCigbUmnnEpX8xD1WXa4o3QN48scdx+NUW9CBLU0VYbknVGzXaSRvXCWI73AnHTCPnoWTzXTR6KDcvNhL1pfQATk0JA1peIYVFl+81r7QsjIrco6Czjm58xNkjs6Byf0d0HXFV965M5VuvcOXj/fq59dLUsA= 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=uynVu288; arc=none smtp.client-ip=209.85.128.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="uynVu288" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-604000fefccso2791547b3.3 for ; Wed, 31 Jan 2024 12:14:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706732078; x=1707336878; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=e2rDkqb+E2xnp8mp8D2lOafAWaTbfc+6G88WUXMkCnU=; b=uynVu288tuT6FM9IUjM89aS+6yNJbrhQ9ePKfKm2pzhiNhuMjVZU3Dj0CSSCcIiyaO HsEDTIc9Q/z9RJgWfz46lEkCcmSx2VmiKNKS+EWZ+9Ttz6NuYBEIAV/30l+89NqQDsHg gtI3BBgCMjmfQrKSKYj6OBXlDA+bO1F6xtG9O4pON+68N/326cXIqLfcujK6J/EIF3Wb Bn5K0HpOXoYjeua2ET+Us13Yg1c01qFuJDpICEWOXHXJxVuZZ9ruFt9aS68j8FVnbGG1 jYG4UEepdhyIH8CkOKCdm2Cvxgpyr2ctJgrDBkH3QFI4Oc2s2pDcIl2XJHIKn9Xl/QnL 68Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706732078; x=1707336878; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=e2rDkqb+E2xnp8mp8D2lOafAWaTbfc+6G88WUXMkCnU=; b=n7iprYKl0l7fbTDx5z0OKFvJxLWILLmQtO/+QjFZ1cgsA6uxZR7EZgiqTfu88TAgj3 yrZlhrNkozhqFh5K3UqG/1CMs8rqxshSPZtl1msESyW90JK8WLYlAbKIh4tY6MQb0moU RH7UgnO09NI1aZk8GgPArC2UzJLFP3TY3+6O36hNOf88IWT9LnvQLDkrtp7/i7YQa5P5 L+Hfm0B0qrtaTJXrMFQT8HXBZJUQ3Sw26X2cQl5zO5DAFG6O7yg86yX9L8TyhIx58HZd I2D32LK4S0ltD7waaY8lFZolH3Yys0a2SMfw24eXWeJxcQ71i6liE7BdoRTUAxluzWcS krsw== X-Gm-Message-State: AOJu0YySsPcuDhiSoOEU6QchmfWwyCnnoEQo/4Azogab1RiapdXaQBOC rNJHV1eXygTsAb6d+GNXteRSfxYMX5b05wT5VIHvhbcIHkTNm8lrsvKeCZ5QQ9zu7polrMPHT3S yLGS0sQ== X-Google-Smtp-Source: AGHT+IFkL/HMYecG4pjlmM4yPPuHGrpUEc/72BDkAeeoCz3jqncXNV5/D+bTqDzVyiVwPgHnDVcvwQwGIfR7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a05:690c:f85:b0:5f9:abfe:243c with SMTP id df5-20020a05690c0f8500b005f9abfe243cmr424360ywb.3.1706732078491; Wed, 31 Jan 2024 12:14:38 -0800 (PST) Date: Wed, 31 Jan 2024 12:14:29 -0800 Message-Id: <20240131201429.792138-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v1] perf jevents: Drop or simplify small integer values From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kajol Jain , John Garry , Jing Zhang , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Weilin Wang , Veronika Molnarova , Michael Petlan , Edward Baker , Perry Taylor Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Prior to this patch '0' would be dropped as the config values default to 0. Some json values are hex and the string '0' wouldn't match '0x0' as zero. Add a more robust is_zero test to drop these event terms. When encoding numbers as hex, if the number is between 0 and 9 inclusive then don't add a 0x prefix. Update test expectations for these changes. On x86 this reduces the event/metric C string by 58,411 bytes. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/pmu-events/jevents.py | 23 ++++++++++++++++++++--- tools/perf/tests/pmu-events.c | 22 +++++++++++----------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 53ab050c8fa4..2c7e5d61ce92 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -203,7 +203,7 @@ class JsonEvent: =20 def llx(x: int) -> str: """Convert an int to a string similar to a printf modifier of %#llx.= """ - return '0' if x =3D=3D 0 else hex(x) + return str(x) if x >=3D 0 and x < 10 else hex(x) =20 def fixdesc(s: str) -> str: """Fix formatting issue for the desc string.""" @@ -294,6 +294,23 @@ class JsonEvent: } return table[unit] if unit in table else f'uncore_{unit.lower()}' =20 + def is_zero(val: str) -> bool: + try: + if val.startswith('0x'): + return int(val, 16) =3D=3D 0 + else: + return int(val) =3D=3D 0 + except e: + return False + + def canonicalize_value(val: str) -> str: + try: + if val.startswith('0x'): + return llx(int(val, 16)) + return str(int(val)) + except e: + return val + eventcode =3D 0 if 'EventCode' in jd: eventcode =3D int(jd['EventCode'].split(',', 1)[0], 0) @@ -358,8 +375,8 @@ class JsonEvent: ('RdWrMask', 'rdwrmask=3D'), ] for key, value in event_fields: - if key in jd and jd[key] !=3D '0': - event +=3D ',' + value + jd[key] + if key in jd and not is_zero(jd[key]): + event +=3D f',{value}{canonicalize_value(jd[key])}' if filter: event +=3D f',{filter}' if msr: diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index a56d32905743..47a7c3277540 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -70,7 +70,7 @@ static const struct perf_pmu_test_event segment_reg_loads= _any =3D { .event =3D { .pmu =3D "default_core", .name =3D "segment_reg_loads.any", - .event =3D "event=3D0x6,period=3D200000,umask=3D0x80", + .event =3D "event=3D6,period=3D200000,umask=3D0x80", .desc =3D "Number of segment register loads", .topic =3D "other", }, @@ -82,7 +82,7 @@ static const struct perf_pmu_test_event dispatch_blocked_= any =3D { .event =3D { .pmu =3D "default_core", .name =3D "dispatch_blocked.any", - .event =3D "event=3D0x9,period=3D200000,umask=3D0x20", + .event =3D "event=3D9,period=3D200000,umask=3D0x20", .desc =3D "Memory cluster signals to block micro-op dispatch for any rea= son", .topic =3D "other", }, @@ -94,11 +94,11 @@ static const struct perf_pmu_test_event eist_trans =3D { .event =3D { .pmu =3D "default_core", .name =3D "eist_trans", - .event =3D "event=3D0x3a,period=3D200000,umask=3D0x0", + .event =3D "event=3D0x3a,period=3D200000", .desc =3D "Number of Enhanced Intel SpeedStep(R) Technology (EIST) trans= itions", .topic =3D "other", }, - .alias_str =3D "event=3D0x3a,period=3D0x30d40,umask=3D0", + .alias_str =3D "event=3D0x3a,period=3D0x30d40", .alias_long_desc =3D "Number of Enhanced Intel SpeedStep(R) Technology (E= IST) transitions", }; =20 @@ -128,7 +128,7 @@ static const struct perf_pmu_test_event *core_events[] = =3D { static const struct perf_pmu_test_event uncore_hisi_ddrc_flux_wcmd =3D { .event =3D { .name =3D "uncore_hisi_ddrc.flux_wcmd", - .event =3D "event=3D0x2", + .event =3D "event=3D2", .desc =3D "DDRC write commands", .topic =3D "uncore", .long_desc =3D "DDRC write commands", @@ -156,13 +156,13 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_= response_miss_eviction =3D { static const struct perf_pmu_test_event uncore_hyphen =3D { .event =3D { .name =3D "event-hyphen", - .event =3D "event=3D0xe0,umask=3D0x00", + .event =3D "event=3D0xe0", .desc =3D "UNC_CBO_HYPHEN", .topic =3D "uncore", .long_desc =3D "UNC_CBO_HYPHEN", .pmu =3D "uncore_cbox", }, - .alias_str =3D "event=3D0xe0,umask=3D0", + .alias_str =3D "event=3D0xe0", .alias_long_desc =3D "UNC_CBO_HYPHEN", .matching_pmu =3D "uncore_cbox_0", }; @@ -170,13 +170,13 @@ static const struct perf_pmu_test_event uncore_hyphen= =3D { static const struct perf_pmu_test_event uncore_two_hyph =3D { .event =3D { .name =3D "event-two-hyph", - .event =3D "event=3D0xc0,umask=3D0x00", + .event =3D "event=3D0xc0", .desc =3D "UNC_CBO_TWO_HYPH", .topic =3D "uncore", .long_desc =3D "UNC_CBO_TWO_HYPH", .pmu =3D "uncore_cbox", }, - .alias_str =3D "event=3D0xc0,umask=3D0", + .alias_str =3D "event=3D0xc0", .alias_long_desc =3D "UNC_CBO_TWO_HYPH", .matching_pmu =3D "uncore_cbox_0", }; @@ -184,7 +184,7 @@ static const struct perf_pmu_test_event uncore_two_hyph= =3D { static const struct perf_pmu_test_event uncore_hisi_l3c_rd_hit_cpipe =3D { .event =3D { .name =3D "uncore_hisi_l3c.rd_hit_cpipe", - .event =3D "event=3D0x7", + .event =3D "event=3D7", .desc =3D "Total read hits", .topic =3D "uncore", .long_desc =3D "Total read hits", @@ -265,7 +265,7 @@ static const struct perf_pmu_test_event sys_ccn_pmu_rea= d_cycles =3D { static const struct perf_pmu_test_event sys_cmn_pmu_hnf_cache_miss =3D { .event =3D { .name =3D "sys_cmn_pmu.hnf_cache_miss", - .event =3D "eventid=3D0x1,type=3D0x5", + .event =3D "eventid=3D1,type=3D5", .desc =3D "Counts total cache misses in first lookup result (high priori= ty)", .topic =3D "uncore", .pmu =3D "uncore_sys_cmn_pmu", --=20 2.43.0.429.g432eaa2c6b-goog