Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1172588lqj; Mon, 3 Jun 2024 12:23:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUqxEsWUKzbbY3dnvLKwgSLv2T71N11e5O2uT5Vw2JFz1kz2ETvc9hZqeFZmBxhq5cLFeWDngZ1B2oPvpjgR5724bmAchNEwNQ99Q0jlA== X-Google-Smtp-Source: AGHT+IF6pqO+uXGSlRRs2HKLHRR6KpRWpqFPfjk6zwbUhVfyRtxwVCskJ02hpJXRepQyaXZey47e X-Received: by 2002:a50:d657:0:b0:57a:33a5:9b78 with SMTP id 4fb4d7f45d1cf-57a364496famr6149467a12.34.1717442626394; Mon, 03 Jun 2024 12:23:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717442626; cv=pass; d=google.com; s=arc-20160816; b=vuts6pZsImD3zQqyjxffbW0R7q4IPMbCkRbTojnIfhGUmV3NQIw3xSP7B5fSfSys6s DyGTvtmpgLGXY5uRbT1IVcWnGL7ycs4rsY5oxijSb4rpZ8QC8lZVyBah6Oeid+kXXT5Q I6DgDYsOsjs9n2eveKa2T9ya14T39xAC10Hlbh1Yp8/YcXRzkvTFxy7QUnAjRbhdRARo H5y0WHGntRRihH/QGdgIsPrRPc1rqba1GO4NRB1hcmEV9cdnhfn1GGk4jKXsjWMDYHhI jJdKZUoql0hNjPuML1mswRKg9rotoqJ5jBq3m3cj+Jelv5ZjhcQP6NQMJbWwpZm9dqUw xLQw== 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=+u2+pNqQ/IkFed41rEQE9sp3j16Vilx7bqH2Fmv+E+o=; fh=YfcaVrAzBpSwi8dOlqHV4K1os6qdULs4cyXFG/DyLfE=; b=y15bXSy6j5F6veP01EQ9DgqKacuRpUff/FM+sRG+M0DIWfmtnDjeuaJX/8UK0/yLpL rW19nBVlQi95uo+POvMibd4nZZ+mVIg5zmMEiADvEyNTbUtVa3yw1dkIPm0seDVua9RG xvhnqCSFFFgV4t2YCiNsYP1Vb6REeoqUzCfnCe8HVnCnYIr5F0ptLuwNAXkKdDwhhxfx 4z12o4ifX/rBNoJr/K60QEiNpWV4tQmkFbiAAd8wvf45ucEfE4odOBeXjzecD8B4wClT 6Vp1Hue7XKCSDulRfY/G2YlI6MOAW0ra1lwnbIzxQRbKp1S0jGx+T904xUB+3e/F67Ja W82g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199619-linux.lists.archive=gmail.com@vger.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-57a31ca5a30si4338716a12.518.2024.06.03.12.23.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 12:23:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199619-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199619-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 6D0BC1F25848 for ; Mon, 3 Jun 2024 19:13:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CCAF14265F; Mon, 3 Jun 2024 19:07:20 +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 D0C5113D247; Mon, 3 Jun 2024 19:07:13 +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=1717441633; cv=none; b=ojzmbZXLN/xF8ev5vlN5dycBZoeH00x/1KL6rBWiqswn64w3GxySlLLgFgEeA8mU8zIkAVJWXxBlAcEviJLJFalj3/iaRVzdUsEuN5TF53Cuv+XN7bR0wqF5zH9PPqS5EAMl5OvRPV6NZHx9uDphVypAWgIunZkVzD0EBwXVzGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717441633; c=relaxed/simple; bh=Pm7PSUxREyu8vazVQyA1LZW0yMStfKzkpurO/Q2407g=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=MnS0hPK+y/fAqJWAY9nm+AU16bRi5VFfQFWy+zbfENnKuTaAc4hQxCXktNu73nrwpVAhb6Un1BD3NtNamozCLqpW3eh8Vs7++c5mKZochKIva3zDxU7gT1aGMpIi2EF1m+sAAeb0HjIQA9PqCxzrQLqogvp0UNs7Kt/iYW/2GLs= 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 AF147C4AF18; Mon, 3 Jun 2024 19:07:13 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sED2e-00000009TxR-384F; Mon, 03 Jun 2024 15:08:24 -0400 Message-ID: <20240603190824.604448781@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 03 Jun 2024 15:07:27 -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 v3 23/27] function_graph: Use bitmask to loop on fgraph entry References: <20240603190704.663840775@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). 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