Update internal config tool for EDMM support

This commit is contained in:
Hui, Chunyang 2022-12-21 14:39:16 +08:00 committed by volcano
parent 22ff266958
commit 08b3dc7268
4 changed files with 80 additions and 6 deletions

@ -1,6 +1,7 @@
{ {
"resource_limits": { "resource_limits": {
"kernel_space_heap_size": "40MB", "kernel_space_heap_size": "40MB",
"kernel_space_heap_max_size": "512MB",
"kernel_space_stack_size": "1MB", "kernel_space_stack_size": "1MB",
"user_space_size": "600MB", "user_space_size": "600MB",
"max_num_of_threads": 32 "max_num_of_threads": 32

@ -77,6 +77,7 @@ version = "0.2.0"
dependencies = [ dependencies = [
"clap", "clap",
"env_logger", "env_logger",
"lazy_static",
"log", "log",
"regex", "regex",
"serde", "serde",
@ -109,6 +110,12 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.70" version = "0.2.70"

@ -19,3 +19,4 @@ log = "0.4"
env_logger = "0.7" env_logger = "0.7"
serde-xml-rs = "0.4" serde-xml-rs = "0.4"
regex = "1" regex = "1"
lazy_static = "1.4.0"

@ -7,6 +7,7 @@ extern crate serde_derive;
extern crate serde_xml_rs; extern crate serde_xml_rs;
use clap::{App, Arg, SubCommand}; use clap::{App, Arg, SubCommand};
use lazy_static::lazy_static;
use log::debug; use log::debug;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
@ -14,6 +15,37 @@ use std::fs::File;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
// Some hardcode implicit config value. Please update the values defined in "init()" when necessary.
lazy_static! {
static ref DEFAULT_CONFIG: DefaultConfig = DefaultConfig::init();
}
struct DefaultConfig {
// Corresponds to HeapMaxSize in Enclave.xml
kernel_heap_max_size: &'static str,
// Corresponds to TCSMaxNum in Enclave.xml
num_of_tcs_max: u32,
// Corresponds to MiscSelect in Enclave.xml
misc_select: &'static str,
// Corresponds to MiscMask in Enclave.xml
misc_mask: &'static str,
}
impl DefaultConfig {
fn init() -> Self {
Self {
kernel_heap_max_size: "1024MB",
num_of_tcs_max: 4096,
// If UserRegionSize is not configured, but the heap, stack and thread related
// configurations have dynamic part, set MiscSelect[0] = 1 and MiscMask[0] = 0,
// the enclave can be loaded on SGX 1.0 and 2.0 platform, and on SGX 2.0 platform,
// it can utilize the dynamic components.
misc_select: "1",
misc_mask: "0x0",
}
}
}
fn main() { fn main() {
env_logger::init(); env_logger::init();
@ -125,6 +157,11 @@ fn main() {
enclave_config_file_path enclave_config_file_path
); );
// get the number of TCS
let tcs_num = occlum_config.resource_limits.max_num_of_threads;
let tcs_min_pool = tcs_num;
let tcs_max_num = std::cmp::max(tcs_num, DEFAULT_CONFIG.num_of_tcs_max);
// get the kernel stack size // get the kernel stack size
let stack_max_size = let stack_max_size =
parse_memory_size(&occlum_config.resource_limits.kernel_space_stack_size); parse_memory_size(&occlum_config.resource_limits.kernel_space_stack_size);
@ -135,16 +172,36 @@ fn main() {
); );
return; return;
} }
// get the kernel heap size // get the kernel heap size
let heap_max_size = let heap_init_size =
parse_memory_size(&occlum_config.resource_limits.kernel_space_heap_size); parse_memory_size(&occlum_config.resource_limits.kernel_space_heap_size);
if heap_max_size.is_err() { if heap_init_size.is_err() {
println!( println!(
"The kernel_space_heap_size \"{}\" is not correct.", "The kernel_space_heap_size \"{}\" is not correct.",
occlum_config.resource_limits.kernel_space_heap_size occlum_config.resource_limits.kernel_space_heap_size
); );
return; return;
} }
// For max heap size, try to use the values provided by users. If not provided, use the default value
let heap_max_size = {
if let Some(ref kernel_space_heap_max_size) =
occlum_config.resource_limits.kernel_space_heap_max_size
{
let heap_max_size = parse_memory_size(&kernel_space_heap_max_size);
if heap_max_size.is_err() {
println!(
"The kernel_space_heap_max_size \"{}\" is not correct.",
kernel_space_heap_max_size
);
return;
}
heap_max_size
} else {
parse_memory_size(DEFAULT_CONFIG.kernel_heap_max_size)
}
};
// get the user space size // get the user space size
let user_space_size = parse_memory_size(&occlum_config.resource_limits.user_space_size); let user_space_size = parse_memory_size(&occlum_config.resource_limits.user_space_size);
if user_space_size.is_err() { if user_space_size.is_err() {
@ -183,16 +240,19 @@ fn main() {
ISVSVN: occlum_config.metadata.version_number, ISVSVN: occlum_config.metadata.version_number,
StackMaxSize: stack_max_size.unwrap() as u64, StackMaxSize: stack_max_size.unwrap() as u64,
StackMinSize: stack_max_size.unwrap() as u64, // just use the same size as max size StackMinSize: stack_max_size.unwrap() as u64, // just use the same size as max size
HeapInitSize: heap_init_size.unwrap() as u64,
HeapMaxSize: heap_max_size.unwrap() as u64, HeapMaxSize: heap_max_size.unwrap() as u64,
HeapMinSize: heap_max_size.unwrap() as u64, // just use the same size as max size HeapMinSize: heap_init_size.unwrap() as u64,
TCSNum: occlum_config.resource_limits.max_num_of_threads, TCSNum: tcs_num,
TCSMinPool: tcs_min_pool,
TCSMaxNum: tcs_max_num,
TCSPolicy: 1, TCSPolicy: 1,
DisableDebug: match occlum_config.metadata.debuggable { DisableDebug: match occlum_config.metadata.debuggable {
true => 0, true => 0,
false => 1, false => 1,
}, },
MiscSelect: "0".to_string(), MiscSelect: DEFAULT_CONFIG.misc_select.to_string(),
MiscMask: "0xFFFFFFFF".to_string(), MiscMask: DEFAULT_CONFIG.misc_mask.to_string(),
ReservedMemMaxSize: user_space_size.unwrap() as u64, ReservedMemMaxSize: user_space_size.unwrap() as u64,
ReservedMemMinSize: user_space_size.unwrap() as u64, ReservedMemMinSize: user_space_size.unwrap() as u64,
ReservedMemInitSize: user_space_size.unwrap() as u64, ReservedMemInitSize: user_space_size.unwrap() as u64,
@ -426,6 +486,8 @@ struct OcclumConfiguration {
struct OcclumResourceLimits { struct OcclumResourceLimits {
max_num_of_threads: u32, max_num_of_threads: u32,
kernel_space_heap_size: String, kernel_space_heap_size: String,
#[serde(default)]
kernel_space_heap_max_size: Option<String>,
kernel_space_stack_size: String, kernel_space_stack_size: String,
user_space_size: String, user_space_size: String,
#[cfg(feature = "ms_buffer")] #[cfg(feature = "ms_buffer")]
@ -497,9 +559,12 @@ struct EnclaveConfiguration {
ISVSVN: u32, ISVSVN: u32,
StackMaxSize: u64, StackMaxSize: u64,
StackMinSize: u64, StackMinSize: u64,
HeapInitSize: u64,
HeapMaxSize: u64, HeapMaxSize: u64,
HeapMinSize: u64, HeapMinSize: u64,
TCSNum: u32, TCSNum: u32,
TCSMaxNum: u32,
TCSMinPool: u32,
TCSPolicy: u32, TCSPolicy: u32,
DisableDebug: u32, DisableDebug: u32,
MiscSelect: String, MiscSelect: String,