| 93 | static THashMap<int, TCPUSetInfo> CPUSets; |
| 94 | |
| 95 | void BindToSocket(int n) { |
| 96 | TGuard<TMutex> gg(CPUSetsLock); |
| 97 | if (CPUSets.find(n) == CPUSets.end()) { |
| 98 | TCPUSetInfo& res = CPUSets[n]; |
| 99 | |
| 100 | bool foundCPU = false; |
| 101 | #ifdef _linux_ |
| 102 | for (int cpuId = 0; cpuId < TCPUSet::MAX_SIZE; ++cpuId) { |
| 103 | try { // I just wanna check if file exists, I don't want your stinking exceptions :/ |
| 104 | TIFStream f(Sprintf("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpuId).c_str()); |
| 105 | TString s; |
| 106 | if (f.ReadLine(s) && !s.empty()) { |
| 107 | //printf("cpu%d - %s\n", cpuId, s.c_str()); |
| 108 | int physCPU = atoi(s.c_str()); |
| 109 | if (physCPU == 0) { |
| 110 | res.IsOk = true; |
| 111 | res.CPUSet.Set(cpuId); |
| 112 | foundCPU = true; |
| 113 | } |
| 114 | } else { |
| 115 | break; |
| 116 | } |
| 117 | } catch (const TFileError&) { |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | #endif |
| 122 | if (!foundCPU && n == 0) { |
| 123 | for (int i = 0; i < 6; ++i) { |
| 124 | res.CPUSet.Set(i); |
| 125 | } |
| 126 | res.IsOk = true; |
| 127 | foundCPU = true; |
| 128 | } |
| 129 | } |
| 130 | { |
| 131 | TCPUSetInfo& cc = CPUSets[n]; |
| 132 | if (cc.IsOk) { |
| 133 | cc.CPUSet.SetAffinity(); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | } |