From owner-svn-src-all@FreeBSD.ORG Tue Sep 14 04:57:31 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3B54A106566B; Tue, 14 Sep 2010 04:57:31 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 10B8C8FC15; Tue, 14 Sep 2010 04:57:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o8E4vUI7068724; Tue, 14 Sep 2010 04:57:30 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8E4vUKM068723; Tue, 14 Sep 2010 04:57:30 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201009140457.o8E4vUKM068723@svn.freebsd.org> From: Alexander Motin Date: Tue, 14 Sep 2010 04:57:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212601 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Sep 2010 04:57:31 -0000 Author: mav Date: Tue Sep 14 04:57:30 2010 New Revision: 212601 URL: http://svn.freebsd.org/changeset/base/212601 Log: Replace spin lock with the set of atomics. It is impractical for one tc_ticktock() call to wait for another's completion -- just skip it. Modified: head/sys/kern/kern_clock.c Modified: head/sys/kern/kern_clock.c ============================================================================== --- head/sys/kern/kern_clock.c Tue Sep 14 04:48:04 2010 (r212600) +++ head/sys/kern/kern_clock.c Tue Sep 14 04:57:30 2010 (r212601) @@ -374,8 +374,7 @@ int ticks; int psratio; static DPCPU_DEFINE(int, pcputicks); /* Per-CPU version of ticks. */ -static struct mtx global_hardclock_mtx; -MTX_SYSINIT(global_hardclock_mtx, &global_hardclock_mtx, "ghc_mtx", MTX_SPIN); +static int global_hardclock_run = 0; /* * Initialize clock frequencies and start both clocks running. @@ -485,8 +484,10 @@ hardclock_anycpu(int cnt, int usermode) struct thread *td = curthread; struct proc *p = td->td_proc; int *t = DPCPU_PTR(pcputicks); - int flags; - int global, newticks; + int flags, global, newticks; +#ifdef SW_WATCHDOG + int i; +#endif /* SW_WATCHDOG */ /* * Update per-CPU and possibly global ticks values. @@ -535,19 +536,22 @@ hardclock_anycpu(int cnt, int usermode) callout_tick(); /* We are in charge to handle this tick duty. */ if (newticks > 0) { - mtx_lock_spin(&global_hardclock_mtx); - tc_ticktock(); + /* Dangerous and no need to call these things concurrently. */ + if (atomic_cmpset_acq_int(&global_hardclock_run, 0, 1)) { + tc_ticktock(); #ifdef DEVICE_POLLING - hardclock_device_poll(); /* This is very short and quick. */ + /* This is very short and quick. */ + hardclock_device_poll(); #endif /* DEVICE_POLLING */ + atomic_store_rel_int(&global_hardclock_run, 0); + } #ifdef SW_WATCHDOG if (watchdog_enabled > 0) { - watchdog_ticks -= newticks; - if (watchdog_ticks <= 0) + i = atomic_fetchadd_int(&watchdog_ticks, -newticks); + if (i > 0 && i <= newticks) watchdog_fire(); } #endif /* SW_WATCHDOG */ - mtx_unlock_spin(&global_hardclock_mtx); } if (curcpu == CPU_FIRST()) cpu_tick_calibration();