Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1767828lqb; Sun, 26 May 2024 17:10:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOWsYQmw1LF5lPGLlZukk3zWaep1w1HZvslV34rcq4n2I17IJygdlS8bCI5r3f+CB8ZELmKzPPKTKcmfrXy9BxrI4ZTWxqULiPhUGcxg== X-Google-Smtp-Source: AGHT+IESb8AjGfUh8xsb0sAPJ/BSoFsRmkPFsqnUpsXqjEVVYqHN+ulHjL10etAQn9tEgpfSu7Mw X-Received: by 2002:a1c:7902:0:b0:41b:c024:8e88 with SMTP id 5b1f17b1804b1-42108a0dc79mr48045445e9.33.1716768605248; Sun, 26 May 2024 17:10:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716768605; cv=pass; d=google.com; s=arc-20160816; b=y4eLP5aPOtBfKhXiLRfqOqtks1Um83OKEWf6reG7CZSt1BItNRCK588RK6I/R+9/Bg /xXpj3wWeazbRZXtGc6WgUQxto/aLb+QEJaFy6q5nQP0KwM9eyjrC03fUXJALb7sxkDD HusGtHlKBky+ntUe3hGoxawuehX1FcrAvE+6whQfmGe3kkLtJyeec4vUQ4FhuYrx7zsJ PaEmLf8lynuJF/OH2dGcANGHY0+cWGvBOn5asJintLu16zSYgeE8pL/9BQmuCJ4sFKjp a9iiYlvx7l77pJBAKcv5I0K1HArGYPcA6eEzmAvFYlx2odA73LUCUZGeKtkrJU7kpO8O KjyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=9iTGgJIF7LwnxToX0+EuvTg1GIl/yxyek4s3zR+FqOk=; fh=jPbTOLaFRquCWSHePkx5JyHgrJfqc0pfK3tHoljjLqk=; b=qXuhw8BG9Cxf53+qYtLxtQ8Wc6420+U8iIgdM4mlhmADmU6LsZdqOV+qWSBa/fcxnO xKfMsGoGZJU1i18XFpo+09ZilosJ5b9YzpbO4aObVcxJBv/oK5vIiHrhXxaXl4Y4Xbmh /dgsvpyH+RIQuxhyrtwe0waCOOm4hoNLTT3MC5GGdwTv2Koh7QQjqcVbr3fJeudNic+L NiI20E08BtTF+SDazknf1VriNvVSD8GFwDEXWlJ/FXZeYt/+89HfScovHyJ+oQYGq5vw E08ciPcqOtG9lCBOFnpY40A6uRY2W/G2+vdI1hGDgy7kcJprX7attceyRPv89HnPBf6X 27Cg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qvc25599; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189910-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57863dd8ddesi2474073a12.256.2024.05.26.17.10.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 17:10:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189910-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qvc25599; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189910-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 F0B541F219ED for ; Mon, 27 May 2024 00:10:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6062F653; Mon, 27 May 2024 00:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qvc25599" 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 7DA23BA33; Mon, 27 May 2024 00:09: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=1716768596; cv=none; b=oEw12SUXVQTdJsGEX9hw7zywC0yPoAM0fhorF2vtqFKYcCvnEyl6jGxwSWsItpMBLC5Gccya4Lix7qvGn4TCDX6CTzAT/UEZSGuEmI2DFbPmyMXpoAs724tX/98RRteWXeZDfi0zK+6BijOwZ61843ux8Ei5zPc+Gt7hvrmK9h8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716768596; c=relaxed/simple; bh=nl9oLr8Xc4c24Mq1utQNIikN4+8tQIWkxiS58d/4E84=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=rcgfo+4BKh3aZE+z7Nig4nQtRP1mqhvT3UeSzi0GI/yCuByezPNubHFm7EH6wSrB5u9f5F0tQM1qiVeXIL9Q9mf0u6hGqo7kW5fOiKzjS5r2uW6qS4Ii0pobzbuM/c1GbsSlJgC+tN7W7k0nccYD8wTp25ObSCw1Yqv3i3BbAJg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qvc25599; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8193AC2BD10; Mon, 27 May 2024 00:09:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716768596; bh=nl9oLr8Xc4c24Mq1utQNIikN4+8tQIWkxiS58d/4E84=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Qvc25599Y15SqQsaZIBOMO66Htbhp9Yu10mOr0OOQLB3WSuRTRG0f0lsUDGFyNfnK D4uO923onj/cs+zUTI26yvNrkgL7K0Vacsup9WL4N0cwkIuXxZRL9Mt1LEOTCq0FhQ gaZBSl6bV8wULBhFfWA/zbTaGlKJ7fVMLfvnb474juMjUW6bkkKso53g7gDkxZ4giM ygvNee0gHhiDXMdiAPOoQg9eZG4vvquZX37QYJmgFy7p17MdPktpA+jwiC7TGjqZIG uKkhMopQCAk8APld1fVF+WzHRSTlbGy5TvG+bPcZBj2GXZ9AIdrusO+qfyzJmV/Y2p bzCa4/7nyq9HA== Date: Mon, 27 May 2024 09:09:49 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, 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: Re: [PATCH 20/20] function_graph: Use bitmask to loop on fgraph entry Message-Id: <20240527090949.70151ecb2e7d98d4f284c2c8@kernel.org> In-Reply-To: <20240525023744.390040466@goodmis.org> References: <20240525023652.903909489@goodmis.org> <20240525023744.390040466@goodmis.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 24 May 2024 22:37:12 -0400 Steven Rostedt wrote: > 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). This is OK because anyway we check gops == &fgraph_stub. By the way, shouldn't we also make "if (gops == &fgraph_stub)" check unlikely()? This change looks good to me. Reviewed-by: Masami Hiramatsu (Google) Thank you, > > 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 > > -- Masami Hiramatsu (Google)