aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2021-07-30 03:16:22 +0000
committerAlexander Motin <mav@FreeBSD.org>2021-08-13 01:48:17 +0000
commit7eb023696a7db1d66a811756b81e0cc7d617cc23 (patch)
treeb5f0684fb8ff1cb9a1d4ce33f643d7ef82740623
parentb41b86b65f10ccaa8cce8cc11a030ad464b654c0 (diff)
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)
-rw-r--r--sys/dev/coretemp/coretemp.c57
1 files changed, 36 insertions, 21 deletions
diff --git a/sys/dev/coretemp/coretemp.c b/sys/dev/coretemp/coretemp.c
index 884ed6309f0e..53a2434254f6 100644
--- a/sys/dev/coretemp/coretemp.c
+++ b/sys/dev/coretemp/coretemp.c
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/proc.h> /* for curthread */
-#include <sys/sched.h>
+#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
@@ -310,14 +310,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
@@ -329,27 +347,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);
+ struct coretemp_args args;
+ cpuset_t cpus;
- thread_lock(curthread);
- sched_unbind(curthread);
- thread_unlock(curthread);
+ 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