Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp920309ybx; Thu, 7 Nov 2019 04:42:39 -0800 (PST) X-Google-Smtp-Source: APXvYqywz8UFCbBUxsuIfr7YOyD8DLU03j4Owk5ByRNil4QjLNnuYHWkDimqD967WKfFaM4+OxdF X-Received: by 2002:a17:906:fc13:: with SMTP id ov19mr2850701ejb.184.1573130559555; Thu, 07 Nov 2019 04:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573130559; cv=none; d=google.com; s=arc-20160816; b=Z5vcugN6zyTKLI07igZuEWw1SU1h+y0DJByT+k0belnTx0WJDmhph2mf9G3B92vPpv 6ltuveAoMt3wZaBvKVjycdSBrTTjNvYi1Y6h5pKM6B1ZUX3xrcIicpQqAqLjp2y+cx+q 5bml9WaXssNQZVf6jgA0/X4pMHYV3rVX+NLsIFaGW9Z2MGZCgs7ouhn/moIJCXpoPSIY 9F17eTCRmsDqNasuCaLDQaogzvcnKW9GIEqHob+Gv8KN9WfZ1Q0e0stEOujqakq82e5n boXu3wdEEvY3DMk6kFJbIxSA7HkMAMPdH/14ZV/lvAzmdSMcx3jYe41KUWT/nowNefVg ynTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=tfSuwBW5q0yo/zYTFEIdAhgskRNlV+a+Xs6aTFM5ZCQ=; b=u9G9hZwCNNkGuPPbMfMWT3nBF1gH1mqoy+l+IVoXgdd+GAdf0DiHJvc3OWj7vLEhVg xB4ARdBqzUKCBILlKoyxroqCS5sW+YK6DRHWtEhPnWuucZOoO2YDdkde/GxEj7W5BfSY /RwEBwe4IH0/T4EsusCd8eO/AcBzAcYZ5kkQ5MrUAXn4g1zNXw0GvOJxcBrYW0kziihK 0b9zUs6Lq8jDCLFjo6PwcdreQXg8kWaIAT7Ki0xLBrvHBX7tKEDQqfGPzCV6edqPeVXV 7+gtSQsHQeQm285nxBI3y76n/bm1QxKMtXBD8ace8wjAvm7+sufuDxCqC8SnApWiiExU 7sRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p21si1331215edc.305.2019.11.07.04.42.15; Thu, 07 Nov 2019 04:42:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388582AbfKGMkv (ORCPT + 99 others); Thu, 7 Nov 2019 07:40:51 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:47500 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388564AbfKGMku (ORCPT ); Thu, 7 Nov 2019 07:40:50 -0500 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iSh5j-0005IA-Kd; Thu, 07 Nov 2019 13:40:47 +0100 Date: Thu, 7 Nov 2019 13:40:47 +0100 (CET) From: Thomas Gleixner To: Peter Zijlstra cc: Jan Stancek , linux-kernel@vger.kernel.org, ltp@lists.linux.it, viro@zeniv.linux.org.uk, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, rfontana@redhat.com Subject: Re: [PATCH] kernel: use ktime_get_real_ts64() to calculate acct.ac_btime In-Reply-To: <20191107123224.GA6315@hirez.programming.kicks-ass.net> Message-ID: References: <20191107123224.GA6315@hirez.programming.kicks-ass.net> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Nov 2019, Peter Zijlstra wrote: > Lets start by saying this accounting stuff is terrible crap and it > deserves to fail and burn. No argument about that. > And what does btime want? As implemented it jumps around if you ask the > question twice with an adjtime() call or suspend in between. Of course, > if we take an actual CLOCK_REALTIME timestamp at fork() the value > doesn't change, but then it can be in the future (DST,adjtime()), which > is exactly the reason why CLOCK_REALTIME is absolute shit for timestamps > (logging, accounting, etc.). > > And your 'fix' is pretty terible too. Arguably ktime_get_seconds() wants > fixing for not having the ns accumulation and actually differing from > tv_sec, but now you accrue one source of ns while still disregarding > another (also, I friggin hate timespec, it's a terrible interface for > time). > > All in all, I'm tempted to just declare this stuff broken and -EWONTFIX, > but if we have to do something, something like the below is at least > internally consistent. Kinda :) > + mono = ktime_get_ns(); > + real = ktime_get_real_ns(); > + /* > + * Compute btime by subtracting the elapsed time from the current > + * CLOCK_REALTIME. > + * > + * XXX totally buggered, because it changes results across > + * adjtime() calls and suspend/resume. > + */ > + delta = mono - tsk->start_time; // elapsed in ns > + btime = real - delta; // real ns - elapsed ns > + do_div(btime, NSEC_PER_SEC); // truncated to seconds > + stats->ac_btime = btime; That has pretty much the same problem as just storing the CLOCK_REALTIME start time at fork and additionally it is wreckaged vs. suspend resume. So a CLOCK_REALTIME time stamp at fork would at least be correct vs. suspend resume. The same result is achieved by: boot = ktime_get_boot_ns(); delta = boot = tsk->real_start_time; Typing real_start_time makes me really cringe. Thanks, tglx