Revision 2c9e18bdefb96b8d8ea591ac05cabd8e5a991d32 authored by Marco Danelutto on 28 October 2011, 20:34:56 UTC, committed by Roberto Di Cosmo on 07 November 2011, 20:51:23 UTC
Needs autoconf and support for different OSs.
1 parent cd664c1
Raw File
setcore.c
#include <stdio.h>
#include <unistd.h>
//#define _GNU_SOURCE             /* See feature_test_macros(7) */
#include <sched.h>
#include <errno.h>
#include <caml/mlvalues.h>

CAMLprim value setcore(value which) {
  int numCPU = sysconf( _SC_NPROCESSORS_ONLN );
  int w = Int_val(which) % numCPU; // stay in the space of existing cores
  cpu_set_t cpus;   
  int retcode; 
  fprintf(stderr,"pinning to cpu %d out of %d\n",w,numCPU);
  CPU_ZERO(&cpus); 
  CPU_SET (which,&cpus);
  retcode = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpus);
  if(retcode != 0) {
    fprintf(stderr,"error in pinning to cpu %d",w); 
  }
  return Val_unit;
}
back to top