@@ -46,75 +46,80 @@ where
46
46
const PROCESS_EVQ : u32 = 3 ;
47
47
const PROCESS_NOTIFY_BACKEND : u32 = 4 ;
48
48
49
- pub fn handle_rxq_event ( & mut self , evset : EventSet ) -> bool {
49
+ pub fn handle_rxq_event ( & mut self , evset : EventSet ) {
50
50
if evset != EventSet :: IN {
51
51
warn ! ( "vsock: rxq unexpected event {:?}" , evset) ;
52
52
METRICS . rx_queue_event_fails . inc ( ) ;
53
- return false ;
53
+ return ;
54
54
}
55
55
56
- let mut raise_irq = false ;
57
56
if let Err ( err) = self . queue_events [ RXQ_INDEX ] . read ( ) {
58
57
error ! ( "Failed to get vsock rx queue event: {:?}" , err) ;
59
58
METRICS . rx_queue_event_fails . inc ( ) ;
60
59
} else if self . backend . has_pending_rx ( ) {
61
- raise_irq |= self . process_rx ( ) ;
60
+ if self . process_rx ( ) {
61
+ self . signal_used_queue ( RXQ_INDEX )
62
+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
63
+ }
62
64
METRICS . rx_queue_event_count . inc ( ) ;
63
65
}
64
- raise_irq
65
66
}
66
67
67
- pub fn handle_txq_event ( & mut self , evset : EventSet ) -> bool {
68
+ pub fn handle_txq_event ( & mut self , evset : EventSet ) {
68
69
if evset != EventSet :: IN {
69
70
warn ! ( "vsock: txq unexpected event {:?}" , evset) ;
70
71
METRICS . tx_queue_event_fails . inc ( ) ;
71
- return false ;
72
+ return ;
72
73
}
73
74
74
- let mut raise_irq = false ;
75
75
if let Err ( err) = self . queue_events [ TXQ_INDEX ] . read ( ) {
76
76
error ! ( "Failed to get vsock tx queue event: {:?}" , err) ;
77
77
METRICS . tx_queue_event_fails . inc ( ) ;
78
78
} else {
79
- raise_irq |= self . process_tx ( ) ;
79
+ if self . process_tx ( ) {
80
+ self . signal_used_queue ( TXQ_INDEX )
81
+ . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
82
+ }
80
83
METRICS . tx_queue_event_count . inc ( ) ;
81
84
// The backend may have queued up responses to the packets we sent during
82
85
// TX queue processing. If that happened, we need to fetch those responses
83
86
// and place them into RX buffers.
84
- if self . backend . has_pending_rx ( ) {
85
- raise_irq |= self . process_rx ( ) ;
87
+ if self . backend . has_pending_rx ( ) && self . process_rx ( ) {
88
+ self . signal_used_queue ( RXQ_INDEX )
89
+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
86
90
}
87
91
}
88
- raise_irq
89
92
}
90
93
91
- pub fn handle_evq_event ( & mut self , evset : EventSet ) -> bool {
94
+ pub fn handle_evq_event ( & mut self , evset : EventSet ) {
92
95
if evset != EventSet :: IN {
93
96
warn ! ( "vsock: evq unexpected event {:?}" , evset) ;
94
97
METRICS . ev_queue_event_fails . inc ( ) ;
95
- return false ;
98
+ return ;
96
99
}
97
100
98
101
if let Err ( err) = self . queue_events [ EVQ_INDEX ] . read ( ) {
99
102
error ! ( "Failed to consume vsock evq event: {:?}" , err) ;
100
103
METRICS . ev_queue_event_fails . inc ( ) ;
101
104
}
102
- false
103
105
}
104
106
105
107
/// Notify backend of new events.
106
- pub fn notify_backend ( & mut self , evset : EventSet ) -> bool {
108
+ pub fn notify_backend ( & mut self , evset : EventSet ) {
107
109
self . backend . notify ( evset) ;
108
110
// After the backend has been kicked, it might've freed up some resources, so we
109
111
// can attempt to send it more data to process.
110
112
// In particular, if `self.backend.send_pkt()` halted the TX queue processing (by
111
113
// returning an error) at some point in the past, now is the time to try walking the
112
114
// TX queue again.
113
- let mut raise_irq = self . process_tx ( ) ;
114
- if self . backend . has_pending_rx ( ) {
115
- raise_irq |= self . process_rx ( ) ;
115
+ if self . process_tx ( ) {
116
+ self . signal_used_queue ( TXQ_INDEX )
117
+ . expect ( "vsock: Could not trigger device interrupt or TX queue" ) ;
118
+ }
119
+ if self . backend . has_pending_rx ( ) && self . process_rx ( ) {
120
+ self . signal_used_queue ( RXQ_INDEX )
121
+ . expect ( "vsock: Could not trigger device interrupt or RX queue" ) ;
116
122
}
117
- raise_irq
118
123
}
119
124
120
125
fn register_runtime_events ( & self , ops : & mut EventOps ) {
@@ -182,19 +187,14 @@ where
182
187
let evset = event. event_set ( ) ;
183
188
184
189
if self . is_activated ( ) {
185
- let mut raise_irq = false ;
186
190
match source {
187
191
Self :: PROCESS_ACTIVATE => self . handle_activate_event ( ops) ,
188
- Self :: PROCESS_RXQ => raise_irq = self . handle_rxq_event ( evset) ,
189
- Self :: PROCESS_TXQ => raise_irq = self . handle_txq_event ( evset) ,
190
- Self :: PROCESS_EVQ => raise_irq = self . handle_evq_event ( evset) ,
191
- Self :: PROCESS_NOTIFY_BACKEND => raise_irq = self . notify_backend ( evset) ,
192
+ Self :: PROCESS_RXQ => self . handle_rxq_event ( evset) ,
193
+ Self :: PROCESS_TXQ => self . handle_txq_event ( evset) ,
194
+ Self :: PROCESS_EVQ => self . handle_evq_event ( evset) ,
195
+ Self :: PROCESS_NOTIFY_BACKEND => self . notify_backend ( evset) ,
192
196
_ => warn ! ( "Unexpected vsock event received: {:?}" , source) ,
193
197
} ;
194
- if raise_irq {
195
- self . signal_used_queue ( source as usize )
196
- . expect ( "vsock: Could not trigger device interrupt" ) ;
197
- }
198
198
} else {
199
199
warn ! (
200
200
"Vsock: The device is not yet activated. Spurious event received: {:?}" ,
@@ -302,7 +302,9 @@ mod tests {
302
302
let mut ctx = test_ctx. create_event_handler_context ( ) ;
303
303
ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
304
304
305
- assert ! ( !ctx. device. handle_txq_event( EventSet :: IN ) ) ;
305
+ let metric_before = METRICS . tx_queue_event_fails . count ( ) ;
306
+ ctx. device . handle_txq_event ( EventSet :: IN ) ;
307
+ assert_eq ! ( metric_before + 1 , METRICS . tx_queue_event_fails. count( ) ) ;
306
308
}
307
309
}
308
310
@@ -363,7 +365,9 @@ mod tests {
363
365
let mut ctx = test_ctx. create_event_handler_context ( ) ;
364
366
ctx. mock_activate ( test_ctx. mem . clone ( ) , test_ctx. interrupt . clone ( ) ) ;
365
367
ctx. device . backend . set_pending_rx ( false ) ;
366
- assert ! ( !ctx. device. handle_rxq_event( EventSet :: IN ) ) ;
368
+ let metric_before = METRICS . rx_queue_event_fails . count ( ) ;
369
+ ctx. device . handle_rxq_event ( EventSet :: IN ) ;
370
+ assert_eq ! ( metric_before + 1 , METRICS . rx_queue_event_fails. count( ) ) ;
367
371
}
368
372
}
369
373
@@ -374,7 +378,9 @@ mod tests {
374
378
let test_ctx = TestContext :: new ( ) ;
375
379
let mut ctx = test_ctx. create_event_handler_context ( ) ;
376
380
ctx. device . backend . set_pending_rx ( false ) ;
377
- assert ! ( !ctx. device. handle_evq_event( EventSet :: IN ) ) ;
381
+ let metric_before = METRICS . ev_queue_event_fails . count ( ) ;
382
+ ctx. device . handle_evq_event ( EventSet :: IN ) ;
383
+ assert_eq ! ( metric_before + 1 , METRICS . ev_queue_event_fails. count( ) ) ;
378
384
}
379
385
}
380
386
0 commit comments