-
Notifications
You must be signed in to change notification settings - Fork 8
/
getcpu_linux_amd64_test.go
62 lines (55 loc) · 1.12 KB
/
getcpu_linux_amd64_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package numa
import (
"runtime"
"sync"
"testing"
"github.com/stretchr/testify/require"
)
func TestGetNodeAndCPU2(t *testing.T) {
if !Available() || !fastway {
t.Skip("not available or fastwway")
}
var (
nodem = NewBitmask(NodePossibleCount())
mu sync.Mutex
wg sync.WaitGroup
assert = require.New(t)
)
fastway = false
defer func() { fastway = true }()
cpum := make([]Bitmask, NodePossibleCount())
for i := 0; i < len(cpum); i++ {
cpum[i] = NewBitmask(CPUPossibleCount())
}
for i := 0; i < CPUCount(); i++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 100; i++ {
cpu, node := GetCPUAndNode()
mu.Lock()
cpum[node].Set(cpu, true)
nodem.Set(node, true)
mu.Unlock()
runtime.Gosched()
}
}()
}
wg.Wait()
nmask := NodeMask()
for i := 0; i < nodem.Len(); i++ {
if !nodem.Get(i) {
continue
}
assert.True(nmask.Get(i), "node %d", i)
cpumask, err := NodeToCPUMask(i)
assert.NoError(err)
cmask := cpum[i]
for j := 0; j < cmask.Len(); j++ {
if !cmask.Get(j) {
continue
}
assert.True(cpumask.Get(j), "cpu %d @ node %d", j, i)
}
}
}