Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp526273pja; Thu, 7 Nov 2019 00:57:28 -0800 (PST) X-Google-Smtp-Source: APXvYqx137hlSjZ2yTz5mz8jI9WUuyNDxjEGJXdVX4EDETm0wW/bqQq3I04b1LtkTiTUhrIxrGQG X-Received: by 2002:a17:906:2ccc:: with SMTP id r12mr1770963ejr.249.1573117048352; Thu, 07 Nov 2019 00:57:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573117048; cv=none; d=google.com; s=arc-20160816; b=iPuoywpWLjhpdhELkfB525AlDu4Q8En3hKAR8NHGwpAEYm/jo1wAkt4q9yLjp3Iyhw +r7M1c0VWwE+VUXWL1+ol6765tsIk53KXZ/fh8aH/XxhIsWRRZAyHoTC3yJ57WJlhA9c W30fGrsLns5O9Hr2l7s67k44OxlPGcwxFlAwCqOdu942wojGWLcQKWabpM1u374BiRiO 6CCIE/kWBRawG4kKWgM7+EZjjXhurVltkOtBVcEXytynAiy/UsNlM4DrvTUHHZxwzU47 zInHcaJ3oJcum1OgooDPGUS6r+tfCg4cpa98J+TfSvpcjHpERWBVYlbT1O2Cm+EOAHkq +Psw== 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=xjzfOenTxj3uRKz65Wb5s3pTOcz0qCsadpByU8Hl4v4=; b=rCXuhpwJezdP7gSBeoLkvYb8ffIvriLjwIZRoabBsVa8yIuUYTuEbytOI7Tt/FXrCL JLE48Y8+N2bpkXqZ623yfvMZjYJW5Nn41kVYRYDImuVEMjxn9NdVl4qIVZLnZ7Uafg/c 5/nUjeSr0ZkBKelItgAVshgSilHRx+nbL+foouuSNkDHGZRsWfmoiMJ6k5SJRn8wCnwc yONBR63INWKSHmq2WdX7H5BuHAF8yxOW17la1S0VwKRU2mbpuSZoaZVdVwpAx6vdLihV lGQcACREAanFQP5XRFeI3BVqYSoIlZVXOF8Tk6y2N/Vtp8dPFusdZ+Xn7evMkwir/P9/ tyeQ== 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 b20si851601edx.344.2019.11.07.00.57.04; Thu, 07 Nov 2019 00:57:28 -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 S1733289AbfKGI4Y (ORCPT + 99 others); Thu, 7 Nov 2019 03:56:24 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:46606 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727693AbfKGI4X (ORCPT ); Thu, 7 Nov 2019 03:56:23 -0500 Received: from p5b06da22.dip0.t-ipconnect.de ([91.6.218.34] helo=nanos.glx-home) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iSdaU-0001WD-DO; Thu, 07 Nov 2019 09:56:18 +0100 Date: Thu, 7 Nov 2019 09:56:12 +0100 (CET) From: Thomas Gleixner To: Jan Stancek cc: LKML , ltp@lists.linux.it, Al Viro , Greg KH , Peter Zijlstra , Ingo Molnar Subject: Re: [PATCH] kernel: use ktime_get_real_ts64() to calculate acct.ac_btime In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jan, The subsystem prefix for acct is surely not 'kernel.'. Try: git log --oneline kernel/acct.c On Sat, 2 Nov 2019, Jan Stancek wrote: > diff --git a/kernel/acct.c b/kernel/acct.c > index 81f9831a7859..991c898160cd 100644 > --- a/kernel/acct.c > +++ b/kernel/acct.c > @@ -417,6 +417,7 @@ static void fill_ac(acct_t *ac) > struct pacct_struct *pacct = ¤t->signal->pacct; > u64 elapsed, run_time; > struct tty_struct *tty; > + struct timespec64 ts; > > /* > * Fill the accounting struct with the needed info as recorded > @@ -448,7 +449,8 @@ static void fill_ac(acct_t *ac) > } > #endif > do_div(elapsed, AHZ); > - ac->ac_btime = get_seconds() - elapsed; > + ktime_get_real_ts64(&ts); > + ac->ac_btime = ts.tv_sec - elapsed; So the calculation goes like this: runtime = ktime_get_ns() - current->...->start_time; elapsed = ns_to_ahz(runtime) elapsed /= AHZ -> runtime in seconds And then you retrieve the current wall time and just use the seconds portion for building the delta. That still can fail in corner cases when the runtime to seconds conversion does not have truncation in the conversions and the timespec nanoseconds part is close to 1e9. There is another issue related to suspend. If the system suspends then runtime is accurate vs. clock MONOTONIC, but the offset between clock MONOTONIC and clock REALTIME is not longer the same due to the suspend/resume which has the same issue as what you are trying to solve because runtime = totaltime - time_in_suspend so your ac_btime will be off by time_in_suspend. Something like this should work: runtime = ktime_get_ns() - current->...->start_time; .... runtime_boot = ktime_get_boot_ns() - current->...->real_start_time; start_ns = ktime_get_real_ns() - runtime_boot; start_s = startns / NSEC_PER_SEC; current->...->real_start_time is clearly a misnomer as it suggests CLOCK_REALTIME at first sight ... But it would be way simpler just to store the CLOCK_REALTIME start time along with BOOT and MONOTONIC and just get rid of all these horrible calculations which are bound to be wrong. Peter? Thanks, tglx