From patchwork Fri Feb 23 14:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 205419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp614039dyb; Fri, 23 Feb 2024 06:19:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVoMsT0HrIe2J2Snb6C+7zUyXQ8Wx6qjK31+ImUn8IDuAM+ta5Qir5U2MpXufTSOj/RHlgVdToM70z2J8nQCHhkEvoYWQ== X-Google-Smtp-Source: AGHT+IGS3yl70yFTqbQkZFlk3jszVuOxD1JAZo0+GnNqWtLxuZKotjNsPznax5cJbQpppmZpNUI0 X-Received: by 2002:a05:622a:1a05:b0:42e:5da9:37c3 with SMTP id f5-20020a05622a1a0500b0042e5da937c3mr2181051qtb.65.1708697978297; Fri, 23 Feb 2024 06:19:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708697978; cv=pass; d=google.com; s=arc-20160816; b=0eQ8KR+09nQba9uJrh3h8yDpiPuzVypu4FYa8CJHXDIUuWWdRLB7GPPsveHpPrI9N2 Cu/9dNhWqkauZ0FM69PSSg/2kOU5xmTWZ4XXtS6aSAFLX64ziIKv8pbqXAz+2X1NqdMN 8vcpiDHutCwBo4R08rRaKiYtNF9sXAqXaWJnHE/Ks+i415dcTXinCB0VPTqWFGmRqPUM V2JEW+uGFSeop8rP3eC41IVh5eEEsq1pSR7OjfekGfLOn1mhLwtiSK7nyry6Km3N87hc Lvnk5YtD940BM+koH72VgT24ye1jIolMeEHgTJsg2oLR3x7DyL8NkPCET/F4ALqxZTS6 ImFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=KF62jqPKUMfmQARCISte8UuKFaty1MYvqqtU0E/nVGY=; fh=b7EyyZDi2buDZAF2B8ag3tZdxj3t/1S4ygn7fEeyjgQ=; b=tV12isLuo29H688Fn9Nu2EQvV/N5g5K1FoRvjlMYsbxzWz75c+4XIkNIgyYuONKwM0 cnmPr5G6j4pSCydMcPxNC84OdmbnFCl09PpQw2s35wkxrGKqjoS2L8f4yu6IeXje8st2 jQbAq0OcvaJ+7bjtcaxzOBip2pk1NgQcbGZ0rLaKqDQiCoJHFYgHLxNciFeFycOn46cP wiWWFTSbTl/nTxYqT6yztS7d7t+nf9g8BspjEtBCo0wBagQTC5MWwKdCd4dx7t9S/eRb KwoQhjmnviGo8T1LTg4OxYugbSc3IWhJUQQ64ptAiPy51bEHzF8nhvMu1cLIqcC7evW/ Fk7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-78463-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78463-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ka6-20020a05622a440600b0042c4e4c4f62si14127731qtb.797.2024.02.23.06.19.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 06:19:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78463-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-78463-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78463-ouuuleilei=gmail.com@vger.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 1BD5B1C227FD for ; Fri, 23 Feb 2024 14:19:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A05ED8662E; Fri, 23 Feb 2024 14:17:13 +0000 (UTC) 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 8C2CD823CD for ; Fri, 23 Feb 2024 14:17:10 +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=1708697830; cv=none; b=fKt284zUtIsGd4ZzCPB4cCv3tZwGy5tkdCVuCCW4pVdisREr55yPCxKVRXO8YnGbuQzSndBPFZHE1bGauIkeaO+X+PJghuSD6nC5VagW2Lk/VjrRWqNoKtGqGHkemjHiHP89HuRZ1C6t1V2a8B0wfENiR4gelGxGTzL+IW1HqQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708697830; c=relaxed/simple; bh=TRTlBeIWlLJicEJm6c+SDXQxnX8BueJpz4S9NWvpEnU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Xp6O3B8SNT3o2JWIkVf3+tFGHIxNCfUELQ9SMsng5iXmBEd9bFFtL+xeAbBFSSpPKZh91FKJkGMiFDrQ8dRSpUf3yJzArkdTvgRnaFs6jiCTGmm3zZTytJOgVYWDp7nzvlyjTuovZ2aJ2gAvxx6qMBWVVr6O4clrLA9/RGl3Fes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 079ADC433C7; Fri, 23 Feb 2024 14:17:10 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rdWOF-000000077PA-03aA; Fri, 23 Feb 2024 09:19:03 -0500 Message-ID: <20240223141902.873290088@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 23 Feb 2024 09:18:47 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Rodrigo Vivi , Chuck Lever Subject: [for-next][PATCH 09/13] tracing: Do not calculate strlen() twice for __string() fields References: <20240223141838.985298316@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791699691104932971 X-GMAIL-MSGID: 1791699691104932971 From: "Steven Rostedt (Google)" The TRACE_EVENT() macro handles dynamic strings by having: TP_PROTO(struct some_struct *s), TP_ARGS(s), TP_STRUCT__entry( __string(my_string, s->string) ), TP_fast_assign( __assign_str(my_string, s->string); ) TP_printk("%s", __get_str(my_string)) There's even some code that may call a function helper to find the s->string value. The problem with the above is that the work to get the s->string is done twice. Once at the __string() and again in the __assign_str(). The length of the string is calculated via a strlen(), not once, but twice. Once during the __string() macro and again in __assign_str(). But the length is actually already recorded in the data location and here's no reason to call strlen() again. Just use the saved length that was saved in the __string() code for the __assign_str() code. Link: https://lore.kernel.org/linux-trace-kernel/20240222211442.793074999@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= Cc: Rodrigo Vivi Cc: Chuck Lever Signed-off-by: Steven Rostedt (Google) --- include/trace/stages/stage6_event_callback.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h index b3e2f321e787..c0e5d097324e 100644 --- a/include/trace/stages/stage6_event_callback.h +++ b/include/trace/stages/stage6_event_callback.h @@ -32,8 +32,9 @@ #undef __assign_str #define __assign_str(dst, src) \ - strcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \ - __data_offsets.dst##_ptr_ : "(null)") + memcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \ + __data_offsets.dst##_ptr_ : "(null)", \ + __get_dynamic_array_len(dst)) #undef __assign_str_len #define __assign_str_len(dst, src, len) \ @@ -94,8 +95,9 @@ #undef __assign_rel_str #define __assign_rel_str(dst, src) \ - strcpy(__get_rel_str(dst), __data_offsets.dst##_ptr_ ? \ - __data_offsets.dst##_ptr_ : "(null)") + memcpy(__get_rel_str(dst), __data_offsets.dst##_ptr_ ? \ + __data_offsets.dst##_ptr_ : "(null)", \ + __get_rel_dynamic_array_len(dst)) #undef __assign_rel_str_len #define __assign_rel_str_len(dst, src, len) \