From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (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 D4CA512B93 for ; Tue, 19 Nov 2024 14:46:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732027571; cv=none; b=hEcbDpbZRjJucqlC8qMJm96VePEO1+lz+WzVAdAFpKwrb3FyfwIPX9MCiaW/EvmE1P7N8wRwcq7A9pOGTp5ItETOxiW2614dqFLqqHCVkZgMIttrl/eZICKIHxENqnceDC7nhKvx13/ilT15KOH1vm4/J+iRO/FSzrlOLNnHYfQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732027571; c=relaxed/simple; bh=SSIKxmB2fh1W69s26nybQf6B+XQvQkwxPHdKhXyUFK8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hgmopEcT/AG58ktqUHnyib0Q1J78ChDXFPFoDC2Jra5Nw2Wnk8UlvgP4nmkLKpqCRTy9MyihI7hd3cfQOykFJArMzKtItz0oLQ2/hd6OcD63awISk7VirZtn5eWoIEQszNata4b1F1eWb/HBBAx8hj+TrbLniP09w0mIJ0AkNJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tqzdF9pW; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tqzdF9pW" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1732027561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FF/T4hhTCAKYsTlyXmjfOHtqpoESmMEYBoYdcHTjVxo=; b=tqzdF9pW1OALLcKZA9JQwyYaNmPmHSWppFHMEO6brUcSikR/JK2fE/6Qe/d7GP/PLIz2I+ cD4KTsQtz4VLfAJzYl0njvPlh8JvDZetYEvbYMnSTGj4mffZPbj1ILXBkokLDsVuQGBNdw nxRTbFSnhGtiJnS8O0YgqsKE3dkWEPI= Date: Tue, 19 Nov 2024 06:45:57 -0800 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v7 4/4] selftests/bpf: add usage example for cpu cycles kfuncs To: Peter Zijlstra Cc: Borislav Petkov , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Thomas Gleixner , Yonghong Song , Mykola Lysenko , x86@kernel.org, bpf@vger.kernel.org, Martin KaFai Lau References: <20241118185245.1065000-1-vadfed@meta.com> <20241118185245.1065000-5-vadfed@meta.com> <20241119114714.GD2328@noisy.programming.kicks-ass.net> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vadim Fedorenko In-Reply-To: <20241119114714.GD2328@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 19/11/2024 03:47, Peter Zijlstra wrote: > On Mon, Nov 18, 2024 at 10:52:45AM -0800, Vadim Fedorenko wrote: > >> +int bpf_cpu_cycles(void) >> +{ >> + struct bpf_pidns_info pidns; >> + __u64 start; >> + >> + start = bpf_get_cpu_cycles(); >> + bpf_get_ns_current_pid_tgid(0, 0, &pidns, sizeof(struct bpf_pidns_info)); >> + cycles = bpf_get_cpu_cycles() - start; >> + ns = bpf_cpu_cycles_to_ns(cycles); >> + return 0; >> +} > > Oh, the intent is to use that cycles_to_ns() on deltas. That wasn't at > all clear. Yep, that's the main use case, it was discussed in the previous versions of the patchset. > > Anyway, the above has more problems than just bad naming. TSC is > constant and not affected by DVFS, so depending on the DVFS state of > things your function will return wildly different readings. Why should I care about DVFS? The use case is to measure the time spent in some code. If we replace it with bpf_ktime_get_ns(), it will also be affected by DVFS, and it's fine. We will be able to see the difference for different DVFS states. > Why do you think you need this?