Repository navigation
Expand file tree
/
Copy pathunit_homa_timer.c
More file actions
307 lines (279 loc) · 8.7 KB
/
Copy pathunit_homa_timer.c
File metadata and controls
307 lines (279 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0+
#include "homa_impl.h"
#include "homa_grant.h"
#include "homa_peer.h"
#include "homa_pool.h"
#include "homa_rpc.h"
#define KSELFTEST_NOT_MAIN 1
#include "kselftest_harness.h"
#include "ccutils.h"
#include "mock.h"
#include "utils.h"
FIXTURE(homa_timer) {
struct in6_addr client_ip[1];
int client_port;
struct in6_addr server_ip[1];
int server_port;
u64 client_id;
u64 server_id;
union sockaddr_in_union server_addr;
struct homa homa;
struct homa_net *hnet;
struct homa_sock hsk;
};
FIXTURE_SETUP(homa_timer)
{
self->client_ip[0] = unit_get_in_addr("196.168.0.1");
self->client_port = 40000;
self->server_ip[0] = unit_get_in_addr("1.2.3.4");
self->server_port = 99;
self->client_id = 1234;
self->server_id = 1235;
self->server_addr.in6.sin6_family = AF_INET;
self->server_addr.in6.sin6_addr = *self->server_ip;
self->server_addr.in6.sin6_port = htons(self->server_port);
homa_init(&self->homa);
self->hnet = mock_hnet(0, &self->homa);
self->homa.resend_ticks = 2;
self->homa.timer_ticks = 100;
#ifndef __STRIP__ /* See strip.py */
self->homa.unsched_bytes = 10000;
self->homa.grant->window = 10000;
#endif /* See strip.py */
mock_sock_init(&self->hsk, self->hnet, 0);
unit_log_clear();
}
FIXTURE_TEARDOWN(homa_timer)
{
homa_destroy(&self->homa);
unit_teardown();
}
TEST_F(homa_timer, homa_timer_check_rpc__request_ack)
{
struct homa_rpc *srpc = unit_server_rpc(&self->hsk, UNIT_OUTGOING,
self->client_ip, self->server_ip, self->client_port,
self->server_id, 100, 100);
ASSERT_NE(NULL, srpc);
self->homa.request_ack_ticks = 2;
/* First call: do nothing (response not fully transmitted). */
homa_rpc_lock(srpc);
homa_timer_check_rpc(srpc);
EXPECT_EQ(0, srpc->done_timer_ticks);
homa_xmit_data(srpc);
/* Second call: set done_timer_ticks. */
unit_log_clear();
homa_timer_check_rpc(srpc);
EXPECT_EQ(100, srpc->done_timer_ticks);
EXPECT_STREQ("", unit_log_get());
/* Third call: haven't hit request_ack_ticks yet. */
unit_log_clear();
self->homa.timer_ticks++;
homa_timer_check_rpc(srpc);
EXPECT_EQ(100, srpc->done_timer_ticks);
EXPECT_STREQ("", unit_log_get());
/* Fourth call: request ack. */
unit_log_clear();
self->homa.timer_ticks++;
homa_timer_check_rpc(srpc);
homa_rpc_unlock(srpc);
EXPECT_EQ(100, srpc->done_timer_ticks);
EXPECT_STREQ("xmit NEED_ACK", unit_log_get());
}
#ifndef __STRIP__ /* See strip.py */
TEST_F(homa_timer, homa_timer_check_rpc__all_granted_bytes_received)
{
struct homa_rpc *crpc = unit_client_rpc(&self->hsk,
UNIT_RCVD_ONE_PKT, self->client_ip, self->server_ip,
self->server_port, self->client_id, 100, 5000);
ASSERT_NE(NULL, crpc);
unit_log_clear();
crpc->msgin.granted = 1400;
crpc->silent_ticks = 10;
homa_rpc_lock(crpc);
homa_timer_check_rpc(crpc);
homa_rpc_unlock(crpc);
EXPECT_EQ(0, crpc->silent_ticks);
EXPECT_STREQ("", unit_log_get());
}
#endif /* See strip.py */
TEST_F(homa_timer, homa_timer_check_rpc__no_buffer_space)
{
struct homa_rpc *crpc;
crpc = unit_client_rpc(&self->hsk, UNIT_RCVD_ONE_PKT, self->client_ip,
self->server_ip, self->server_port,
self->client_id, 100, 5000);
ASSERT_NE(NULL, crpc);
unit_log_clear();
homa_pool_free_bufs(crpc->hsk->buffer_pool, crpc->msgin.num_bpages,
crpc->msgin.bpage_offsets);
crpc->msgin.num_bpages = 0;
crpc->silent_ticks = 10;
homa_rpc_lock(crpc);
homa_timer_check_rpc(crpc);
homa_rpc_unlock(crpc);
EXPECT_EQ(0, crpc->silent_ticks);
EXPECT_STREQ("", unit_log_get());
}
TEST_F(homa_timer, homa_timer_check_rpc__server_has_received_request)
{
struct homa_rpc *srpc = unit_server_rpc(&self->hsk, UNIT_IN_SERVICE,
self->client_ip, self->server_ip, self->client_port,
self->server_id, 100, 100);
ASSERT_NE(NULL, srpc);
unit_log_clear();
srpc->silent_ticks = 10;
homa_rpc_lock(srpc);
homa_timer_check_rpc(srpc);
homa_rpc_unlock(srpc);
EXPECT_EQ(0, srpc->silent_ticks);
EXPECT_STREQ("", unit_log_get());
}
TEST_F(homa_timer, homa_timer_check_rpc__granted_bytes_not_sent)
{
struct homa_rpc *crpc = unit_client_rpc(&self->hsk,
UNIT_OUTGOING, self->client_ip, self->server_ip,
self->server_port, self->client_id, 5000, 200);
ASSERT_NE(NULL, crpc);
crpc->msgout.next_xmit_offset = 0;
unit_log_clear();
crpc->silent_ticks = 10;
homa_rpc_lock(crpc);
homa_timer_check_rpc(crpc);
homa_rpc_unlock(crpc);
EXPECT_EQ(0, crpc->silent_ticks);
EXPECT_STREQ("", unit_log_get());
}
TEST_F(homa_timer, homa_timer_check_rpc__timeout)
{
struct homa_rpc *crpc = unit_client_rpc(&self->hsk,
UNIT_RCVD_ONE_PKT, self->client_ip, self->server_ip,
self->server_port, self->client_id, 200, 10000);
ASSERT_NE(NULL, crpc);
unit_log_clear();
crpc->silent_ticks = self->homa.timeout_ticks-1;
homa_rpc_lock(crpc);
homa_timer_check_rpc(crpc);
#ifndef __STRIP__ /* See strip.py */
EXPECT_EQ(0, homa_metrics_per_cpu()->rpc_timeouts);
#endif /* See strip.py */
EXPECT_EQ(0, crpc->error);
crpc->silent_ticks = self->homa.timeout_ticks;
homa_timer_check_rpc(crpc);
homa_rpc_unlock(crpc);
#ifndef __STRIP__ /* See strip.py */
EXPECT_EQ(1, homa_metrics_per_cpu()->rpc_timeouts);
#endif /* See strip.py */
EXPECT_EQ(ETIMEDOUT, -crpc->error);
}
TEST_F(homa_timer, homa_timer_check_rpc__request_retransmission)
{
struct homa_rpc *crpc = unit_client_rpc(&self->hsk,
UNIT_RCVD_ONE_PKT, self->client_ip, self->server_ip,
self->server_port, self->client_id, 200, 10000);
ASSERT_NE(NULL, crpc);
self->homa.resend_ticks = 3;
self->homa.resend_interval = 2;
#ifndef __STRIP__ /* See strip.py */
crpc->msgin.granted = 5000;
crpc->msgout.granted = 0;
#endif /* See strip.py */
/* First call: resend_ticks-1. */
crpc->silent_ticks = 2;
unit_log_clear();
homa_timer_check_rpc(crpc);
EXPECT_STREQ("", unit_log_get());
/* Second call: resend_ticks. */
crpc->silent_ticks = 3;
unit_log_clear();
homa_rpc_lock(crpc);
homa_timer_check_rpc(crpc);
#ifndef __STRIP__ /* See strip.py */
EXPECT_STREQ("xmit RESEND 1400-4999@7", unit_log_get());
#else /* See strip.py */
EXPECT_STREQ("xmit RESEND 1400-9999", unit_log_get());
#endif /* See strip.py */
/* Third call: not yet time for next resend. */
crpc->silent_ticks = 4;
unit_log_clear();
homa_timer_check_rpc(crpc);
EXPECT_STREQ("", unit_log_get());
/* Fourth call: time for second resend. */
crpc->silent_ticks = 5;
unit_log_clear();
homa_timer_check_rpc(crpc);
homa_rpc_unlock(crpc);
#ifndef __STRIP__ /* See strip.py */
EXPECT_STREQ("xmit RESEND 1400-4999@7", unit_log_get());
#else /* See strip.py */
EXPECT_STREQ("xmit RESEND 1400-9999", unit_log_get());
#endif /* See strip.py */
}
TEST_F(homa_timer, homa_timer__basics)
{
struct homa_rpc *crpc = unit_client_rpc(&self->hsk,
UNIT_RCVD_ONE_PKT, self->client_ip, self->server_ip,
self->server_port, self->client_id, 200, 5000);
ASSERT_NE(NULL, crpc);
self->homa.timeout_ticks = 5;
self->homa.resend_ticks = 3;
self->homa.resend_interval = 2;
unit_log_clear();
crpc->silent_ticks = 1;
homa_timer(&self->homa);
EXPECT_EQ(2, crpc->silent_ticks);
EXPECT_STREQ("", unit_log_get());
/* Send RESEND. */
unit_log_clear();
homa_timer(&self->homa);
EXPECT_EQ(3, crpc->silent_ticks);
#ifndef __STRIP__ /* See strip.py */
EXPECT_STREQ("xmit RESEND 1400-4999@7", unit_log_get());
#else /* See strip.py */
EXPECT_STREQ("xmit RESEND 1400-4999", unit_log_get());
#endif /* See strip.py */
/* Don't send another RESEND (resend_interval not reached). */
unit_log_clear();
homa_timer(&self->homa);
EXPECT_EQ(4, crpc->silent_ticks);
EXPECT_STREQ("", unit_log_get());
/* Timeout the peer. */
unit_log_clear();
#ifndef __STRIP__ /* See strip.py */
crpc->peer->outstanding_resends = self->homa.timeout_resends;
#endif /* See strip.py */
homa_timer(&self->homa);
#ifndef __STRIP__ /* See strip.py */
EXPECT_EQ(1, homa_metrics_per_cpu()->rpc_timeouts);
#endif /* See strip.py */
EXPECT_EQ(ETIMEDOUT, -crpc->error);
}
TEST_F(homa_timer, homa_timer__reap_dead_rpcs)
{
struct homa_rpc *dead;
mock_no_high_order_pages = true;
dead = unit_client_rpc(&self->hsk, UNIT_RCVD_MSG, self->client_ip,
self->server_ip, self->server_port,
self->client_id, 60000, 1000);
ASSERT_NE(NULL, dead);
homa_rpc_end(dead);
EXPECT_EQ(16, self->hsk.dead_frags);
// First call to homa_timer: not enough dead skbs.
self->homa.dead_frags_limit = 16;
homa_timer(&self->homa);
EXPECT_EQ(16, self->hsk.dead_frags);
// Second call to homa_timer: must reap.
self->homa.dead_frags_limit = 15;
homa_timer(&self->homa);
EXPECT_EQ(0, self->hsk.dead_frags);
}
TEST_F(homa_timer, homa_timer__rpc_in_service)
{
struct homa_rpc *srpc = unit_server_rpc(&self->hsk, UNIT_IN_SERVICE,
self->client_ip, self->server_ip, self->client_port,
self->server_id, 5000, 5000);
ASSERT_NE(NULL, srpc);
unit_log_clear();
homa_timer(&self->homa);
EXPECT_EQ(0, srpc->silent_ticks);
EXPECT_STREQ("", unit_log_get());
}