The cpu hz sensor is more accurate and updates faster than than the value
currently used for hw.cpuspeed. So return that value (scaled).

This doesn't set cpuspeed directly because the acpi does that and it's hard
to create a whole system of priority overrides. I think it's simpler and
maybe even better to track every value, and then return the best one
available.


Index: identcpu.c
===================================================================
RCS file: /home/cvs/src/sys/arch/amd64/amd64/identcpu.c,v
retrieving revision 1.124
diff -u -p -r1.124 identcpu.c
--- identcpu.c  26 Apr 2022 10:48:20 -0000      1.124
+++ identcpu.c  15 May 2022 00:15:39 -0000
@@ -64,6 +64,7 @@ void  cpu_check_vmm_cap(struct cpu_info *
 /* sysctl wants this. */
 char cpu_model[48];
 int cpuspeed;
+uint64_t sensorspeed;
 
 int amd64_has_xcrypt;
 #ifdef CRYPTO
@@ -244,6 +245,8 @@ int
 cpu_amd64speed(int *freq)
 {
        *freq = cpuspeed;
+       if (sensorspeed)
+               *freq = sensorspeed / 1000000000000ULL;
        return (0);
 }
 
@@ -337,6 +340,8 @@ cpu_hz_update_sensor(void *args)
                val = (adelta * 1000000) / mdelta * tsc_frequency;
                val = ((val + FREQ_50MHZ / 2) / FREQ_50MHZ) * FREQ_50MHZ; 
                ci->ci_hz_sensor.value = val;
+               if (CPU_IS_PRIMARY(ci))
+                       sensorspeed = val;
        }
 
        atomic_clearbits_int(&curproc->p_flag, P_CPUPEG);

Reply via email to