| 207 | } |
| 208 | |
| 209 | static cbm_system_info_t detect_system_linux(void) { |
| 210 | cbm_system_info_t info; |
| 211 | memset(&info, 0, sizeof(info)); |
| 212 | |
| 213 | /* Host fallbacks. */ |
| 214 | long nprocs = sysconf(_SC_NPROCESSORS_ONLN); |
| 215 | int host_cpus = nprocs > 0 ? (int)nprocs : DEFAULT_CORES; |
| 216 | |
| 217 | size_t host_ram = 0; |
| 218 | struct sysinfo si; |
| 219 | if (sysinfo(&si) == 0) { |
| 220 | host_ram = (size_t)si.totalram * (size_t)si.mem_unit; |
| 221 | } |
| 222 | |
| 223 | /* Cgroup-aware overrides. min(cgroup, host) defends against |
| 224 | * mis-mounted cgroups that report values larger than the host. */ |
| 225 | int cg_cpus = cbm_detect_cgroup_cpus("/sys/fs/cgroup"); |
| 226 | info.total_cores = (cg_cpus > 0 && cg_cpus < host_cpus) ? cg_cpus : host_cpus; |
| 227 | info.perf_cores = info.total_cores; /* Linux doesn't distinguish P/E */ |
| 228 | |
| 229 | size_t cg_ram = cbm_detect_cgroup_mem("/sys/fs/cgroup"); |
| 230 | info.total_ram = (cg_ram > 0 && (host_ram == 0 || cg_ram < host_ram)) ? cg_ram : host_ram; |
| 231 | |
| 232 | return info; |
| 233 | } |
| 234 | |
| 235 | #endif /* __APPLE__ / BSD / Linux */ |
| 236 |
no test coverage detected