forked from spddl/GoInterruptPolicy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
114 lines (96 loc) · 2.51 KB
/
init.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"log"
"strconv"
"time"
"golang.org/x/sys/windows/registry"
)
type Device struct {
Idata DevInfoData
reg registry.Key
IrqPolicy int32
DeviceDesc string
DeviceIDs []string
DevObjName string
Driver string
LocationInformation string
FriendlyName string
LastChange time.Time
// AffinityPolicy
DevicePolicy uint32
DevicePriority uint32
AssignmentSetOverride Bits
// MessageSignaledInterruptProperties
MsiSupported uint32
MessageNumberLimit uint32
MaxMSILimit uint32
InterruptTypeMap Bits
}
const (
// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/interrupt-affinity-and-priority
IrqPolicyMachineDefault = iota // 0
IrqPolicyAllCloseProcessors // 1
IrqPolicyOneCloseProcessor // 2
IrqPolicyAllProcessorsInMachine // 3
IrqPolicySpecifiedProcessors // 4
IrqPolicySpreadMessagesAcrossAllProcessors // 5
)
type Bits uint64
var CPUMap map[Bits]string
var CPUArray []string
var CPUBits []Bits
var InterruptTypeMap = map[Bits]string{
0: "unknown",
1: "LineBased",
2: "Msi",
4: "MsiX",
}
var sysInfo SystemInfo
var handle DevInfo
const ZeroBit = Bits(0)
func Set(b, flag Bits) Bits { return b | flag }
func Clear(b, flag Bits) Bits { return b &^ flag }
func Toggle(b, flag Bits) Bits { return b ^ flag }
func Has(b, flag Bits) bool { return b&flag != 0 }
// https://gist.github.com/chiro-hiro/2674626cebbcb5a676355b7aaac4972d
func i64tob(val uint64) []byte {
r := make([]byte, 8)
for i := uint64(0); i < 8; i++ {
r[i] = byte((val >> (i * 8)) & 0xff)
}
return r
}
func btoi64(val []byte) uint64 {
r := uint64(0)
for i := uint64(0); i < 8; i++ {
r |= uint64(val[i]) << (8 * i)
}
return r
}
func btoi32(val []byte) uint32 {
r := uint32(0)
for i := uint32(0); i < 4; i++ {
r |= uint32(val[i]) << (8 * i)
}
return r
}
func btoi16(val []byte) uint16 {
r := uint16(0)
for i := uint16(0); i < 2; i++ {
r |= uint16(val[i]) << (8 * i)
}
return r
}
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
sysInfo = GetSystemInfo()
CPUMap = make(map[Bits]string, sysInfo.NumberOfProcessors)
var index Bits = 1
for i := 0; i < int(sysInfo.NumberOfProcessors); i++ {
indexString := strconv.Itoa(i)
CPUMap[index] = indexString
CPUArray = append(CPUArray, indexString)
CPUBits = append(CPUBits, index)
index *= 2
}
}