Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp162758lqb; Tue, 4 Jun 2024 08:00:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVeBnqe5Clm1FDx14Si8FC7DwHnvuuVoRK6y23wveroRRAk+VXoe/w5AlOIpUQ/f/LKrUgEehqwoPUMyjGJYESyXu3pJUqqdWllLmvqHg== X-Google-Smtp-Source: AGHT+IFMmls+ZPwUhAaE//hedW7PEmMz82/mu+GAV8RURoo22CskKr2k0AkP0fcLaMg8NjF60m5p X-Received: by 2002:a05:6a20:3949:b0:1a7:aecd:9785 with SMTP id adf61e73a8af0-1b26f11f073mr13905605637.25.1717513211968; Tue, 04 Jun 2024 08:00:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717513211; cv=pass; d=google.com; s=arc-20160816; b=oRgrZgejfZ0tfhNPrSb14I/lsd0KthM0Dk2H9R8MUe3gvFROT/bmk1n4dGxuIxJNR5 nZCCaZ6WSzP8l0xZhY6llfLXAvJ8aBpGhxFbTjtXrlT2NIj1jT6iYOw8De+WcYUby6n/ FgwXYXByYlnnswdwMQgN+fmOJyPfdzyvv4SnkcbU8P2pAIcDviP+H6fclcnhVY+YQq4G hFlcm+VyO/tnWuamUYxfYnHOv0W8+37hqWkBWEhWx7SZGUuVI8GbatNk7L7nVD422tNS Bc59dzAcrrIEgG9/JcxaxyZHZFFF1c/1tYCDBmb2iSLQWZeTwlc7Pf0C0Ifa1gJo/4UM sg8w== 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=v+tP+V54uSOQXZaV/L1oMtqpW3SbllASN5p3bLExCC8=; fh=/wy5e/q+z2qlOMkv0QH/u80KV4ZXPtz68q6c1OyjqGY=; b=0cJc0g7BMhLXkhIGIj0DurNcKlDpF/194sAjpWV4ddKnrO6bAGnQsx4TO3qg7GFgnr zXrnBN1EQ3C7EniPSSXdqPbjKVX+v8syQ/7y7Awp+dGUuo6xBnSvnDo4PVfzOAxvBVfF 2nJ4ONJWjuxkPXRhRytIYId7DdtVREuOrEKxxTnNtcdCJvt9xbQcjxJho1oZnIYfh+7P ChSsf0SDGa2XvZhJZzaMmyVamYZ8Q16i8oF5iro35aLscxx3DDeRHEZj2P75Jo26bXnq gFu+Y7RsVlJagFykYE+5O5tflKrlP1nnQSRwNfhaG5qQisKJTYC9cjZsc6y2eEryFInY suVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200884-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200884-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c359e09db3si1527737a12.423.2024.06.04.08.00.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 08:00:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200884-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-200884-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200884-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1F76F286D8F for ; Tue, 4 Jun 2024 14:49:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 390E114EC74; 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 BCCA114A0BC; Tue, 4 Jun 2024 14:42:18 +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=1717512138; cv=none; b=a++cNANo7jwR6/f0aZJEhRG3VSbOwTKv3UydF7FEolpN5UAEe/rxnPPgS/0Y3YMb3x55UMZdsQ6mPb0+MLwKXMuxcrxKMHUpconJ+O71vWYtMTYMcE9+bz8Np5f7h4hwfabIu1l5bKqMy9UWIgWPzk+yaD/pckvFf1bIo5B3pnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717512138; c=relaxed/simple; bh=Pyur7WLvWYb5zL5/rTJ/K0q1Rf4L3oxuDRz/ogVLsII=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BhtPzj7URHlmLOEh+kdePJ8OdOASvWZJcv6fUS+tOjGUwkggrqTeAIaJ0DYQr9svtgiYVx+u3PAMn7/p1YWgXEX9jeNJnORIa7L4NS3L4hFDYOPTnh5JY/4QFZeQMVIuxRJ7A8qZOq6VII9c0D0kuNU9Q//HWpbM96/X9DwKsOY= 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 A09D0C4AF11; Tue, 4 Jun 2024 14:42:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sEVMf-00000000Z4V-3QXO; Tue, 04 Jun 2024 10:42:17 -0400 Message-ID: <20240604144217.676052910@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 04 Jun 2024 10:41:26 -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 23/27] function_graph: Use bitmask to loop on fgraph entry 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)" 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). Link: https://lore.kernel.org/linux-trace-kernel/20240603190824.604448781@goodmis.org 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 | 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