From patchwork Sun Feb 19 09:28:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 59097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp772166wrn; Sun, 19 Feb 2023 01:32:16 -0800 (PST) X-Google-Smtp-Source: AK7set+RGTTiObk92A3SdEcdO3ja7QXYwynOo+DeoIFBgVsL/xMf0/GiqQ4YgvD2EQ9gz0eCYYuT X-Received: by 2002:a17:906:9f19:b0:879:ec1a:4ac with SMTP id fy25-20020a1709069f1900b00879ec1a04acmr7152486ejc.76.1676799136358; Sun, 19 Feb 2023 01:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676799136; cv=none; d=google.com; s=arc-20160816; b=DkdnMTtQpVtMJUW3mslnh9yzbzyBmBmdRpGor7NZOVm5o5rGE93ZnOMmOkTcX0Cl0m hJpbo+g7lsnIWfQEZzsjsqwgcGhBzS5O2z5qxs+w7JSLpW77q/GDBoRGTqqmiil/pyVe 4JbxtX9x5Rh/hEv86aUhItFU24B2SfP3jsLsvQCgo27vryYmZdO/WUUS4JhfCMUtkgaY lKYMwq5XLrKsiNSK7Q0i0Ao87kHnukz0Ii/hHaWb6RToOIawj9rjB3PGUx/Bc/rS3tg+ v3GsSUSFKZ5Zqi0alkIGPwzcewC2LWuI1mMh3AEJk3GyS1Os8f6VtCL5rC5Kg84xMYKK x9AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=ZekM3DFhsGli0TNli/C0IYKvA9f7AyUZpwfMde3iUAk=; b=e2n+hpKvJz9GH6cF9Yxc1KsjLn/XLe1SCSgMdeRKcH80NJe3H7d7uS1txb00WfQILg j8xB2HW/jpTmEzzqss0f5LwOIpupMlXDV46igD1CtR9Y2Nwpx4qMLSR3TPvWtOnZ/V+n smtrnmYybOrTiNnYyXTYLDEYpczf7ul+zIH3ve7t1VnADvgbtpIThX1MADodqiaOG0K3 GrymbF2mf7UitRP7rK/S4437NoxYsD3iGxg+seiKLletNbo0DmbU0X0FbN8upGg/uwpz axt+vpnjH0p2LqDNeOsgp1yHQGwSAhIEe77OFANAaBhrwbFNm4iDmTKsmI6JGyTF8LvV YbXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=njwS0zdv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020aa7c703000000b004acc75b447bsi11481741edq.273.2023.02.19.01.31.53; Sun, 19 Feb 2023 01:32:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=njwS0zdv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbjBSJax (ORCPT + 99 others); Sun, 19 Feb 2023 04:30:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjBSJar (ORCPT ); Sun, 19 Feb 2023 04:30:47 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95775DBF9 for ; Sun, 19 Feb 2023 01:30:19 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id o14-20020a25730e000000b009419f64f6afso2219572ybc.2 for ; Sun, 19 Feb 2023 01:30:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZekM3DFhsGli0TNli/C0IYKvA9f7AyUZpwfMde3iUAk=; b=njwS0zdvPBr2f5Gwgx+MnFdMKJsacyJ3/qym2jLfPEHxAMivAGs+rlWWdk+Du+BWeG roLMmds7cxYanNraNuE8rI1XscoaMpSnYds3csTWiUZXGSDGsb+iX6X/mzHsk16/KvNg JIRRQggidvMZ9LijU87B8gNDY3B0npD5/KmjFMTlcvpZlx5GcIoFBSm4uQcG+OTZrVCB ryA5rcmtM4YDU3yMrGfDKb+E+nYgR15LIJmRsygIIdD202+A6TIyuwJoFUQHcUClbq2W k75D//NmRE3BNcT8UUVZbhzSfbsObFP7TGXybtoz712NdmByjrR0HfRP9//XsBj4ATZb B3Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZekM3DFhsGli0TNli/C0IYKvA9f7AyUZpwfMde3iUAk=; b=fkIFPKKN1h2UsXuPX7h36j/deB/HdGMeN0ruy33kiSvEwH2LQv3GWCkfSbOwJavdYs JoHNi8WvkDYxmQNpaDwSA0n5RmBseG5fmqJZCuE+8r+c2/XVK+kJFtMaiMMxaUNqsofZ 5MsC/tiqIS3j+zkN1ZB9wdLNRetgyr5NlEG2OGvnNQXAnjWZg71+1lE9vXmFG62ANZAi d9pfzOR0W0eMqVJAhoAu7wi2mmL5kwS4FzBXePV1z2TrQTpem6rT/56aU6bgT841gtYg J6yiaz6zUOahtWYA7SHWq5Gvz1fbu0P4FZ8BFXNviUpeJmcERHMJRUck9JXHfO/6h5LQ pZdA== X-Gm-Message-State: AO0yUKUD9R4054MHU0ys3kU72ZqsCYWq3y3d/6hwLrNc0C/CP7zA/qq8 2MhvjunU6Xo6f7w1ZeYczlMDgMDZi5PZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:cde9:3fbc:e1f1:6e3b]) (user=irogers job=sendgmr) by 2002:a81:8482:0:b0:533:a071:d7f8 with SMTP id u124-20020a818482000000b00533a071d7f8mr449175ywf.547.1676799016916; Sun, 19 Feb 2023 01:30:16 -0800 (PST) Date: Sun, 19 Feb 2023 01:28:06 -0800 In-Reply-To: <20230219092848.639226-1-irogers@google.com> Message-Id: <20230219092848.639226-10-irogers@google.com> Mime-Version: 1.0 References: <20230219092848.639226-1-irogers@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Subject: [PATCH v1 09/51] perf pmu-events: Don't '\0' terminate enum values From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Maxime Coquelin , Alexandre Torgue , Zhengjun Xing , Sandipan Das , James Clark , Kajol Jain , John Garry , Kan Liang , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Suzuki Poulouse , Leo Yan , Florian Fischer , Ravi Bangoria , Jing Zhang , Sean Christopherson , Athira Rajeev , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Perry Taylor , Caleb Biggers Cc: Stephane Eranian , Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758251331334271935?= X-GMAIL-MSGID: =?utf-8?q?1758251331334271935?= Encoding enums like '1\0' wastes a byte and could be '1' (no '\0' terminator) if the 0 case is '0', it also removes a branch for decompressing. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index dc0c56dccb5e..e82dff3a1228 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -54,6 +54,8 @@ _json_metric_attributes = [ 'metric_name', 'metric_group', 'metric_expr', 'desc', 'long_desc', 'unit', 'compat', 'aggr_mode', 'event_grouping' ] +# Attributes that are bools or enum int values, encoded as '0', '1',... +_json_enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg'] def removesuffix(s: str, suffix: str) -> str: """Remove the suffix from a string @@ -360,7 +362,10 @@ class JsonEvent: # Convert parsed metric expressions into a string. Slashes # must be doubled in the file. x = x.ToPerfJson().replace('\\', '\\\\') - s += f'{x}\\000' if x else '\\000' + if attr in _json_enum_attributes: + s += x if x else '0' + else: + s += f'{x}\\000' if x else '\\000' return s def to_c_string(self, metric: bool) -> str: @@ -690,16 +695,18 @@ static void decompress_event(int offset, struct pmu_event *pe) { \tconst char *p = &big_c_string[offset]; """) - enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg'] for attr in _json_event_attributes: _args.output_file.write(f'\n\tpe->{attr} = ') - if attr in enum_attributes: - _args.output_file.write("(*p == '\\0' ? 0 : *p - '0');\n") + if attr in _json_enum_attributes: + _args.output_file.write("*p - '0';\n") else: _args.output_file.write("(*p == '\\0' ? NULL : p);\n") if attr == _json_event_attributes[-1]: continue - _args.output_file.write('\twhile (*p++);') + if attr in _json_enum_attributes: + _args.output_file.write('\tp++;') + else: + _args.output_file.write('\twhile (*p++);') _args.output_file.write("""} static void decompress_metric(int offset, struct pmu_metric *pm) @@ -708,13 +715,16 @@ static void decompress_metric(int offset, struct pmu_metric *pm) """) for attr in _json_metric_attributes: _args.output_file.write(f'\n\tpm->{attr} = ') - if attr in enum_attributes: - _args.output_file.write("(*p == '\\0' ? 0 : *p - '0');\n") + if attr in _json_enum_attributes: + _args.output_file.write("*p - '0';\n") else: _args.output_file.write("(*p == '\\0' ? NULL : p);\n") if attr == _json_metric_attributes[-1]: continue - _args.output_file.write('\twhile (*p++);') + if attr in _json_enum_attributes: + _args.output_file.write('\tp++;') + else: + _args.output_file.write('\twhile (*p++);') _args.output_file.write("""} int pmu_events_table_for_each_event(const struct pmu_events_table *table,