From patchwork Thu Feb 22 19:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 20819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp172515dyb; Thu, 22 Feb 2024 11:50:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV3EF8n0W9TQGJCdZAKWgxXRiOl1oDZtjHujq9HcJpkWRSwZYOJg/1wMNcChv6Vhlx874Y3Ti+RfTF3F08fOxukKOsk2w== X-Google-Smtp-Source: AGHT+IFFkrzK8/k7ao0pZT/qGlzvc+LL5x5TM8LNEwIT+T34yrK67gW4AGIQtO5l7dqSn6S9YBEu X-Received: by 2002:a05:6214:3011:b0:68f:8587:205c with SMTP id ke17-20020a056214301100b0068f8587205cmr243352qvb.7.1708631450729; Thu, 22 Feb 2024 11:50:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708631450; cv=pass; d=google.com; s=arc-20160816; b=I1INRydoQXwP+7giko6qyzofA2du0a0m10Ij68GHhWtu5LlXRXVXCLgVSqeo2T39sd e6e4cMXbjPPlftyk78Bej95PDPtwMr3Wz+TtCfdJltRq4gYKbzw//vbGQjyytqa4UsqN n2t1BlDTPmwEVRthjIe6sfzQDkY23hmaDYGEvga23y4j25+0RmCfBQeaDWdTeRblQTkc 7tgi39lW9B+nQy22FN7vDIzb7jwKcQF7az6fQ7XObQpFyfBtqxgE1v2JMBZ9rm9Jw7hf +kOMLS5ai4orDXahDBxYkhfdDgScdWfLZFEaQmVxBlglW+OPpdbGOFEZEP44DoP3rMxQ dK2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:subject:cc:to :from:date:user-agent:message-id; bh=NFcPwVawv1Ju45X8Fj4GQ2y9IovLnYMBln6D9eQM63c=; fh=6lU0d7+j2gvP0RlfbRyidxN6N8cP9012O+fDGzz+FVE=; b=KMGCb5qX+rHdv19yZL8R9U3zPq9+paEKboJykK0AaIl3B3Kc2RwIlEm3hmKaAapY/7 6FbB/ip+YP1jLCRSq8oESTi+HHpPNidNEb+sgAz1SQYgpAbC4QlgF2lL3WaRyXute6N3 QQvYe6+FDj4lLy8mc5piPXysGTyDOJ0PCaY/0YruqW8fCrwIC/YcxAkvkMYYoxzUCWuS CVFhWQNQUcT72O0ZQhgl8ufNhBX6c0KflLjE6FZFt7/weJiBTLW+UriTtWyZGEte2DyH fPYnGviPBx/LVsGyO4bpy1SElnLhbPcIIAL2LOfpyPgCxYwumuQAcYsmZCz39Np9oSDF mvXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77283-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77283-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r10-20020a056214212a00b0068fcc6a4593si1045756qvc.38.2024.02.22.11.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 11:50:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77283-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77283-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77283-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 837171C20B08 for ; Thu, 22 Feb 2024 19:50:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5D2D71725; Thu, 22 Feb 2024 19:50:16 +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 0ACEC6E5EC; Thu, 22 Feb 2024 19:50:14 +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=X2AFL0Ne0B91/qwn+v4KCKnLBIVNlbOQ2mPexNGIGXSC1FmrGenMupbmbLhLhAl+UB4uaYDPE63GUC5sgCf00o/doHiDkL9vn/h4yki46UwzFe5AjZZdu7U1NoKG5mvKw0GQb2InD1++5K6ADrxg7j9M9hz3WYEAwoSwm5JFsjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708631415; c=relaxed/simple; bh=9xM0zDSZnj/WQCIfmV1M1iafWnZdArwmz7MnQziBy8w=; h=Message-ID:Date:From:To:Cc:Subject; b=uVoutYr2WmIdEUkIi2eG8myLt5QnBcpgMEYyd/0T2Hy9qIZOiqYFsdiLq8sibwZ9yLv6P6e3eh96yVU9VJhJ0Heb2sZMQgJa+q8tJB56qd9SZQKThyTdiQXpN56+Zqt50XpW08adrPMol5V5tAFt4DeCiN0VuYDcdm0DGPWCZZM= 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 AEA95C433C7; Thu, 22 Feb 2024 19:50:14 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rdF6z-00000006fXj-32Nl; Thu, 22 Feb 2024 14:52:05 -0500 Message-ID: <20240222195111.139824528@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 22 Feb 2024 14:51:11 -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 0/2] tracing: Optimize __string()/__assign_str() processing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791629932182150156 X-GMAIL-MSGID: 1791629932182150156 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 (using strcpy). The length is actually already recorded in the data location from __string() and here's no reason to call strcpy() in __assign_str() as the length is already known. The __string() macro uses dynamic_array() which has a helper structure that is created holding the offsets and length of the string fields. Instead of finding the string twice, just save it off in another field in that helper structure, and have __assign_str() use that instead. Steven Rostedt (Google) (2): tracing: Rework __assign_str() and __string() to not duplicate getting the string tracing: Do not calculate strlen() twice for __string() fields ---- include/trace/stages/stage2_data_offsets.h | 4 ++-- include/trace/stages/stage5_get_offsets.h | 15 ++++++++++----- include/trace/stages/stage6_event_callback.h | 14 ++++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-)