Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1125893lqt; Tue, 19 Mar 2024 13:32:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZ13qQDjILM4I9Wsk9KiPAKkG6wk1KDzRJPdAhEeoqWhgDBb9p41FKSkY3pHhUYfA+XNrn8AefcPIx8tJ6UxaegSD1WoYYZba0+SXwlA== X-Google-Smtp-Source: AGHT+IF+m77gVJdZKtDOHpwfaKhoPyYyro4JJJb/eKhy2x6HaiWP/roshwZVvS145HuYO2PPmAXd X-Received: by 2002:a05:620a:190c:b0:789:e6cc:5f7b with SMTP id bj12-20020a05620a190c00b00789e6cc5f7bmr4812980qkb.48.1710880363199; Tue, 19 Mar 2024 13:32:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710880363; cv=pass; d=google.com; s=arc-20160816; b=04XeM1MsR6S2l83yE0qson9bS0DbfMRp64fRaq7YtvvEKBZ0vtZ9ch8BesG9KeCaqZ wGc+Ry2JB7NmZMRRTuw/JgKO04z1G2G4wLWxVo6X29xjZm60FOIsWnKO0dGKH0D+8Ykt WCDXMrdnjtsv0Lrj9bx8SZIlJ6m/Hp0kbd2RiLqwmt2eyFY3lceTFVxhkFSjL678ymf/ sIt/pGkqes3sXCcndkvlzTkgnYVMLV+56M15C1ES4NPPgMC/DQ0YUKPvqn1NHqxK+yj9 qiEamzRSOD9xBzDm4WDaT0ZFD1F0AC10HjDjb27+VwZZdMdaYXitA5VGMFlFH2B+2MbI iJjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hZyK9tBduWWl7pJjU/cdImC0tnVSs73z9cYUtud++NA=; fh=WdQf7Zh6eoTlODJlRiMkCpZc471rSBMDGkHxCj0Bybg=; b=JyrbgR3kcmsohQ3AJ435mQDN3F4Hvgk964Y2lAA0+GDqKr+BIO+XWoJy5G+w2YbmTg Dy5WGeK+hnnGG+SXRM38LrkJcAf9fWG4yNSdql9dwh2uiPIqA5JLYqQmCCDiTtamfplo zxzyAhEtbE3dlQNsLtoOJ/AJUQ7XV/LprixOWqYZCQAcrVKNqEBCpofrnhEaq5xqAsMp bY7JzMiYnOwy8sXpd0/3cE8/zW08yNl2nMSuD1uPjXIix2Xk0nrfXki2aBZ2zNeoteq+ n2N0KQhU9Yjfll37zuCE7EI8jOV3z8dO218Z9ZJ257d8qVfcsr/CYiWQSl8D1At4gWVL Myrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZyrLRWdB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108109-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108109-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p22-20020a05620a113600b00789e28bd8b7si10463495qkk.728.2024.03.19.13.32.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 13:32:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108109-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZyrLRWdB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108109-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108109-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D80921C21CE3 for ; Tue, 19 Mar 2024 20:32:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C39FE3BBC7; Tue, 19 Mar 2024 20:32:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZyrLRWdB" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B689338F99 for ; Tue, 19 Mar 2024 20:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710880358; cv=none; b=NpjtRZsdxvlYZnJ4WcHnv8mEfVfCLJlxnZqkTBFRjDmncdh8u+NZhZ5P3jBFK3ZnoCiGswnzmrmSPr6w8II6YWNUyUGtfcVhw01eEQjwFuS9h7IfApRygEY1p0xzS9HvM9KqrpWvVlB5SPiKbbBr24i22nIABLh02R+R+Ti/Fjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710880358; c=relaxed/simple; bh=jl51Jx65J5tyULR4PNJC7HoZKpTsX3eJNnK4CEMrUMI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KXjSuq8p6Ee4tdULkH3K0WF4pfVqLYN0V2QZteHx/jxTHFS7oiddJSx3BJjGJCH5RbE7GiNSjC/azbEwr66g0XNAZlxqvm7HHb0Bw4JBmIQsEjT5fVqIviHIlWuv+KQ7A41PMDDds/uL4yNx13jizOa/NdUnyfletBSe3Ra3Ab0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZyrLRWdB; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8516C433F1; Tue, 19 Mar 2024 20:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710880358; bh=jl51Jx65J5tyULR4PNJC7HoZKpTsX3eJNnK4CEMrUMI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZyrLRWdBq8KJKWKTy35Xo8DkD+AMjorIATrYB9Zojek/hkkWpcwcKVHfgqSmfH5zf ynonC/k05wIqkB6jttH8GdRL/a6xsN5o8GZ+PlkfUQFy6lhbecECwAIsOTKa3mZ9Vt e6zOlUzTnLow7WBzKXbGW2VmevC73AzGrhGiVfQv5xdzrR7PwGVhdqjuKBV8lCowA2 HPN+jkMyQRfK7cB+1K32aMqG/Hsbh3Pm1lhvxCHx2tjTvvwMq61Hi6SfM3SKp5ImnC /y0H5yj7Stu8HOa4RV03aVkcA5+9q/meOM2pKSmaegFqLa6q9eyJnXTnozldHyM5xa uzFFdMYbD7HZQ== Date: Tue, 19 Mar 2024 17:32:34 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Adrian Hunter , Jiri Olsa , Namhyung Kim , Linux Kernel Mailing List Subject: Re: [PATCH 1/1] perf beauty: Introduce scraper script for 'clone' syscall 'flags' argument Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Mar 19, 2024 at 01:15:57PM -0700, Ian Rogers wrote: > On Tue, Mar 19, 2024 at 11:06 AM Arnaldo Carvalho de Melo > wrote: > > > > It was using the first variation on producing a string representation > > for a binary flag, one that used the copy of uapi/linux/sched.h with > > preprocessor tricks that had to be updated everytime a new flag was > > introduced. > > > > Use the more recent scraper script + strarray + strarray__scnprintf_flags() combo. > > > > $ tools/perf/trace/beauty/clone.sh | head -5 > > static const char *clone_flags[] = { > > [ilog2(0x00000100) + 1] = "VM", > > [ilog2(0x00000200) + 1] = "FS", > > [ilog2(0x00000400) + 1] = "FILES", > > [ilog2(0x00000800) + 1] = "SIGHAND", > > $ > > > > Now we can move uapi/linux/sched.h from tools/include/, that is used for > > building perf to the scrap only directory tools/perf/trace/beauty/include. > > nit: scrape? I learn this at some point, keep trying :-) > Reviewed-by: Ian Rogers Thanks! - Arnaldo > Thanks, > Ian > > > Cc: Adrian Hunter > > Cc: Ian Rogers > > Cc: Jiri Olsa > > Cc: Namhyung Kim > > Signed-off-by: Arnaldo Carvalho de Melo > > --- > > tools/perf/Makefile.perf | 14 ++++-- > > tools/perf/check-headers.sh | 2 +- > > tools/perf/trace/beauty/clone.c | 46 ++----------------- > > tools/perf/trace/beauty/clone.sh | 17 +++++++ > > .../trace/beauty}/include/uapi/linux/sched.h | 0 > > 5 files changed, 34 insertions(+), 45 deletions(-) > > create mode 100755 tools/perf/trace/beauty/clone.sh > > rename tools/{ => perf/trace/beauty}/include/uapi/linux/sched.h (100%) > > > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > > index f5654d06e31385b7..ccd2dcbc64f720d2 100644 > > --- a/tools/perf/Makefile.perf > > +++ b/tools/perf/Makefile.perf > > @@ -485,13 +485,20 @@ x86_arch_asm_dir := $(srctree)/tools/arch/x86/include/asm/ > > > > beauty_outdir := $(OUTPUT)trace/beauty/generated > > beauty_ioctl_outdir := $(beauty_outdir)/ioctl > > -drm_ioctl_array := $(beauty_ioctl_outdir)/drm_ioctl_array.c > > -drm_hdr_dir := $(srctree)/tools/include/uapi/drm > > -drm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/drm_ioctl.sh > > > > # Create output directory if not already present > > $(shell [ -d '$(beauty_ioctl_outdir)' ] || mkdir -p '$(beauty_ioctl_outdir)') > > > > +clone_flags_array := $(beauty_outdir)/clone_flags_array.c > > +clone_flags_tbl := $(srctree)/tools/perf/trace/beauty/clone.sh > > + > > +$(clone_flags_array): $(beauty_uapi_linux_dir)/sched.h $(clone_flags_tbl) > > + $(Q)$(SHELL) '$(clone_flags_tbl)' $(beauty_uapi_linux_dir) > $@ > > + > > +drm_ioctl_array := $(beauty_ioctl_outdir)/drm_ioctl_array.c > > +drm_hdr_dir := $(srctree)/tools/include/uapi/drm > > +drm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/drm_ioctl.sh > > + > > $(drm_ioctl_array): $(drm_hdr_dir)/drm.h $(drm_hdr_dir)/i915_drm.h $(drm_ioctl_tbl) > > $(Q)$(SHELL) '$(drm_ioctl_tbl)' $(drm_hdr_dir) > $@ > > > > @@ -765,6 +772,7 @@ build-dir = $(or $(__build-dir),.) > > > > prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders \ > > arm64-sysreg-defs \ > > + $(clone_flags_array) \ > > $(drm_ioctl_array) \ > > $(fadvise_advice_array) \ > > $(fsconfig_arrays) \ > > diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh > > index 859cd6f35b0ac9b1..413c9b747216020f 100755 > > --- a/tools/perf/check-headers.sh > > +++ b/tools/perf/check-headers.sh > > @@ -15,7 +15,6 @@ FILES=( > > "include/uapi/linux/kvm.h" > > "include/uapi/linux/in.h" > > "include/uapi/linux/perf_event.h" > > - "include/uapi/linux/sched.h" > > "include/uapi/linux/seccomp.h" > > "include/uapi/linux/vhost.h" > > "include/linux/bits.h" > > @@ -93,6 +92,7 @@ BEAUTY_FILES=( > > "include/uapi/linux/fs.h" > > "include/uapi/linux/mount.h" > > "include/uapi/linux/prctl.h" > > + "include/uapi/linux/sched.h" > > "include/uapi/linux/usbdevice_fs.h" > > "include/uapi/sound/asound.h" > > ) > > diff --git a/tools/perf/trace/beauty/clone.c b/tools/perf/trace/beauty/clone.c > > index f4db894e0af6d14b..c9fa8f7e82b909fb 100644 > > --- a/tools/perf/trace/beauty/clone.c > > +++ b/tools/perf/trace/beauty/clone.c > > @@ -7,52 +7,16 @@ > > > > #include "trace/beauty/beauty.h" > > #include > > +#include > > #include > > -#include > > +#include > > > > static size_t clone__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix) > > { > > - const char *prefix = "CLONE_"; > > - int printed = 0; > > +#include "trace/beauty/generated/clone_flags_array.c" > > + static DEFINE_STRARRAY(clone_flags, "CLONE_"); > > > > -#define P_FLAG(n) \ > > - if (flags & CLONE_##n) { \ > > - printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ > > - flags &= ~CLONE_##n; \ > > - } > > - > > - P_FLAG(VM); > > - P_FLAG(FS); > > - P_FLAG(FILES); > > - P_FLAG(SIGHAND); > > - P_FLAG(PIDFD); > > - P_FLAG(PTRACE); > > - P_FLAG(VFORK); > > - P_FLAG(PARENT); > > - P_FLAG(THREAD); > > - P_FLAG(NEWNS); > > - P_FLAG(SYSVSEM); > > - P_FLAG(SETTLS); > > - P_FLAG(PARENT_SETTID); > > - P_FLAG(CHILD_CLEARTID); > > - P_FLAG(DETACHED); > > - P_FLAG(UNTRACED); > > - P_FLAG(CHILD_SETTID); > > - P_FLAG(NEWCGROUP); > > - P_FLAG(NEWUTS); > > - P_FLAG(NEWIPC); > > - P_FLAG(NEWUSER); > > - P_FLAG(NEWPID); > > - P_FLAG(NEWNET); > > - P_FLAG(IO); > > - P_FLAG(CLEAR_SIGHAND); > > - P_FLAG(INTO_CGROUP); > > -#undef P_FLAG > > - > > - if (flags) > > - printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); > > - > > - return printed; > > + return strarray__scnprintf_flags(&strarray__clone_flags, bf, size, show_prefix, flags); > > } > > > > size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg) > > diff --git a/tools/perf/trace/beauty/clone.sh b/tools/perf/trace/beauty/clone.sh > > new file mode 100755 > > index 0000000000000000..18b6c0d75693721d > > --- /dev/null > > +++ b/tools/perf/trace/beauty/clone.sh > > @@ -0,0 +1,17 @@ > > +#!/bin/sh > > +# SPDX-License-Identifier: LGPL-2.1 > > + > > +if [ $# -ne 1 ] ; then > > + beauty_uapi_linux_dir=tools/perf/trace/beauty/include/uapi/linux/ > > +else > > + beauty_uapi_linux_dir=$1 > > +fi > > + > > +linux_sched=${beauty_uapi_linux_dir}/sched.h > > + > > +printf "static const char *clone_flags[] = {\n" > > +regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' > > +grep -E $regex ${linux_sched} | \ > > + sed -r "s/$regex/\2 \1/g" | \ > > + xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n" > > +printf "};\n" > > diff --git a/tools/include/uapi/linux/sched.h b/tools/perf/trace/beauty/include/uapi/linux/sched.h > > similarity index 100% > > rename from tools/include/uapi/linux/sched.h > > rename to tools/perf/trace/beauty/include/uapi/linux/sched.h > > -- > > 2.44.0 > >