Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp913642lqb; Fri, 24 May 2024 19:41:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX7ZnZ+0A1om2c5VuJCusMWtuVC8jc012JMz0fw9ufxUR7zuXulGXvTvgMlmhbg7VKs/Cg2yk4w1GB8We6d7zvSD1rVjywJFGQSd2u3Pg== X-Google-Smtp-Source: AGHT+IH42o30SI1e6BPpx8WQeQULPT6/7g7cj+RyYK7yH9cizTVSDTE/fqHjaToDEusWcd1rcMUt X-Received: by 2002:a05:620a:cca:b0:794:782c:b0ad with SMTP id af79cd13be357-794ab05fa29mr369802485a.4.1716604901865; Fri, 24 May 2024 19:41:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716604901; cv=pass; d=google.com; s=arc-20160816; b=VIzQgzrl5d1cJ+h3+sqSNOwHB5bQXpM9ATo1rcDNfOaiS4YUl6C8DDHVXW138K/7Yo YEgtjqLzCX72WnnMFSfW/ReYHi1wDG9GOs1QvZNswpisrVa5PjofFLoUWL0R4FXIoqDm QX1qjD03NdAc9QgTJxA/H2QU8TzHdI1OFY0J22bl5g+71u8iJ7rmvsVQhBqcOtVWCkQa +Mc54DNk6DlCJUIK/JlRN5171jLsUFo/K7R2YJHAGVnyec3ZFNng5ilaTewiaNeqD68h aRHMZNN30yeZ7cxp3Mh+CQWWZxxgX5c0j43Bl/Wro0meM/xgyCLY0/L15NMDg9Qj+JvW HtdQ== 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=NmSrXkfnYkD9L9u+wTzVICHWZGkPSMoolxNvBFxymeI=; fh=YfcaVrAzBpSwi8dOlqHV4K1os6qdULs4cyXFG/DyLfE=; b=lDgBVnC/tGzzjoyYkZxdzHngaaMV81n15wjrl6ptp6zlSpXcmKht5lQBxDzQjzHXr3 rjFUygp2RSGO6R1ZJ+/VJJTMULDwkCFVhH5P7YUdPdiqHuDlBPeFiQcAhmJsmiC5uhxL 9aVvuTvd9+6g21uHIIDN+nqjaY5GjGC6+7wQAXMQVo+X7GJlwrnFz9vilU78om+DvaiF R1BZRkfBNJFzEeICHQs3048KTl6Y+5eBF/LxcBL9aaQpEkKaC4XzclIpqWFQBewn/6ee fepKIUOD/QJnrnhZ2B5GwAHxSNA8TxxLtFYPBqCu2ex282qZ4Phhi7yuzRp2Bg8GqQKU PE0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-189261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189261-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-794abcc7d43si291036585a.186.2024.05.24.19.41.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 19:41:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189261-linux.lists.archive=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-189261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189261-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8567C1C22017 for ; Sat, 25 May 2024 02:41:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64BCE12B17B; Sat, 25 May 2024 02:37:01 +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 1CA59482E2; Sat, 25 May 2024 02:36:56 +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=1716604616; cv=none; b=qBwhvJGJ7TGH9jgb6/G5n9eVS9AY0AzcWV59e2W0FNJaL1NBRLs1T3bxsuphfg09nG5Bf1j5w/FXr48fzjlAghhHaonFi3JkDccFbRpgFQ/bR7SiM7kg5nRY0xDcXuZvvFAl28EdyDXlZkChAqEeD03ICdruJB+bkBLP8Dt+yeg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716604616; c=relaxed/simple; bh=SzvcQSHtCTZDrarq3GkKkV913OM7ddRg0/jQltGll9I=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VWjBX8PPcSGIAri4hciUhf0rsEwV9lJ7WdEf2WGCJbTRKcx1pW71mG2K7c7u3geRRn81yk3wx1mLPOt/l7R2WMSTamdzyIM64lLu5y+9kdJmD8eItmXfrAN6y+610vn8xEp5soo7mHe2zv9gypKJZU9yPeEqLDqIaJkbOxDw5eA= 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 D7CE2C4AF68; Sat, 25 May 2024 02:36:55 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sAhI0-00000007DRZ-2DBo; Fri, 24 May 2024 22:37:44 -0400 Message-ID: <20240525023744.390040466@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 24 May 2024 22:37:12 -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 20/20] function_graph: Use bitmask to loop on fgraph entry References: <20240525023652.903909489@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) --- 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 5e8e13ffcfb6..1aae521e5997 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -173,6 +173,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]; @@ -197,6 +198,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; } @@ -211,6 +214,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; } @@ -632,7 +637,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