Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2060280rdh; Sat, 25 Nov 2023 11:56:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzsau5NX9wSSga8RjpV2wE6j20PtjdHwOKiA8tfQES0ieJ/8/2g0yKKpzbZSCl2+Cn8m9K X-Received: by 2002:a17:902:f691:b0:1cf:a90d:ed31 with SMTP id l17-20020a170902f69100b001cfa90ded31mr7156049plg.22.1700942198390; Sat, 25 Nov 2023 11:56:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700942198; cv=none; d=google.com; s=arc-20160816; b=LuFn3lm2TkCMeAMljWjPe5P0YyGIQAPd6GTTB8JkQJIxWOw8ta74F6VHy9VV2Mgcgp XhHzKKnXqmf+RTYSeneblXMyQFYMfrMOm/H3++sf51u3vH3rpOTSfDVknbqr8CNTw3x2 SpnFrUBRZmbeAz+s3UcFWBEwCQu0OYAE8P8Hcf8bOnFZ9Jqi/pHwvpVmCYTQKazMtMzq BGakyKVYvGomSbab9H/KoeekeH+DNL780bceBL5Kx8RC032brOkPRoncWlRQy2gyx0N0 jNXRUZr05zNmW/hcURNqtdXJBZuU3aySFXLxTxPiW0XZn6btuFzTpYgmhrv2i+S7hz9C NG1A== 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:dkim-signature:date; bh=yo+m6dTGrzcH0zVhx/EUgCNWh3lQ29xIfd4T/sQd3P0=; fh=B8/OJvWHlKgoWNeWTRtHgiWCwGyU0HInq60kIFJl/h8=; b=zOYaHgg2JkSd02OdFjw1eYWBXx4kIjnrKngL/OxyNQsFeVxbTaCZYNFQx7/fx5WXw0 WeCTwbgICONwvSsybsowMAblOysh/GNiqJ/CiYEZu4EF9igVy6DNHvyWN3QRiBpcr8mD gggrLuyEl8A6DyHIqQmIEaT8zGUtB+FzsTror/zWkv7zxDNkoboJfMWOSm40NR6CqEWA qgKJeYx6b+0aMkX3e7RMmBgtZ8QrBXSKfKBMCrURkylh5wu1D1Uayqr0XSTOpLAjoGVZ taoVlieHH+yrjtoBASgkfVGRwiLOI/ZnbnPp+Jb9hXSd+xPoG9Gh4WmS3ca9pbYInOv3 2CWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Nzd82Lse; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id z12-20020a170902cccc00b001c74d1da69csi6845564ple.362.2023.11.25.11.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 11:56:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Nzd82Lse; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0207C803DB37; Sat, 25 Nov 2023 11:56:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229507AbjKYT4U (ORCPT + 99 others); Sat, 25 Nov 2023 14:56:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjKYT4T (ORCPT ); Sat, 25 Nov 2023 14:56:19 -0500 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [IPv6:2001:41d0:1004:224b::aa]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 242DAD3 for ; Sat, 25 Nov 2023 11:56:25 -0800 (PST) Date: Sat, 25 Nov 2023 14:56:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700942183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yo+m6dTGrzcH0zVhx/EUgCNWh3lQ29xIfd4T/sQd3P0=; b=Nzd82LseHWt2CYxnwyxSxGn1BUyNx/pIL4cFvsZAMp8gLj333tj6FiUJqXdPn2GNnzYP0v Tcl4sV1BGZLWU0bYPHKpAoTvVOx+FYH5nVQQoDfC0QbjSdxoQOhj3bH2EIWalBxjT/Za0G smobkRXnG6VMGemRkjzlIXLHXGiNkRE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Masahiro Yamada Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-kbuild@vger.kernel.org Subject: Re: [PATCH] kbuild: Allow gcov to be enabled on the command line Message-ID: <20231125195620.rjgkooixugucv2vp@moria.home.lan> References: <20231122235527.180507-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sat, 25 Nov 2023 11:56:36 -0800 (PST) On Fri, Nov 24, 2023 at 11:02:00AM +0900, Masahiro Yamada wrote: > On Thu, Nov 23, 2023 at 8:55 AM Kent Overstreet > wrote: > > > > This allows gcov to be enabled for a particular kernel source > > subdirectory on the command line, without editing makefiles, like so: > > > > make GCOV_PROFILE_fs_bcachefs=y > > > > Cc: Masahiro Yamada > > Cc: Nathan Chancellor > > Cc: Nick Desaulniers > > Cc: Nicolas Schier > > Cc: linux-kbuild@vger.kernel.org > > Signed-off-by: Kent Overstreet > > --- > > scripts/Kbuild.include | 10 ++++++++++ > > scripts/Makefile.lib | 2 +- > > 2 files changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include > > index 7778cc97a4e0..5341736f2e30 100644 > > --- a/scripts/Kbuild.include > > +++ b/scripts/Kbuild.include > > @@ -277,3 +277,13 @@ ifneq ($(and $(filter notintermediate, $(.FEATURES)),$(filter-out 4.4,$(MAKE_VER > > else > > .SECONDARY: > > endif > > + > > + # expand_parents(a/b/c) = a/b/c a/b a > > +expand_parents2 = $(if $(subst .,,$(1)),$(call expand_parents,$(1)),) > > +expand_parents = $(1) $(call expand_parents2,$(patsubst %/,%,$(dir $(1)))) > > + > > +# flatten_dirs(a/b/c) = a_b_c a_b a > > +flatten_dirs = $(subst /,_,$(call expand_parents,$(1))) > > + > > +# eval_vars(X_,a/b/c) = $(X_a_b_c) $(X_a_b) $(X_a) > > +eval_vars = $(foreach var,$(call flatten_dirs,$(2)),$($(1)$(var))) > > > > I do not like tricky code like this. > > Also, with "fs_bcachefs", it is unclear which directory > is enabled. It's consistent with how we can specify options in makefiles for a particular file. I suppose CONFIG_GCOV_PROFILE_DIRS would be fine, but your patch isn't complete so I can't test it. > > > > > How about this? > > > > [1] Specify the list of directories by GCOV_PROFILE_DIRS > > > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib > index 1a965fe68e01..286a569556b3 100644 > --- a/scripts/Makefile.lib > +++ b/scripts/Makefile.lib > @@ -147,8 +147,12 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) > $(CPPFLAGS_$(target-stem).lds) > # (in this order) > # > ifeq ($(CONFIG_GCOV_KERNEL),y) > +ifneq ($(filter $(obj),$(GCOV_PROFILE_DIRS)),) > +export GCOV_PROFILE_SUBDIR := y > +endif > + > _c_flags += $(if $(patsubst n%,, \ > - > $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), > \ > + > $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(GCOV_PROFILE_SUBDIR)$(CONFIG_GCOV_PROFILE_ALL)), > \ > $(CFLAGS_GCOV)) > endif > > > > Usage: > > $ make GCOV_PROFILE_DIRS=fs/bcachefs > > -> enable GCOV in fs/bachefs and its subdirectories. > > or > > $ make GCOV_PROFILE_DIRS="drivers/gpio drivers/pinctrl" > > -> enable GCOV in drivers/gpio, drivers/pinctrl, and their subdirectories. > > > > > [2] Do equivalent, but from a CONFIG option > > > config GCOV_PROFILE_DIRS > string "Directories to enable GCOV" > > > Then, you can set CONFIG_GCOV_PROFILE_DIRS="fs/bcachefs" > > > This might be a more natural approach because we already have > CONFIG_GCOV_PROFILE_ALL, although it might eventually go away > because CONFIG_GCOV_PROFILE_ALL=y is almost equivalent to > CONFIG_GCOV_PROFILE_DIRS="." > > > > > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib > index 1a965fe68e01..286a569556b3 100644 > --- a/scripts/Makefile.lib > +++ b/scripts/Makefile.lib > @@ -147,8 +147,12 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) > $(CPPFLAGS_$(target-stem).lds) > # (in this order) > # > ifeq ($(CONFIG_GCOV_KERNEL),y) > +ifneq ($(filter $(obj),$(CONFIG_GCOV_PROFILE_DIRS)),) > +export GCOV_PROFILE_SUBDIR := y > +endif > + > _c_flags += $(if $(patsubst n%,, \ > - > $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), > \ > + > $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(GCOV_PROFILE_SUBDIR)$(CONFIG_GCOV_PROFILE_ALL)), > \ > $(CFLAGS_GCOV)) > endif > > > > > > > > > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib > > index 1a965fe68e01..0b4581a8bc33 100644 > > --- a/scripts/Makefile.lib > > +++ b/scripts/Makefile.lib > > @@ -148,7 +148,7 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) > > # > > ifeq ($(CONFIG_GCOV_KERNEL),y) > > _c_flags += $(if $(patsubst n%,, \ > > - $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ > > + $(GCOV_PROFILE_$(basetarget).o)$(call eval_vars,GCOV_PROFILE_,$(src))$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ > > $(CFLAGS_GCOV)) > > endif > > > > -- > > 2.42.0 > > > > > -- > Best Regards > Masahiro Yamada