Skip to content

Commit cf84543

Browse files
authored
Merge pull request #49 from deeglaze/no_burst
Make ratelimiting flag-configurable, set burst to 1
2 parents 8ac7f5f + 4547e2c commit cf84543

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

client/client_linux.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package client
1919

2020
import (
21+
"flag"
2122
"fmt"
2223
"time"
2324

@@ -28,8 +29,13 @@ import (
2829
const (
2930
// defaultSevGuestDevicePath is the platform's usual device path to the SEV guest.
3031
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")
3339
)
3440

3541
// LinuxDevice implements the Device interface with Linux ioctls.
@@ -83,16 +89,16 @@ func (d *LinuxDevice) Ioctl(command uintptr, req any) (uintptr, error) {
8389
if d.burst == 0 {
8490
sinceLast := time.Since(d.lastCmd)
8591
// 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)
8894
}
8995
}
9096
switch sreq := req.(type) {
9197
case *labi.SnpUserGuestRequest:
9298
abi := sreq.ABI()
9399
result, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(d.fd), command, uintptr(abi.Pointer()))
94100
abi.Finish(sreq)
95-
d.burst = (d.burst + 1) % burstMax
101+
d.burst = (d.burst + 1) % *burstMax
96102
if d.burst == 0 {
97103
d.lastCmd = time.Now()
98104
}

0 commit comments

Comments
 (0)