Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2273388rwb; Thu, 27 Jul 2023 05:03:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlG0QmLzj49fUAxudDrxCu4MlJNOWuMXQaIXnDDQBepw2mwyT1c8f/xvoTUGLEQgW2OYuPlp X-Received: by 2002:a05:6a21:66cb:b0:13b:1482:261 with SMTP id ze11-20020a056a2166cb00b0013b14820261mr3871707pzb.44.1690459437836; Thu, 27 Jul 2023 05:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690459437; cv=none; d=google.com; s=arc-20160816; b=sKP6mp6avKmJfeskPcB+FBFksX/hJvPQ76cG89jXw3dIRC+soO314kdJAk+Amgk3kr 7dWcvNWsAq3UijMGc46qWBKS1dI2Xy6fJM4/ryhrpS4UumwbVX27t4M6sFWi/XWkNwn2 2mxIfn6DI/GGa1tmPtqsZFjQLsQPzBBljDSeajjD22zBX7N1hBsbEsfduUwlXWU0TBaR DoQTb0pazd4aiWAwiet0GP0RsuyT0HPrYvN56/HDOI2ZqIBhCC2s5QAEEHskFk8E+83h VenCNph6UdxDxGsFfEt/Tw6ApnwXYQjZi6/I8SohHiPvMaswyl0IM7KViJUO9jAHXnPG nF6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mIRmk7ikOGe1YAfoS9KPRNeDo5SA2MaqWgT4f/KmEoo=; fh=eA2UoYZhZ6A03BHDORtJEWCEBpxBlRn/T+xz8n2KiyY=; b=wZodMzHd0ZbSPezTZDZ3Q2ku/XsqeJRPHPCRz1v7FzJ0AoEnIFd7JkG4U6A+SgGCTM oO43F4rVIfSMAVs3mPRTigPXF7beRWOAID+4ZK7RpQwp/OhmkQl7FHZDCZNjKBNhrKIo TW2sxiHp0UCEIpBskb7Giq68dhodIEVutd9NBE1hWbTYVE8RFRxq7qyAU4QC9vI5Fh1Y pOYU1Iyngb4BA2cA4ZX3kyqIP2gAVwiYfQBIt/W1qlL9uj1NWMvdZJ06lcLf3B2tp75Z k4DdcMr/2935wW2Hlm93EUkeqIrzAdhq0mEP/OpPMcu0HJX/a8m3LBZ7ROvHCa+baEeg obhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FmmKSFBA; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l3-20020a6542c3000000b005579d6bdf7esi1146890pgp.856.2023.07.27.05.03.28; Thu, 27 Jul 2023 05:03:57 -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=@kernel.org header.s=k20201202 header.b=FmmKSFBA; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232483AbjG0Lca (ORCPT + 99 others); Thu, 27 Jul 2023 07:32:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232640AbjG0LcY (ORCPT ); Thu, 27 Jul 2023 07:32:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 361A43592; Thu, 27 Jul 2023 04:31:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7B6AF61E2F; Thu, 27 Jul 2023 11:31:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85A64C433C8; Thu, 27 Jul 2023 11:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690457515; bh=jAv2xm8xm8vlOThiQFo8mIHkMj+NUOu1NvVJLlhozh8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FmmKSFBAdaqVmu0Mbij36D0w+KKlSOmbEAhoUYZK6DY+gW49UVkGLQoLXkCIQuOUt H9gvK7gPiSdkpdmiUtGD0nHzRft7EEW2HN86CVgC/GgWQdRrsXRKg6O6JqOorwtNWP WYyuAsHqOQgcOg7D6Ublo516uZBG51+CeeFp55+xDEhbVPupJoGDgPyioR+2RDbtyp lLmEAkULimXHETO1xHkMAtfLirsg0kj6LkBji2frRyebd/gid+auq1oVCjSsP+9uFK 0YGH42rmCHjw1kSCsCHS8SvO3XJOqE3/8UfV5qHsA02zUbNStxgaCPs2umZkVKBJbS fouw9+RItvL1A== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id C5F8A40516; Thu, 27 Jul 2023 08:31:52 -0300 (-03) Date: Thu, 27 Jul 2023 08:31:52 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Anup Sharma , stable@vger.kernel.org Subject: Re: [PATCH 1/2] perf build: Update build rule for generated files Message-ID: References: <20230726133642.750342-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Em Wed, Jul 26, 2023 at 11:45:44PM -0700, Namhyung Kim escreveu: > On Wed, Jul 26, 2023 at 9:48 PM Ian Rogers wrote: > > On Wed, Jul 26, 2023 at 6:01 PM Namhyung Kim wrote: > > > On Wed, Jul 26, 2023 at 5:36 PM Ian Rogers wrote: > > > > On Wed, Jul 26, 2023 at 3:57 PM Namhyung Kim wrote: > > > > > On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers wrote: > > > > > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim wrote: > > > > > > > The bison and flex generate C files from the source (.y and .l) > > > > > > > files. When O= option is used, they are saved in a separate directory > > > > > > > but the default build rule assumes the .C files are in the source > > > > > > > directory. So it might read invalid file if there are generated files > > > > > > > from an old version. The same is true for the pmu-events files. > > > > > > > > > > > > > > For example, the following command would cause a build failure: > > > > > > > > > > > > > > $ git checkout v6.3 > > > > > > > $ make -C tools/perf # build in the same directory > > > > > > > > > > > > > > $ git checkout v6.5-rc2 > > > > > > > $ mkdir build # create a build directory > > > > > > > $ make -C tools/perf O=build # build in a different directory but it > > > > > > > # refers files in the source directory > > > > > > > > > > > > > > Let's update the build rule to specify those cases explicitly to depend > > > > > > > on the files in the output directory. > > > > > > > > > > > > > > Note that it's not a complete fix and it needs the next patch for the > > > > > > > include path too. > > > > > > > > > > > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > > > > > > Cc: stable@vger.kernel.org > > > > > > > Signed-off-by: Namhyung Kim > > > > > > > --- > > > > > > > tools/build/Makefile.build | 8 ++++++++ > > > > > > > tools/perf/pmu-events/Build | 4 ++++ > > > > > > > 2 files changed, 12 insertions(+) > > > > > > > > > > > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > > > > > > index 89430338a3d9..f9396696fcbf 100644 > > > > > > > --- a/tools/build/Makefile.build > > > > > > > +++ b/tools/build/Makefile.build > > > > > > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > > > > > > $(call rule_mkdir) > > > > > > > $(call if_changed_dep,cc_s_c) > > > > > > > > > > > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > > > > > > + $(call rule_mkdir) > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > + > > > > > > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > > > > > > + $(call rule_mkdir) > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > + > > > > > > > > > > > > Hi Namhyung, > > > > > > > > > > > > as we have: > > > > > > ``` > > > > > > $(OUTPUT)%.o: %.c FORCE > > > > > > $(call rule_mkdir) > > > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > > > ``` > > > > > > I'm not sure what the 2 additional rules achieve. > > > > > > > > > > The above rule assumes the .c files are in the source directory > > > > > (without $(OUTPUT) prefix). It caused a trouble when the > > > > > flex and bison files are generated in the output directory and > > > > > you have an old version of them in the source directory. > > > > > > > > > > > > # Gather build data: > > > > > > > # obj-y - list of build objects > > > > > > > # subdir-y - list of directories to nest > > > > > > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > > > > > > index 150765f2baee..f38a27765604 100644 > > > > > > > --- a/tools/perf/pmu-events/Build > > > > > > > +++ b/tools/perf/pmu-events/Build > > > > > > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > > > > > > $(call rule_mkdir) > > > > > > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > > > > > > endif > > > > > > > + > > > > > > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > > > > > > + $(call rule_mkdir) > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > > > > > > If we add this, do the Makefile.build changes still need to happen? > > > > > > > > > > The Makefile.build changes are specific to flex and bison files. > > > > > So yes, we need this for pmu-events.c to work properly with O= > > > > > option. > > > > > > > > Got it, you are right I was confusing the flex/bison with the jevents > > > > case. Can we get away with a single rule then: > > > > ``` > > > > $(OUTPUT)%.o: $(OUTPUT)%.c FORCE > > > > $(call rule_mkdir) > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > ``` > > > > > > Probably, but I wonder if it affects the normal .c files expecting > > > them in the OUTPUT directory. > > > > Hmm.. I think the longer matches may be necessary to trigger the "more > > specific" ordering: > > https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html > > > > I'm not keen on these extra rules that mirror existing rules, it is a > > bit cryptic what is going on. I wonder if it would be cleaner just to > > fail the build if the bogus pmu-events.c exists. For example: > > I prefer just making it build instead of failing. But not strongly > against your idea. It'd be nice to hear what others think.. Arnaldo? I think that we should just ignore any build files in the source tree when using 'O=', i.e.: make -C tools/perf genereated files (in the source tree) should not be used when, right after running it, we run: make -C tools/perf O=/some/build/dir If we run 'make -C tools/perf' and there is a pmu-events.c, use it if its timestamp is more recent than the files from which it was generated, as usual for a make managed build. - Arnaldo > > ``` > > --- a/tools/perf/pmu-events/Build > > +++ b/tools/perf/pmu-events/Build > > @@ -12,6 +12,14 @@ EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c > > PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c > > METRIC_TEST_LOG = $(OUTPUT)pmu-events/metric_test.log > > > > +ifneq ($(OUTPUT),) > > +ifneq ($(wildcard pmu-events/pmu-events.c),) > > +dummy := $(error OUTPUT set but tools/perf/pmu-events/pmu-events.c exists. \ > > + This can mean the generated version of pmu-events.c is not > > compiled. \ > > + Try 'cd tools/perf; make clean; cd -' and then rebuilding.) > > I've tested this and this message is buried in the stream of > parallel build outputs. :( > > Thanks, > Namhyung > > > > +endif > > +endif > > + > > ifeq ($(JEVENTS_ARCH),) > > JEVENTS_ARCH=$(SRCARCH) > > endif > > ``` -- - Arnaldo