Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 20 | use lazy_static::lazy_static; |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 21 | use std::time::Duration; |
| 22 | |
| 23 | /// Holder for the various timeouts we use. |
| 24 | #[derive(Debug, Copy, Clone)] |
| 25 | pub struct Timeouts { |
| 26 | /// Total time that odrefresh may take to perform compilation |
| 27 | pub odrefresh_max_execution_time: Duration, |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 28 | /// Time allowed for the CompOS VM to start up and become ready. |
| 29 | pub vm_max_time_to_ready: Duration, |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 30 | /// Time we wait for a VM to exit once the payload has finished. |
| 31 | pub vm_max_time_to_exit: Duration, |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 34 | lazy_static! { |
| 35 | /// The timeouts that are appropriate on the current platform. |
| 36 | pub static ref TIMEOUTS: Timeouts = if nested_virt::is_nested_virtualization().unwrap() { |
Alan Stokes | c3f2ac2 | 2022-06-23 12:19:46 +0100 | [diff] [blame] | 37 | // Nested virtualization is slow. |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 38 | EXTENDED_TIMEOUTS |
| 39 | } else { |
| 40 | NORMAL_TIMEOUTS |
| 41 | }; |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /// The timeouts that we use normally. |
Alan Stokes | c3f2ac2 | 2022-06-23 12:19:46 +0100 | [diff] [blame] | 45 | const NORMAL_TIMEOUTS: Timeouts = Timeouts { |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 46 | // Note: the source of truth for this odrefresh timeout is art/odrefresh/odrefresh.cc. |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 47 | odrefresh_max_execution_time: Duration::from_secs(300), |
Alan Stokes | 758f9fd | 2022-03-17 16:10:48 +0000 | [diff] [blame] | 48 | vm_max_time_to_ready: Duration::from_secs(15), |
Alan Stokes | 0fc6ce5 | 2022-08-02 17:01:48 +0100 | [diff] [blame] | 49 | vm_max_time_to_exit: Duration::from_secs(5), |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 52 | /// The timeouts that we use when running under nested virtualization. |
Alan Stokes | c3f2ac2 | 2022-06-23 12:19:46 +0100 | [diff] [blame] | 53 | const EXTENDED_TIMEOUTS: Timeouts = Timeouts { |
Alan Stokes | 7140377 | 2022-06-21 14:56:28 +0100 | [diff] [blame] | 54 | // Note: the source of truth for this odrefresh timeout is art/odrefresh/odrefresh.cc. |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 55 | odrefresh_max_execution_time: Duration::from_secs(480), |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 56 | vm_max_time_to_ready: Duration::from_secs(120), |
Alan Stokes | 0fc6ce5 | 2022-08-02 17:01:48 +0100 | [diff] [blame] | 57 | vm_max_time_to_exit: Duration::from_secs(20), |
Alan Stokes | 17aed5c | 2021-10-20 14:25:57 +0100 | [diff] [blame] | 58 | }; |