Skip to content

Commit 0cc6b9c

Browse files
Implement basic functionality of mRPC (#92)
* save * move transport implementations to a separate directory * save * add mrpc register (not finished) * save, working on socket datapath * save, creating service and customer * save, pass compile * minor fix, update KOALA_PATH * save, graph abstraction * save, add infrastructure of building engine graph * save, update customer and server, a lot compile error to fix * pass compile * minor fix * fix minor bug in print_lat * save * save * save, implementing uverbs * save, port ulib to koala * save * save, implement rpc_adapter * save, fix several issues, pass compile * finish coding, there are many places which do not make much sense * fix some bugs * minor update * minor changes, also update a todo list for the initial RPC to run * finish rpc client side async glue code and non-blocking get_request in rpc_adapter * implemented switch_addr_space at the koala side * fix many bugs * fix more bugs, now can do rpc of a round-trip * fix many bugs, now switch_addr_space works * now can send multiple RPC requests * save * fix many bugs in memory mapping, now can stably run multiple messages * minor change * backport bugfix from the main branch * minor change Co-authored-by: lsh <[email protected]>
1 parent a3f86aa commit 0cc6b9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+9173
-1157
lines changed

Cargo.lock

+337-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
[workspace]
2-
members = ["src/experimental", "src/koala", "src/ipc", "src/engine", "src/rdma", "src/utils", "src/libkoala", "src/koala_examples"]
2+
members = [
3+
"src/experimental",
4+
"src/koala",
5+
"src/ipc",
6+
"src/rdma",
7+
"src/utils",
8+
"src/libkoala",
9+
"src/koala_examples",
10+
"src/memmap-fixed",
11+
]
312

413
[profile.release]
514
debug=true

koala.toml

+60-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,65 @@
1-
modules = ["transport"]
1+
log_env = "KOALA_LOG"
2+
default_log_level = "debug"
23

3-
[transport]
4+
# modules = ["transport-rdma", "transport-tcp", "mrpc", "rpc-adapter", "overload"]
5+
modules = ["Mrpc", "RpcAdapter", "Overload"]
6+
7+
[control]
8+
prefix = "/tmp/koala"
9+
path = "koala-control.sock"
10+
11+
[transport-rdma]
412
prefix = "/tmp/koala"
5-
module_path = "koala-transport.sock"
6-
engine_basename = "koala-transport-engine"
13+
engine_basename = "koala-transport-engine-rdma"
714
datapath_wq_depth = 32
815
datapath_cq_depth = 32
916
command_max_interval_ms = 1000
17+
18+
[[node]]
19+
id = "mrpc.0"
20+
type = "Mrpc"
21+
22+
# [[node]]
23+
# id = "overload"
24+
# type = "Overload"
25+
26+
[[node]]
27+
id = "rpc-adapter"
28+
type = "RpcAdapter"
29+
30+
[edges]
31+
egress = [
32+
["mrpc.0", "rpc-adapter"],
33+
]
34+
# egress = [
35+
# ["mrpc.0", "overload"],
36+
# ["overload", "rpc-adapter"],
37+
# ]
38+
ingress = [
39+
["rpc-adapter", "mrpc.0"],
40+
]
41+
42+
# [[egress]]
43+
# from = "mrpc.0"
44+
# to = "overload"
45+
46+
# instances = [
47+
# {
48+
# "id": 1,
49+
# "type":"mrpc",
50+
# "tx_output": [2],
51+
# "rx_input": [3]
52+
# },
53+
# {
54+
# "id": 2,
55+
# "type":"overload",
56+
# "tx_input": [1],
57+
# "tx_output": [3]
58+
# },
59+
# {
60+
# "id": 3,
61+
# "type":"adapter",
62+
# "tx_input": [2],
63+
# "rx_output": [1]
64+
# }
65+
# ]

scripts/build_release.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -euo pipefail
44

55
main() {
6-
cmake -DCMAKE_BUILD_TYPE=Release -Bbuild
6+
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -Bbuild
77
cmake --build build
88
}
99

scripts/count_loc.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
function info {
4+
echo "$(tput bold)$(tput setaf 10)"$*"$(tput sgr 0)"
5+
}
6+
7+
8+
info "miscellaneous code:"
9+
find src/experimental -type f -name "*.rs" | xargs wc -l
10+
info "rdma bindings:"
11+
find src/rdma -type f -name "*.rs" | grep -v bindings | xargs wc -l
12+
info "koala examples:"
13+
find src/koala_examples -type f -name "*.rs" | xargs wc -l
14+
15+
info "koala total:"
16+
find src/ -type f -name "*.rs" | grep -v "experimental" | grep -v bindings.rs | grep -v koala_examples | xargs wc -l

src/engine/Cargo.toml

-16
This file was deleted.

src/engine/src/lib.rs

-36
This file was deleted.

src/experimental/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ serde = { version = "1.0.130", features = ["derive"] }
2424
bincode = "1.3.3"
2525
anyhow = "1.0.44"
2626
ipc = { path = "../ipc" }
27-
engine = { path = "../engine" }
2827
interface = { path = "../interface" }
2928
uuid = "0.8.2"
3029
thiserror = "1.0.29"
3130
shmem-ipc = "0.2.0"
31+
toml = { version = "0.5.8", features = ["preserve_order"] }
32+
petgraph = "0.6.0"
33+
linked-hash-map = "0.5.4"
34+
zerocopy = "0.3.0"
3235

3336
[dev-dependencies]
3437
rand = "0.8.3"

src/experimental/examples/bench_shmem_ipc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use structopt::StructOpt;
1515
use shmem_ipc::sharedring::{Receiver, Sender};
1616

1717
use experimental::*;
18-
use ipc::{recv_fd, send_fd};
18+
use experimental::ipc::{recv_fd, send_fd};
1919

2020
type Value = [u8; 64];
2121

src/experimental/examples/bench_shmem_ipc_sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use structopt::StructOpt;
1414
use shmem_ipc::sharedring::{Receiver, Sender};
1515

1616
use experimental::*;
17-
use ipc::{recv_fd, send_fd};
17+
use experimental::ipc::{recv_fd, send_fd};
1818

1919
type Value = [u8; 64];
2020

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
use std::fs;
2+
use std::path::{Path, PathBuf};
3+
4+
use serde::{Serialize, Deserialize};
5+
6+
use interface::engine::EngineType;
7+
8+
#[derive(Debug, Clone, Serialize, Deserialize)]
9+
#[serde(deny_unknown_fields)]
10+
struct Node {
11+
id: String,
12+
#[serde(alias = "type")]
13+
engine_type: EngineType,
14+
#[serde(default)]
15+
tx_input: Vec<String>,
16+
#[serde(default)]
17+
tx_output: Vec<String>,
18+
#[serde(default)]
19+
rx_input: Vec<String>,
20+
#[serde(default)]
21+
rx_output: Vec<String>,
22+
}
23+
24+
// #[derive(Debug, Clone, Copy)]
25+
// struct Node {
26+
// id: usize,
27+
// engine_type: EngineType,
28+
// }
29+
30+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
31+
enum DatapathDir {
32+
Tx,
33+
Rx,
34+
}
35+
36+
#[derive(Debug, Clone, Copy)]
37+
struct Edge {
38+
dp: DatapathDir,
39+
}
40+
41+
type Graph = petgraph::Graph<Node, Edge>;
42+
43+
#[derive(Debug, Clone, Serialize, Deserialize)]
44+
struct Profile {
45+
log_env: String,
46+
default_log_level: String,
47+
modules: Vec<String>,
48+
control: Control,
49+
#[serde(alias = "transport-rdma")]
50+
transport_rdma: Option<RdmaTransportConfig>,
51+
node: Vec<Node>,
52+
}
53+
54+
#[derive(Debug, Clone, Serialize, Deserialize)]
55+
#[serde(deny_unknown_fields)]
56+
struct Control {
57+
prefix: PathBuf,
58+
path: PathBuf,
59+
}
60+
61+
#[derive(Debug, Clone, Serialize, Deserialize)]
62+
#[serde(deny_unknown_fields)]
63+
struct RdmaTransportConfig {
64+
prefix: PathBuf,
65+
engine_basename: String,
66+
datapath_wq_depth: usize,
67+
datapath_cq_depth: usize,
68+
command_max_interval_ms: u32,
69+
}
70+
71+
struct Config {
72+
toml_config: toml::Value,
73+
profile: Profile,
74+
// graph: Graph,
75+
}
76+
77+
const VALID_KEYS: [&str; 4] = ["log_env", "default_log_level", "modules", "control"];
78+
79+
impl Config {
80+
fn parse_graph(config: &toml::Value, profile: &Profile) -> anyhow::Result<Graph> {
81+
let modules = &profile.modules;
82+
match config {
83+
toml::Value::Table(config) => {
84+
for key in config.keys() {
85+
let engine_type_str = if let Some((a, _)) = key.split_once("-") {
86+
a.to_owned()
87+
} else {
88+
key.clone()
89+
};
90+
if !modules.contains(&engine_type_str) { continue; }
91+
// let module: Module = &config[key].to_string().parse().unwrap();
92+
println!("engine_type_str: {:?}", engine_type_str);
93+
println!("to_str: {:?}", config[key].to_string());
94+
let module: Node = toml::from_str(&config[key].to_string()).unwrap();
95+
println!("module: {:?}", module);
96+
}
97+
Err(anyhow::anyhow!("Config has a wrong format"))
98+
}
99+
_ => Err(anyhow::anyhow!("Config has a wrong format")),
100+
}
101+
}
102+
103+
fn verify_config(config: &toml::Value, profile: &Profile) -> anyhow::Result<()> {
104+
let modules = &profile.modules;
105+
match config {
106+
toml::Value::Table(config) => {
107+
for key in config.keys() {
108+
if VALID_KEYS.contains(&key.as_str()) {
109+
continue;
110+
}
111+
if modules.contains(key) {
112+
continue;
113+
}
114+
if let Some((a, _b)) = key.split_once("-") {
115+
if modules.contains(&a.to_owned()) {
116+
continue;
117+
}
118+
}
119+
return Err(anyhow::anyhow!("Invalid key: {}", key));
120+
}
121+
return Ok(());
122+
}
123+
_ => Err(anyhow::anyhow!("Config has a wrong format")),
124+
}
125+
}
126+
127+
fn from_path<P: AsRef<Path>>(path: P) -> anyhow::Result<Self> {
128+
let content = fs::read_to_string(path).unwrap();
129+
let config = content.parse::<toml::Value>().unwrap();
130+
let profile = toml::from_str(&content).unwrap();
131+
// let graph = Self::parse_graph(&config, &profile)?;
132+
// Self::verify_config(&config, &profile)?;
133+
println!("profile: {:#?}", profile);
134+
Ok(Self {
135+
toml_config: config,
136+
profile,
137+
// graph,
138+
})
139+
}
140+
}
141+
142+
fn main() {
143+
let content = fs::read_to_string("koala.toml").unwrap();
144+
let config = content.parse::<toml::Value>().unwrap();
145+
// println!("config: {:#?}", config["log_env"]);
146+
// println!("config: {:#?}", config["default_log_level"]);
147+
// println!("config: {:#?}", config["modules"]);
148+
// println!("config: {:#?}", config["control"]);
149+
// println!("config: {:#?}", config["transport-rdma"]);
150+
// println!("config: {:#?}", config["Mrpc-0"]);
151+
// if let toml::Value::Table(config) = config {
152+
// for k in config.keys() {
153+
// println!("key: {:?}", k);
154+
// }
155+
// }
156+
157+
let profile: Profile = toml::from_str(&content).unwrap();
158+
println!("profile: {:#?}", profile);
159+
160+
let config = Config::from_path("koala.toml").unwrap();
161+
}

0 commit comments

Comments
 (0)