From owner-svn-src-head@freebsd.org Fri Sep 25 13:03:58 2015 Return-Path: Delivered-To: svn-src-head@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 3F934A0804E; Fri, 25 Sep 2015 13:03:58 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 304E31B16; Fri, 25 Sep 2015 13:03:58 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8PD3wjE038619; Fri, 25 Sep 2015 13:03:58 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8PD3wjh038618; Fri, 25 Sep 2015 13:03:58 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201509251303.t8PD3wjh038618@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 25 Sep 2015 13:03:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r288216 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Sep 2015 13:03:58 -0000 Author: kib Date: Fri Sep 25 13:03:57 2015 New Revision: 288216 URL: https://svnweb.freebsd.org/changeset/base/288216 Log: Use per-cpu values for base and last in tc_cpu_ticks(). The values are updated lockess, different CPUs write its own view of timecounter state. The critical section is done for safety, callers of tc_cpu_ticks() are supposed to already enter critical section, or to own a spinlock. The change fixes sporadical reports of too high values reported for the (W)CPU on platforms that do not provide cpu ticker and use tc_cpu_ticks(), in particular, arm*. Diagnosed and reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/sys/kern/kern_tc.c Modified: head/sys/kern/kern_tc.c ============================================================================== --- head/sys/kern/kern_tc.c Fri Sep 25 10:14:39 2015 (r288215) +++ head/sys/kern/kern_tc.c Fri Sep 25 13:03:57 2015 (r288216) @@ -1924,20 +1924,27 @@ SYSINIT(timecounter, SI_SUB_CLOCKS, SI_O static int cpu_tick_variable; static uint64_t cpu_tick_frequency; +static DPCPU_DEFINE(uint64_t, tc_cpu_ticks_base); +static DPCPU_DEFINE(unsigned, tc_cpu_ticks_last); + static uint64_t tc_cpu_ticks(void) { - static uint64_t base; - static unsigned last; - unsigned u; struct timecounter *tc; + uint64_t res, *base; + unsigned u, *last; + critical_enter(); + base = DPCPU_PTR(tc_cpu_ticks_base); + last = DPCPU_PTR(tc_cpu_ticks_last); tc = timehands->th_counter; u = tc->tc_get_timecount(tc) & tc->tc_counter_mask; - if (u < last) - base += (uint64_t)tc->tc_counter_mask + 1; - last = u; - return (u + base); + if (u < *last) + *base += (uint64_t)tc->tc_counter_mask + 1; + *last = u; + res = u + *base; + critical_exit(); + return (res); } void