-
Notifications
You must be signed in to change notification settings - Fork 45
/
homa_utils.c
720 lines (670 loc) · 20.6 KB
/
homa_utils.c
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
// SPDX-License-Identifier: BSD-2-Clause
/* This file contains miscellaneous utility functions for Homa, such
* as initializing and destroying homa structs.
*/
#include "homa_impl.h"
#include "homa_peer.h"
#include "homa_rpc.h"
#include "homa_skb.h"
struct completion homa_pacer_kthread_done;
/**
* homa_init() - Constructor for homa objects.
* @homa: Object to initialize.
*
* Return: 0 on success, or a negative errno if there was an error. Even
* if an error occurs, it is safe (and necessary) to call
* homa_destroy at some point.
*/
int homa_init(struct homa *homa)
{
int i, err;
_Static_assert(HOMA_MAX_PRIORITIES >= 8,
"homa_init assumes at least 8 priority levels");
homa->pacer_kthread = NULL;
init_completion(&homa_pacer_kthread_done);
atomic64_set(&homa->next_outgoing_id, 2);
atomic64_set(&homa->link_idle_time, sched_clock());
spin_lock_init(&homa->grantable_lock);
homa->grantable_lock_time = 0;
atomic_set(&homa->grant_recalc_count, 0);
INIT_LIST_HEAD(&homa->grantable_peers);
INIT_LIST_HEAD(&homa->grantable_rpcs);
homa->num_grantable_rpcs = 0;
homa->last_grantable_change = sched_clock();
homa->max_grantable_rpcs = 0;
homa->oldest_rpc = NULL;
homa->num_active_rpcs = 0;
for (i = 0; i < HOMA_MAX_GRANTS; i++) {
homa->active_rpcs[i] = NULL;
atomic_set(&homa->active_remaining[i], 0);
}
homa->grant_nonfifo = 0;
homa->grant_nonfifo_left = 0;
spin_lock_init(&homa->pacer_mutex);
homa->pacer_fifo_fraction = 50;
homa->pacer_fifo_count = 1;
homa->pacer_wake_time = 0;
spin_lock_init(&homa->throttle_lock);
INIT_LIST_HEAD_RCU(&homa->throttled_rpcs);
homa->throttle_add = 0;
homa->throttle_min_bytes = 200;
atomic_set(&homa->total_incoming, 0);
homa->next_client_port = HOMA_MIN_DEFAULT_PORT;
homa->port_map = kmalloc(sizeof(*homa->port_map), GFP_KERNEL);
if (!homa->port_map) {
pr_err("%s couldn't create port_map: kmalloc failure",
__func__);
return -ENOMEM;
}
homa_socktab_init(homa->port_map);
homa->peers = kmalloc(sizeof(*homa->peers), GFP_KERNEL);
if (!homa->peers) {
pr_err("%s couldn't create peers: kmalloc failure", __func__);
return -ENOMEM;
}
err = homa_peertab_init(homa->peers);
if (err) {
pr_err("%s couldn't initialize peer table (errno %d)\n",
__func__, -err);
return err;
}
err = homa_skb_init(homa);
if (err) {
pr_err("Couldn't initialize skb management (errno %d)\n",
-err);
return err;
}
/* Wild guesses to initialize configuration values... */
homa->unsched_bytes = 40000;
homa->window_param = 100000;
homa->link_mbps = 25000;
homa->poll_usecs = 50;
homa->num_priorities = HOMA_MAX_PRIORITIES;
for (i = 0; i < HOMA_MAX_PRIORITIES; i++)
homa->priority_map[i] = i;
homa->max_sched_prio = HOMA_MAX_PRIORITIES - 5;
homa->unsched_cutoffs[HOMA_MAX_PRIORITIES - 1] = 200;
homa->unsched_cutoffs[HOMA_MAX_PRIORITIES - 2] = 2800;
homa->unsched_cutoffs[HOMA_MAX_PRIORITIES - 3] = 15000;
homa->unsched_cutoffs[HOMA_MAX_PRIORITIES - 4] = HOMA_MAX_MESSAGE_LENGTH;
#ifdef __UNIT_TEST__
/* Unit tests won't send CUTOFFS messages unless the test changes
* this variable.
*/
homa->cutoff_version = 0;
#else
homa->cutoff_version = 1;
#endif
homa->fifo_grant_increment = 10000;
homa->grant_fifo_fraction = 50;
homa->max_overcommit = 8;
homa->max_incoming = 400000;
homa->max_rpcs_per_peer = 1;
homa->resend_ticks = 5;
homa->resend_interval = 5;
homa->timeout_ticks = 100;
homa->timeout_resends = 5;
homa->request_ack_ticks = 2;
homa->reap_limit = 10;
homa->dead_buffs_limit = 5000;
homa->max_dead_buffs = 0;
homa->pacer_kthread = kthread_run(homa_pacer_main, homa,
"homa_pacer");
if (IS_ERR(homa->pacer_kthread)) {
err = PTR_ERR(homa->pacer_kthread);
homa->pacer_kthread = NULL;
pr_err("couldn't create homa pacer thread: error %d\n", err);
return err;
}
homa->pacer_exit = false;
homa->max_nic_queue_ns = 5000;
homa->ns_per_mbyte = 0;
homa->verbose = 0;
homa->max_gso_size = 10000;
homa->gso_force_software = 0;
homa->hijack_tcp = 0;
homa->max_gro_skbs = 20;
homa->gro_policy = HOMA_GRO_NORMAL;
homa->busy_usecs = 100;
homa->gro_busy_usecs = 5;
homa->timer_ticks = 0;
spin_lock_init(&homa->metrics_lock);
homa->metrics = NULL;
homa->metrics_capacity = 0;
homa->metrics_length = 0;
homa->metrics_active_opens = 0;
homa->flags = 0;
homa->freeze_type = 0;
homa->bpage_lease_usecs = 10000;
homa->next_id = 0;
homa_outgoing_sysctl_changed(homa);
homa_incoming_sysctl_changed(homa);
return 0;
}
/**
* homa_destroy() - Destructor for homa objects.
* @homa: Object to destroy.
*/
void homa_destroy(struct homa *homa)
{
#ifdef __UNIT_TEST__
#include "utils.h"
unit_homa_destroy(homa);
#endif /* __UNIT_TEST__ */
if (homa->pacer_kthread) {
homa_pacer_stop(homa);
wait_for_completion(&homa_pacer_kthread_done);
}
/* The order of the following statements matters! */
if (homa->port_map) {
homa_socktab_destroy(homa->port_map);
kfree(homa->port_map);
homa->port_map = NULL;
}
if (homa->peers) {
homa_peertab_destroy(homa->peers);
kfree(homa->peers);
homa->peers = NULL;
}
homa_skb_cleanup(homa);
kfree(homa->metrics);
homa->metrics = NULL;
}
/**
* homa_print_ipv4_addr() - Convert an IPV4 address to the standard string
* representation.
* @addr: Address to convert, in network byte order.
*
* Return: The converted value. Values are stored in static memory, so
* the caller need not free. This also means that storage is
* eventually reused (there are enough buffers to accommodate
* multiple "active" values).
*
* Note: Homa uses this function, rather than the %pI4 format specifier
* for snprintf et al., because the kernel's version of snprintf isn't
* available in Homa's unit test environment.
*/
char *homa_print_ipv4_addr(__be32 addr)
{
#define NUM_BUFS_IPV4 4
#define BUF_SIZE_IPV4 30
static char buffers[NUM_BUFS_IPV4][BUF_SIZE_IPV4];
__u32 a2 = ntohl(addr);
static int next_buf;
char *buffer;
buffer = buffers[next_buf];
next_buf++;
if (next_buf >= NUM_BUFS_IPV4)
next_buf = 0;
snprintf(buffer, BUF_SIZE_IPV4, "%u.%u.%u.%u", (a2 >> 24) & 0xff,
(a2 >> 16) & 0xff, (a2 >> 8) & 0xff, a2 & 0xff);
return buffer;
}
/**
* homa_print_ipv6_addr() - Convert an IPv6 address to a human-readable string
* representation. IPv4-mapped addresses are printed in IPv4 syntax.
* @addr: Address to convert, in network byte order.
*
* Return: The converted value. Values are stored in static memory, so
* the caller need not free. This also means that storage is
* eventually reused (there are enough buffers to accommodate
* multiple "active" values).
*/
char *homa_print_ipv6_addr(const struct in6_addr *addr)
{
#define NUM_BUFS BIT(2)
#define BUF_SIZE 64
static char buffers[NUM_BUFS][BUF_SIZE];
static int next_buf;
char *buffer;
buffer = buffers[next_buf];
next_buf++;
if (next_buf >= NUM_BUFS)
next_buf = 0;
#ifdef __UNIT_TEST__
struct in6_addr zero = {};
if (ipv6_addr_equal(addr, &zero)) {
snprintf(buffer, BUF_SIZE, "0.0.0.0");
} else if ((addr->s6_addr32[0] == 0) &&
(addr->s6_addr32[1] == 0) &&
(addr->s6_addr32[2] == htonl(0x0000ffff))) {
__u32 a2 = ntohl(addr->s6_addr32[3]);
snprintf(buffer, BUF_SIZE, "%u.%u.%u.%u", (a2 >> 24) & 0xff,
(a2 >> 16) & 0xff, (a2 >> 8) & 0xff, a2 & 0xff);
} else {
const char *inet_ntop(int af, const void *src, char *dst,
size_t size);
inet_ntop(AF_INET6, addr, buffer + 1, BUF_SIZE);
buffer[0] = '[';
strcat(buffer, "]");
}
#else
snprintf(buffer, BUF_SIZE, "%pI6", addr);
#endif
return buffer;
}
/**
* homa_print_packet() - Print a human-readable string describing the
* information in a Homa packet.
* @skb: Packet whose information should be printed.
* @buffer: Buffer in which to generate the string.
* @buf_len: Number of bytes available at @buffer.
*
* Return: @buffer
*/
char *homa_print_packet(struct sk_buff *skb, char *buffer, int buf_len)
{
struct homa_common_hdr *common;
char header[HOMA_MAX_HEADER];
struct in6_addr saddr;
int used = 0;
if (!skb) {
snprintf(buffer, buf_len, "skb is NULL!");
buffer[buf_len - 1] = 0;
return buffer;
}
homa_skb_get(skb, &header, 0, sizeof(header));
common = (struct homa_common_hdr *)header;
saddr = skb_canonical_ipv6_saddr(skb);
used = homa_snprintf(buffer, buf_len, used,
"%s from %s:%u, dport %d, id %llu",
homa_symbol_for_type(common->type),
homa_print_ipv6_addr(&saddr),
ntohs(common->sport), ntohs(common->dport),
be64_to_cpu(common->sender_id));
switch (common->type) {
case DATA: {
struct homa_skb_info *homa_info = homa_get_skb_info(skb);
struct homa_data_hdr *h = (struct homa_data_hdr *)header;
int data_left, i, seg_length, pos, offset;
if (skb_shinfo(skb)->gso_segs == 0) {
seg_length = homa_data_len(skb);
data_left = 0;
} else {
seg_length = homa_info->seg_length;
if (seg_length > homa_info->data_bytes)
seg_length = homa_info->data_bytes;
data_left = homa_info->data_bytes - seg_length;
}
offset = ntohl(h->seg.offset);
if (offset == -1)
offset = ntohl(h->common.sequence);
used = homa_snprintf(buffer, buf_len, used,
", message_length %d, offset %d, data_length %d, incoming %d",
ntohl(h->message_length), offset,
seg_length, ntohl(h->incoming));
if (ntohs(h->cutoff_version) != 0)
used = homa_snprintf(buffer, buf_len, used,
", cutoff_version %d",
ntohs(h->cutoff_version));
if (h->retransmit)
used = homa_snprintf(buffer, buf_len, used,
", RETRANSMIT");
if (skb_shinfo(skb)->gso_type == 0xd)
used = homa_snprintf(buffer, buf_len, used,
", TSO disabled");
if (skb_shinfo(skb)->gso_segs <= 1)
break;
pos = skb_transport_offset(skb) + sizeof32(*h) + seg_length;
used = homa_snprintf(buffer, buf_len, used, ", extra segs");
for (i = skb_shinfo(skb)->gso_segs - 1; i > 0; i--) {
if (homa_info->seg_length < skb_shinfo(skb)->gso_size) {
struct homa_seg_hdr seg;
homa_skb_get(skb, &seg, pos, sizeof(seg));
offset = ntohl(seg.offset);
} else {
offset += seg_length;
}
if (seg_length > data_left)
seg_length = data_left;
used = homa_snprintf(buffer, buf_len, used,
" %d@%d", seg_length, offset);
data_left -= seg_length;
pos += skb_shinfo(skb)->gso_size;
};
break;
}
case GRANT: {
struct homa_grant_hdr *h = (struct homa_grant_hdr *)header;
char *resend = (h->resend_all) ? ", resend_all" : "";
used = homa_snprintf(buffer, buf_len, used,
", offset %d, grant_prio %u%s",
ntohl(h->offset), h->priority, resend);
break;
}
case RESEND: {
struct homa_resend_hdr *h = (struct homa_resend_hdr *)header;
used = homa_snprintf(buffer, buf_len, used,
", offset %d, length %d, resend_prio %u",
ntohl(h->offset), ntohl(h->length),
h->priority);
break;
}
case UNKNOWN:
/* Nothing to add here. */
break;
case BUSY:
/* Nothing to add here. */
break;
case CUTOFFS: {
struct homa_cutoffs_hdr *h = (struct homa_cutoffs_hdr *)header;
used = homa_snprintf(buffer, buf_len, used,
", cutoffs %d %d %d %d %d %d %d %d, version %u",
ntohl(h->unsched_cutoffs[0]),
ntohl(h->unsched_cutoffs[1]),
ntohl(h->unsched_cutoffs[2]),
ntohl(h->unsched_cutoffs[3]),
ntohl(h->unsched_cutoffs[4]),
ntohl(h->unsched_cutoffs[5]),
ntohl(h->unsched_cutoffs[6]),
ntohl(h->unsched_cutoffs[7]),
ntohs(h->cutoff_version));
break;
}
case FREEZE:
/* Nothing to add here. */
break;
case NEED_ACK:
/* Nothing to add here. */
break;
case ACK: {
struct homa_ack_hdr *h = (struct homa_ack_hdr *)header;
int i, count;
count = ntohs(h->num_acks);
used = homa_snprintf(buffer, buf_len, used, ", acks");
for (i = 0; i < count; i++) {
used = homa_snprintf(buffer, buf_len, used,
" [sp %d, id %llu]",
ntohs(h->acks[i].server_port),
be64_to_cpu(h->acks[i].client_id));
}
break;
}
}
buffer[buf_len - 1] = 0;
return buffer;
}
/**
* homa_print_packet_short() - Print a human-readable string describing the
* information in a Homa packet. This function generates a shorter
* description than homa_print_packet.
* @skb: Packet whose information should be printed.
* @buffer: Buffer in which to generate the string.
* @buf_len: Number of bytes available at @buffer.
*
* Return: @buffer
*/
char *homa_print_packet_short(struct sk_buff *skb, char *buffer, int buf_len)
{
struct homa_common_hdr *common;
char header[HOMA_MAX_HEADER];
common = (struct homa_common_hdr *)header;
homa_skb_get(skb, header, 0, HOMA_MAX_HEADER);
switch (common->type) {
case DATA: {
struct homa_data_hdr *h = (struct homa_data_hdr *)header;
struct homa_skb_info *homa_info = homa_get_skb_info(skb);
int data_left, used, i, seg_length, pos, offset;
if (skb_shinfo(skb)->gso_segs == 0) {
seg_length = homa_data_len(skb);
data_left = 0;
} else {
seg_length = homa_info->seg_length;
data_left = homa_info->data_bytes - seg_length;
}
offset = ntohl(h->seg.offset);
if (offset == -1)
offset = ntohl(h->common.sequence);
pos = skb_transport_offset(skb) + sizeof32(*h) + seg_length;
used = homa_snprintf(buffer, buf_len, 0, "DATA%s %d@%d",
h->retransmit ? " retrans" : "",
seg_length, offset);
for (i = skb_shinfo(skb)->gso_segs - 1; i > 0; i--) {
if (homa_info->seg_length < skb_shinfo(skb)->gso_size) {
struct homa_seg_hdr seg;
homa_skb_get(skb, &seg, pos, sizeof(seg));
offset = ntohl(seg.offset);
} else {
offset += seg_length;
}
if (seg_length > data_left)
seg_length = data_left;
used = homa_snprintf(buffer, buf_len, used,
" %d@%d", seg_length, offset);
data_left -= seg_length;
pos += skb_shinfo(skb)->gso_size;
}
break;
}
case GRANT: {
struct homa_grant_hdr *h = (struct homa_grant_hdr *)header;
char *resend = h->resend_all ? " resend_all" : "";
snprintf(buffer, buf_len, "GRANT %d@%d%s", ntohl(h->offset),
h->priority, resend);
break;
}
case RESEND: {
struct homa_resend_hdr *h = (struct homa_resend_hdr *)header;
snprintf(buffer, buf_len, "RESEND %d-%d@%d", ntohl(h->offset),
ntohl(h->offset) + ntohl(h->length) - 1,
h->priority);
break;
}
case UNKNOWN:
snprintf(buffer, buf_len, "UNKNOWN");
break;
case BUSY:
snprintf(buffer, buf_len, "BUSY");
break;
case CUTOFFS:
snprintf(buffer, buf_len, "CUTOFFS");
break;
case FREEZE:
snprintf(buffer, buf_len, "FREEZE");
break;
case NEED_ACK:
snprintf(buffer, buf_len, "NEED_ACK");
break;
case ACK:
snprintf(buffer, buf_len, "ACK");
break;
default:
snprintf(buffer, buf_len, "unknown packet type 0x%x",
common->type);
break;
}
return buffer;
}
/**
* homa_freeze_peers() - Send FREEZE packets to all known peers.
* @homa: Provides info about peers.
*/
void homa_freeze_peers(struct homa *homa)
{
struct homa_socktab_scan scan;
struct homa_freeze_hdr freeze;
struct homa_peer **peers;
int num_peers, i, err;
struct homa_sock *hsk;
/* Find a socket to use (any will do). */
hsk = homa_socktab_start_scan(homa->port_map, &scan);
homa_socktab_end_scan(&scan);
if (!hsk) {
tt_record("homa_freeze_peers couldn't find a socket");
return;
}
peers = homa_peertab_get_peers(homa->peers, &num_peers);
if (!peers) {
tt_record("homa_freeze_peers couldn't find peers to freeze");
return;
}
freeze.common.type = FREEZE;
freeze.common.sport = htons(hsk->port);
freeze.common.dport = 0;
freeze.common.flags = HOMA_TCP_FLAGS;
freeze.common.urgent = htons(HOMA_TCP_URGENT);
freeze.common.sender_id = 0;
for (i = 0; i < num_peers; i++) {
tt_record1("Sending freeze to 0x%x", tt_addr(peers[i]->addr));
err = __homa_xmit_control(&freeze, sizeof(freeze), peers[i], hsk);
if (err != 0)
tt_record2("homa_freeze_peers got error %d in xmit to 0x%x\n",
err, tt_addr(peers[i]->addr));
}
kfree(peers);
}
/**
* homa_snprintf() - This function makes it easy to use a series of calls
* to snprintf to gradually append information to a fixed-size buffer.
* If the buffer fills, the function can continue to be called, but nothing
* more will get added to the buffer.
* @buffer: Characters accumulate here.
* @size: Total space available in @buffer.
* @used: Number of bytes currently occupied in the buffer, not including
* a terminating null character; this is typically the result of
* the previous call to this function.
* @format: Format string suitable for passing to printf-like functions,
* followed by values for the various substitutions requested
* in @format
* @ ...
*
* Return: The number of characters now occupied in @buffer, not
* including the terminating null character.
*/
int homa_snprintf(char *buffer, int size, int used, const char *format, ...)
{
int new_chars;
va_list ap;
va_start(ap, format);
if (used >= (size - 1))
return used;
new_chars = vsnprintf(buffer + used, size - used, format, ap);
if (new_chars < 0)
return used;
if (new_chars >= (size - used))
return size - 1;
return used + new_chars;
}
/**
* homa_symbol_for_type() - Returns a printable string describing a packet type.
* @type: A value from those defined by &homa_packet_type.
*
* Return: A static string holding the packet type corresponding to @type.
*/
char *homa_symbol_for_type(uint8_t type)
{
switch (type) {
case DATA:
return "DATA";
case GRANT:
return "GRANT";
case RESEND:
return "RESEND";
case UNKNOWN:
return "UNKNOWN";
case BUSY:
return "BUSY";
case CUTOFFS:
return "CUTOFFS";
case FREEZE:
return "FREEZE";
case NEED_ACK:
return "NEED_ACK";
case ACK:
return "ACK";
}
return "??";
}
/**
* homa_prios_changed() - This function is called whenever configuration
* information related to priorities, such as @homa->unsched_cutoffs or
* @homa->num_priorities, is modified. It adjusts the cutoffs if needed
* to maintain consistency, and it updates other values that depend on
* this information.
* @homa: Contains the priority info to be checked and updated.
*/
void homa_prios_changed(struct homa *homa)
{
int i;
if (homa->num_priorities > HOMA_MAX_PRIORITIES)
homa->num_priorities = HOMA_MAX_PRIORITIES;
/* This guarantees that we will choose priority 0 if nothing else
* in the cutoff array matches.
*/
homa->unsched_cutoffs[0] = INT_MAX;
for (i = HOMA_MAX_PRIORITIES - 1; ; i--) {
if (i >= homa->num_priorities) {
homa->unsched_cutoffs[i] = 0;
continue;
}
if (i == 0) {
homa->unsched_cutoffs[i] = INT_MAX;
homa->max_sched_prio = 0;
break;
}
if (homa->unsched_cutoffs[i] >= HOMA_MAX_MESSAGE_LENGTH) {
homa->max_sched_prio = i - 1;
break;
}
}
homa->cutoff_version++;
}
/**
* homa_spin() - Delay (without sleeping) for a given time interval.
* @ns: How long to delay (in nanoseconds)
*/
void homa_spin(int ns)
{
__u64 end;
end = sched_clock() + ns;
while (sched_clock() < end)
/* Empty loop body.*/
;
}
/**
* homa_throttle_lock_slow() - This function implements the slow path for
* acquiring the throttle lock. It is invoked when the lock isn't immediately
* available. It waits for the lock, but also records statistics about
* the waiting time.
* @homa: Overall data about the Homa protocol implementation.
*/
void homa_throttle_lock_slow(struct homa *homa)
__acquires(&homa->throttle_lock)
{
__u64 start = sched_clock();
tt_record("beginning wait for throttle lock");
spin_lock_bh(&homa->throttle_lock);
tt_record("ending wait for throttle lock");
INC_METRIC(throttle_lock_misses, 1);
INC_METRIC(throttle_lock_miss_ns, sched_clock() - start);
}
/**
* homa_freeze() - Freezes the timetrace if a particular kind of freeze
* has been requested through sysctl.
* @rpc: If we freeze our timetrace, we'll also send a freeze request
* to the peer for this RPC.
* @type: Condition that just occurred. If this doesn't match the
* externally set "freeze_type" value, then we don't freeze.
* @format: Format string used to generate a time trace record describing
* the reason for the freeze; must include "id %d, peer 0x%x"
*/
void homa_freeze(struct homa_rpc *rpc, enum homa_freeze_type type, char *format)
{
if (type != rpc->hsk->homa->freeze_type)
return;
rpc->hsk->homa->freeze_type = 0;
if (!tt_frozen) {
// struct homa_freeze_hdr freeze;
int dummy;
pr_notice("freezing in %s with freeze_type %d\n", __func__,
type);
tt_record1("homa_freeze calling homa_rpc_log_active with freeze_type %d", type);
homa_rpc_log_active_tt(rpc->hsk->homa, 0);
homa_validate_incoming(rpc->hsk->homa, 1, &dummy);
pr_notice("%s\n", format);
tt_record2(format, rpc->id, tt_addr(rpc->peer->addr));
tt_freeze();
// homa_xmit_control(FREEZE, &freeze, sizeof(freeze), rpc);
homa_freeze_peers(rpc->hsk->homa);
}
}