Date: Fri, 13 Aug 2021 01:56:03 GMT From: Alexander Motin <mav@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 6004eaaf0fc4 - stable/12 - coretemp(4): Switch to smp_rendezvous_cpus(). Message-ID: <202108130156.17D1u3tj025217@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=6004eaaf0fc4f0e7af1cfec335f78e372937d4c4 commit 6004eaaf0fc4f0e7af1cfec335f78e372937d4c4 Author: Alexander Motin <mav@FreeBSD.org> AuthorDate: 2021-07-30 03:16:22 +0000 Commit: Alexander Motin <mav@FreeBSD.org> CommitDate: 2021-08-13 01:55:55 +0000 coretemp(4): Switch to smp_rendezvous_cpus(). Use of smp_rendezvous_cpus() instead of sched_bind() allows to not block indefinitely if target CPU is running some thread with higher priority, while all we need is single rdmsr/wrmsr instruction call. I guess it should also be much cheaper than full thread migration. MFC after: 2 weeks Sponsored by: iXsystems, Inc. (cherry picked from commit 74f80bc1af2ffd56ec290f610c80e46f768731a0) --- sys/dev/coretemp/coretemp.c | 59 ++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/sys/dev/coretemp/coretemp.c b/sys/dev/coretemp/coretemp.c index 8b9fc3b82350..b4f3fb7700f5 100644 --- a/sys/dev/coretemp/coretemp.c +++ b/sys/dev/coretemp/coretemp.c @@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$"); #include <sys/kernel.h> #include <sys/sysctl.h> #include <sys/proc.h> /* for curthread */ -#include <sys/sched.h> +#include <sys/smp.h> #include <machine/specialreg.h> #include <machine/cpufunc.h> @@ -308,14 +308,32 @@ coretemp_detach(device_t dev) return (0); } +struct coretemp_args { + u_int msr; + uint64_t val; +}; + +static void +coretemp_rdmsr(void *arg) +{ + struct coretemp_args *args = arg; + + args->val = rdmsr(args->msr); +} + +static void +coretemp_wrmsr(void *arg) +{ + struct coretemp_args *args = arg; + + wrmsr(args->msr, args->val); +} + static uint64_t coretemp_get_thermal_msr(int cpu) { - uint64_t msr; - - thread_lock(curthread); - sched_bind(curthread, cpu); - thread_unlock(curthread); + struct coretemp_args args; + cpuset_t cpus; /* * The digital temperature reading is located at bit 16 @@ -327,27 +345,24 @@ coretemp_get_thermal_msr(int cpu) * The temperature is computed by subtracting the temperature * reading by Tj(max). */ - msr = rdmsr(MSR_THERM_STATUS); - - thread_lock(curthread); - sched_unbind(curthread); - thread_unlock(curthread); - - return (msr); + args.msr = MSR_THERM_STATUS; + CPU_SETOF(cpu, &cpus); + smp_rendezvous_cpus(cpus, smp_no_rendezvous_barrier, coretemp_rdmsr, + smp_no_rendezvous_barrier, &args); + return (args.val); } static void coretemp_clear_thermal_msr(int cpu) { - thread_lock(curthread); - sched_bind(curthread, cpu); - thread_unlock(curthread); - - wrmsr(MSR_THERM_STATUS, 0); - - thread_lock(curthread); - sched_unbind(curthread); - thread_unlock(curthread); + struct coretemp_args args; + cpuset_t cpus; + + args.msr = MSR_THERM_STATUS; + args.val = 0; + CPU_SETOF(cpu, &cpus); + smp_rendezvous_cpus(cpus, smp_no_rendezvous_barrier, coretemp_wrmsr, + smp_no_rendezvous_barrier, &args); } static int
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108130156.17D1u3tj025217>