--- torque-3.0.4/src/resmom/linux/cpuset.c.orig 2011-07-12 16:07:28.000000000 -0600 +++ torque-3.0.4/src/resmom/linux/cpuset.c 2012-04-24 17:56:57.596835662 -0600 @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -31,14 +32,16 @@ #ifndef SUCCESS #define SUCCESS 1 #endif /* SUCCESS */ +#ifndef MAXCPUSETSTRSIZE +#define MAXCPUSETSTRSIZE 4095 /* kernel VFS limit */ +#endif /* MAXCPUSETSTRSIZE */ + #ifdef NUMA_SUPPORT extern numanode numa_nodes[]; extern int num_numa_nodes; #endif /* NUMA_SUPPORT */ -extern long system_ncpus; - /* FIXME: TODO: TTORQUECPUSET_PATH, enabling cpuset support, and correct error * checking need a run-time config */ @@ -58,6 +61,10 @@ int get_cpuset_strings(job *pjob,char *,char *); int create_vnodesets(job *,char *path,char *,mode_t); int init_jobset(char *,job *,mode_t,char *); +int compare_int (const void * a, const void * b) + { + return ( *(int*)a - *(int*)b ); + } /* end private functions */ @@ -882,6 +889,8 @@ int ratio = 0; char tmpStr[MAXPATHLEN]; int numa_index; + int *cpu; + int last; #ifdef NUMA_SUPPORT numanode *numa_tmp; @@ -904,6 +913,7 @@ } } + cpu = (int *)malloc((pjob->ji_numvnod)*sizeof(int)); for (j = 0;j < pjob->ji_numvnod;++j, np++) { char *dash = strchr(np->vn_host->hn_host,'-'); @@ -924,9 +934,6 @@ numa_index = 0; } - if (CpuStr[0] != '\0') - strcat(CpuStr, ","); - #ifdef NUMA_SUPPORT numa_tmp = numa_nodes + numa_index; cpu_index = np->vn_index + numa_tmp->cpu_offset; @@ -936,9 +943,7 @@ cpu_index = np->vn_index; #endif /* NUMA_SUPPORT */ - sprintf(tmpStr, "%d", cpu_index); - - strcat(CpuStr, tmpStr); + cpu[j] = cpu_index; #ifdef NUMA_SUPPORT sprintf(tmpStr,"%d",mem_index); @@ -953,6 +958,48 @@ #endif } + qsort(cpu, pjob->ji_numvnod, sizeof(int), compare_int); /* sort cpu array */ + + sprintf(tmpStr, "%d", cpu[0]); + strcat(CpuStr, tmpStr); + last = cpu[0]; /* last cpuid written to CpuStr */ + for (j = 1; j < pjob->ji_numvnod; ++j) + { + if (cpu[j] == cpu[j-1] + 1) continue; + if (last == cpu[j-1]) + { + sprintf(tmpStr, ",%d", cpu[j]); + } + else + { + sprintf(tmpStr, "-%d,%d", cpu[j-1], cpu[j]); + } + if (strlen(tmpStr) + strlen(CpuStr) > MAXCPUSETSTRSIZE) + { + sprintf(log_buffer, + "maximum length for list of cpus reached at cpuid: %d\n", cpu[j]); + log_err(-1, id, log_buffer); + free(cpu); + return(FAILURE); + } + strcat(CpuStr, tmpStr); + last = cpu[j]; + } + if (last != cpu[pjob->ji_numvnod - 1]) + { + sprintf(tmpStr, "-%d", cpu[pjob->ji_numvnod - 1]); + if (strlen(tmpStr) + strlen(CpuStr) > MAXCPUSETSTRSIZE) + { + sprintf(log_buffer, + "maximum length for list of cpus reached at cpuid: %d\n", + cpu[pjob->ji_numvnod - 1]); + log_err(-1, id, log_buffer); + free(cpu); + return(FAILURE); + } + strcat(CpuStr, tmpStr); + } + if (LOGLEVEL >= 7) { sprintf(log_buffer, @@ -961,6 +1008,7 @@ log_ext(-1, id, log_buffer, LOG_DEBUG); } + free(cpu); return(SUCCESS); } @@ -1181,10 +1229,10 @@ { FILE *fd; char *id = "add_cpus_to_jobset"; - char cpusbuf[MAXPATHLEN+1]; + char cpusbuf[MAXCPUSETSTRSIZE]; char tmppath[MAXPATHLEN+1]; #ifdef NUMA_SUPPORT - char memsbuf[MAXPATHLEN+1]; + char memsbuf[MAXCPUSETSTRSIZE]; #endif /* end NUMA_SUPPORT */ if ((pjob == NULL) || @@ -1193,7 +1241,6 @@ return(FAILURE); } - /* Make the string defining the CPUs to add into the jobset */ #ifdef NUMA_SUPPORT get_cpuset_strings(pjob,cpusbuf,memsbuf); #else