summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/sharedmem/queue
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-10-28 00:30:40 +0000
committergVisor bot <gvisor-bot@google.com>2021-10-28 00:30:40 +0000
commit56cb3487c737c7ab6de68d27185b678968682e7c (patch)
tree3096bb5d26e2c48d2a1b7a65f46e1938314cda22 /pkg/tcpip/link/sharedmem/queue
parentd909cd18a7be8ebb2145414645ce796dcf46bb58 (diff)
parent8acc3a9bb2225a5af9e5bf587d2a2baad0e5f841 (diff)
Merge release-20211019.0-48-g8acc3a9bb (automated)
Diffstat (limited to 'pkg/tcpip/link/sharedmem/queue')
-rw-r--r--pkg/tcpip/link/sharedmem/queue/rx.go17
-rw-r--r--pkg/tcpip/link/sharedmem/queue/tx.go16
2 files changed, 25 insertions, 8 deletions
diff --git a/pkg/tcpip/link/sharedmem/queue/rx.go b/pkg/tcpip/link/sharedmem/queue/rx.go
index a78826ebc..89bdf5ef6 100644
--- a/pkg/tcpip/link/sharedmem/queue/rx.go
+++ b/pkg/tcpip/link/sharedmem/queue/rx.go
@@ -49,9 +49,16 @@ const (
sizeOfConsumedBuffer = 28
// The following are the allowed states of the shared data area.
- eventFDUninitialized = 0
- eventFDDisabled = 1
- eventFDEnabled = 2
+ // EventFDUinitialized is the value stored at the start of the shared data
+ // region when it hasn't been initialized.
+ EventFDUninitialized = 0
+ // EventFDDisabled is the value stored at the start of the shared data region
+ // when notifications using eventFD has been disabled.
+ EventFDDisabled = 1
+ // EventFDEnabled is the value stored at the start of the shared data region
+ // when eventFD should be notified as the peer might be blocked waiting on
+ // notifications.
+ EventFDEnabled = 2
)
// RxBuffer is the descriptor of a receive buffer.
@@ -84,13 +91,13 @@ func (r *Rx) Init(tx, rx []byte, sharedEventFDState *uint32) {
// EnableNotification updates the shared state such that the peer will notify
// the eventfd when there are packets to be dequeued.
func (r *Rx) EnableNotification() {
- atomic.StoreUint32(r.sharedEventFDState, eventFDEnabled)
+ atomic.StoreUint32(r.sharedEventFDState, EventFDEnabled)
}
// DisableNotification updates the shared state such that the peer will not
// notify the eventfd.
func (r *Rx) DisableNotification() {
- atomic.StoreUint32(r.sharedEventFDState, eventFDDisabled)
+ atomic.StoreUint32(r.sharedEventFDState, EventFDDisabled)
}
// PostedBuffersLimit returns the maximum number of buffers that can be posted
diff --git a/pkg/tcpip/link/sharedmem/queue/tx.go b/pkg/tcpip/link/sharedmem/queue/tx.go
index beffe807b..09907c761 100644
--- a/pkg/tcpip/link/sharedmem/queue/tx.go
+++ b/pkg/tcpip/link/sharedmem/queue/tx.go
@@ -16,6 +16,7 @@ package queue
import (
"encoding/binary"
+ "sync/atomic"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/tcpip/link/sharedmem/pipe"
@@ -49,14 +50,23 @@ type TxBuffer struct {
//
// This struct is thread-compatible.
type Tx struct {
- tx pipe.Tx
- rx pipe.Rx
+ tx pipe.Tx
+ rx pipe.Rx
+ sharedEventFDState *uint32
}
// Init initializes the transmit queue with the given pipes.
-func (t *Tx) Init(tx, rx []byte) {
+func (t *Tx) Init(tx, rx []byte, sharedEventFDState *uint32) {
t.tx.Init(tx)
t.rx.Init(rx)
+ t.sharedEventFDState = sharedEventFDState
+}
+
+// NotificationsEnabled returns true if eventFD should be used to notify the
+// peer of events (eg. packet transmit etc).
+func (t *Tx) NotificationsEnabled() bool {
+ // Notifications are considered enabled unless explicitly disabled.
+ return atomic.LoadUint32(t.sharedEventFDState) != EventFDDisabled
}
// Enqueue queues the given linked list of buffers for transmission as one