Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1414928lqa; Mon, 29 Apr 2024 07:56:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWs4mywgwQ6Chbvs9Uti22hAzcNtH64SOVcwOldQIdvyfZ8W37920UjrWP37oGVpOd645jcBsD6IPPrQO7SURyC+zm9XDVpmfAck76uog== X-Google-Smtp-Source: AGHT+IFxvWTjDxie1yheUrtpDpwVbyd9HmBNEGVaK9a0oIb38Fli5VofSzgq4oGU6n0uyZv0rplS X-Received: by 2002:a50:d5dd:0:b0:572:6b19:6fbe with SMTP id g29-20020a50d5dd000000b005726b196fbemr4218164edj.0.1714402589885; Mon, 29 Apr 2024 07:56:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714402589; cv=pass; d=google.com; s=arc-20160816; b=XaIh3tRuNXD3wJTLJ3sN5mFHhUpKJbe81b9fQ0DMRZpyLZC46V5eTob+3QtK6MDY8z mJagBU8nVm+Tf4LhcaBCeIQb7c8Mm617fTIeEwZWNEitFf0tfGZDfUWgkvRqJ8pxFPEx Q/Bofb2kI+Q+mE6yqqbxqzbeqMza9huX5bXBjgjW8tmHoh3uHZZghvV+hzzkO8MUceZb /lkKK/0ysdBJEvMvwIVnK0RQOL/QktTA0Exxdps1qC0JlhBQP9OUCMP0eAiVDM0WNPrd /k9P++nY2ueOcvwv/Epw/VzZtOZS60lmjJgaZxApj+Vy9Nod7tsWcIOT/jpJhYPl7DQL PJNg== 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=lU30PCW2yA7F6gNKkBtnoJDGwcp3bmqfZ1dmv4UF7Sw=; fh=ndRn/JTK2HZCNXJXUMBxBTahd2bYNsNuzvF29YiCTsc=; b=tp8Xn4jri1Q2XzpkOFa+E4CLwvDu5+DHr1CfqhtyqtWnhjG+zd+F3gQDfZlizx8eRh eOV/hl2479QALm6o9MG5sgXcvnBauUWvuKwwCzW/b0EgtrzPRpJfi0CIHOSD5pcMyzMF vIjtF13jC98SE4xDFbdFrH9+hg9R4VRHsIavapX6vhuMPff5CochLpr0aKE2UEh6ufYZ 3tptJ4WtOKcDs3deF6T13DF937ntY551rcO66MMZB0PWYmQq4Hnm+pUqqWfJE/KuHzXi IAA3Wg5oZAnWOYwman2LJjsWJHMsPNhcGxGn20KJX9TOoZXoVqdZZ2JS//nYqlDYRKhI hjKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i+p+QHU3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-162500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162500-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 f15-20020a056402354f00b005723f4543a2si5680048edd.517.2024.04.29.07.56.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 07:56:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162500-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=i+p+QHU3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-162500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162500-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 737661F23D3A for ; Mon, 29 Apr 2024 14:56:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB3D78063B; Mon, 29 Apr 2024 14:56:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i+p+QHU3" 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 C323C745C5; Mon, 29 Apr 2024 14:56:19 +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=1714402579; cv=none; b=i93Mn8Di+UeLNAUG6dMOHvDdBA++3xsEtbJbnLRKTmrRHV+n+8JoQUlXJ3g1IJ/oCeTzW9rWopzz/WfxRdemgZAtALblBHSGgv1LSJ5hG420Xrbn2OSeNKAS9tcCCZnsrvvMdSnzcEcoPNopE/SoucYRw+HiFUHPVG83/3GNp/c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714402579; c=relaxed/simple; bh=fCYjkbds6+k3U7rGawEZ2BQELDslwiIzCq0b1cVevoY=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=rjsw3FRb4qzUxMt2CaG8Mwk0XWJ8kdbtT1IbZTUJyun20WVcqGe/tSrcCE3RDGPdnbgq7GcC9H6wciKTMEP8PEp39JyslsYbdViV044tkypKp4M0ALB5D4++Lvt7ohY/k2cR4L1u0991cPG49R+PcNDMPFLCnD7LFedQmqDqTqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i+p+QHU3; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55D10C113CD; Mon, 29 Apr 2024 14:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714402579; bh=fCYjkbds6+k3U7rGawEZ2BQELDslwiIzCq0b1cVevoY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=i+p+QHU3Yvn2nxaT5tP2uoTDxPHU1gIBRx2z8tmHGgbXJxhYr/uO/MFSS972M0lT+ 7XcC1A3MuPiAt5nCWDQDSqOAJZI8X76SieMpvJZ4Oey+fNANRjJMr9QhOSRtYy7srz iDQM6md2m5pNDLv1aJzmA724kLUWclE+Ih1L+lzqpgpmE/k3yDOqRP1PrOMNbNDmGf ObgZi5rTDRglasez2L9rpHn2y/6XJTwsa5YCtEAiYezewA0RXCTBpkyFbw5Ra3mOq2 eP27rft7AYo4v1iw61sAvgex52Oe1bgORaJCRGZcyO4BdiAAkvq1cl2OYizlAMx755 NsAwfiuVNLXVw== Date: Mon, 29 Apr 2024 23:56:13 +0900 From: Masami Hiramatsu (Google) To: Andrii Nakryiko Cc: Alexei Starovoitov , Steven Rostedt , Florent Revest , linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH v9 36/36] fgraph: Skip recording calltime/rettime if it is not nneeded Message-Id: <20240429235613.784fa3266d15047af3e467df@kernel.org> In-Reply-To: References: <171318533841.254850.15841395205784342850.stgit@devnote2> <171318575984.254850.17464878774926779209.stgit@devnote2> 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=UTF-8 Content-Transfer-Encoding: 8bit On Thu, 25 Apr 2024 13:15:08 -0700 Andrii Nakryiko wrote: > On Mon, Apr 15, 2024 at 6:25 AM Masami Hiramatsu (Google) > wrote: > > > > From: Masami Hiramatsu (Google) > > > > Skip recording calltime and rettime if the fgraph_ops does not need it. > > This is a kind of performance optimization for fprobe. Since the fprobe > > user does not use these entries, recording timestamp in fgraph is just > > a overhead (e.g. eBPF, ftrace). So introduce the skip_timestamp flag, > > and all fgraph_ops sets this flag, skip recording calltime and rettime. > > > > Suggested-by: Jiri Olsa > > Signed-off-by: Masami Hiramatsu (Google) > > --- > > Changes in v9: > > - Newly added. > > --- > > include/linux/ftrace.h | 2 ++ > > kernel/trace/fgraph.c | 46 +++++++++++++++++++++++++++++++++++++++------- > > kernel/trace/fprobe.c | 1 + > > 3 files changed, 42 insertions(+), 7 deletions(-) > > > > diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h > > index d845a80a3d56..06fc7cbef897 100644 > > --- a/include/linux/ftrace.h > > +++ b/include/linux/ftrace.h > > @@ -1156,6 +1156,8 @@ struct fgraph_ops { > > struct ftrace_ops ops; /* for the hash lists */ > > void *private; > > int idx; > > + /* If skip_timestamp is true, this does not record timestamps. */ > > + bool skip_timestamp; > > }; > > > > void *fgraph_reserve_data(int idx, int size_bytes); > > diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c > > index 7556fbbae323..a5722537bb79 100644 > > --- a/kernel/trace/fgraph.c > > +++ b/kernel/trace/fgraph.c > > @@ -131,6 +131,7 @@ DEFINE_STATIC_KEY_FALSE(kill_ftrace_graph); > > int ftrace_graph_active; > > > > static struct fgraph_ops *fgraph_array[FGRAPH_ARRAY_SIZE]; > > +static bool fgraph_skip_timestamp; > > > > /* LRU index table for fgraph_array */ > > static int fgraph_lru_table[FGRAPH_ARRAY_SIZE]; > > @@ -475,7 +476,7 @@ void ftrace_graph_stop(void) > > static int > > ftrace_push_return_trace(unsigned long ret, unsigned long func, > > unsigned long frame_pointer, unsigned long *retp, > > - int fgraph_idx) > > + int fgraph_idx, bool skip_ts) > > { > > struct ftrace_ret_stack *ret_stack; > > unsigned long long calltime; > > @@ -498,8 +499,12 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, > > ret_stack = get_ret_stack(current, current->curr_ret_stack, &index); > > if (ret_stack && ret_stack->func == func && > > get_fgraph_type(current, index + FGRAPH_RET_INDEX) == FGRAPH_TYPE_BITMAP && > > - !is_fgraph_index_set(current, index + FGRAPH_RET_INDEX, fgraph_idx)) > > + !is_fgraph_index_set(current, index + FGRAPH_RET_INDEX, fgraph_idx)) { > > + /* If previous one skips calltime, update it. */ > > + if (!skip_ts && !ret_stack->calltime) > > + ret_stack->calltime = trace_clock_local(); > > return index + FGRAPH_RET_INDEX; > > + } > > > > val = (FGRAPH_TYPE_RESERVED << FGRAPH_TYPE_SHIFT) | FGRAPH_RET_INDEX; > > > > @@ -517,7 +522,10 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, > > return -EBUSY; > > } > > > > - calltime = trace_clock_local(); > > + if (skip_ts) > > would it be ok to add likely() here to keep the least-overhead code path linear? It's not "likely", but hmm, yes as you said. We can keep the least overhead. OK, let me add likely. Thank you, > > > + calltime = 0LL; > > + else > > + calltime = trace_clock_local(); > > > > index = READ_ONCE(current->curr_ret_stack); > > ret_stack = RET_STACK(current, index); > > @@ -601,7 +609,8 @@ int function_graph_enter_regs(unsigned long ret, unsigned long func, > > trace.func = func; > > trace.depth = ++current->curr_ret_depth; > > > > - index = ftrace_push_return_trace(ret, func, frame_pointer, retp, 0); > > + index = ftrace_push_return_trace(ret, func, frame_pointer, retp, 0, > > + fgraph_skip_timestamp); > > if (index < 0) > > goto out; > > > > @@ -654,7 +663,8 @@ int function_graph_enter_ops(unsigned long ret, unsigned long func, > > return -ENODEV; > > > > /* Use start for the distance to ret_stack (skipping over reserve) */ > > - index = ftrace_push_return_trace(ret, func, frame_pointer, retp, gops->idx); > > + index = ftrace_push_return_trace(ret, func, frame_pointer, retp, gops->idx, > > + gops->skip_timestamp); > > if (index < 0) > > return index; > > type = get_fgraph_type(current, index); > > @@ -732,6 +742,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret, > > *ret = ret_stack->ret; > > trace->func = ret_stack->func; > > trace->calltime = ret_stack->calltime; > > + trace->rettime = 0; > > trace->overrun = atomic_read(¤t->trace_overrun); > > trace->depth = current->curr_ret_depth; > > /* > > @@ -792,7 +803,6 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe > > return (unsigned long)panic; > > } > > > > - trace.rettime = trace_clock_local(); > > if (fregs) > > ftrace_regs_set_instruction_pointer(fregs, ret); > > > > @@ -808,6 +818,8 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe > > continue; > > if (gops == &fgraph_stub) > > continue; > > + if (!trace.rettime && !gops->skip_timestamp) > > In addition to the above, do you mind adding unlikely() here as well? > > > + trace.rettime = trace_clock_local(); > > > > gops->retfunc(&trace, gops, fregs); > > } > > [...] -- Masami Hiramatsu (Google)