Repository navigation
Expand file tree
/
Copy pathconfig
More file actions
executable file
·919 lines (829 loc) · 32.5 KB
/
Copy pathconfig
File metadata and controls
executable file
·919 lines (829 loc) · 32.5 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
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
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
#!/usr/bin/python3
# Copyright (c) 2023 Homa Developers
# SPDX-License-Identifier: BSD-1-Clause
"""
This script is used to configure CloudLab nodes for running Homa experiments.
It does things such as (re-)installing Homa, setting Homa configuration
parameters, and configuring the system in various ways such as setting
power management parameters and enabling RPS.
"""
import fcntl
import functools
from glob import glob
import os
import re
import subprocess
import sys
import time
from switch import *
# Names for the main network interface and VLAN for this host. Set by
# get_interfaces
interface = None
vlan = None
# Cached result of get_cpu_type.
cpu_type = None
# Cached result of get_link_speed (integer Mbits/sec.)
link_mbps = None
# Cached result of get_nic_type.
nic_type = None
# Number of this node (e.g. 1 for "node1"). Set by get_node_num.
node_num = None
# CloudLab node type for this machine, such as xl170 or c6525-100g.
# Set by get_node_type.
node_type = None
# Number of nodes in the experiment (0 means uninitialized).
num_nodes = 0
# Cached result of get_node_names.
node_names = []
# Set from command line option to request detailed output.
verbose = False
# Contains information from /proc/cpuinfo with one entry for each
# "processor" in /proc/cpuinfo. The entry is a dictionary with the
# following entries (same names as in /proc/cpuinfo):
# processor: number of this core (hyperthread)
# core id: number of the physical core (same for all hyperthreads
# on the core)
# physical id: number for the socket containing this core
# This array is filled in by read_cpu_info().
cpu_info = []
# The total number of physical cores (i.e. distinct values of "core id"
# in cpuinfo). Filled in by read_cpu_info().
num_phys_cores = 0
# Describes the the full channel mappings for xl170 machines at CloudLab.
# Entry i is the core that will handle incoming packets on channel i.
xl170_default_cores = [0, 10, 7, 19, 8, 18, 6, 16, 4, 14,
11, 1, 7, 17, 15, 5, 13, 3, 2, 12]
# False means that the installed version of Homa doesn't support sysctls.
sysctl_avl = True
def get_core_mask(core = -1):
"""
Returns a string representing a bit mask containing one bit for each
core. The mask is represented with one or more 32-bit hex values:
"val,val,...val". If the core argument is -1, then all of the bits are
ones (i.e. all cores are selected). If the core argument is >=0, then
all of the bits will be zeros except for the one selecting the indicated
core.
core: Either -1 (to select all cores) or the number of a single core
to select..
"""
read_cpu_info()
mask_words = [0]
for cpu in cpu_info:
cur_core = cpu["processor"]
word = core//32
while word >= len(mask_words):
mask_words.append(0);
if (core == -1) or (cur_core == core):
mask_words[word] |= 1<<(cur_core & 0x1f);
result = ""
while len(mask_words) > 0:
if len(result) != 0:
result += ",";
result += ("%x" % (mask_words[-1]))
mask_words.pop()
return result
def get_cpu_type():
"""
Return information about the processor we're running on (the "model name"
from /proc/cpuinfo)
"""
global cpu_type
if cpu_type == None:
read_cpu_info()
if cpu_type == None:
raise Exception("Couldn't find 'model name' line in /proc/cpuinfo")
return cpu_type
def get_exp_ports():
"""
Return a list containing all of the switch egress port numbers used by
nodes in the current CloudLab experiment.
"""
ports = []
for name in get_node_names():
match = re.match('[^0-9]+([0-9]+)', name)
if not match:
raise Exception("bad host name %s: expected number at end" % (name))
ports.append(int(match.group(1)) % 40)
return ports
def get_interfaces():
"""
Runs ifconfig and parses its output to identify the key network
interfaces for this host. Returns a list containing two interface
names. The first is the name of the hardware interface, and the
second is the name of the VLAN associated with that interface.
"""
global interface, vlan
if interface:
return [interface, vlan]
available = ""
for line in exec_cmd(["ifconfig"], check=True).stdout.splitlines():
match = re.match('^([a-z0-9]*):', line)
if match:
current = match.group(1)
if available:
available += ", "
available += current
if (('s1f1' in current) or ('s1f0' in current)
or ('s0f0' in current) or ('s0f1' in current)
or (current == 'eno1')) and not interface:
ethtool_info = exec_cmd(["ethtool", current], check=True).stdout
if "Link detected: yes" in ethtool_info:
interface = current
continue
if re.match(r'^[ ]+ inet 10\.0\.1\.', line):
vlan = current
if not vlan or not interface:
print("Found the following interfaces: %s" % (available))
if not vlan:
raise Exception("Couldn't identify vlan interface")
if not interface:
raise Exception("Couldn't identify primary network interface")
print("Primary network interface is %s, vlan is %s" % (interface, vlan))
return [interface, vlan]
def get_link_speed():
"""
Return the link speed for the primary NIC, in Mbits/sec.
"""
global link_mbps
if link_mbps != None:
return link_mbps
nic = get_interfaces()[0]
num_channels = -1
for line in exec_cmd(["ethtool", nic], check=True).stdout.splitlines():
match = re.match('.*Speed: ([0-9]+)Mb/s', line)
if match:
link_mbps = int(match.group(1))
print("Link speed for %s is %d Mbps" % (nic, link_mbps))
return link_mbps
raise Exception("Couldn't find link speed in ethtool output")
def get_nic_irqs():
"""
Returns a list containing the IRQ numbers for NIC channels (entry
0 in the list corresponds to channel 0, and so on).
"""
irqs = {}
f = open("/proc/interrupts")
for line in f:
match = re.match('([0-9]+): .* mlx5_comp([0-9]+)@pci:0000:03:00.1', line)
if not match:
continue
irq = int(match.group(1))
channel = int(match.group(2))
irqs[channel] = irq
result = []
for i in range(len(irqs)):
if not i in irqs:
raise Exception('Couldn\'t find IRQ for NIC channel %d' % (i))
result.append(irqs[i])
f.close()
return result
def get_nic_type():
"""
Returns the type of driver for the primary NIC, such as "ice" for
the Intel driver.
"""
global nic_type
if nic_type != None:
return nic_type
info = exec_cmd(["sudo", "ethtool", "-i", get_interfaces()[0]],
check=True).stdout
match = re.search(r'.*driver:\s*(\S+)', info, re.MULTILINE)
if not match:
raise Exception("Couldn't identify NIC type (no 'driver' info in "
"ethtool output")
nic_type = match.group(1)
print("Driver type for primary network interface is %s" % (nic_type))
return nic_type
def get_node_num():
"""
Returns the (integer) number of this node (e.g., 1 for "node1").
"""
global node_num
if node_num != None:
return node_num
hostname = exec_cmd(["hostname"], check=True).stdout
match = re.match(r'node([0-9]+)\.', hostname)
if not match:
raise Exception("Couldn't figure out node number for this node")
node_num = int(match.group(1))
print("Number of this node is %d" % (node_num))
return node_num
def get_node_type():
"""
Returns the node type for this machine (assumes we're running on a
Cloudlab machine).
"""
global node_type
if node_type:
return node_type
f = open("/var/emulab/boot/nodetype")
node_type = f.read().strip()
f.close()
print("Type of this node is %s" % (node_type))
return node_type
def get_node_names():
"""
Return a list, in order of node number (node0 first), containing the
name of each node in the experiment, such as hp083.
"""
global node_names
if len(node_names) > 0:
return node_names
node_map = {}
f = open("/var/emulab/boot/ltpmap")
for line in f:
match = re.search('H node([0-9]+) ([^ ]+)', line)
if match:
num = int(match.group(1))
node_map[int(match.group(1))] = match.group(2)
f.close()
if len(node_map) != get_num_nodes():
raise Exception("get_node_names found only %d nodes, but expected %d"
% (len(node_map), get_num_nodes()))
node_names = []
for i in range(len(node_map)):
if not i in node_map:
raise Exception("Couldn't find host name for node%d" % (i))
node_names.append(node_map[i])
return node_names
def get_num_nodes():
"""
Returns the number of nodes in this experiment.
"""
global num_nodes
if num_nodes > 0:
return num_nodes
f = open("/var/emulab/boot/hostmap")
for line in f:
if re.match('node([-0-9.]+)', line):
num_nodes += 1
f.close()
return num_nodes
def get_qdisc_config():
"""
Returns a dictionary with the following keys, which describe the current
configuration of queuing disciplines for the current interface:
root_handle: The handle (e.g. ":0" of the root qdisc for the interface)
children: A list of dictionaries describing the queue-specific qdiscs:
type: The type of the qdisc (e.g. fg_codel or homa)
handle: The handle for that qdisc
queue: The queue number that the qdisc is associated with
(e.g. if the parent handle is "1:4", the queue
will be 4)
"""
result = {}
result['children'] = []
nic = get_interfaces()[0]
for line in exec_cmd(['tc', 'qdisc', 'show', 'dev', nic],
check=True).stdout.splitlines():
match = re.match('qdisc mq ([0-9a-f]+:[0-9a-f]*) root', line)
if match:
result['root_handle'] = match.group(1)
match = re.match('qdisc ([^ ]+) ([0-9a-f]+:[0-9a-f]*) '
'parent [^:]*:([0-9a-f]+)', line);
if match:
type = match.group(1)
handle = match.group(2)
queue = int(match.group(3), 16)
result['children'].append({'type': type, 'handle': handle,
'queue': queue})
return result
def print_rss():
"""
Print out the current RSS configuration (how many channels and which
cores will handle them)
"""
nic = get_interfaces()[0]
irqs = get_nic_irqs()
num_channels = -1
for line in exec_cmd(["ethtool", "-l", nic],
check=True).stdout.splitlines():
match = re.match('Combined:[^0-9]+([0-9]+)', line)
if match:
num_channels = int(match.group(1))
if num_channels <= 0:
raise Exception('Couldn\'t get number of channels from ethtool')
print('Number of NIC channels: %d' % (num_channels))
print('Channel Core')
for i in range(num_channels):
f = open('/proc/irq/%s/smp_affinity_list' % (irqs[i]))
core = int(f.read())
f.close()
print('%-4d %4d' % (i, core))
def read_cpu_info():
"""
Read the file /proc/cpuinfo and store information from it in various
global arrays above.
"""
global cpu_info, cpu_type, num_phys_cores
if len(cpu_info) > 0:
return
cpu = None
cores = {}
sockets = {}
f = open("/proc/cpuinfo", "r")
for line in f:
match = re.match(r'([^\t]*)[\t ]+: (.*)', line)
if match:
name = match.group(1)
value = match.group(2)
# print("name '%s' value '%s'" % (name, value))
if name == 'model name' and cpu_type == None:
cpu_type = value
print("CPU type is %s" % (cpu_type))
if name == 'processor':
cpu = int(value)
cpu_info.append({name: int(value)})
elif cpu == None:
continue
if name == "core id":
cpu_info[-1][name] = int(value)
cores[value] = 1
elif name == "physical id":
cpu_info[-1][name] = int(value)
sockets[value] = 1
f.close()
num_phys_cores = len(cores)
s = "sockets"
if len(sockets) == 1:
s = "socket"
if num_phys_cores == len(cpu_info):
print("This node has %d %s, %d cores, no hyperthreading" % (
len(sockets), s, num_phys_cores))
else:
print("This node has %d %s, %d logical cores, %d-way "
"hyperthreading" % (len(sockets), s, len(cpu_info),
len(cpu_info)/num_phys_cores))
def add_ipv6_to_etc_hosts(num_hosts):
"""
If /etc/hosts doesn't already contain IPv6 addresses for hosts
in the cluster, add them. The num_hosts argument indicates how
many hosts should be present in /etc/hosts.
"""
# First see which, if any, entries are already in /etc/hosts.
f = open("/etc/hosts", "r")
old = f.read()
f.close()
for first in range(num_hosts-1, -1, -1):
if ("fd00::%d" % (first+1)) in old:
first += 1
break
if first < (num_hosts-1):
print("Adding IPv6 addresses for nodes %d-%d to /etc/hosts" % (
first, num_hosts-1))
input = ""
for i in range(first, num_hosts):
input += "fd00::%d node%d\n" % (i+1, i)
exec_cmd(["sudo", "bash", "-c", "cat >> /etc/hosts"],
input=input, encoding="utf-8", check=True)
else:
print("/etc/hosts already contains IPv6 addresses for nodes 0-%d" % (
num_hosts-1))
def exec_cmd(*args, **kwargs):
"""
This method is a wrapper around subprocess.run, which arranges for the
output to be captured and also performs logging. The arguments are the
same as those for subprocess.run.
"""
global verbose
if verbose:
print("%% %s" % (" ".join(args[0])))
try:
return subprocess.run(*args, text=True, capture_output=True, **kwargs)
except subprocess.CalledProcessError as e:
if not verbose:
print("%% %s" % (" ".join(args[0])))
print(e.stderr)
raise
def set_sysctl(name, value):
"""
Set a Homa sysctl configuration option as given by name and value.
"""
global sysctl_avl
if not sysctl_avl:
return
exec_cmd(["sudo", "sysctl", ".net.homa.%s=%s" % (name, value)],
check=True)
def config_ecn_threshold(kb):
"""
Modify the configuration of this experiment's egress ports at the
top-of-rack switch to enable optimal Homa performance.
"""
s = Switch(True)
for port in get_exp_ports():
print("Configuring ECN threshold for port %d" % (port))
s.set_ecn_threshold(port, kb)
s.close()
def config_homa(mod):
"""
Install the Homa kernel driver and configure it appropriately for
this node type.
mod: the path to the Homa module '.ko' file
"""
type = get_node_type()
print("Installing Homa kernel module from %s" % (mod))
exec_cmd(["sudo", "rmmod", "homa"], check=False)
exec_cmd(["sudo", "bash", "-c", "insmod %s" % (mod)],
check=True)
# See if Homa supports sysctls (if it has been stripped down for Linux
# upstreaming, it might not).
result = exec_cmd(["sysctl", ".net.homa.num_priorities"], check=False)
if result.returncode != 0:
global sysctl_avl
print("Homa doesn't appear to support sysctls")
sysctl_avl = False
set_sysctl("num_priorities", "8")
link_mbps = get_link_speed()
set_sysctl ("link_mbps", str(link_mbps))
set_sysctl("max_nic_est_backlog_usecs", "5")
if link_mbps == 10000:
set_sysctl("unsched_bytes", "30000")
set_sysctl("max_incoming", "400000")
set_sysctl("max_gso_size", "10000")
elif link_mbps == 25000:
set_sysctl("unsched_bytes", "60000")
set_sysctl("max_incoming", "480000")
set_sysctl("max_gso_size", "10000")
elif link_mbps == 100000:
set_sysctl("unsched_bytes", "60000")
set_sysctl("max_incoming", "1600000")
set_sysctl("max_gso_size", "100000")
else:
raise Exception("Can't configure Homa: no config info available "
"for link speed %d Mbps" % (link_mbps))
if get_nic_type() == "ice":
print("Enabling TCP hijacking")
set_sysctl("hijack_tcp", 1)
def config_ipv6(num_hosts, vlan):
"""
Configure this node to enable IPv6.
num_hosts: the total number of hosts in the cluster (OK to overestimate).
vlan: name of the VLAN interface to configure with IPv6 info
"""
vlan = get_interfaces()[1]
# Configure ifconfig and route if not already done.
if "inet6 fd00::" in exec_cmd(["ifconfig", vlan], check=True).stdout:
print("IPv6 already configured")
else:
print("Configuring IPv6")
exec_cmd(["sudo", "ifconfig", vlan, "add", "fd00::%d/64" % (
get_node_num() + 1)], check=True)
exec_cmd(["sudo", "route", "-6", "add", "fd00::/16", vlan],
check=True)
add_ipv6_to_etc_hosts(num_hosts)
def config_lb(config):
"""
Configures load balancing as specified by config. This includes RSS
(Receive-Side Scaling) and SoftIRQ steering by setting the number of
NIC channels and which cores will handle each. It will also configure
Homa's mechanism for choosing SoftIRQ cores as described in gen3.txt,
and it will set related sysctl parameters such as gro_policy and
gro_busy_usecs.
config: Indicates which configuration is desired; one of:
xl170_default: Same as Gen2, except with the default boot-time
assignment of network channels to cores
gen2: For Homa Gen2 load balancing: one channel/core
gen3: For Homa Gen3 load balancing: one channel/4 cores
gen3_alt: Gen3 with one channel/2 cores
"""
read_cpu_info()
if config == 'xl170_default':
cores = xl170_default_cores
set_sysctl('gro_policy', '114')
set_sysctl('gro_busy_usecs', '0')
elif config == 'gen2':
cores = range(len(cpu_info))
set_sysctl('gro_policy', '114')
set_sysctl('gro_busy_usecs', '0')
elif config == 'gen3':
cores = [2*i for i in range(len(cpu_info)//4)]
set_sysctl('gro_policy', '226')
set_sysctl('gro_busy_usecs', '2')
elif config == 'gen3_alt':
cores = range(len(cpu_info)//2)
set_sysctl('gro_policy', '226')
set_sysctl('gro_busy_usecs', '2')
else:
raise Exception('Bad load balancing config "%s"; must be '
'xl170_default, gen2, gen3, or gen3_alt' % (config))
exec_cmd(["sudo", "ethtool", "-L", get_interfaces()[0], "combined",
str(len(cores))], check=True)
irqs = get_nic_irqs()
half_cores = len(cpu_info)//2
for i in range(len(cores)):
softirq_cores = []
core = cores[i]
if config == 'gen3':
# Use every 4th core for GRO, with 3 choices for SoftIRQ
softirq_cores = [2*i + 1, half_cores + 2*i, half_cores + 2*i + 1]
elif config == 'gen3_alt':
# Use every other core for GRO, with only 1 choice for SoftIRQ
softirq_cores = [(half_cores + (core+1)%half_cores), -1, -1]
softirq_msg = ''
if softirq_cores:
softirq_msg = ", SoftIRQ on cores %s" % (softirq_cores)
exec_cmd(["sudo", "sysctl",
".net.homa.gen3_softirq_cores=%d %d %d %d" % (cores[i],
softirq_cores[0], softirq_cores[1], softirq_cores[2])],
check=True)
exec_cmd(["sudo", "bash", "-c",
"echo %d > /proc/irq/%s/smp_affinity_list" % (cores[i], irqs[i])],
check=True)
print("Configured RSS for channel %d (IRQ %d): NAPI on core %d%s"
% (i, irqs[i], cores[i], softirq_msg))
def config_mtu(size):
"""
Set the maximum allowable packet length for this node to size.
"""
[interface, vlan] = get_interfaces()
exec_cmd(["sudo", "ip", "link", "set", interface, "mtu", str(size)],
check=True)
exec_cmd(["sudo", "ip", "link", "set", vlan, "mtu", str(size)],
check=True)
print("MTU set to %d bytes" % (size))
def config_nic():
"""
Configure the NIC for best performance (turn off interrupt delaying
mechanisms and flow steering).
"""
interface = get_interfaces()[0]
# Use a separate ethtool command for each paramemeter. Otherwise,
# if one parameter isn't supported the command will be aborted
# and no parameters will get set.
print("Configuring NIC to reduce interrupt latency")
exec_cmd(["sudo", "ethtool", "-C", interface, "adaptive-rx", "off"],
check=False)
exec_cmd(["sudo", "ethtool", "-C", interface, "rx-usecs", "0"], check=False)
exec_cmd(["sudo", "ethtool", "-C", interface, "rx-frames", "1"], check=False)
print("Configuring NIC to reduce recover tx buffers faster")
exec_cmd(["sudo", "ethtool", "-C", interface, "adaptive-tx", "off"],
check=False)
exec_cmd(["sudo", "ethtool", "-C", interface, "tx-usecs", "5"], check=False)
if get_nic_type() == "ice":
print("Increasing tx ring size for Intel NIC")
exec_cmd(["sudo", "ethtool", "-G", interface, "tx", "1024"],
check=True)
# As of 7/2026, RPS doesn't scale well with ICE NICs and drivers:
# with 20 nodes and thousands of open sockets per node, it can take
# 250 usecs to configure RPS for a flow. This happens at SoftIRQ
# level, so it blocks packet processing and causes large increases
# in tail latency. I don't yet know whether this is a problem for
# other NIC/driver combinations, but measurements suggest that there
# is no advantage to RPS anyway.
print("Disabling flow steering")
exec_cmd(["sudo", "ethtool", "-K", interface, "ntuple", "off"],
check=False)
def config_power():
"""
Configure the machine's power management for best Homa performance.
"""
if "intel" in get_cpu_type().lower():
# For Intel processors, it's best to leave C-states enabled. This
# can cause CPUs to sleep in power-saving mode, but if C-states
# are disabled, then so is Turbo mode, and that will hurt peak peformance.
print("Configuring power settings for Intel CPUs")
try:
exec_cmd(["sudo", "cpupower", "frequency-set", "-g",
"performance"], check=True)
except subprocess.CalledProcessError:
print("*** cpupower error; ignoring for now")
else:
print("Skipping power settings (non-Intel CPU type)")
def config_qdisc():
"""
Install Homa's queuing discipline for all of the queues of the NIC.
This will only work if the Homa version of tc is in the search path.
"""
nic = get_interfaces()[0]
config = get_qdisc_config()
root = config['root_handle']
# If the option 'homa_share' isn't available, then Homa was compiled
# without homa_qdisc (e.g. for a stripped version).
result = exec_cmd(['sysctl', '.net.homa.homa_share'], check=False)
if result.returncode != 0:
print("Can't install Homa qdisc: it isn't available "
"(maybe Homa is stripped?)")
return
print('Installing Homa qdisc')
if root == '0:':
# Must reset the root qdisc (it isn't possible to modify the
# default one)
exec_cmd(['sudo', 'tc', 'qdisc', 'add', 'dev', nic, 'root', 'handle',
'1:', 'mq'], check=True)
root = '1:'
# Replace the qdisc for each NIC queue with a homa one.
for child in config['children']:
if child['handle'] != '0:':
exec_cmd(['sudo', 'tc', 'qdisc', 'del', 'dev', nic,
'parent', '%s%x' % (root, child['queue']), 'handle',
child['handle']], check=True)
exec_cmd(['sudo', 'tc', 'qdisc', 'add', 'dev', nic,
'parent', '%s%x' % (root, child['queue']), 'handle',
'%x:' % (64 + child['queue']), 'homa'], check=True)
def config_reset_qdisc():
"""
Reset the qdisc configuration to its boot-time default.
"""
nic = get_interfaces()[0]
print('Restoring storing default qdisc configuration')
# Make sure we're not already in the default configuration, to
# avoid error messages.
first_line = exec_cmd(['tc', 'qdisc', 'show', 'dev', nic],
check=True).stdout.splitlines()[0]
if first_line.split()[2] != '0:':
exec_cmd(['sudo', 'tc', 'qdisc', 'del', 'dev', nic, 'root'],
check=True)
def config_reset_switch_all_ports():
"""
Reset the configuration of all egress ports at the top-of-rack switch
to undo a previous config_all_switch_ports.
"""
s = Switch(True)
s.reset_all_ports()
s.close()
def config_reset_switch_ports():
"""
Reset the configuration of the egress ports at the top-of-rack switch
to undo a previous config_switch_ports.
"""
s = Switch(True)
for port in get_exp_ports():
print("Resetting TOR port for port %d:" % (port))
s.reset_port(port)
s.close()
def config_rps():
"""
Enable RPS (Receive Packet Steering).
"""
interface = get_interfaces()[0]
mask = get_core_mask()
exec_cmd(["sudo", "sysctl", "-w",
"net.core.rps_sock_flow_entries=32768"], check=True)
flow_cnt = 0
for file in glob("/sys/class/net/%s/queues/rx-*/rps_flow_cnt"
% (interface)):
exec_cmd(["sudo", "bash", "-c", "echo 2048 > %s" % (file)],
check=True)
flow_cnt += 1
cpus = 0
for file in glob("/sys/class/net/%s/queues/rx-*/rps_cpus" % (interface)):
exec_cmd(["sudo", "bash", "-c", "echo %s > %s" % (mask, file)],
check=True)
cpus += 1
print("Configured RPS: %d rps_flow_cnt files and %d rps_cpus files"
% (flow_cnt, cpus))
def config_switch_buffer_limit(mbytes):
"""
Restrict the total amount of buffer space available for egress ports
in the top-of-rack switch.
mbytes: New limit, in Mbytes
"""
s = Switch(True)
s.set_buffer_limit(mbytes)
s.close()
def config_switch_all_ports():
"""
Modify the configuration of all egress ports at the top-of-rack switch
to enable optimal Homa performance.
"""
s = Switch(True)
s.config_all_ports()
s.close()
def config_switch_ports():
"""
Modify the configuration of the egress ports at the top-of-rack switch
to enable optimal Homa performance.
"""
s = Switch(True)
for port in get_exp_ports():
print("Configuring TOR port for port %d:" % (port))
s.config_port(port)
s.close()
def print_help():
print("Performs any of several configuration tasks to prepare a node for")
print("running Homa applications.")
print("Usage: config feature feature ...")
print("\nEach feature may be one of the following:")
print(" --help Print this help text and exit")
print(" --verbose Print details of commands executed and results")
print(" default Normal configuration for Homa: equivalent to")
print(" 'reset_qdisc homa ~/bin/homa.ko ipv6 nic power")
print(" rps'")
print(" ecn_threshold KB Set the ECN marking threshold for all ports in")
print(" the experiment to KB (Kbytes)")
print(" homa HHH Install and configure the Homa kernel driver;")
print(" HHH is the path to the homa.ko file")
print(" ipv6 Set up routing information so that IPv6")
print(" addresses can be used.")
print(" lb CONFIG Configure load balancing, including RSS, SoftIRQ")
print(" core selection, and various sysctl parameters,")
print(" as indicated by CONFIG (xl170_default, gen2,")
print(" gen3, or gen3_alt)")
print(" mtu NNN Set the maximum packet length to NNN")
print(" node_names Print out the names of all the nodes in ")
print(" the experiment")
print(" nic Configure the NIC for optimal Homa performance")
print(" power Configure power management (e.g., C-states)")
print(" for best Homa performance")
print(" print_rss Print out current RSS configuration")
print(" qdisc Install Homa's queuing discipline for all")
print(" of the NIC tx queues")
print(" reset_qdisc Uninstall Homa's queuing discipline for any")
print(" NIC queues where it is installed, and install")
print(" fq in its place")
print(" reset_switch_all_ports Issue commands to TOR switch to restore original")
print(" port settings for all ports on the switch")
print(" (even those not used by current experiment)")
print(" reset_switch_ports Issue commands to TOR switch to restore")
print(" original port settings (only restores ports")
print(" used by the current experiment)")
print(" rps Set up (and enable) RPS and RFS")
print(" switch_buffer_limit MB Set max egress buffer space in TOR switch to")
print(" MB Mbytes")
print(" switch_all_ports Issue commands to TOR switch to configure ")
print(" egress ports for all ports on the switch")
print(" (even those not used by current experiment)")
print(" switch_ports Issue commands to TOR switch to configure ")
print(" egress ports for Homa (only configures ports")
print(" used by the current experiment)")
# Force print to always flush (turn off line buffering).
print = functools.partial(print, flush=True)
i = 1
while i < len(sys.argv):
arg = sys.argv[i]
i += 1
if arg == "--help":
print_help()
exit(0)
elif arg == "--verbose":
verbose = True
elif arg == "default":
config_reset_qdisc()
config_homa("~/bin/homa.ko")
config_ipv6(get_num_nodes(), vlan)
config_nic()
config_power()
config_rps()
config_qdisc()
elif arg == "ecn_threshold":
if i >= len(sys.argv):
raise Exception("No argument provided for 'ecn_threshold' command");
exit(1)
kb = int(sys.argv[i])
i += 1
config_ecn_threshold(kb)
elif arg == "homa":
if i >= len(sys.argv):
raise Exception("No argument provided for 'homa' command");
exit(1)
mod = sys.argv[i]
i += 1
config_homa(mod)
elif arg == "ipv6":
config_ipv6(get_num_nodes(), vlan)
elif arg == "lb":
if i >= len(sys.argv):
raise Exception("No argument provided for 'lb' command");
exit(1)
config_lb(sys.argv[i])
i += 1
elif arg == "mtu":
if i >= len(sys.argv):
raise Exception("No argument provided for 'mtu' command");
exit(1)
mtu = int(sys.argv[i])
i += 1
config_mtu(mtu)
elif arg == "nic":
config_nic()
elif arg == "node_names":
for name in get_node_names():
print(name)
elif arg == "power":
config_power()
elif arg == "print_rss":
print_rss()
elif arg == "qdisc":
config_qdisc()
elif arg == "reset_qdisc":
config_reset_qdisc()
elif arg == "reset_switch_all_ports":
config_reset_switch_all_ports()
elif arg == "reset_switch_ports":
config_reset_switch_ports()
elif arg == "rps":
config_rps()
elif arg == "switch_buffer_limit":
if i >= len(sys.argv):
raise Exception("No argument provided for 'switch_buffer_limit' command");
exit(1)
config_switch_buffer_limit(float(sys.argv[i]))
i += 1
elif arg == "switch_all_ports":
config_switch_all_ports()
elif arg == "switch_ports":
config_switch_ports()
elif arg == "test":
get_cpu_type()
else:
raise Exception("Unknown feature '%s'" % (arg))