13
13
14
14
from host_tools .cargo_build import gcc_compile
15
15
16
-
17
- @ pytest . mark . parametrize (
18
- "vcpu_count" , [ 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 ]
19
- )
20
- def test_custom_udev_rule_latency (
21
- microvm_factory , guest_kernel_linux_acpi_only , rootfs_rw , vcpu_count
22
- ):
23
- """Test the latency for hotplugging and booting CPUs in the guest"""
24
- api_durations = []
25
- onlining_durations = []
26
- print ( f"Vcpu count: { vcpu_count } " )
27
- for i in range ( 5 ):
28
- uvm_hotplug = microvm_factory . build ( guest_kernel_linux_acpi_only , rootfs_rw )
29
- uvm_hotplug .jailer . extra_args . update ({ "no-seccomp" : None } )
30
- uvm_hotplug .help . enable_console ()
31
- uvm_hotplug .spawn ( )
32
- uvm_hotplug .basic_config ( vcpu_count = 1 , mem_size_mib = 128 )
33
- uvm_hotplug .add_net_iface ()
34
- uvm_hotplug .start ( )
35
- uvm_hotplug .ssh .run ( "rm /usr/lib/udev/rules.d/40-vm-hotadd.rules" )
36
- uvm_hotplug . ssh . scp_put (
37
- Path ("./host_tools /1-cpu-hotplug.rules" ),
38
- Path ( "/usr/lib/udev/rules.d/1-cpu-hotplug.rules" ),
39
- )
40
-
41
- time . sleep ( 0.25 )
42
-
43
- uvm_hotplug . api . hotplug . put ( Vcpu = { "add" : vcpu_count } )
44
- time . sleep ( 0.25 )
45
- _ , stdout , _ = uvm_hotplug . ssh . run ( "dmesg" )
46
-
47
- # Extract API call duration
48
- api_duration = (
49
- float (
50
- re . findall (
51
- r"Total previous API call duration: (\d+) us\." ,
52
- uvm_hotplug . log_data ,
53
- )[ - 1 ]
54
- )
55
- / 1000
56
- )
57
-
58
- # Extract onlining timings
59
- start = float (
60
- re . findall ( r"\[\s+(\d+\.\d+)\] CPU1 has been hot-added\n" , stdout )[ 0 ]
61
- )
62
- end = float ( re . findall ( r"\[\s+(\d+\.\d+)\] \w+" , stdout )[ - 1 ])
63
- elapsed_time = ( end - start ) * 1000
64
- print (f"Api call duration: { api_duration } ms" )
65
- print ( f"Onlining duration: { elapsed_time } ms" )
66
- api_durations .append (api_duration )
67
- onlining_durations . append ( elapsed_time )
68
- uvm_hotplug . kill ( )
69
- time . sleep ( 1 )
70
-
71
- avg_api_duration = sum (api_durations ) / 5
72
- avg_onlining_duration = sum ( onlining_durations ) / 5
73
- print (f"Averages for { vcpu_count } hotplugged vcpus: " )
74
- print (f"\t Average API call duration: { avg_api_duration } ms" )
75
- print ( f" \t Average onliing duration: { avg_onlining_duration } ms" )
76
-
77
-
78
- @ pytest . mark . parametrize (
79
- "vcpu_count" , [ 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 ]
80
- )
81
- def test_default_udev_rule_latency (
82
- microvm_factory , guest_kernel_linux_acpi_only , rootfs_rw , vcpu_count
83
- ):
84
- """Test the latency for hotplugging and booting CPUs in the guest"""
85
- api_durations = []
86
- onlining_durations = []
87
- print ( f"Vcpu count: { vcpu_count } " )
88
- for i in range ( 5 ):
89
- uvm_hotplug = microvm_factory . build ( guest_kernel_linux_acpi_only , rootfs_rw )
90
- uvm_hotplug .jailer . extra_args . update ({ "no-seccomp" : None } )
91
- uvm_hotplug .help . enable_console ()
92
- uvm_hotplug .spawn ( )
93
- uvm_hotplug .basic_config ( vcpu_count = 1 , mem_size_mib = 128 )
94
- uvm_hotplug .add_net_iface ()
95
- uvm_hotplug . start ()
96
-
97
- time . sleep ( 0.25 )
98
-
99
- _ , stdout , _ = uvm_hotplug . ssh . run ( "ls /usr/lib/udev/rules.d" )
100
- default_rule = re . search ( r"40-vm-hotadd\.rules" , stdout )
101
- assert default_rule is not None
102
-
103
- uvm_hotplug . api . hotplug . put ( Vcpu = { "add" : vcpu_count } )
104
- time . sleep ( 0.25 )
105
- _ , stdout , _ = uvm_hotplug . ssh . run ( "dmesg" )
106
-
107
- # Extract API call duration
108
- api_duration = (
109
- float (
110
- re . findall (
111
- r"Total previous API call duration: (\d+) us\." ,
112
- uvm_hotplug . log_data ,
113
- )[ - 1 ]
114
- )
115
- / 1000
116
- )
117
-
118
- # Extract onlining timings
119
- start = float (
120
- re . findall ( r"\[\s+(\d+\.\d+)\] CPU1 has been hot-added\n" , stdout )[ 0 ]
121
- )
122
- end = float ( re . findall ( r"\[\s+(\d+\.\d+)\] \w+" , stdout )[ - 1 ])
123
- elapsed_time = ( end - start ) * 1000
124
- print (f"Api call duration: { api_duration } ms" )
125
- print ( f"Onlining duration: { elapsed_time } ms" )
126
- api_durations .append (api_duration )
127
- onlining_durations . append ( elapsed_time )
128
- uvm_hotplug . kill ( )
129
- time . sleep ( 1 )
130
-
131
- avg_api_duration = sum (api_durations ) / 5
132
- avg_onlining_duration = sum ( onlining_durations ) / 5
133
- print (f"Averages for { vcpu_count } hotplugged vcpus: " )
134
- print (f"\t Average API call duration: { avg_api_duration } ms" )
135
- print ( f" \t Average onliing duration: { avg_onlining_duration } ms" )
16
+ # @pytest.mark.parametrize(
17
+ # "vcpu_count", [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]
18
+ # )
19
+ # def test_custom_udev_rule_latency(
20
+ # microvm_factory, guest_kernel_linux_acpi_only, rootfs_rw, vcpu_count
21
+ # ):
22
+ # """Test the latency for hotplugging and booting CPUs in the guest"""
23
+ # api_durations = []
24
+ # onlining_durations = []
25
+ # print(f"Vcpu count: {vcpu_count}")
26
+ # for i in range(5):
27
+ # uvm_hotplug = microvm_factory.build(guest_kernel_linux_acpi_only, rootfs_rw)
28
+ # uvm_hotplug.jailer.extra_args.update({"no-seccomp": None} )
29
+ # uvm_hotplug.help.enable_console( )
30
+ # uvm_hotplug.spawn ()
31
+ # uvm_hotplug.basic_config(vcpu_count=1, mem_size_mib=128 )
32
+ # uvm_hotplug.add_net_iface( )
33
+ # uvm_hotplug.start ()
34
+ # uvm_hotplug.ssh.run("rm /usr/lib/udev/rules.d/40-vm-hotadd.rules" )
35
+ # uvm_hotplug.ssh.scp_put(
36
+ # Path("./host_tools/1-cpu-hotplug.rules"),
37
+ # Path("/usr/lib/udev/rules.d /1-cpu-hotplug.rules"),
38
+ # )
39
+ #
40
+ # time.sleep(0.25)
41
+ #
42
+ # uvm_hotplug.api.hotplug.put(Vcpu={"add": vcpu_count})
43
+ # time.sleep(0.25 )
44
+ # _, stdout, _ = uvm_hotplug.ssh.run("dmesg" )
45
+ #
46
+ # # Extract API call duration
47
+ # api_duration = (
48
+ # float (
49
+ # re.findall (
50
+ # r"Total previous API call duration: (\d+) us\.",
51
+ # uvm_hotplug.log_data ,
52
+ # )[-1]
53
+ # )
54
+ # / 1000
55
+ # )
56
+ #
57
+ # # Extract onlining timings
58
+ # start = float(
59
+ # re.findall(r"\[\s+(\d+\.\d+)\] CPU1 has been hot-added\n", stdout)[0]
60
+ # )
61
+ # end = float(re.findall(r"\[\s+(\d+\.\d+)\] \w+", stdout)[-1] )
62
+ # elapsed_time = (end - start) * 1000
63
+ # print(f"Api call duration: {api_duration} ms")
64
+ # print(f"Onlining duration: {elapsed_time } ms")
65
+ # api_durations.append(api_duration )
66
+ # onlining_durations .append(elapsed_time )
67
+ # uvm_hotplug.kill( )
68
+ # time.sleep(1 )
69
+ #
70
+ # avg_api_duration = sum(api_durations) / 5
71
+ # avg_onlining_duration = sum(onlining_durations ) / 5
72
+ # print(f"Averages for {vcpu_count} hotplugged vcpus:")
73
+ # print(f"\tAverage API call duration: {avg_api_duration} ms ")
74
+ # print(f"\tAverage onliing duration: {avg_onlining_duration } ms")
75
+ #
76
+ #
77
+ # @pytest.mark.parametrize(
78
+ # "vcpu_count", [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]
79
+ # )
80
+ # def test_default_udev_rule_latency(
81
+ # microvm_factory, guest_kernel_linux_acpi_only, rootfs_rw, vcpu_count
82
+ # ):
83
+ # """Test the latency for hotplugging and booting CPUs in the guest"""
84
+ # api_durations = []
85
+ # onlining_durations = []
86
+ # print(f"Vcpu count: {vcpu_count}")
87
+ # for i in range(5):
88
+ # uvm_hotplug = microvm_factory.build(guest_kernel_linux_acpi_only, rootfs_rw)
89
+ # uvm_hotplug.jailer.extra_args.update({"no-seccomp": None} )
90
+ # uvm_hotplug.help.enable_console( )
91
+ # uvm_hotplug.spawn ()
92
+ # uvm_hotplug.basic_config(vcpu_count=1, mem_size_mib=128 )
93
+ # uvm_hotplug.add_net_iface( )
94
+ # uvm_hotplug.start ()
95
+ #
96
+ # time.sleep(0.25)
97
+ #
98
+ # _, stdout, _ = uvm_hotplug.ssh.run("ls /usr/lib/udev/rules.d")
99
+ # default_rule = re.search(r"40-vm-hotadd\.rules", stdout )
100
+ # assert default_rule is not None
101
+ #
102
+ # uvm_hotplug.api.hotplug.put(Vcpu={"add": vcpu_count})
103
+ # time.sleep(0.25 )
104
+ # _, stdout, _ = uvm_hotplug.ssh.run("dmesg" )
105
+ #
106
+ # # Extract API call duration
107
+ # api_duration = (
108
+ # float (
109
+ # re.findall (
110
+ # r"Total previous API call duration: (\d+) us\.",
111
+ # uvm_hotplug.log_data ,
112
+ # )[-1]
113
+ # )
114
+ # / 1000
115
+ # )
116
+ #
117
+ # # Extract onlining timings
118
+ # start = float(
119
+ # re.findall(r"\[\s+(\d+\.\d+)\] CPU1 has been hot-added\n", stdout)[0]
120
+ # )
121
+ # end = float(re.findall(r"\[\s+(\d+\.\d+)\] \w+", stdout)[-1] )
122
+ # elapsed_time = (end - start) * 1000
123
+ # print(f"Api call duration: {api_duration} ms")
124
+ # print(f"Onlining duration: {elapsed_time } ms")
125
+ # api_durations.append(api_duration )
126
+ # onlining_durations .append(elapsed_time )
127
+ # uvm_hotplug.kill( )
128
+ # time.sleep(1 )
129
+ #
130
+ # avg_api_duration = sum(api_durations) / 5
131
+ # avg_onlining_duration = sum(onlining_durations ) / 5
132
+ # print(f"Averages for {vcpu_count} hotplugged vcpus:")
133
+ # print(f"\tAverage API call duration: {avg_api_duration} ms ")
134
+ # print(f"\tAverage onliing duration: {avg_onlining_duration } ms")
135
+ #
136
136
137
137
138
138
@pytest .mark .skipif (
@@ -142,7 +142,7 @@ def test_default_udev_rule_latency(
142
142
"vcpu_count" , [2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 ]
143
143
)
144
144
def test_manual_latency (
145
- microvm_factory , guest_kernel_linux_acpi_only , rootfs_rw , vcpu_count
145
+ microvm_factory , guest_kernel_linux_acpi_only , rootfs_rw , vcpu_count , results_dir
146
146
):
147
147
"""Test the latency for hotplugging and booting CPUs in the guest"""
148
148
gcc_compile (Path ("./host_tools/hotplug_time.c" ), Path ("host_tools/hotplug_time.o" ))
@@ -193,8 +193,11 @@ def test_manual_latency(
193
193
# Extract onlining timings
194
194
data .append ({"vcpus" : vcpu_count , "api" : api_duration , "onlining" : timestamp })
195
195
196
- df = pandas .DataFrame .from_dict (data ).to_csv (
197
- f"../test_results/manual-hotplug_{ vcpu_count } .csv" ,
196
+ output_file = results_dir / f"hotplug-{ vcpu_count } .csv"
197
+
198
+ csv_data = pandas .DataFrame .from_dict (data ).to_csv (
198
199
index = False ,
199
200
float_format = "%.3f" ,
200
201
)
202
+
203
+ output_file .write_text (csv_data )
0 commit comments