File tree Expand file tree Collapse file tree 5 files changed +43
-2
lines changed Expand file tree Collapse file tree 5 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -239,7 +239,7 @@ jobs:
239
239
- name : install packages
240
240
run : |
241
241
./alpine.sh apk update
242
- ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja
242
+ ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja util-linux
243
243
244
244
- name : avoid d8 tests (jsvu is not compatible with alpine)
245
245
run : |
Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ jobs:
135
135
- name : install packages
136
136
run : |
137
137
./alpine.sh apk update
138
- ./alpine.sh apk add build-base cmake git python3 clang ninja py3-pip
138
+ ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja util-linux
139
139
140
140
- name : avoid d8 tests (jsvu is not compatible with alpine)
141
141
run : |
Original file line number Diff line number Diff line change 20
20
#include < iostream>
21
21
#include < string>
22
22
23
+ #ifdef __linux__
24
+ #include < sched.h> // For sched_getaffinity
25
+ #endif
26
+
23
27
#include " compiler-support.h"
28
+ #include " support/debug.h"
24
29
#include " threads.h"
25
30
#include " utilities.h"
26
31
27
32
// debugging tools
28
33
34
+ // DEBUG_TYPE is for BYN_TRACE macro. This tracing can be enabled at runtime
35
+ #define DEBUG_TYPE " threads"
36
+
37
+ // BINARYEN_THREAD_DEBUG is a build-time setting for detailed thread tracing
29
38
#ifdef BINARYEN_THREAD_DEBUG
30
39
static std::mutex debug;
31
40
#define DEBUG_THREAD (x ) \
@@ -145,9 +154,24 @@ size_t ThreadPool::getNumCores() {
145
154
return 1 ;
146
155
#else
147
156
size_t num = std::max (1U , std::thread::hardware_concurrency ());
157
+ #ifdef __linux__
158
+ // On linux we can do better since we can get the number of CPU that are
159
+ // actually usable by the current process.
160
+ cpu_set_t cpu_set;
161
+ CPU_ZERO (&cpu_set);
162
+ if (sched_getaffinity (0 , sizeof (cpu_set), &cpu_set) == 0 ) {
163
+ num = 0 ;
164
+ for (int i = 0 ; i < CPU_SETSIZE; i++) {
165
+ if (CPU_ISSET (i, &cpu_set)) {
166
+ num++;
167
+ }
168
+ }
169
+ }
170
+ #endif
148
171
if (getenv (" BINARYEN_CORES" )) {
149
172
num = std::stoi (getenv (" BINARYEN_CORES" ));
150
173
}
174
+ BYN_TRACE (" getNumCores: " << num << " \n " );
151
175
return num;
152
176
#endif
153
177
}
Original file line number Diff line number Diff line change 1
1
import os
2
+ import sys
2
3
import lit .formats
3
4
4
5
config .name = "Binaryen lit tests"
26
27
python = sys .executable .replace ('\\ ' , '/' )
27
28
config .substitutions .append ((tool , python + ' ' + tool_file ))
28
29
30
+ if 'linux' in sys .platform :
31
+ config .available_features .add ('linux' )
32
+
29
33
# Finds the given executable 'program' in PATH.
30
34
# Operates like the Unix tool 'which'.
31
35
# This is similar to script/test/shared.py, but does not use binaryen_root, and
Original file line number Diff line number Diff line change
1
+ ;; REQUIRES: linux
2
+ ;; Test that getNumCores honors thread affinity on linux
3
+
4
+ (module
5
+ (func $a )
6
+ )
7
+
8
+ ;; RUN: taskset -c 0 wasm-opt -O1 --debug=threads %s 2>&1 | filecheck %s
9
+ ;; RUN: taskset -c 0,2 wasm-opt -O1 --debug=threads %s 2>&1 | filecheck %s --check-prefix=TWO
10
+
11
+ ;; CHECK: getNumCores: 1
12
+
13
+ ;; TWO: getNumCores: 2
You can’t perform that action at this time.
0 commit comments