blob: d0d107f72521d774d6d730ce8914e0e259eb8d82 [file] [log] [blame]
Alan Stokes17aed5c2021-10-20 14:25:57 +01001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! Timeouts for common situations, with support for longer timeouts when using nested
18//! virtualization.
19
20use anyhow::Result;
Alan Stokes17aed5c2021-10-20 14:25:57 +010021use std::time::Duration;
22
23/// Holder for the various timeouts we use.
24#[derive(Debug, Copy, Clone)]
25pub struct Timeouts {
26 /// Total time that odrefresh may take to perform compilation
27 pub odrefresh_max_execution_time: Duration,
Alan Stokes17aed5c2021-10-20 14:25:57 +010028 /// Time allowed for the CompOS VM to start up and become ready.
29 pub vm_max_time_to_ready: Duration,
30}
31
Alan Stokes17aed5c2021-10-20 14:25:57 +010032/// Return the timeouts that are appropriate on the current platform.
33pub fn timeouts() -> Result<&'static Timeouts> {
Alan Stokesc3f2ac22022-06-23 12:19:46 +010034 // Nested virtualization is slow.
35 if nested_virt::is_nested_virtualization()? {
Alan Stokes17aed5c2021-10-20 14:25:57 +010036 Ok(&EXTENDED_TIMEOUTS)
37 } else {
38 Ok(&NORMAL_TIMEOUTS)
39 }
40}
41
42/// The timeouts that we use normally.
Alan Stokesc3f2ac22022-06-23 12:19:46 +010043const NORMAL_TIMEOUTS: Timeouts = Timeouts {
Alan Stokes17aed5c2021-10-20 14:25:57 +010044 // Note: the source of truth for these odrefresh timeouts is art/odrefresh/odr_config.h.
45 odrefresh_max_execution_time: Duration::from_secs(300),
Alan Stokes758f9fd2022-03-17 16:10:48 +000046 vm_max_time_to_ready: Duration::from_secs(15),
Alan Stokes17aed5c2021-10-20 14:25:57 +010047};
48
49/// The timeouts that we use when need_extra_time() returns true.
Alan Stokesc3f2ac22022-06-23 12:19:46 +010050const EXTENDED_TIMEOUTS: Timeouts = Timeouts {
Alan Stokes17aed5c2021-10-20 14:25:57 +010051 odrefresh_max_execution_time: Duration::from_secs(480),
Alan Stokes17aed5c2021-10-20 14:25:57 +010052 vm_max_time_to_ready: Duration::from_secs(120),
53};