Browse Source

Merge pull request #1230 from martin-frbg/rhel5

Add sched_getcpu implementation for pre-2.6 glibc
tags/v0.2.20^2
Martin Kroeker GitHub 8 years ago
parent
commit
3db2adf872
1 changed files with 19 additions and 2 deletions
  1. +19
    -2
      driver/others/init.c

+ 19
- 2
driver/others/init.c View File

@@ -354,6 +354,24 @@ static int numa_check(void) {
return common -> num_nodes;
}

#if defined(__GLIBC_PREREQ)
#if !__GLIBC_PREREQ(2, 6)
int sched_getcpu(void)
{
int cpu;
FILE *fp = NULL;
if ( (fp = fopen("/proc/self/stat", "r")) == NULL)
return -1;
if ( fscanf( fp, "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%d", &cpu) != 1) {
fclose (fp);
return -1;
}
fclose (fp);
return(cpu);
}
#endif
#endif

static void numa_mapping(void) {

int node, cpu, core;
@@ -808,7 +826,6 @@ void gotoblas_affinity_init(void) {
common -> shmid = pshmid;

if (common -> magic != SH_MAGIC) {

#ifdef DEBUG
fprintf(stderr, "Shared Memory Initialization.\n");
#endif
@@ -830,7 +847,7 @@ void gotoblas_affinity_init(void) {
if (common -> num_nodes > 1) numa_mapping();

common -> final_num_procs = 0;
for(i = 0; i < common -> avail_count; i++) common -> final_num_procs += rcount(common -> avail[i]) + 1; //Make the max cpu number.
for(i = 0; i < common -> avail_count; i++) common -> final_num_procs += rcount(common -> avail[i]) + 1; //Make the max cpu number.

for (cpu = 0; cpu < common -> final_num_procs; cpu ++) common -> cpu_use[cpu] = 0;



Loading…
Cancel
Save