diff --git a/src/TestConfig.cpp b/src/TestConfig.cpp index c2db3fad..bd28c65c 100644 --- a/src/TestConfig.cpp +++ b/src/TestConfig.cpp @@ -164,6 +164,16 @@ void GlobalTestConfig::parseCommandLine(int argc, char** argv){ // DFS affinity: traverse the topology tree in DFS pattern and pin threads // in the order of PUs found. +void GlobalTestConfig::extendAffinity(std::vector& aff){ + int ori_size = aff.size(); + if((int)aff.size()& aff, hwloc_obj_t obj){ if(obj->type==HWLOC_OBJ_PU){ aff.push_back(obj); @@ -177,6 +187,7 @@ void GlobalTestConfig::buildDFSAffinity_helper(std::vector& aff, hw void GlobalTestConfig::buildDFSAffinity(std::vector& aff){ buildDFSAffinity_helper(aff, hwloc_get_root_obj(topology)); + extendAffinity(aff); } // Default affinity: pin threads on PUs in the same core, then other cores in the socket, @@ -243,6 +254,7 @@ void GlobalTestConfig::buildDefaultAffinity(std::vector& aff){ aff.resize(0); buildDFSAffinity(aff); } + extendAffinity(aff); } // Single affinity: pin all threads to the same PU. @@ -257,6 +269,29 @@ void GlobalTestConfig::buildSingleAffinity_helper(std::vector& aff, } void GlobalTestConfig::buildSingleAffinity(std::vector& aff){ buildSingleAffinity_helper(aff,hwloc_get_root_obj(topology)); + extendAffinity(aff); +} + + +// Single socket affinity: put all threads to the same (first) socket. +// Follow default pattern within the socket. +void GlobalTestConfig::buildSingleSocketAffinity(std::vector& aff){ + hwloc_obj_t obj = hwloc_get_root_obj(topology); + while(obj->type < HWLOC_OBJ_SOCKET){ + obj = obj->children[0]; + } + buildDefaultAffinity_findAndBuildSockets(aff, obj); + extendAffinity(aff); +} + +// Single socket per-core affinity: single-socket version of PerCoreAffinity +void GlobalTestConfig::buildSingleSocketPerCoreAffinity(std::vector& aff, unsigned pu){ + hwloc_obj_t obj = hwloc_get_root_obj(topology); + while(obj->type < HWLOC_OBJ_SOCKET){ + obj = obj->children[0]; + } + buildPerCoreAffinity_helper(aff, pu, obj); + extendAffinity(aff); } // Per-core affinity: pin one thread to $pu$ pu (thread) of each core in the same socket, then go cross socket. @@ -274,6 +309,7 @@ void GlobalTestConfig::buildPerCoreAffinity_helper(std::vector& aff } void GlobalTestConfig::buildPerCoreAffinity(std::vector& aff, unsigned pu){ buildPerCoreAffinity_helper(aff,pu,hwloc_get_root_obj(topology)); + extendAffinity(aff); } // Interleaved affinity: first thread of each socket, then the second thread, and so on. @@ -304,6 +340,7 @@ void GlobalTestConfig::buildInterleavedAffinity(std::vector& aff){ aff.push_back(thread_per_package[j][i]); } } + extendAffinity(aff); } // Interleaved per-core affinity: the $pu$ thread of first core in each socket, then @@ -334,6 +371,7 @@ void GlobalTestConfig::buildInterleavedPerCoreAffinity(std::vector& aff.push_back(thread_per_package[j][i]); } } + extendAffinity(aff); } // reference: @@ -348,15 +386,14 @@ void GlobalTestConfig::buildAffinity(std::vector& aff){ else if (affinity.compare("interleaved")==0){ buildInterleavedAffinity(aff); } + else if (affinity.compare("singleSocket")==0){ + buildSingleSocketAffinity(aff); + } else{ buildDefaultAffinity(aff); } - if((int)aff.size()= task_num); } diff --git a/src/TestConfig.hpp b/src/TestConfig.hpp index 6333c309..fa3df6e8 100644 --- a/src/TestConfig.hpp +++ b/src/TestConfig.hpp @@ -92,6 +92,7 @@ class GlobalTestConfig{ // TODO: make a general-purpose unit of this. void buildPerCoreAffinity(std::vector& aff, unsigned pu); void buildInterleavedPerCoreAffinity(std::vector& aff, unsigned pu); + void buildSingleSocketPerCoreAffinity(std::vector& aff, unsigned pu); // Run the test void runTest(); @@ -103,6 +104,7 @@ class GlobalTestConfig{ // // a bunch needed because of recursive traversal of topologies. void buildAffinity(std::vector& aff); private: + void extendAffinity(std::vector& aff); void buildDFSAffinity_helper(std::vector& aff, hwloc_obj_t obj); void buildDFSAffinity(std::vector& aff); int buildDefaultAffinity_findCoresInSocket(std::vector& aff, hwloc_obj_t obj, std::vector* cores); @@ -111,6 +113,7 @@ class GlobalTestConfig{ void buildDefaultAffinity(std::vector& aff); void buildSingleAffinity_helper(std::vector& aff, hwloc_obj_t obj); void buildSingleAffinity(std::vector& aff); + void buildSingleSocketAffinity(std::vector& aff); void buildPerCoreAffinity_helper(std::vector& aff, unsigned pu, hwloc_obj_t obj); void buildInterleavedAffinity(std::vector& aff); void buildInterleavedAffinity_traversePackages(std::vector>& thread_per_package, hwloc_obj_t obj); @@ -153,4 +156,4 @@ class Test{ }; -#endif \ No newline at end of file +#endif