Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp179119lqb; Tue, 4 Jun 2024 08:19:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUU94kEClqvWX5Y3YjLl6IFaw1DLh+u0UhX5Ef/wYcMiDyYT/Vq6iQf2GmoGoHPNPYFM+c3gM3FGLvqhHrQkDBXrFPxdh82YwyVEEBOcg== X-Google-Smtp-Source: AGHT+IF29TXpcChQryYSebY+mhDiXT4PeSIW/GiSiGEwKEoKC8l+ppraprAinWeYu+5TYndrZ3qM X-Received: by 2002:a05:6358:888:b0:19c:6050:a9a5 with SMTP id e5c5f4694b2df-19c6050aa01mr46342955d.32.1717514394376; Tue, 04 Jun 2024 08:19:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717514394; cv=pass; d=google.com; s=arc-20160816; b=Q+mmDBIdSI6Dipe5I0p8BOtDKUoT7s479um04s4taVQ1GUIcr/03UpwP7O1g1PM0VF x4YCsVNErtbXnSQfqjXghWztCZcytRx9gOXiYpAPnePdH/Q7h0r6oJQyAmGgoiT3yqVe XGcJgqINivGqlYW7fGGoUIdO8RQOlW6OZ0JipVMw9g00+/MM6ZLjqscH1dJOZsvbaafX m1hIFSkj6WS3iSeyT1Gz09OEE6ejAyKRqsE7w6GKp7q/SYoXZOfelAZQGwLzm+IypusX pN0XQQtRoRVdqZh6j3tlwByRafmIfNRO12zHvgvtmQjApQVse+hvUbbFVNKwHcss8c2G DOxQ== 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=l5pj2QFikS/FiPfCQl7c5RX2MKW8jpkfeb5oI1CxGBo=; fh=/wy5e/q+z2qlOMkv0QH/u80KV4ZXPtz68q6c1OyjqGY=; b=nkKvccK5QqzpNJSfOGWTFx/anRVSiAmC8UDOpZiGG2yoBJ+X7POt5V5MJ5mrJpp1XE gwmVmgT7ROnqFjOY2JeMq4gMGrHCFCSBZDzElzeZ2aWkObr1XRzjO05KlUYoK7gCx7K/ bvx2MIFA5rmdVyWXRcMP1JBFnLreQAHToObyUxNPQTOPMV9Q/BM9uC0t8euF0yGILWBy /l69mQVXq/E6V0OicYdwCfEjD6ZW+E3Breo4agcAZZFzFp2j65BAjvKSS+Wm1JdKTwOO 0uj6c4fcBl2nTHWr7EWb1FhuQNKYoUmL3Ao+r9kqPDd2IuUiaazX/guTIWWio0wDeLc/ 0i0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200889-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35b40c5d0si8362830a12.592.2024.06.04.08.19.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 08:19:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200889-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0E092B24A0A for ; Tue, 4 Jun 2024 14:49:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 988AA14F11A; Tue, 4 Jun 2024 14:42:25 +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 8A87914B07A; Tue, 4 Jun 2024 14:42:19 +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=1717512140; cv=none; b=pjuQoygkiThCidezu3OdRNfEJZdyaEVkJrsuCSXpdM4+CsvspQLp4Fw6dAhXrePe3g5LMianro8Q+RfTIP/kRNsqfxqhR2tQEyXZxF32sG4rwekq0Z/ZKPm9cRVEtJDlFqgxtAvMLGv6hdrvLFdyDHkAOfdetg84L3hg3Jjxcrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717512140; c=relaxed/simple; bh=395fk8BtpJ1/aVzTVpOcPZBJz0c012Ont4Ro29hIzqw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Kxy/Tw4DSbmO5YNvR1ThR8Wp856z0Q1lBelPBDu0dHiKpBdu4OBGSLHorkMgjEnM3MbYK+fEplICI2KMtrrCLri5hUOwEoKI+e9Xsnfw7FGFUUjlYUgAOLOLIHssQNlVVBFCFuxqzWxGqIbAOvcuPtv7O+81/lc5/AI1QV87d0g= 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 15406C4AF10; Tue, 4 Jun 2024 14:42:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sEVMg-00000000Z5V-0ajs; Tue, 04 Jun 2024 10:42:18 -0400 Message-ID: <20240604144218.003617145@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Jun 2024 10:41:28 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Alexei Starovoitov , Florent Revest , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [for-next][PATCH 25/27] function_graph: Use static_call and branch to optimize return function References: <20240604144103.293353991@goodmis.org> 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 From: "Steven Rostedt (Google)" In most cases function graph is used by a single user. Instead of calling a loop to call function graph callbacks in this case, call the function return callback directly. Use the static_key that is set when the function graph tracer has less than 2 callbacks registered. It will do the direct call in that case, and will do the loop over all callers when there are 2 or more callbacks registered. Link: https://lore.kernel.org/linux-trace-kernel/20240603190824.921460797@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Alexei Starovoitov Cc: Florent Revest Cc: Martin KaFai Lau Cc: bpf Cc: Sven Schnelle Cc: Alexei Starovoitov Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Daniel Borkmann Cc: Alan Maguire Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Guo Ren Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 7c3b0261b1bb..4bf91eebbb08 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -514,6 +514,7 @@ static struct fgraph_ops fgraph_stub = { static struct fgraph_ops *fgraph_direct_gops = &fgraph_stub; DEFINE_STATIC_CALL(fgraph_func, ftrace_graph_entry_stub); +DEFINE_STATIC_CALL(fgraph_retfunc, ftrace_graph_ret_stub); DEFINE_STATIC_KEY_TRUE(fgraph_do_direct); /** @@ -808,13 +809,21 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs bitmap = get_bitmap_bits(current, offset); - for_each_set_bit(i, &bitmap, sizeof(bitmap) * BITS_PER_BYTE) { - struct fgraph_ops *gops = fgraph_array[i]; +#ifdef CONFIG_HAVE_STATIC_CALL + if (static_branch_likely(&fgraph_do_direct)) { + if (test_bit(fgraph_direct_gops->idx, &bitmap)) + static_call(fgraph_retfunc)(&trace, fgraph_direct_gops); + } else +#endif + { + for_each_set_bit(i, &bitmap, sizeof(bitmap) * BITS_PER_BYTE) { + struct fgraph_ops *gops = fgraph_array[i]; - if (gops == &fgraph_stub) - continue; + if (gops == &fgraph_stub) + continue; - gops->retfunc(&trace, gops); + gops->retfunc(&trace, gops); + } } /* @@ -1232,17 +1241,20 @@ static void init_task_vars(int idx) static void ftrace_graph_enable_direct(bool enable_branch) { trace_func_graph_ent_t func = NULL; + trace_func_graph_ret_t retfunc = NULL; int i; for_each_set_bit(i, &fgraph_array_bitmask, sizeof(fgraph_array_bitmask) * BITS_PER_BYTE) { func = fgraph_array[i]->entryfunc; + retfunc = fgraph_array[i]->retfunc; fgraph_direct_gops = fgraph_array[i]; } if (WARN_ON_ONCE(!func)) return; static_call_update(fgraph_func, func); + static_call_update(fgraph_retfunc, retfunc); if (enable_branch) static_branch_disable(&fgraph_do_direct); } @@ -1252,6 +1264,7 @@ static void ftrace_graph_disable_direct(bool disable_branch) if (disable_branch) static_branch_disable(&fgraph_do_direct); static_call_update(fgraph_func, ftrace_graph_entry_stub); + static_call_update(fgraph_retfunc, ftrace_graph_ret_stub); fgraph_direct_gops = &fgraph_stub; } -- 2.43.0