Skip to content

Commit

Permalink
check invalid topology
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyever committed Aug 10, 2023
1 parent 3f62c8d commit c99b2e5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/freebsd/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,27 @@ struct cpuinfo_freebsd_topology cpuinfo_freebsd_detect_topology(void) {
cpuinfo_log_error("failed to parse topology_spec:%s",
topology_spec);
free(topology_spec);
return topology;
goto fail;
}
free(topology_spec);
topology.cores = sysctl_int("kern.smp.cores");
if (topology.cores == 0) {
topology.packages = 0;
return topology;
goto fail;
}
if (topology.cores < topology.packages) {
goto fail;
}
topology.threads_per_core = sysctl_int("kern.smp.threads_per_core");
if (topology.threads_per_core == 0) {
topology.packages = 0;
return topology;
goto fail;
}
cpuinfo_log_debug("freebsd topology: packages = %d, cores = %d, "
"threads_per_core = %d",
topology.packages, topology.cores,
topology.threads_per_core);
topology.threads = topology.threads_per_core * topology.cores;
return topology;
fail:
topology.packages = 0;
return topology;
}

0 comments on commit c99b2e5

Please sign in to comment.