How to enable CPU turbo mode on FreeBSD?

Pierre-Luc Drouin pldrouin at pldrouin.net
Fri Sep 11 15:05:32 UTC 2009


Bruce Cran wrote:
> On Thu, 10 Sep 2009 20:57:32 -0400
> Pierre-Luc Drouin <pldrouin at pldrouin.net> wrote:
>
>   
>> Hi,
>>
>> I have an overclocked i7 920 CPU for which I have enabled Turbo Mode
>> in the BIOS (21x multiplier). The base clock is set at 190 MHz, so
>> the CPU frequency with Turbo mode activated should be 3990 MHz.
>> However the maximum value FreeBSD amd64 shows for the CPU frequency
>> in dmesg and sysctl is 3790 MHz. How can I enable the Turbo Mode?
>>
>> CPU: Intel(R) Core(TM) i7 CPU         920  @ 2.67GHz (3790.52-MHz 
>> K8-class CPU)
>>
>> machdep.acpi_timer_freq: 3579545
>> machdep.tsc_freq: 3790522507
>> machdep.i8254_freq: 1193182
>> dev.cpu.0.freq: 349
>> dev.cpu.0.freq_levels: 2793/130000 2443/113750 2094/97500 1745/81250 
>> 1396/65000 1047/48750 698/32500 349/16250
>>     
>
> You may be able to use the cpuctl kernel module with sysutils/x86info
> to see when the CPUs are using Turbo mode. I haven't had any success
> yet but I know in Windows the System control panel reported the 2.66GHz
> CPU running at 2.83GHz without me doing anything, so I guess FreeBSD
> should be doing the same.
>
>   
So I managed to test that the Turbo Mode is working. Here is how I 
tested it, if it can be useful for other people in the future:

I wrote this very dumb program in C (compiled using gcc -lpthread -o 
test test.c):
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>

int main(int nargs, char* args[]);
void* floop(void* args);
long long int niters;

int main(int nargs, char* args[])
{
 int nthrs;
 int i;
 pthread_t *threads;
 --nargs;
 ++args;

 if(nargs!=2) {
   fprintf(stderr,"Usage: loop nthreads niters\n");
   return 1;
 }
 sscanf(args[0],"%i",&nthrs);
 sscanf(args[1],"%lli",&niters);

 printf("Number of threads: %i\n",nthrs);
 printf("Number of iterations: %lli\n",niters);

 threads=(pthread_t*)malloc(nthrs*sizeof(pthread_t));

 for(i=nthrs-1; i>=0; --i) pthread_create(threads+i,NULL,floop,NULL);

 for(i=nthrs-1; i>=0; --i) pthread_join(threads[i],NULL);

 free(threads);
 return 0;
}

void* floop(void* args){
 long long int i;
 for(i=niters-1; i>=0; --i);
 return NULL;
}

I ran it with 8 threads and 150 000 000 000 iterations/threads using
time ./test 8 150000000000

I got a user time of 1827.24 sec with turbo and 1908.69 sec without, a 
4.5% speed difference, which is pretty close to the expected 5% (1-21/20 
where 21/20 is the ratio of CPU multipliers with and without turbo for 
my i7 920 CPU)


More information about the freebsd-stable mailing list