From patchwork Thu Feb 22 19:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 205025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp175266dyb; Thu, 22 Feb 2024 11:57:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVUHcVP8QCXbnIZ8+IUztZodmvXSKSUt9s1JV7Pyvbd/QEHpAOA8YBFgnuqdxmoCGd3DOBQpxjigFjvXyUlhngXc8b0QQ== X-Google-Smtp-Source: AGHT+IH7L7/Sk921RiowB7SH8SkOGdvuDnDU+SD0j5q3qGuBGmWzFuz52gRW/1AmuEa9HcDMxxCh X-Received: by 2002:aa7:c742:0:b0:564:fe3a:280a with SMTP id c2-20020aa7c742000000b00564fe3a280amr3748903eds.9.1708631847215; Thu, 22 Feb 2024 11:57:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708631847; cv=pass; d=google.com; s=arc-20160816; b=a38Vo3RQFAkkAjHz2LAhpz+Awbirk63pn6xcgJRdg5bwSQ+qH3TM9a8UuTLvYUaBqU O7/O0kc3oe2JkEmGH+/OYBiDFTS6CTEaWNa3PrxHe0IraEcBmPRUyB1ZUiXD/AxjvoMk sUmlN73E7C+vfK57ULrVl7HKZOPX5w+wP6Tmv/2gn0Va9+RzPyvD8cnEf3Q29KPFRcNM /fbvWJktIspWdK3eS+82zp/nEfnPt+AJ/+EEDcLtpQCTkS0qJ6YY/lt1ktwiuXbkV29K kuwkBKDkNOrSs8KjVM0cpxVDn7iZfJJ1s96eulTX3/5PwfA9XlAL1lM0NJM3b1S+RdGb blJg== 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=QS4Al3z06aMht8nQWeFqjEbhxpru2epX+zH77SvbZQ0=; fh=6lU0d7+j2gvP0RlfbRyidxN6N8cP9012O+fDGzz+FVE=; b=LvoaanxuTOo6od7BD07K4Q3evsaKxKYZfS9QMPkd67Gj2Dw5ILRxCr3QQcJexBIlxU 6+qaM2r8tpmsJLDcNg+ADOXaRQHOxd50QNOOs3Bw3BZ4UBoRGowM6Avo9POIAVSxpkZS Hym7pmMORwAZRpTasdU4OCvnjvOV/Jx7PvN5b/ybobEYi7tf1wtBAeY8jVsIPVXcnTi6 hq8Z1JxVjhjFP0gTPDFE5I+jXjq0gIRQf1GacPDSFAtYJgv24EUhVzFCxNslSBLFwAgc 0RwzbAh9VccmDOJZymyZa+DYEQCP8y2AI8TuV89ognSgOIJZQ10sJ4kA7iz2wcEekgZD 7wow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77285-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77285-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m20-20020a50d7d4000000b0056178b386cesi5740145edj.0.2024.02.22.11.57.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 11:57:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77285-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77285-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77285-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5FA091F2A9F3 for ; Thu, 22 Feb 2024 19:50:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E99354919; Thu, 22 Feb 2024 19:50:17 +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 3BFDD6E5F0; Thu, 22 Feb 2024 19:50:15 +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=1708631415; cv=none; b=BXZemLbkIiEN9uFhw3/qhECgVgshDzpmiE/I7y3rzWjpiHy83uwAdDh4ZGwLWf3jK/Zk0TB37CuoPqbxdJzlbDqmo50eq3yPee7qakDqcdt62NtPzYrfg2jN7heLPD6AVPszU1Zyvx/nYp/v2x8bP8Eax41squd28KVvtbl4IPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708631415; c=relaxed/simple; bh=DN/mPR/MulUxISIwqdVAZ+Dv5KqrCmA0c9BnouZcZQI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dGvxEd5cYFtv2BFOwEFoR9yDBy/5fGm398a7fM8I2K6Pzq4m4B95xu7YGK50FNZ8hjymplp6hDG0Q0L3AwxK1w9+41Ind2x7Af0O0QVdt9y3hMxjKDVtsxwe4jqYZeklbvKl62wHU6jQTLiqQIiHBJ+XdeqkEdwAHszy/6XsAdk= 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 E1BFAC433A6; Thu, 22 Feb 2024 19:50:14 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rdF70-00000006fYj-0CcN; Thu, 22 Feb 2024 14:52:06 -0500 Message-ID: <20240222195205.909016488@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 22 Feb 2024 14:51:13 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Rodrigo Vivi , Chuck Lever Subject: [PATCH 2/2] tracing: Do not calculate strlen() twice for __string() fields References: <20240222195111.139824528@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: 1791630347736587692 X-GMAIL-MSGID: 1791630347736587692 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 length of 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 (via strcpy() in __assign_str()). Once during the __string() macro and again in __assign_str(). But the length is actually already recorded in the data location and there's no reason to call strlen() again. Just use the saved length that was saved in the __string() code for the __assign_str() code. 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 e09e3d019dcc..d389725937e9 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) \