Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp285340lqj; Sat, 1 Jun 2024 20:42:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiGr1x3AkFpoHLBQf87y7G8a10qO/pDFcgUZwGK+lkjcpA+u/KjtmN+BzhJRiuXS46l2EMaPMfkEkQzndutfJo+R/Haqv2f9gej2tkPw== X-Google-Smtp-Source: AGHT+IHU9ISH8QTp9PxKNB/jOST+BPqrGpLbp1E6HUm/tvIlUposJt6PopF+mT8X64B/gL+k0xWA X-Received: by 2002:a50:ab45:0:b0:575:a0c:4b8c with SMTP id 4fb4d7f45d1cf-57a3644584bmr5189042a12.38.1717299725138; Sat, 01 Jun 2024 20:42:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717299725; cv=pass; d=google.com; s=arc-20160816; b=pg3sC7cdRhBkW2kljbIwvuxyhuld8LRbWhJ5csGhHMCTplNu9yN/AOsbqVo7Ny/tsM wvvnqWF0hTWFfJgm8GRFD+ZDXmToT3voy0CcX+mu9i58xtdwhfQPRow3QXNnzQagOg22 e+ERA3tp2NvHOtDD0nTmEijw7CqDsStUo7rkHu4BhPVCdB+9/Xi3YEuUWVA3qKx1/7En MfhEp8s7jmx0q8LZxL9kX9IEIb+MMuWQ/FjpBE6AFah6AC/7iRuOurOHF0SVRLn5tqWJ /DBe7jpaYWrKUsrIGiacWgk6GlWqWHU2xbupnaj3OaXNs/Koplqu6WbUb1WflgshXqi6 iteA== 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=uhc1QgcM5G2/eNkqJIbaRSeiQ/G+fzpKL5h85ZVHBEQ=; fh=YfcaVrAzBpSwi8dOlqHV4K1os6qdULs4cyXFG/DyLfE=; b=dRetjeJMoEBm+YYGd6xgBfg5PzsucDzCgQzNtEob09VyHiFW2oSCXffXgRli8sk7/M 8+r/Q/YnTGxCHbCJhpJlF6SqfA38D0j0ac0xQHZA7YNdq1ywgkHV7BMvjGTndgN0Kaai c8uu1I6iqIH4lwdtC8yTXDLaqEGiCjlpKPi4/wR4D6ARj7UhbKBQs5YaNRVHn53DsQOn kfArkQ3nCrmjkBGCnIuXNFuYAU15Yi8Mt8hlwLF56SR3T+wgtSl24/5DmNW5sWivPdeT +I6kQj0nbC2sqjOeDGr4rlJIyIgyuuHXTqIPsRp0oTmJTf1O+vYJ16NnnrsBqS5i1gaP //xA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-198104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198104-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a50836a3bsi950858a12.617.2024.06.01.20.42.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 20:42:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-198104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198104-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 858571F22A89 for ; Sun, 2 Jun 2024 03:42:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B4B97640D; Sun, 2 Jun 2024 03:37:32 +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 C9D483BBF4; Sun, 2 Jun 2024 03:37:27 +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=1717299447; cv=none; b=j7rtz/Qwi9HFEMt2zLMIJa5ag0tgojVwopBZrmcRK0xNE65HqdF5YrgOqMuZFs1mubkJ4HP4AqAjeN7EOMW/JK1SL6zDPLG05+PrwtSnPPVFGT1vn2R7nmPaIyRY6yBWKDMWc0PM7rKx521uaEwShz5Qv4/XTCHFKFA9fNlWNKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717299447; c=relaxed/simple; bh=zNX+8r8t+PUCLhsB1Ks9Ro5ISDleDaihMu+uhUeTdwc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=n17Hnf240/8Vfh2m6XxamP9cv0sCEG82Iht1KgohfzpJ2KCwqIT2QJLY7bzppiN+wcvYZhHN/ULBNORYGzAdJmSoNQliDWYR5mW59d4EEluBGJvgUI+c1c4bFLxwZTCw9e+v2VaF90KzDCeI2J5PJHTy1uRAB3tmcioT/yS1feE= 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 AF5DAC4AF08; Sun, 2 Jun 2024 03:37:27 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sDc3G-000000094UR-46LC; Sat, 01 Jun 2024 23:38:34 -0400 Message-ID: <20240602033834.833336234@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 01 Jun 2024 23:38:07 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-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: [PATCH v2 23/27] function_graph: Use bitmask to loop on fgraph entry References: <20240602033744.563858532@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)" Instead of looping through all the elements of fgraph_array[] to see if there's an gops attached to one and then calling its gops->func(). Create a fgraph_array_bitmask that sets bits when an index in the array is reserved (via the simple lru algorithm). Then only the bits set in this bitmask needs to be looked at where only elements in the array that have ops registered need to be looked at. Note, we do not care about races. If a bit is set before the gops is assigned, it only wastes time looking at the element and ignoring it (as it did before this bitmask is added). Signed-off-by: Steven Rostedt (Google) Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 0827b67f746d..4d566a0a741d 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -172,6 +172,7 @@ DEFINE_STATIC_KEY_FALSE(kill_ftrace_graph); int ftrace_graph_active; static struct fgraph_ops *fgraph_array[FGRAPH_ARRAY_SIZE]; +static unsigned long fgraph_array_bitmask; /* LRU index table for fgraph_array */ static int fgraph_lru_table[FGRAPH_ARRAY_SIZE]; @@ -196,6 +197,8 @@ static int fgraph_lru_release_index(int idx) fgraph_lru_table[fgraph_lru_last] = idx; fgraph_lru_last = (fgraph_lru_last + 1) % FGRAPH_ARRAY_SIZE; + + clear_bit(idx, &fgraph_array_bitmask); return 0; } @@ -210,6 +213,8 @@ static int fgraph_lru_alloc_index(void) fgraph_lru_table[fgraph_lru_next] = -1; fgraph_lru_next = (fgraph_lru_next + 1) % FGRAPH_ARRAY_SIZE; + + set_bit(idx, &fgraph_array_bitmask); return idx; } @@ -631,7 +636,8 @@ int function_graph_enter(unsigned long ret, unsigned long func, if (offset < 0) goto out; - for (i = 0; i < FGRAPH_ARRAY_SIZE; i++) { + for_each_set_bit(i, &fgraph_array_bitmask, + sizeof(fgraph_array_bitmask) * BITS_PER_BYTE) { struct fgraph_ops *gops = fgraph_array[i]; int save_curr_ret_stack; -- 2.43.0