@@ -14,6 +14,11 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
+ #![ expect(
18
+ clippy:: disallowed_macros,
19
+ reason = "This is a benchmark file, so using disallowed macros is fine here."
20
+ ) ]
21
+
17
22
use std:: sync:: Mutex ;
18
23
19
24
use criterion:: { Criterion , criterion_group, criterion_main} ;
@@ -117,6 +122,54 @@ fn guest_call_benchmark(c: &mut Criterion) {
117
122
} ) ;
118
123
} ) ;
119
124
125
+ // Measure the time between calling interrupt_handle.kill() and the guest function returning.
126
+ group. bench_function ( "guest_call_time_to_interrupt" , |b| {
127
+ use std:: sync:: { Arc , Barrier } ;
128
+ use std:: thread;
129
+ use std:: time:: Instant ;
130
+
131
+ b. iter_custom ( |iters| {
132
+ let mut total_interrupt_latency = std:: time:: Duration :: ZERO ;
133
+
134
+ for _ in 0 ..iters {
135
+ let mut sbox = create_multiuse_sandbox ( ) ;
136
+ let interrupt_handle = sbox. interrupt_handle ( ) ;
137
+
138
+ let start_barrier = Arc :: new ( Barrier :: new ( 2 ) ) ;
139
+ let start_barrier_clone = Arc :: clone ( & start_barrier) ;
140
+
141
+ let observer_thread = thread:: spawn ( move || {
142
+ start_barrier_clone. wait ( ) ;
143
+
144
+ // Small delay to ensure the guest function is running in VM before interrupting
145
+ thread:: sleep ( std:: time:: Duration :: from_millis ( 1 ) ) ;
146
+ let kill_start = Instant :: now ( ) ;
147
+ interrupt_handle. kill ( ) ;
148
+ kill_start
149
+ } ) ;
150
+
151
+ start_barrier. wait ( ) ;
152
+
153
+ let result = sbox. call :: < i32 > ( "Spin" , ( ) ) ;
154
+
155
+ let call_end = Instant :: now ( ) ;
156
+ let kill_start = observer_thread. join ( ) . unwrap ( ) ;
157
+
158
+ assert ! (
159
+ matches!(
160
+ result,
161
+ Err ( hyperlight_host:: HyperlightError :: ExecutionCanceledByHost ( ) )
162
+ ) ,
163
+ "Guest function should be interrupted"
164
+ ) ;
165
+
166
+ total_interrupt_latency += call_end. duration_since ( kill_start) ;
167
+ }
168
+
169
+ total_interrupt_latency
170
+ } ) ;
171
+ } ) ;
172
+
120
173
group. finish ( ) ;
121
174
}
122
175
@@ -228,7 +281,6 @@ fn function_call_serialization_benchmark(c: &mut Criterion) {
228
281
group. finish ( ) ;
229
282
}
230
283
231
- #[ allow( clippy:: disallowed_macros) ]
232
284
fn sample_workloads_benchmark ( c : & mut Criterion ) {
233
285
let mut group = c. benchmark_group ( "sample_workloads" ) ;
234
286
0 commit comments