From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751056AbdAYPlI (ORCPT ); Wed, 25 Jan 2017 10:41:08 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55628 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750711AbdAYPlG (ORCPT ); Wed, 25 Jan 2017 10:41:06 -0500 Date: Wed, 25 Jan 2017 16:40:54 +0100 From: Martin Schwidefsky To: Frederic Weisbecker Cc: LKML , Tony Luck , Wanpeng Li , Peter Zijlstra , Michael Ellerman , Heiko Carstens , Benjamin Herrenschmidt , Thomas Gleixner , Paul Mackerras , Ingo Molnar , Fenghua Yu , Rik van Riel , Stanislaw Gruszka Subject: Re: [PATCH 37/37] s390: Prevent from cputime leaks In-Reply-To: <20170125152518.GA3302@lerouge> References: <1485109213-8561-1-git-send-email-fweisbec@gmail.com> <1485109213-8561-38-git-send-email-fweisbec@gmail.com> <20170123104456.74cb2ef3@mschwideX1> <20170125152518.GA3302@lerouge> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17012515-0040-0000-0000-0000033A61C1 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17012515-0041-0000-0000-00001EACFE38 Message-Id: <20170125164054.3b0d9bcf@mschwideX1> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-01-25_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701250150 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 25 Jan 2017 16:25:20 +0100 Frederic Weisbecker wrote: > On Mon, Jan 23, 2017 at 10:44:56AM +0100, Martin Schwidefsky wrote: > > On Sun, 22 Jan 2017 19:20:13 +0100 > > Frederic Weisbecker wrote: > > > > > The s390 clock has a higher granularity than nanoseconds. 1 nanosec > > > equals 4.096 in s390 cputime_t. Therefore we leak a remainder while > > > flushing the cputime through cputime_to_nsecs(). > > > > > > For more precision, make sure we keep that remainder on cputime > > > accumulators for later accounting. > > > > > > Reported-by: Martin Schwidefsky > > > Cc: Benjamin Herrenschmidt > > > Cc: Paul Mackerras > > > Cc: Michael Ellerman > > > Cc: Heiko Carstens > > > Cc: Martin Schwidefsky > > > Cc: Tony Luck > > > Cc: Fenghua Yu > > > Cc: Peter Zijlstra > > > Cc: Rik van Riel > > > Cc: Thomas Gleixner > > > Cc: Ingo Molnar > > > Cc: Stanislaw Gruszka > > > Cc: Wanpeng Li > > > Signed-off-by: Frederic Weisbecker > > > > NAK. Good intention but the patch is just broken. with 36 of the 37 > > patches applied all looks good but the last one completely breaks the > > accounting for s390. This is from an idle system: > > > > top - 10:39:33 up 0 min, 1 user, load average: 0,00, 0,00, 0,00 > > Tasks: 106 total, 1 running, 105 sleeping, 0 stopped, 0 zombie > > %Cpu0 : 8,9 us, 21,6 sy, 0,0 ni, 0,0 id, 0,0 wa, 10,8 hi, 4,3 si, 54,4 st > > %Cpu1 : 0,0 us, 23,5 sy, 0,0 ni, 0,0 id, 0,0 wa, 19,0 hi, 13,1 si, 44,3 st > > %Cpu2 : 0,0 us, 30,3 sy, 0,0 ni, 0,0 id, 0,0 wa, 14,7 hi, 14,8 si, 40,2 st > > KiB Mem : 1009304 total, 818808 free, 57284 used, 133212 buff/cache > > KiB Swap: 1048556 total, 1048556 free, 0 used. 917356 avail Mem > > Oh ok. I must have done something wrong. > > > > > There is another issue that affects precision, there is no s390 specific > > version of cputime_to_nsecs. The generic version uses cputime_to_usecs > > and mulitplies by 1000 to get nano-seconds. That already looses precision. > > That's right. And that's the point of this patch. I'm not sure we can have a > more precise version of cputime_to_nsecs() if 1 nsec == 4.096 cputime_t I am thinking about a version that does the calculation (cputime * 1000) >> 12 in several steps, like this nsecs = (((((cputime * 5) >> 3) * 5) >> 3) * 5) >> 3 To multiply with 5 is a shift by 2 and an add. In total that would gives us 6 shifts and 3 adds for the conversion. -- blue skies, Martin. "Reality continues to ruin my life." - Calvin.