| 49 | |
| 50 | #if TS_USE_HWLOC |
| 51 | hwloc_obj_type_t |
| 52 | thread_affinity() |
| 53 | { |
| 54 | hwloc_obj_type_t obj_type = HWLOC_OBJ_MACHINE; |
| 55 | char const *obj_name = nullptr; |
| 56 | |
| 57 | switch (affinity) { |
| 58 | case 3: { |
| 59 | // assign threads to real cores |
| 60 | obj_type = HWLOC_OBJ_CORE; |
| 61 | obj_name = "Core"; |
| 62 | break; |
| 63 | } |
| 64 | case 1: { |
| 65 | // assign threads to NUMA nodes (often 1:1 with sockets) |
| 66 | obj_type = HWLOC_OBJ_NODE; |
| 67 | obj_name = "NUMA Node"; |
| 68 | if (hwloc_get_nbobjs_by_type(ink_get_topology(), obj_type) > 0) { |
| 69 | break; |
| 70 | } |
| 71 | [[fallthrough]]; |
| 72 | } |
| 73 | case 2: { |
| 74 | // assign threads to sockets |
| 75 | obj_type = HWLOC_OBJ_SOCKET; |
| 76 | obj_name = "Socket"; |
| 77 | break; |
| 78 | } |
| 79 | case 4: { |
| 80 | // assign threads to logical processing units |
| 81 | #if HAVE_HWLOC_OBJ_PU |
| 82 | // Older versions of libhwloc (eg. Ubuntu 10.04) don't have HWLOC_OBJ_PU. |
| 83 | obj_type = HWLOC_OBJ_PU; |
| 84 | obj_name = "Logical Processor"; |
| 85 | break; |
| 86 | #endif // HAVE_HWLOC_OBJ_PU |
| 87 | [[fallthrough]]; |
| 88 | } |
| 89 | default: // assign threads to the machine as a whole (a level below SYSTEM) |
| 90 | obj_type = HWLOC_OBJ_MACHINE; |
| 91 | obj_name = "Machine"; |
| 92 | } |
| 93 | |
| 94 | if (debug_enabled) { |
| 95 | std::cout << "thread affinity type = " << obj_name << " (" << affinity << ")" << std::endl; |
| 96 | } |
| 97 | |
| 98 | return obj_type; |
| 99 | } |
| 100 | #endif // TS_USE_HWLOC |
| 101 | |
| 102 | void * |
no test coverage detected