From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BD6BC433E1 for ; Tue, 18 Aug 2020 21:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B3DD20786 for ; Tue, 18 Aug 2020 21:11:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="eE6+s0Ne"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cS+RRI8Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbgHRVLu (ORCPT ); Tue, 18 Aug 2020 17:11:50 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:47029 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbgHRVLt (ORCPT ); Tue, 18 Aug 2020 17:11:49 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 88B7D5C0058; Tue, 18 Aug 2020 17:11:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 18 Aug 2020 17:11:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= mime-version:content-transfer-encoding:content-type:cc:subject :from:to:date:message-id:in-reply-to; s=fm1; bh=QS1MqSS+ObdNKAEI 9D/28OrqnncNLKCTH+R889x7y0w=; b=eE6+s0NefrdgthrnY3HyRbc+MFy1NM6+ URxCR6UymqcLO3UVrBEICYijCak4SGqIQfSHgomjnL2dnyADli6m/mkxux7NdJJP 1iuYnUaJX/r667IXl90KrelFbELZ9Iv8T2/buZkYvZJjOGhD7O09oP9hEChHb5C2 RWfJQZeBdBuzFiTkLi0ZhY1eLLPl//v4dqdyxE991Wv/p6K/lJD5VXQceovEPJas KeldrxadZXfzkQfodvku03qYdcls16MkfwCGr/V8XVPOZuiBUV8YTQq0CkYPIGS1 YbmfwsYvneFIVBrb6DmBwyRW+2rTiEPZVt1u3YZlqt8n/5QFMiPe1Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=QS1MqSS+ObdNKAEI9D/28OrqnncNLKCTH+R889x7y0w=; b=cS+RRI8Q g2/GCc+B5vogl/Qct7eXg7knS+R2MSFje7G9iY/JLCCqGlqs2TBR7kXiVF63xRJg PuInscrvW5ZZFYR3/1L5UfJrlBVuViqhcT0YcTom0KtV9dph3VuhKyjcGokcq9rM FmvCA2R5WH62i0qthG6MyuLKZIs2u2SstAX0Y/A0T73YYvfv1+HGWsJ74cy4oBeo THdet88UDIhXx1y3mNCCNY6WcOw2J/lxGEd4+myN0rwqoJ04c9Z0ekstfa3FIGqF ajh/K78BufW5QhDnHg+KVV1Bos4uOFptHmnDttocyh+cy6lL+PuVRLmYiTuOIZHv bu/44WP2oe8vDw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddtiedgudefkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdefhedmnecujfgurhepggfgtgfuhffvfffkjgesthhqredttddt jeenucfhrhhomhepfdffrghnihgvlhcuighufdcuoegugihusegugihuuhhurdighiiiqe enucggtffrrghtthgvrhhnpeejfefhudeffefhjedvvefhheduledtueejvedugedvjedv jeeljefggedtjeejveenucfkphepjeefrdelfedrvdegjedrudefgeenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdig hiii X-ME-Proxy: Received: from localhost (c-73-93-247-134.hsd1.ca.comcast.net [73.93.247.134]) by mail.messagingengine.com (Postfix) with ESMTPA id 1A71E3060067; Tue, 18 Aug 2020 17:11:47 -0400 (EDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Cc: "bpf" , "Networking" , , "Alexei Starovoitov" , "Daniel Borkmann" , "Martin Lau" , , Subject: Re: [PATCH] bpf: Add bpf_ktime_get_real_ns From: "Daniel Xu" To: "Andrii Nakryiko" , Date: Tue, 18 Aug 2020 13:50:48 -0700 Message-Id: In-Reply-To: Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Mon Jul 27, 2020 at 10:01 PM PDT, Andrii Nakryiko wrote: > On Mon, Jul 27, 2020 at 4:35 PM wrote: > > > > From: Ashkan Nikravesh > > > > The existing bpf helper functions to get timestamp return the time > > elapsed since system boot. This timestamp is not particularly useful > > where epoch timestamp is required or more than one server is involved > > and time sync is required. Instead, you want to use CLOCK_REALTIME, > > which provides epoch timestamp. > > Hence add bfp_ktime_get_real_ns() based around CLOCK_REALTIME. > > > > This doesn't seem like a good idea. With time-since-boot it's very > easy to translate timestamp into a real time on the host.=20 For bpftrace, we have a need to get millisecond-level precision on timestamps. bpf has nanosecond level precision via bpf_ktime_get[_boot]_ns(), but to the best of my knowledge userspace doesn't have a high precision boot timestamp. There's /proc/stat's btime, but that's second-level precision. There's also /proc/uptime which has millisecond-level precision but you need to make a second call to get current time. Between those two calls there could be some unknown delta. For millisecond we could probably get away with calculating a delta and warning on large delta but maybe one day we'll want microsecond-level precision. I'll probably put up a patch to add nanoseconds to btime (new field in /proc/stat) to see how it's received. But either this patch or my patch would work for bpftrace. [...] Thanks, Daniel