Skip to content

Commit

Permalink
should fix it. there are not the same number of cores visible when we…
Browse files Browse the repository at this point in the history
… are in a cgroup
  • Loading branch information
rschoene committed Jun 26, 2024
1 parent 856064d commit db75521
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions include/firestarter/Environment/CPUTopology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class CPUTopology {
virtual ~CPUTopology();

unsigned numThreads() const {
return _numThreadsPerCore * _numCoresPerPackage * _numPackages;
return _numThreadsPerCore * _numCoresTotal;
}
unsigned maxNumThreads() const;
unsigned numThreadsPerCore() const { return _numThreadsPerCore; }
unsigned numCoresPerPackage() const { return _numCoresPerPackage; }
unsigned numCoresTotal() const { return _numCoresTotal; }
unsigned numPackages() const { return _numPackages; }

std::string const &architecture() const { return _architecture; }
Expand Down Expand Up @@ -72,7 +72,7 @@ class CPUTopology {
static std::stringstream getFileAsStream(std::string const &filePath);

unsigned _numThreadsPerCore;
unsigned _numCoresPerPackage;
unsigned _numCoresTotal;
unsigned _numPackages;
std::string _architecture;
std::string _vendor = "";
Expand Down
23 changes: 16 additions & 7 deletions src/firestarter/Environment/CPUTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ using namespace firestarter::environment;
std::ostream &CPUTopology::print(std::ostream &stream) const {
stream << " system summary:\n"
<< " number of processors: " << this->numPackages() << "\n"
<< " number of cores per package: " << this->numCoresPerPackage()
<< "\n"
<< " number of cores (total)): " << this->numCoresTotal() << "\n"
<< " (this includes only cores in the cgroup)" << "\n"
<< " number of threads per core: " << this->numThreadsPerCore()
<< "\n"
<< " total number of threads: " << this->numThreads() << "\n\n";
Expand Down Expand Up @@ -152,7 +152,6 @@ CPUTopology::CPUTopology(std::string architecture)
if (nr_cpukinds > 1) {
log::warn() << "FIRESTARTER detected a hybrid CPU set-up";
}

// get number of packages
int depth = hwloc_get_type_depth(this->topology, HWLOC_OBJ_PACKAGE);

Expand All @@ -163,16 +162,22 @@ CPUTopology::CPUTopology(std::string architecture)
this->_numPackages = hwloc_get_nbobjs_by_depth(this->topology, depth);
}

log::trace() << "Number of Packages:" << this->_numPackages;
// get number of cores per package
depth = hwloc_get_type_depth(this->topology, HWLOC_OBJ_CORE);

if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
this->_numCoresPerPackage = 1;
this->_numCoresTotal = 1;
log::warn() << "Could not get number of cores";
} else {
this->_numCoresPerPackage =
hwloc_get_nbobjs_by_depth(this->topology, depth) / this->_numPackages;
this->_numCoresTotal =
hwloc_get_nbobjs_by_depth(this->topology, depth);
if ( this->_numCoresTotal == 0 ) {
log::warn() << "Could not get number of cores";
this->_numCoresTotal = 1;
}
}
log::trace() << "Number of Cores:" << this->_numCoresTotal;

// get number of threads per core
depth = hwloc_get_type_depth(this->topology, HWLOC_OBJ_PU);
Expand All @@ -183,7 +188,11 @@ CPUTopology::CPUTopology(std::string architecture)
} else {
this->_numThreadsPerCore =
hwloc_get_nbobjs_by_depth(this->topology, depth) /
this->_numCoresPerPackage / this->_numPackages;
this->_numCoresTotal ;
if ( this->_numThreadsPerCore == 0 ) {
log::warn() << "Could not get number of threads per core";
this->_numThreadsPerCore = 1;
}
}

// get vendor, processor name and clockrate for linux
Expand Down

0 comments on commit db75521

Please sign in to comment.