Read the first "isa" string from /proc/cpuinfo and filter out the H extension, while correctly preserving multi-letter extensions.
()
| 125 | // Read the first "isa" string from /proc/cpuinfo and filter out the H extension, |
| 126 | // while correctly preserving multi-letter extensions. |
| 127 | fn isa_string_from_host() -> Result<String, Error> { |
| 128 | let file = File::open("/proc/cpuinfo").map_err(Error::OpenCpuInfo)?; |
| 129 | let reader = BufReader::new(file); |
| 130 | |
| 131 | for line in reader.lines() { |
| 132 | let line = line.map_err(Error::ReadCpuInfo)?; |
| 133 | let trimmed_line = line.trim(); |
| 134 | |
| 135 | if trimmed_line.starts_with("isa") { |
| 136 | let parts: Vec<&str> = trimmed_line.split(':').collect(); |
| 137 | if parts.len() == 2 { |
| 138 | let isa_string = parts[1].trim(); |
| 139 | |
| 140 | // Split the string by underscores to separate single letter vs long-form |
| 141 | // extensions |
| 142 | let mut components: Vec<String> = |
| 143 | isa_string.split('_').map(|s| s.to_string()).collect(); |
| 144 | |
| 145 | if components.is_empty() { |
| 146 | return Err(Error::InvalidIsaString(isa_string.to_string())); |
| 147 | } |
| 148 | |
| 149 | // Remove H extension if present in single letter extensions |
| 150 | let first_component = components[0].chars().filter(|&c| c != 'h').collect(); |
| 151 | |
| 152 | components[0] = first_component; |
| 153 | |
| 154 | return Ok(components.join("_")); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | Err(Error::CpuInfoParsing) |
| 160 | } |
| 161 | |
| 162 | /// Configures the system and should be called once per vm before starting vcpu threads. |
| 163 | #[allow(clippy::too_many_arguments)] |
no test coverage detected