MCPcopy Create free account
hub / github.com/catboost/catboost / BindToSocket

Function BindToSocket

library/cpp/netliba/v12/cpu_affinity.cpp:95–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 == n) {
110 res.IsOk = true;
111 res.CPUSet.Set(cpuId);
112 foundCPU = true;
113 }
114 } else {
115 break;
116 }
117 } catch (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}

Callers 4

SessionLevelTestFunction · 0.70
ExecServerThreadMethod · 0.70
ThreadFuncMethod · 0.70
ExecServerThreadMethod · 0.70

Calls 8

SprintfFunction · 0.85
findMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45
ReadLineMethod · 0.45
emptyMethod · 0.45
SetMethod · 0.45
SetAffinityMethod · 0.45

Tested by 1

SessionLevelTestFunction · 0.56