Skip to content

Instantly share code, notes, and snippets.

@gonzopancho
Created March 30, 2015 07:45
Show Gist options
  • Save gonzopancho/52fcab834487491dd8b0 to your computer and use it in GitHub Desktop.
Save gonzopancho/52fcab834487491dd8b0 to your computer and use it in GitHub Desktop.
#include "Platform.h"
#include <stdio.h>
void testRDTSC ( void )
{
int64_t temp = rdtsc();
printf("%d",(int)temp);
}
#if defined(_MSC_VER)
#include <windows.h>
void SetAffinity ( int cpu )
{
SetProcessAffinityMask(GetCurrentProcess(),cpu);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
}
#elif __FreeBSD__
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/cpuset.h>
void
SetAffinity(int cpu)
{
cpuset_t mask;
unsigned int i;
fprintf(stdout, "SetAffinity called with arg %d\n", cpu);
CPU_ZERO(&mask);
i = 0;
do {
if (cpu & 1) {
CPU_SET(i, &mask);
}
i++;
cpu >>= 1;
} while (cpu);
if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset_t), &mask) == -1)
{
fprintf(stderr, "SetAffinity() failed. %s", strerror(errno));
}
}
#else
#include <sched.h>
void SetAffinity ( int /*cpu*/ )
{
#if !defined(__CYGWIN__) && !defined(__APPLE__)
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(2,&mask);
if( sched_setaffinity(0,sizeof(mask),&mask) == -1)
{
printf("WARNING: Could not set CPU affinity\n");
}
#endif
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment