Skip to content

Commit

Permalink
!532 Sync the patches from the dev branch to the master branch
Browse files Browse the repository at this point in the history
From: @yezengruan 
Reviewed-by: @ooorz 
Signed-off-by: @ooorz
  • Loading branch information
xiangxinyong authored and gitee-org committed Sep 16, 2022
2 parents d45d3e7 + dc7bc20 commit 36e9cae
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ https://www.rust-lang.org/tools/install
```sh
$ git clone https://gitee.com/openeuler/stratovirt.git
$ cd stratovirt
$ cargo build --release
$ make build
```
可以在`target/release/stratovirt`路径下找到生成的二进制文件

Expand Down
29 changes: 16 additions & 13 deletions cpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,18 +718,18 @@ impl CPUThreadWorker {
/// The wrapper for topology for VCPU.
#[derive(Clone)]
pub struct CpuTopology {
/// Number of vcpus in VM.
pub nrcpus: u8,
/// Number of sockets in VM.
pub sockets: u8,
/// Number of dies on one socket.
/// Number of dies in one socket.
pub dies: u8,
/// Number of clusters on one socket.
/// Number of clusters in one die.
pub clusters: u8,
/// Number of cores in VM.
/// Number of cores in one cluster.
pub cores: u8,
/// Number of threads in VM.
/// Number of threads in one core.
pub threads: u8,
/// Number of vcpus in VM.
pub nrcpus: u8,
/// Number of online vcpus in VM.
pub max_cpus: u8,
/// Online mask number of all vcpus.
Expand All @@ -738,29 +738,32 @@ pub struct CpuTopology {

impl CpuTopology {
/// * `nr_cpus`: Number of vcpus in one VM.
/// * `nr_threads`: Number of threads on one core.
/// * `nr_cores`: Number of cores on one socket
/// * `nr_sockets`: Number of sockets on in one VM.
/// * `nr_sockets`: Number of sockets in one VM.
/// * `nr_dies`: Number of dies in one socket.
/// * `nr_clusters`: Number of clusters in one die.
/// * `nr_cores`: Number of cores in one cluster.
/// * `nr_threads`: Number of threads in one core.
/// * `max_cpus`: Number of online vcpus in VM.
pub fn new(
nr_cpus: u8,
nr_threads: u8,
nr_cores: u8,
nr_sockets: u8,
nr_dies: u8,
nr_clusters: u8,
nr_sockets: u8,
nr_cores: u8,
nr_threads: u8,
max_cpus: u8,
) -> Self {
let mut mask: Vec<u8> = vec![0; max_cpus as usize];
(0..nr_cpus as usize).for_each(|index| {
mask[index] = 1;
});
Self {
nrcpus: nr_cpus,
sockets: nr_sockets,
dies: nr_dies,
clusters: nr_clusters,
cores: nr_cores,
threads: nr_threads,
nrcpus: nr_cpus,
max_cpus,
online_mask: Arc::new(Mutex::new(mask)),
}
Expand Down
4 changes: 3 additions & 1 deletion docs/config_guidebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ Three properties can be set for USB controller.
Note: Only one USB controller can be configured, USB controller can only support USB keyboard and USB tablet.

### 2.14 USB Keyboard
The USB keyboard is a keyboard that uses the USB protocol. It should be attached to USB controller. Keypad is not supported yet.
The USB keyboard is a keyboard that uses the USB protocol. It should be attached to USB controller. Keypad and led are not supported yet.

One property can be set for USB Keyboard.

Expand All @@ -654,6 +654,7 @@ One property can be set for USB Keyboard.
```

Note: Only one keyboard can be configured.

### 2.15 USB Tablet
Pointer Device which uses alsolute coordinates. It should be attached to USB controller.

Expand All @@ -666,6 +667,7 @@ One property can be set for USB Tablet.
```

Note: Only one tablet can be configured.

## 3. Trace

Users can specify the configuration file which lists events to trace.
Expand Down
6 changes: 3 additions & 3 deletions machine/src/micro_vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ impl LightMachine {
Ok(LightMachine {
cpu_topo: CpuTopology::new(
vm_config.machine_config.nr_cpus,
vm_config.machine_config.nr_threads,
vm_config.machine_config.nr_cores,
vm_config.machine_config.nr_sockets,
vm_config.machine_config.nr_dies,
vm_config.machine_config.nr_clusters,
vm_config.machine_config.nr_sockets,
vm_config.machine_config.nr_cores,
vm_config.machine_config.nr_threads,
vm_config.machine_config.max_cpus,
),
cpus: Vec::new(),
Expand Down
6 changes: 3 additions & 3 deletions machine/src/standard_vm/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ impl StdMachine {

let cpu_topo = CpuTopology::new(
vm_config.machine_config.nr_cpus,
vm_config.machine_config.nr_threads,
vm_config.machine_config.nr_cores,
vm_config.machine_config.nr_sockets,
vm_config.machine_config.nr_dies,
vm_config.machine_config.nr_clusters,
vm_config.machine_config.nr_sockets,
vm_config.machine_config.nr_cores,
vm_config.machine_config.nr_threads,
vm_config.machine_config.max_cpus,
);
let sys_mem = AddressSpace::new(Region::init_container_region(u64::max_value()))
Expand Down
6 changes: 3 additions & 3 deletions machine/src/standard_vm/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ impl StdMachine {

let cpu_topo = CpuTopology::new(
vm_config.machine_config.nr_cpus,
vm_config.machine_config.nr_threads,
vm_config.machine_config.nr_cores,
vm_config.machine_config.nr_sockets,
vm_config.machine_config.nr_dies,
vm_config.machine_config.nr_clusters,
vm_config.machine_config.nr_sockets,
vm_config.machine_config.nr_cores,
vm_config.machine_config.nr_threads,
vm_config.machine_config.max_cpus,
);
let sys_io = AddressSpace::new(Region::init_container_region(1 << 16))
Expand Down
62 changes: 52 additions & 10 deletions machine_manager/src/config/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.

use log::warn;

use super::{
errors::{ErrorKind, Result},
M,
Expand All @@ -19,6 +21,8 @@ use crate::config::{CmdParser, ConfigCheck, MAX_STRING_LENGTH};
/// The maximum number of scanouts.
pub const VIRTIO_GPU_MAX_SCANOUTS: usize = 16;

pub const VIRTIO_GPU_MAX_HOSTMEM: u64 = 256 * M;

#[derive(Clone)]
pub struct GpuConfig {
pub id: String,
Expand All @@ -37,7 +41,7 @@ impl Default for GpuConfig {
edid: true,
xres: 1024,
yres: 768,
max_hostmem: 256 * M,
max_hostmem: VIRTIO_GPU_MAX_HOSTMEM,
}
}
}
Expand All @@ -59,15 +63,12 @@ impl ConfigCheck for GpuConfig {
.into());
}

if self.max_hostmem < 256 * M {
return Err(ErrorKind::IllegalValue(
"max_hostmem".to_string(),
0,
false,
256 * M as u64,
true,
)
.into());
if self.max_hostmem < VIRTIO_GPU_MAX_HOSTMEM {
warn!(
"max_hostmem must >= {}, allocating less than it may cause \
the GPU to fail to start or refresh.",
VIRTIO_GPU_MAX_HOSTMEM
);
}

Ok(())
Expand Down Expand Up @@ -111,3 +112,44 @@ pub fn parse_gpu(gpu_config: &str) -> Result<GpuConfig> {

Ok(gpu_cfg)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_parse_gpu_max_hostmem_greater_than_limit() {
let max_hostmem = VIRTIO_GPU_MAX_HOSTMEM + 1;
let gpu_cfg_cmdline = format!(
"{}{}",
"virtio-gpu-pci,id=gpu_1,bus=pcie.0,addr=0x4.0x0,\
max_outputs=1,edid=true,xres=1024,yres=768,max_hostmem=",
max_hostmem.to_string()
);

let gpu_cfg_ = parse_gpu(&gpu_cfg_cmdline);

assert!(gpu_cfg_.is_ok());

let gpu_cfg = gpu_cfg_.unwrap();
assert_eq!(gpu_cfg.max_hostmem, max_hostmem);
}

#[test]
fn test_parse_gpu_max_hostmem_less_than_limit() {
let max_hostmem = VIRTIO_GPU_MAX_HOSTMEM - 1;
let gpu_cfg_cmdline = format!(
"{}{}",
"virtio-gpu-pci,id=gpu_1,bus=pcie.0,addr=0x4.0x0,\
max_outputs=1,edid=true,xres=1024,yres=768,max_hostmem=",
max_hostmem.to_string()
);

let gpu_cfg_ = parse_gpu(&gpu_cfg_cmdline);

assert!(gpu_cfg_.is_ok());

let gpu_cfg = gpu_cfg_.unwrap();
assert_eq!(gpu_cfg.max_hostmem, max_hostmem);
}
}
12 changes: 5 additions & 7 deletions usb/src/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,20 @@ impl Hid {
self.head - 1
};
let evt = &mut self.pointer.queue[(index & QUEUE_MASK) as usize];
let mut z = evt.pos_z;
evt.pos_z -= z;
if self.num != 0 && evt.pos_z == 0 {
let z = evt.pos_z;
evt.pos_z = 0;
if self.num != 0 {
increase_queue(&mut self.head);
self.num -= 1;
}
z = 0 - z;
let data = vec![
vec![
evt.button_state as u8,
evt.pos_x as u8,
(evt.pos_x >> 8) as u8,
evt.pos_y as u8,
(evt.pos_y >> 8) as u8,
z as u8,
];
data
]
}

/// USB HID device handle control packet.
Expand Down

0 comments on commit 36e9cae

Please sign in to comment.