URI: 
       util.c - libzahl - big integer library
  HTML git clone git://git.suckless.org/libzahl
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       util.c (798B)
       ---
            1 #define COMPILING_UTIL_C
            2 #include "util.h"
            3 
            4 
            5 char timebuf[512];
            6 unsigned long long int freq;
            7 
            8 
            9 void
           10 benchmark_init(void)
           11 {
           12 #if defined(__linux__) && defined(USE_RDTSC)
           13         cpu_set_t cpuset;
           14         FILE *f;
           15         char *line = 0;
           16         size_t size = 0;
           17         char path[PATH_MAX];
           18         CPU_ZERO(&cpuset);
           19         CPU_SET(USE_CPU, &cpuset);
           20         sched_setaffinity(getpid(), sizeof(cpuset), &cpuset);
           21         sprintf(path, "/sys/devices/system/cpu/cpu%i/cpufreq/cpuinfo_max_freq", USE_CPU);
           22         f = fopen(path, "r");
           23         if (getline(&line, &size, f) < 0)
           24                 abort();
           25         fclose(f);
           26         freq = strtoull(line, 0, 10);
           27         free(line);
           28 
           29 #elif defined(__linux__)
           30         cpu_set_t cpuset;
           31         CPU_ZERO(&cpuset);
           32         CPU_SET(USE_CPU, &cpuset);
           33         sched_setaffinity(getpid(), sizeof(cpuset), &cpuset);
           34 
           35 #else
           36         fprintf(stderr, "WARNING: Don't know how to set CPU affinity.\n");
           37 
           38 #endif
           39 }