14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/IProcessorAffinityService.h"
17#include "arcane/utils/ITraceMng.h"
18#include "arcane/utils/OStringStream.h"
20#include "arcane/FactoryService.h"
21#include "arcane/AbstractService.h"
62 void printInfos()
override;
63 String cpuSetString()
override;
64 void bindThread(Int32
cpu)
override;
66 Int32 numberOfCore()
override;
67 Int32 numberOfSocket()
override;
68 Int32 numberOfProcessingUnit()
override;
90_internal_hwloc_obj_snprintf(
char *
string,
size_t size,
91 hwloc_obj *l,
const char *_indexprefix,
int verbose)
93 const char *indexprefix = _indexprefix ? _indexprefix :
"#";
94 char os_index[12] =
"";
99 if (l->os_index != (
unsigned) -1) {
100 std::snprintf(os_index, 12,
"%s%u", indexprefix, l->os_index);
103 hwloc_obj_type_snprintf(type,
sizeof(type), l, verbose);
104 attrlen = hwloc_obj_attr_snprintf(attr,
sizeof(attr), l,
" ", verbose);
107 return std::snprintf(
string, size,
"%s%s(%s)", type, os_index, attr);
109 return std::snprintf(
string, size,
"%s%s", type, os_index);
116void HWLocProcessorAffinityService::
117_outputTopology(hwloc_obj_t l, hwloc_obj_t parent,
int i,OStringStream& ostr)
119 const char * indexprefix =
"#";
121 if (parent && parent->arity == 1 && hwloc_bitmap_isequal(l->cpuset, parent->cpuset)) {
126 info() << ostr.str();
129 for(
int z=0; z<2*i; ++ z)
133 _internal_hwloc_obj_snprintf (line,
sizeof(line)-1, l, indexprefix, 0);
135 unsigned int arity = l->arity;
136 if (arity!=0 || (!i && !arity)){
137 for(
unsigned int x=0; x<arity; ++x ){
138 _outputTopology (l->children[x], l, i,ostr);
146void HWLocProcessorAffinityService::
153 info() <<
"Getting hardware architecture.";
154 int err = hwloc_topology_init (&m_topology);
156 info() <<
"Error in hwloc_topology_init r=" << err;
159 unsigned long flags = 0;
160 hwloc_topology_set_flags(m_topology, flags);
161 err = hwloc_topology_load (m_topology);
163 info() <<
"Error in hwloc_topology_load r=" << err;
172String HWLocProcessorAffinityService::
175 hwloc_bitmap_t new_cpuset = hwloc_bitmap_alloc();
176 hwloc_get_cpubind(m_topology, new_cpuset, 0 | HWLOC_CPUBIND_THREAD);
178 hwloc_bitmap_snprintf(result_s,
sizeof(result_s)-1,new_cpuset);
179 String s{StringView(result_s)};
181 hwloc_bitmap_free(new_cpuset);
188void HWLocProcessorAffinityService::
193 _outputTopology (hwloc_get_root_obj(m_topology), NULL, 0,ostrf);
194 info() << ostrf.str();
195 info() <<
"Cpuset: " << cpuSetString();
201void HWLocProcessorAffinityService::
235int HWLocProcessorAffinityService::
251int HWLocProcessorAffinityService::
254 return _numberOf(HWLOC_OBJ_CORE);
262int HWLocProcessorAffinityService::
265 return _numberOf(HWLOC_OBJ_SOCKET);
272int HWLocProcessorAffinityService::
273numberOfProcessingUnit()
275 return _numberOf(HWLOC_OBJ_PU);
282 IProcessorAffinityService,
#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass, ainterface, aname)
Enregistre un service de fabrique pour la classe aclass.
Classe de base d'un service.
void build() override
Construction de niveau build du service.
Interface d'un service de de trace des appels de fonctions.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Flot de sortie lié à une String.
Structure contenant les informations pour créer un service.
Chaîne de caractères unicode.