From owner-freebsd-current@freebsd.org Fri Jun 3 17:18:17 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 316B9B699AF for ; Fri, 3 Jun 2016 17:18:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A541C1245; Fri, 3 Jun 2016 17:18:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u53HI9t0098921 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Fri, 3 Jun 2016 20:18:10 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u53HI9t0098921 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u53HI9QL098920; Fri, 3 Jun 2016 20:18:09 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 3 Jun 2016 20:18:09 +0300 From: Konstantin Belousov To: Maxim Sobolev Cc: FreeBSD Current Subject: Re: CLOCK_MONOTONIC / CLOCK_UPTIME is not really monotonic between threads Message-ID: <20160603171809.GX38613@kib.kiev.ua> References: <20160603050628.GV38613@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jun 2016 17:18:17 -0000 On Fri, Jun 03, 2016 at 08:04:29AM -0700, Maxim Sobolev wrote: > Konstantin, > > Thanks for taking your time looking into it and sorry for somewhat messy > problem report. I've been trying to fix that problem all day yesterday > thinking it's just application logic that is broken and indeed has been > able to find some bigger issues that were obscuring this one. But it got > very frustrating when the bug popped out anew at a seemingly lower level > now. The issue that triggered this is in some high level python code. Which > makes it quite difficult to narrow and isolate. There is still slight > chance that it's something about threading within the python that screws > this up somehow, however I don't quite see how that could lead to a > consistent result that is just off by few hundred microseconds and not in > some random garbage. > > So, I take from you message, that high level > clock_gettime(CLOCK_MONOTONIC*) is supposed to be monotonic with respect to > the wall time even when called in different threads? I always though it is, > but was not 100% sure about that and wanted to confirm it before I dive > deeper into this and spend more time writing a test case to expose this. Yes, CLOCK_MONOTONIC should be monotonic across all processors. Until the time travel is made possible, of course. > The test case you gave me is interesting, but somewhat low-level. What I > would do if it comes to it, is to make something that uses pthreads and > plain clock_gettime(2). Should not be too difficult to reproduce if it's > real issue. The test I give you verifies clock_gettime() in several threads going backward. > > P.S. I've also tried kern.timecounter.fast_gettime=0, made no difference. > Assuming it does not take a reboot to test it. Neither does > switching kern.timecounter.hardware, I've tested TSC-low(1000) > ACPI-fast(900) HPET(950) i8254(0), all are the same. I am almost sure this is app-level issue. To make me confident, run the test I provided.