From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AFD229B8D0 for ; Sat, 2 May 2026 07:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777707426; cv=none; b=GbHLorbr7N1Cihtrumpwqrzh8ebOZ3qiaVi7A4foOlkCm17T7AUWQ9LIlLwqyfW7NPuSPoiyf8coJyJ7WnL9eGmU6Q2eUOIdg3EZUWdWawscvd5FPnYauz+ENts8w+jq/lTcrdWCMT35kr6m7udyJadP+6HqczDGCk7Q14VNoxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777707426; c=relaxed/simple; bh=OgSupQYuv8M08Z6lDFgcm93HWo22RmGCCbGaM/Spy+A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MumCQbR93ayoBnD0JEhE7WkwDxPQnHAa93AI8MT55toiCYs9E3C6Jl1HHqLBNmRbaeNSVElc4Xw5+WcyThmRosk/AYbakqMqmDHRbWVnsQ745ZxYzvTpUVdClMl1Uj4dlOs30A+9We8YxY6nCZM4OtNPCBDywq7PblnEOtiD27s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FOczte+p; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FOczte+p" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-82748257f5fso2656829b3a.1 for ; Sat, 02 May 2026 00:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777707424; x=1778312224; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BHCOVHKhdHZ6jfgYD/72LtN/jBh0rvDnY8iDxuRsrAA=; b=FOczte+p+X76EKhDjgCbwc3Qsjo3COAILnKWg17ZUiHAy9tOb1b7iCZvH43gL1WEgb u9LZJzGbepyjyDTC7PwFDVG3CQr57RfqsEhz7YP6RtaSXg//cmmfy7n30ITTGPb65F56 2Kx3cmMluohkbUBTz7vtXgpsv/Sls/480d4BGZNlGDXdZ1h0e+TVknGp7+G7aQwlOtMT hEuqL3mFp8Jskg2dxxnxIjeY9idsTA2wOgDNoqADoXh2EKK9sIf4V8FaqkS9gyDLUHrS hxmiT8sUByYHNQc71p5mFcHjNZgDipTXTHld91FEw543zzSExMBpJRKZNVFAEWkcWr6S wusQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777707424; x=1778312224; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BHCOVHKhdHZ6jfgYD/72LtN/jBh0rvDnY8iDxuRsrAA=; b=josIGOc9/jKz/BaLvry+JHvTsMzBiJD+mhFszi0Upq+s/ksqKBxuIyVXyesVUo3w3y n5XzdjSXXIcVxT6DGlzKNTRKBQ9eU3Sk5NZOWGRG30euJMjZtLQwxHH3PGqxJnDgNgNO C4+m+Nbr10Tm/PiV5pidx1XYUMfgLLU/F8GBHHfJiBjsYXN38V16BiOhRCXHXMkJffxF STu4t52M999w966t4f8waykSOJ+8HjmxF63bZxJoSNgyHGwsQZ/x0VUo6wMw8SW9e88z Qx7wNINKgbNPepFCK1jhJXF4aFIQHR0y7RATl5YGeDoPS/yc7KEJOXxbdilSsTDkTOoa DQ7w== X-Forwarded-Encrypted: i=1; AFNElJ93r2TDc9JbQXz14wFySQva2beOkdWNdtwLqXV+9EtdozOve83G9VPGJIvekoDYoNp2xG0QTtUAsTb1eFI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzt1uJ3dRLrGSljUoH01MRqQxUcSX1zdpcMZzDN6Q57rLBW2uOo ogwlul+0ajFmCkXJPofxJh7A4VxktBnqrAO+YjJpcIw+RwIeahDixpu+VRlUT9as X-Gm-Gg: AeBDietBFPZtrDVQnHA+fkwov2IZQkyjByVNPAjqZnv6ERlzPrvKLOwXujbsy+XtJhJ 3Cin4bzEGuRiLWDpmXfJvEaueHhytoUcIHnkQqrQdqXmR60VK9VsdCc2/HViv58xpGptRb8YcCF 6Nx6ViJa9REUA82LlQ5p0EYG0zoDQxFj1vyjw97Gxtn78nBAkCcZ63u2p1n00Pc+854LoTxWVB7 JJI/ZTlKygvpje9cq3/lrWadQf9+ZLflV43ZAhVz0Fs+Swx6t2NQjMuwqCT0HakIYUSAINiLstq cmf5jGANWfJMH1W+0SKf1s8cktV6jpsJ2zClyVExc2ifhl6N/tNMxHMTPjDbGUmS74Px27v/x/Q iR2Z0mNsKWShEuIjv8Lff5/GMjsqW1y3on/LplNm8xuJ3i+IyfqeU7NBu6M9vP27+YVtFCUB9oL CtjeFwguCodwfkHIqSJmmuF95F/lVHYg== X-Received: by 2002:a05:6a21:1405:b0:3a2:cf6d:aa04 with SMTP id adf61e73a8af0-3a3d1b443efmr9564744637.8.1777707424386; Sat, 02 May 2026 00:37:04 -0700 (PDT) Received: from nova ([134.208.63.146]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7ffbc6f66dsm4055562a12.15.2026.05.02.00.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 May 2026 00:37:03 -0700 (PDT) Date: Sat, 2 May 2026 15:37:00 +0800 From: Qian-Yu Lin To: David Laight Cc: rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH] trace_printk: replace _______STR with __UNIQUE_ID(STR) Message-ID: References: <20260429165707.7020-1-tiffany019230@gmail.com> <20260429134226.49e95e9d@robin> <20260501221315.1f709d6d@pumpkin> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260501221315.1f709d6d@pumpkin> On Fri, May 01, 2026 at 10:13:15PM +0100, David Laight wrote: > On Fri, 1 May 2026 22:40:17 +0800 > Qian-Yu Lin wrote: > > ... > > Yes. I measured compile time of kernel/trace/ring_buffer_benchmark.o > > after make clean on an x86_64 machine running Ubuntu 24.04 LTS: > > > > - Original _______STR: 49.8s > > - v1 with __UNIQUE_ID (compiler.h): 53.5s > > - compound literal (no extra include): 33.2s > > That difference looks far to big to me. > And the times are far too large to be measuring the actual compile time. > You're right, my earlier measurements included dependency rebuilds after make clean. I re-measured using touch to isolate the actual compile time of ring_buffer_benchmark.o on x86_64: - Original ___STR: 1.757s - v1 with __UNIQUE_ID (compiler.h): 1.836s - sizeof __stringify (your suggestion): 1.781s > > > > I propose using a compound literal in v2, which eliminates the local > > variable entirely and requires no extra include: > > > > #define trace_printk(fmt, ...) \ > > do { \ > > if (sizeof((char[]) \ > > {__stringify((__VA_ARGS__))}) > 3) \ > > do_trace_printk(fmt, ##__VA_ARGS__); \ > > There has to be a better way to align that code. > Although you should be able to use: > if (sizeof __stringify((__VA_ARGS__)) > 3) > (I've omitted one set of parenthesis for clarity) > > You could change __stringify() to work with __VA_ARGS__ the you don't need > the extra (); this works fine: > #define _x(...) #__VA_ARGS__ > #define x(...) _x(__VA_ARGS__) > #define z abcd > int a = sizeof x(z, v); /* 8 */ > See: https://godbolt.org/z/zo4h4nr9b > > -- David > Yes, this works. I verified with objdump on the samples/trace_printk module that all four cases branch correctly: __trace_bputs, __trace_puts, __trace_bprintk, and __trace_printk. I'll use this form in v3 since it's simpler than the compound literal. > > else \ > > trace_puts(fmt); \ > > } while (0) > > > > This fully eliminates the shadowing risk without any compile overhead. > > > > Qian-Yu > > > > > > > > > > > > #include > > > > #include > > > > #include > > > > @@ -84,15 +85,18 @@ do { \ > > > > * let gcc optimize the rest. > > > > */ > > > > > > > > -#define trace_printk(fmt, ...) \ > > > > +#define ___trace_printk(fmt, str, ...) \ > > > > do { \ > > > > - char _______STR[] = __stringify((__VA_ARGS__)); \ > > > > - if (sizeof(_______STR) > 3) \ > > > > + char str[] = __stringify((__VA_ARGS__)); \ > > > > + if (sizeof(str) > 3) \ > > > > do_trace_printk(fmt, ##__VA_ARGS__); \ > > > > else \ > > > > trace_puts(fmt); \ > > > > } while (0) > > > > > > > > +#define trace_printk(fmt, ...) \ > > > > + ___trace_printk(fmt, __UNIQUE_ID(str), ##__VA_ARGS__) > > > > + > > > > #define do_trace_printk(fmt, args...) \ > > > > do { \ > > > > static const char *trace_printk_fmt __used \ > > > >