Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp424636rwl; Wed, 5 Apr 2023 02:44:02 -0700 (PDT) X-Google-Smtp-Source: AKy350auRGx8U9SIfh/jHfs/WjLhzSK04rEzD6LGcGUasCB0d1WdbE9+TsV6+O8n9duL7d2pPaes X-Received: by 2002:aa7:ccca:0:b0:501:d43e:d1e6 with SMTP id y10-20020aa7ccca000000b00501d43ed1e6mr1431389edt.4.1680687842651; Wed, 05 Apr 2023 02:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680687842; cv=none; d=google.com; s=arc-20160816; b=HV2dpR2LYfcCCDob8ZrKFjJePwpYdE1rCDSEvvbZ8Vlc9Em5PVBTNiaAueT0TGbeFJ mp+84GZ/TyJ8cOp7VXZFFhsFKjF1wSk0/4ZJW699ns6ImTPV/wqcqNIgqkGMF7BTCs0j 7YMc7Oinnwt4b6pLqW+JGv6gch6X7xjcvry4nUGq6N8eoAyY4rP41ZXKNNUUpjxZ9UsG ye7mn9xv7f4ZuRel87qLFhCP6XPd8lrlozzJ6cGuD14DEv5gbRaVEG9XZXc+j58CnCte gP7WG5RY2IzYFAvbWna7WAMPyDsogONV1XANGltALVXenHCTNZOmNurzXvsc5ma9EmMy ua4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature; bh=4wIC1CpZVOaE4w0vpqchy3vQi+52X2p+A7NNpUhaHjs=; b=0JWWNbkRGs3Dp0GPwHGyL7WTHMWq2wOWJ9MhPNkgRleEqQk71bBEyhhLiR+k3R63A9 ychL86mmmRc5Mf2dCdPyWe4K1gChkoPUBBy98Btcy5Ox6GBwsL68Ejcb0EFYOcQIN/J5 psvXq60lnXzn40pi38V3J5EO57c4xkbaTEI4/gZTcdj+UNoKB5uDIfF7ImLzmNlqapur D8bXZmReuXqpKIhYZw+EcDBtW2g0JpYuTQ0FHAktmvDDiEUVEqB+t87RNdl/4gVc1wIf a7fYNOIfG/zVhLM/g+sNakWGECtwc2RI4O7MdeMt+FT3cJPinNV7CMc8KuyKgmbsw5OW gEng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f9pIAWwv; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n23-20020aa7c697000000b004ced100b0b7si2648781edq.316.2023.04.05.02.43.38; Wed, 05 Apr 2023 02:44:02 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=f9pIAWwv; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237302AbjDEJjg (ORCPT + 99 others); Wed, 5 Apr 2023 05:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237250AbjDEJje (ORCPT ); Wed, 5 Apr 2023 05:39:34 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3476B4C25; Wed, 5 Apr 2023 02:39:31 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id bl22so12215261oib.11; Wed, 05 Apr 2023 02:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680687570; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=4wIC1CpZVOaE4w0vpqchy3vQi+52X2p+A7NNpUhaHjs=; b=f9pIAWwvJ1/ZkSjsLBZOYKNN/SvlUJHhIWEYf5hHOmqMKyYatIzDxQ3wF8pmu91t9V KufMBg9Ia2jbxgfRuwcybi2grHwm718EOdRg+4uuSCv6RKoVflaU/Y1VW/N1BVFKV3IJ 5X3x7yBuNkEc99R9L/xY8zpvpx8AZ7b5d0yHJ6pob4J2MAck2mefPm/EfWR62r8Y2LeJ enNQ6K0TAW9V/BZIgAfqfdkKNTTxamM4rUi96e3ugY9/wcX3JNNqM7p3LogtCz8FeQQg J5/FrQJXXf21MNKcExwuTMz3E16S3BAzdnZlAMryofKJ6GAY6k1K7dMVUAy6D1uBc3we kZXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680687570; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4wIC1CpZVOaE4w0vpqchy3vQi+52X2p+A7NNpUhaHjs=; b=V8kZhMuZnc7/KxirIZ/HyQo23EFwusrc9xauD7SZJYYeyn9nzkUA9uHdP9hZ25yAkO wSXj9AMJFAZwMcrNgKOrWzo3QVjTn5q/F/yDmgOodQ3rQYJ5hGeZz0Ak/MgVHGO5NCtK Vjzk9D/xbS1jDYFllSeJ2WcCibIxnHyjlTHsNIhvSjRZq4zg1/KcHgng/VuHwPmpkuf7 M1WRGLhURV7Hi4fo9nZhEhZE8yq5FEGliP2z0XYgUznPXUJ/MGgnTDd1GuvFTObabfw0 jPOIW46uRjeUiHGPJEnf1XsTHmVq/ccErP1ClALc7gRaHxjzM5PJ+SdOBC4apZkmctKw nj0w== X-Gm-Message-State: AAQBX9fieMDT0jH+hJGTuMq56M6tHama3Btj/FJ4L+Kzm70yqQ4y89lt Lgfhgp0mcM9HkyZgNV4PFIs= X-Received: by 2002:aca:1206:0:b0:386:ed63:c511 with SMTP id 6-20020aca1206000000b00386ed63c511mr2416172ois.24.1680687570365; Wed, 05 Apr 2023 02:39:30 -0700 (PDT) Received: from [127.0.0.1] ([187.19.238.117]) by smtp.gmail.com with ESMTPSA id p188-20020acaf1c5000000b0038b2f07dd50sm3348114oih.7.2023.04.05.02.39.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Apr 2023 02:39:28 -0700 (PDT) Date: Wed, 05 Apr 2023 06:39:22 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa , Ian Rogers CC: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Adrian Hunter , James Clark , Suzuki Poulouse , Sean Christopherson , Ravi Bangoria , Rob Herring , Leo Yan , German Gomez , Jing Zhang , Gaosheng Cui , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] perf pmu: Make parser reentrant User-Agent: K-9 Mail for Android In-Reply-To: References: <20230404133630.1985739-1-irogers@google.com> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 On April 5, 2023 4:25:18 AM GMT-03:00, Jiri Olsa wr= ote: >On Tue, Apr 04, 2023 at 06:36:30AM -0700, Ian Rogers wrote: >> By default bison uses global state for compatibility with yacc=2E Make >> the parser reentrant so that it may be used in asynchronous and >> multithreaded situations=2E >>=20 >> Signed-off-by: Ian Rogers > >hum I can't apply this version on Arnaldo's perf/core: Try on tmp=2Eperf-tools-next > >patching file tools/perf/util/pmu=2Ec >Hunk #2 succeeded at 59 with fuzz 1=2E >Hunk #3 FAILED at 80=2E >Hunk #4 FAILED at 90=2E >2 out of 4 hunks FAILED -- saving rejects to file tools/perf/util/pmu=2Ec= =2Erej >patching file tools/perf/util/pmu=2Eh >patching file tools/perf/util/pmu=2El >patching file tools/perf/util/pmu=2Ey > >jirka > > >> --- >> tools/perf/util/pmu=2Ec | 24 ++++++++++++++++++------ >> tools/perf/util/pmu=2Eh | 2 +- >> tools/perf/util/pmu=2El | 17 ++++++++++++----- >> tools/perf/util/pmu=2Ey | 5 ++++- >> 4 files changed, 35 insertions(+), 13 deletions(-) >>=20 >> diff --git a/tools/perf/util/pmu=2Ec b/tools/perf/util/pmu=2Ec >> index 78a407b42ad1=2E=2Ef603cdabf797 100644 >> --- a/tools/perf/util/pmu=2Ec >> +++ b/tools/perf/util/pmu=2Ec >> @@ -24,6 +24,8 @@ >> #include "evsel=2Eh" >> #include "pmu=2Eh" >> #include "pmus=2Eh" >> +#include "pmu-bison=2Eh" >> +#include "pmu-flex=2Eh" >> #include "parse-events=2Eh" >> #include "print-events=2Eh" >> #include "header=2Eh" >> @@ -57,9 +59,6 @@ struct perf_pmu_format { >> struct list_head list; >> }; >> =20 >> -int perf_pmu_parse(struct list_head *list, char *name); >> -extern FILE *perf_pmu_in; >> - >> static bool hybrid_scanned; >> =20 >> static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name); >> @@ -81,6 +80,8 @@ int perf_pmu__format_parse(int dirfd, struct list_hea= d *head) >> while (!ret && (evt_ent =3D readdir(format_dir))) { >> char *name =3D evt_ent->d_name; >> int fd; >> + void *scanner; >> + FILE *file; >> =20 >> if (!strcmp(name, "=2E") || !strcmp(name, "=2E=2E")) >> continue; >> @@ -91,9 +92,20 @@ int perf_pmu__format_parse(int dirfd, struct list_he= ad *head) >> if (fd < 0) >> break; >> =20 >> - perf_pmu_in =3D fdopen(fd, "r"); >> - ret =3D perf_pmu_parse(head, name); >> - fclose(perf_pmu_in); >> + file =3D fdopen(fd, "r"); >> + if (!file) >> + break; >> + >> + ret =3D perf_pmu_lex_init(&scanner); >> + if (ret) { >> + fclose(file); >> + break; >> + } >> + >> + perf_pmu_set_in(file, scanner); >> + ret =3D perf_pmu_parse(head, name, scanner); >> + perf_pmu_lex_destroy(scanner); >> + fclose(file); >> } >> =20 >> closedir(format_dir); >> diff --git a/tools/perf/util/pmu=2Eh b/tools/perf/util/pmu=2Eh >> index 32c3a75bca0e=2E=2Ed53618c65c92 100644 >> --- a/tools/perf/util/pmu=2Eh >> +++ b/tools/perf/util/pmu=2Eh >> @@ -206,7 +206,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, str= uct list_head *head_terms, >> struct perf_pmu_info *info); >> struct list_head *perf_pmu__alias(struct perf_pmu *pmu, >> struct list_head *head_terms); >> -void perf_pmu_error(struct list_head *list, char *name, char const *ms= g); >> +void perf_pmu_error(struct list_head *list, char *name, void *scanner,= char const *msg); >> =20 >> int perf_pmu__new_format(struct list_head *list, char *name, >> int config, unsigned long *bits); >> diff --git a/tools/perf/util/pmu=2El b/tools/perf/util/pmu=2El >> index 58b4926cfaca=2E=2E67b247be693b 100644 >> --- a/tools/perf/util/pmu=2El >> +++ b/tools/perf/util/pmu=2El >> @@ -1,4 +1,6 @@ >> %option prefix=3D"perf_pmu_" >> +%option reentrant >> +%option bison-bridge >> =20 >> %{ >> #include >> @@ -6,16 +8,21 @@ >> #include "pmu=2Eh" >> #include "pmu-bison=2Eh" >> =20 >> -static int value(int base) >> +char *perf_pmu_get_text(yyscan_t yyscanner); >> +YYSTYPE *perf_pmu_get_lval(yyscan_t yyscanner); >> + >> +static int value(yyscan_t scanner, int base) >> { >> + YYSTYPE *yylval =3D perf_pmu_get_lval(scanner); >> + char *text =3D perf_pmu_get_text(scanner); >> long num; >> =20 >> errno =3D 0; >> - num =3D strtoul(perf_pmu_text, NULL, base); >> + num =3D strtoul(text, NULL, base); >> if (errno) >> return PP_ERROR; >> =20 >> - perf_pmu_lval=2Enum =3D num; >> + yylval->num =3D num; >> return PP_VALUE; >> } >> =20 >> @@ -25,7 +32,7 @@ num_dec [0-9]+ >> =20 >> %% >> =20 >> -{num_dec} { return value(10); } >> +{num_dec} { return value(yyscanner, 10); } >> config { return PP_CONFIG; } >> - { return '-'; } >> : { return ':'; } >> @@ -35,7 +42,7 @@ config { return PP_CONFIG; } >> =20 >> %% >> =20 >> -int perf_pmu_wrap(void) >> +int perf_pmu_wrap(void *scanner __maybe_unused) >> { >> return 1; >> } >> diff --git a/tools/perf/util/pmu=2Ey b/tools/perf/util/pmu=2Ey >> index e675d79a0274=2E=2Edff4e892ac4d 100644 >> --- a/tools/perf/util/pmu=2Ey >> +++ b/tools/perf/util/pmu=2Ey >> @@ -1,6 +1,8 @@ >> - >> +%define api=2Epure full >> %parse-param {struct list_head *format} >> %parse-param {char *name} >> +%parse-param {void *scanner} >> +%lex-param {void* scanner} >> =20 >> %{ >> =20 >> @@ -78,6 +80,7 @@ PP_VALUE >> =20 >> void perf_pmu_error(struct list_head *list __maybe_unused, >> char *name __maybe_unused, >> + void *scanner __maybe_unused, >> char const *msg __maybe_unused) >> { >> } >> --=20 >> 2=2E40=2E0=2E348=2Egf938b09366-goog >>=20