From owner-svn-src-head@freebsd.org Mon May 7 15:24:04 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69EEAFB4AC2; Mon, 7 May 2018 15:24:04 +0000 (UTC) (envelope-from gallatin@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 159AB81019; Mon, 7 May 2018 15:24:04 +0000 (UTC) (envelope-from gallatin@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB4171D22F; Mon, 7 May 2018 15:24:03 +0000 (UTC) (envelope-from gallatin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w47FO3vD045056; Mon, 7 May 2018 15:24:03 GMT (envelope-from gallatin@FreeBSD.org) Received: (from gallatin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w47FO3c6045055; Mon, 7 May 2018 15:24:03 GMT (envelope-from gallatin@FreeBSD.org) Message-Id: <201805071524.w47FO3c6045055@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gallatin set sender to gallatin@FreeBSD.org using -f From: Andrew Gallatin Date: Mon, 7 May 2018 15:24:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r333325 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: gallatin X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 333325 X-SVN-Commit-Repository: base 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.25 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: Mon, 07 May 2018 15:24:04 -0000 Author: gallatin Date: Mon May 7 15:24:03 2018 New Revision: 333325 URL: https://svnweb.freebsd.org/changeset/base/333325 Log: Boost thread priority while changing CPU frequency Boost the priority of user-space threads when they set their affinity to a core to adjust its frequency. This avoids a situation where a CPU bound kernel thread with the same affinity is running on a down-clocked core, and will "block" powerd from up-clocking the core until the kernel thread yields. This can lead to poor perfomance, and to things potentially getting stuck on Giant. Reviewed by: kib (imp reviewed earlier version) Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D15246 Modified: head/sys/kern/kern_cpu.c Modified: head/sys/kern/kern_cpu.c ============================================================================== --- head/sys/kern/kern_cpu.c Mon May 7 15:07:28 2018 (r333324) +++ head/sys/kern/kern_cpu.c Mon May 7 15:24:03 2018 (r333325) @@ -245,6 +245,7 @@ cf_set_method(device_t dev, const struct cf_level *lev struct cf_saved_freq *saved_freq, *curr_freq; struct pcpu *pc; int error, i; + u_char pri; sc = device_get_softc(dev); error = 0; @@ -333,6 +334,8 @@ cf_set_method(device_t dev, const struct cf_level *lev /* Bind to the target CPU before switching. */ pc = cpu_get_pcpu(set->dev); thread_lock(curthread); + pri = curthread->td_priority; + sched_prio(curthread, PRI_MIN); sched_bind(curthread, pc->pc_cpuid); thread_unlock(curthread); CF_DEBUG("setting abs freq %d on %s (cpu %d)\n", set->freq, @@ -340,6 +343,7 @@ cf_set_method(device_t dev, const struct cf_level *lev error = CPUFREQ_DRV_SET(set->dev, set); thread_lock(curthread); sched_unbind(curthread); + sched_prio(curthread, pri); thread_unlock(curthread); if (error) { goto out; @@ -357,6 +361,8 @@ cf_set_method(device_t dev, const struct cf_level *lev /* Bind to the target CPU before switching. */ pc = cpu_get_pcpu(set->dev); thread_lock(curthread); + pri = curthread->td_priority; + sched_prio(curthread, PRI_MIN); sched_bind(curthread, pc->pc_cpuid); thread_unlock(curthread); CF_DEBUG("setting rel freq %d on %s (cpu %d)\n", set->freq, @@ -364,6 +370,7 @@ cf_set_method(device_t dev, const struct cf_level *lev error = CPUFREQ_DRV_SET(set->dev, set); thread_lock(curthread); sched_unbind(curthread); + sched_prio(curthread, pri); thread_unlock(curthread); if (error) { /* XXX Back out any successful setting? */