18
18
package client
19
19
20
20
import (
21
+ "flag"
21
22
"fmt"
22
23
"time"
23
24
@@ -28,8 +29,13 @@ import (
28
29
const (
29
30
// defaultSevGuestDevicePath is the platform's usual device path to the SEV guest.
30
31
defaultSevGuestDevicePath = "/dev/sev-guest"
31
- throttleDuration = 2 * time .Second
32
- burstMax = 2
32
+ )
33
+
34
+ // These flags should not be needed for long term health of the project as the Linux kernel
35
+ // catches up with throttling-awareness.
36
+ var (
37
+ throttleDuration = flag .Duration ("self_throttle_duration" , 2 * time .Second , "Rate-limit library-initiated device commands to this duration" )
38
+ burstMax = flag .Int ("self_throttle_burst" , 1 , "Rate-limit library-initiated device commands to this many commands per duration" )
33
39
)
34
40
35
41
// LinuxDevice implements the Device interface with Linux ioctls.
@@ -83,16 +89,16 @@ func (d *LinuxDevice) Ioctl(command uintptr, req any) (uintptr, error) {
83
89
if d .burst == 0 {
84
90
sinceLast := time .Since (d .lastCmd )
85
91
// Self-throttle for tests without guest OS throttle detection
86
- if sinceLast < throttleDuration {
87
- time .Sleep (throttleDuration - sinceLast )
92
+ if sinceLast < * throttleDuration {
93
+ time .Sleep (* throttleDuration - sinceLast )
88
94
}
89
95
}
90
96
switch sreq := req .(type ) {
91
97
case * labi.SnpUserGuestRequest :
92
98
abi := sreq .ABI ()
93
99
result , _ , errno := unix .Syscall (unix .SYS_IOCTL , uintptr (d .fd ), command , uintptr (abi .Pointer ()))
94
100
abi .Finish (sreq )
95
- d .burst = (d .burst + 1 ) % burstMax
101
+ d .burst = (d .burst + 1 ) % * burstMax
96
102
if d .burst == 0 {
97
103
d .lastCmd = time .Now ()
98
104
}
0 commit comments