Source file
src/runtime/os_illumos.go
1
2
3
4
5 package runtime
6
7 import (
8 "unsafe"
9 )
10
11
12
13
14
15
16
17
18
19
20
21
22
23 var (
24 libc_getrctl,
25 libc_rctlblk_get_local_action,
26 libc_rctlblk_get_local_flags,
27 libc_rctlblk_get_value,
28 libc_rctlblk_size libcFunc
29 )
30
31
32
33 func getcpucap() uint64 {
34
35
36
37 const rblkmaxsize = 8 * 1024
38 if rctlblk_size() > rblkmaxsize {
39 return 0
40 }
41
42
43
44
45
46
47 name := []byte("zone.cpu-cap\x00")
48
49
50
51
52 var rblk0 [rblkmaxsize]byte
53 var rblk1 [rblkmaxsize]byte
54 rblk := &rblk0[0]
55 rblkprev := &rblk1[0]
56
57 var flag uint32 = _RCTL_FIRST
58 var capval uint64 = 0
59
60 for {
61 if getrctl(unsafe.Pointer(&name[0]), unsafe.Pointer(rblkprev), unsafe.Pointer(rblk), flag) != 0 {
62
63
64
65
66 break
67 }
68
69 lflags := rctlblk_get_local_flags(unsafe.Pointer(rblk))
70 action := rctlblk_get_local_action(unsafe.Pointer(rblk))
71 if (lflags&_RCTL_LOCAL_MAXIMAL) == 0 && action == _RCTL_LOCAL_DENY {
72
73
74 v := rctlblk_get_value(unsafe.Pointer(rblk))
75 if capval == 0 || capval > v {
76 capval = v
77 }
78 }
79
80
81 t := rblk
82 rblk = rblkprev
83 rblkprev = t
84 flag = _RCTL_NEXT
85 }
86
87 return capval
88 }
89
90 func getncpu() int32 {
91 n := int32(sysconf(__SC_NPROCESSORS_ONLN))
92 if n < 1 {
93 return 1
94 }
95
96 if cents := int32(getcpucap()); cents > 0 {
97
98
99
100 ncap := (cents + 99) / 100
101 if ncap < n {
102 return ncap
103 }
104 }
105
106 return n
107 }
108
109
110 func getrctl(controlname, oldbuf, newbuf unsafe.Pointer, flags uint32) uintptr {
111 return sysvicall4(&libc_getrctl, uintptr(controlname), uintptr(oldbuf), uintptr(newbuf), uintptr(flags))
112 }
113
114
115 func rctlblk_get_local_action(buf unsafe.Pointer) uintptr {
116 return sysvicall2(&libc_rctlblk_get_local_action, uintptr(buf), uintptr(0))
117 }
118
119
120 func rctlblk_get_local_flags(buf unsafe.Pointer) uintptr {
121 return sysvicall1(&libc_rctlblk_get_local_flags, uintptr(buf))
122 }
123
124
125 func rctlblk_get_value(buf unsafe.Pointer) uint64 {
126 return uint64(sysvicall1(&libc_rctlblk_get_value, uintptr(buf)))
127 }
128
129
130 func rctlblk_size() uintptr {
131 return sysvicall0(&libc_rctlblk_size)
132 }
133
View as plain text