You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2020/01/10 06:07:23 UTC

[incubator-teaclave] 01/02: [rpc] Use TCS number as n_workers for threadpool

This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git

commit 4d810b985a3daea702b45c5e5dcdd24fc55a6a61
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Thu Jan 9 21:27:21 2020 -0800

    [rpc] Use TCS number as n_workers for threadpool
---
 rpc/Cargo.toml    | 1 +
 rpc/src/lib.rs    | 1 +
 rpc/src/server.rs | 3 ++-
 rpc/src/utils.rs  | 7 +++++++
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml
index a780765..6c1565f 100644
--- a/rpc/Cargo.toml
+++ b/rpc/Cargo.toml
@@ -26,4 +26,5 @@ webpki     = { version = "0.21.0" }
 
 teaclave_types       = { path = "../types" }
 
+sgx_trts = { version = "1.1.0" }
 sgx_tstd = { version = "1.1.0", features = ["net", "backtrace"], optional = true }
diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs
index 1ac73fe..1e6dd34 100644
--- a/rpc/src/lib.rs
+++ b/rpc/src/lib.rs
@@ -19,6 +19,7 @@ pub mod config;
 mod protocol;
 pub mod server;
 mod transport;
+mod utils;
 
 #[cfg(not(feature = "mesalock_sgx"))]
 #[cfg(test)]
diff --git a/rpc/src/server.rs b/rpc/src/server.rs
index ad3e95d..72ffac2 100644
--- a/rpc/src/server.rs
+++ b/rpc/src/server.rs
@@ -10,6 +10,7 @@ cfg_if! {
 mod sgx_trusted_tls {
     use crate::config::SgxTrustedTlsServerConfig;
     use crate::transport::{ServerTransport, SgxTrustedTlsTransport};
+    use crate::utils;
     use crate::TeaclaveService;
     use anyhow::Result;
     use log::debug;
@@ -50,7 +51,7 @@ mod sgx_trusted_tls {
                 + core::marker::Send
                 + core::marker::Sync,
         {
-            let n_workers = 10;
+            let n_workers = utils::get_tcs_num();
             let pool = threadpool::ThreadPool::new(n_workers);
             for stream in self.listener.incoming() {
                 let session = rustls::ServerSession::new(&self.tls_config);
diff --git a/rpc/src/utils.rs b/rpc/src/utils.rs
new file mode 100644
index 0000000..5ea1822
--- /dev/null
+++ b/rpc/src/utils.rs
@@ -0,0 +1,7 @@
+pub(crate) fn get_tcs_num() -> usize {
+    if sgx_trts::enclave::rsgx_is_supported_EDMM() {
+        sgx_trts::enclave::SgxGlobalData::new().get_dyn_tcs_num() as usize
+    } else {
+        (sgx_trts::enclave::SgxGlobalData::new().get_tcs_max_num() - 1) as usize
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org