Changeset 1709 in kBuild
- Timestamp:
- Sep 2, 2008 8:02:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/main.c
r1701 r1709 47 47 # include <fcntl.h> 48 48 #endif 49 50 #ifdef KMK /* for get_online_cpu_count */ 51 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 52 # include <sys/sysctl.h> 53 # endif 54 # ifdef __OS2__ 55 # define INCL_BASE 56 # include <os2.h> 57 # endif 58 #endif /* KMK*/ 49 59 50 60 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) … … 358 368 -I DIRECTORY, --include-dir=DIRECTORY\n\ 359 369 Search DIRECTORY for included makefiles.\n"), 370 #ifdef KMK 371 N_("\ 372 -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.\n\ 373 The default is the number of active CPUs.\n"), 374 #else 360 375 N_("\ 361 376 -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.\n"), 377 #endif 362 378 N_("\ 363 379 -k, --keep-going Keep going when some targets can't be made.\n"), … … 1104 1120 #endif /* WINDOWS32 */ 1105 1121 1122 #ifdef KMK 1123 /* Determins the number of CPUs that are currently online. 1124 This is used to setup the default number of job slots. */ 1125 static int 1126 get_online_cpu_count(void) 1127 { 1128 # ifdef WINDOWS32 1129 /* Windows: Count the active CPUs. */ 1130 int cpus, i; 1131 SYSTEM_INFO si; 1132 GetSystemInfo(&si); 1133 for (i = cpus = 0; i < sizeof(si.dwActiveProcessorMask) * 8; i++) 1134 { 1135 if (si.dwActiveProcessorMask & 1) 1136 cpus++; 1137 si.dwActiveProcessorMask >>= 1; 1138 } 1139 return cpus ? cpus : 1; 1140 1141 # elif defined(__OS2__) 1142 /* OS/2: Count the active CPUs. */ 1143 int cpus i, j; 1144 MPAFFINITY mp; 1145 if (DosQueryThreadAffinity(AFNTY_SYSTEM, &mp)) 1146 return 1; 1147 for (j = cpus = 0; j < sizeof(mp.mask) / sizeof(mp.mask[0]); j++) 1148 for (i = 0; i < 32; i++) 1149 if (mp.mask[j] & (1UL << i)) 1150 cpus++; 1151 return cpus ? cpus : 1; 1152 1153 # else 1154 /* UNIX like systems, try sysconf and sysctl. */ 1155 int cpus = -1; 1156 # if defined(CTL_HW) 1157 int mib[2]; 1158 size_t sz; 1159 # endif 1160 1161 # ifdef _SC_NPROCESSORS_ONLN 1162 cpus = sysconf(_SC_NPROCESSORS_ONLN); 1163 if (cpus >= 1) 1164 return cpus; 1165 cpus = -1; 1166 # endif 1167 1168 # if defined(CTL_HW) 1169 # ifdef HW_AVAILCPU 1170 sz = sizeof(cpus); 1171 mib[0] = CTL_HW; 1172 mib[1] = HW_AVAILCPU; 1173 if (!sysctl(mib, 2, &cpus, &sz, NULL, 0) 1174 && cpus >= 1) 1175 return cpus; 1176 cpus = -1; 1177 # endif /* HW_AVAILCPU */ 1178 1179 sz = sizeof(cpus); 1180 mib[0] = CTL_HW; 1181 mib[1] = HW_NCPU; 1182 if (!sysctl(mib, 2, &cpus, &sz, NULL, 0) 1183 && cpus >= 1) 1184 return cpus; 1185 cpus = -1; 1186 # endif /* CTL_HW */ 1187 1188 /* no idea / failure, just return 1. */ 1189 return 1; 1190 # endif 1191 } 1192 #endif /* KMK */ 1193 1106 1194 #ifdef __MSDOS__ 1107 1195 static void … … 1420 1508 o_default, f_append, 0); 1421 1509 #endif 1510 1511 #ifdef KMK 1512 /* Initialize the default number of jobs to the cpu/core/smt count. */ 1513 default_job_slots = job_slots = get_online_cpu_count (); 1514 #endif /* KMK */ 1422 1515 1423 1516 /* Read in variables from the environment. It is important that this be
Note:
See TracChangeset
for help on using the changeset viewer.