Skip to content

Commit

Permalink
Update core module
Browse files Browse the repository at this point in the history
  • Loading branch information
eshikafe committed Sep 21, 2024
1 parent 53fb96c commit 1c99103
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 279 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
chrono = "0.4.22"
lazy_static = "1.4.0"
daemonize="0.4.1"
once_cell = "1.17.1"

[build-dependencies]
# time = "0.1"
Expand Down
3 changes: 2 additions & 1 deletion src/core/mod.rs → src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pub mod scheduler;
pub mod shared_obj;
pub mod task;
pub mod traffic_class;
pub mod worker;
pub mod worker;
pub mod utils;
47 changes: 21 additions & 26 deletions src/core/bessctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::shared_obj;
use crate::traffic_class;
// #include "utils/ether.h"
// #include "utils/time.h"
use crate::worker::{self, WorkerStatus};
use crate::worker::{self, WorkerStatus, Worker};

// #include <rte_mempool.h>
// #include <rte_ring.h>
Expand Down Expand Up @@ -571,7 +571,7 @@ impl BessControl for BESSControlService {
&self,
req: Request<EmptyRequest>,
) -> Result<Response<ListWorkersResponse>, Status> {
for wid in 0..worker::K_MAX_WORKERS {
for wid in 0..Worker::K_MAX_WORKERS {
if !worker::is_worker_active(wid) {
continue;
}
Expand Down Expand Up @@ -607,36 +607,31 @@ impl BessControl for BESSControlService {
) -> Result<Response<EmptyResponse>, Status> {
// std::lock_guard<std::recursive_mutex> lock(mutex_);

// uint64_t wid = request->wid();
let wid = request.get_mut().wid;
// if (wid >= Worker::kMaxWorkers) {
// return return_with_error(response, EINVAL, "Invalid worker id");
// }
if wid >= worker::K_MAX_WORKERS as i64 {
let wid = request.get_ref().wid;
if wid >= Worker::K_MAX_WORKERS as i64 {
return Err(Status::aborted("Invalid worker id"));
}
// uint64_t core = request->core();
// if (!is_cpu_present(core)) {
// return return_with_error(response, EINVAL, "Invalid core %d", core);
// }

let core = request.get_ref().core;
// if (is_worker_active(wid)) {
// return return_with_error(response, EEXIST, "worker:%d is already active",
// wid);
// }
if worker::is_worker_active(wid) {
return Err(Status::aborted("active"));
if !worker::is_cpu_present(core) {
let response = format!("Invalid core {}", core);
return Err(Status::invalid_argument(response));
}

if worker::is_worker_active(wid as usize) {
let response = format!("worker: {} is already active", wid);
return Err(Status::already_exists(response));
}

// const std::string& scheduler = request->scheduler();
// if (scheduler != "" && scheduler != "experimental") {
// return return_with_error(response, EINVAL, "Invalid scheduler %s",
// scheduler.c_str());
// }
let scheduler = request.get_ref().scheduler.as_str();
if scheduler != "" && scheduler != "experimental" {
let response = format!("Invalid scheduler {}", scheduler);
return Err(Status::invalid_argument(response));
}

// launch_worker(wid, core, scheduler);
// return Status::OK;
// }
worker::launch_worker(wid, core, scheduler);
return Ok(Response::new(EmptyResponse { error: None }));

}
// Status DestroyWorker(ServerContext*, const DestroyWorkerRequest* request,
// EmptyResponse* response) override {
Expand Down
5 changes: 2 additions & 3 deletions src/core/bessd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ use crate::core::opts::*;
use chrono;
use clap::Parser;
use env_logger::fmt::Color;
use env_logger::{Builder, Target, WriteStyle};
use env_logger::{Target, WriteStyle};
use exitcode;
use exitcode::OK;
use log::*;
use std::io::{self, BufRead,Write};
use std::process::exit;
Expand Down Expand Up @@ -203,4 +202,4 @@ pub fn get_current_directory() -> String {
fn read_file_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>> where P: AsRef<Path>, {
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}
}
7 changes: 2 additions & 5 deletions src/core/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// #include <iostream>
// #include <sstream>
// #include <string>
// #include <vector>

// #include "module.h"
use crate::core::traffic_class;
// use crate::core::traffic_class;
// #include "utils/extended_priority_queue.h"
// #include "worker.h"

Expand Down Expand Up @@ -48,6 +44,7 @@ struct SchedWakeupQueue;

// The non-instantiable base class for schedulers. Implements common routines
// needed for scheduling.

pub struct Scheduler {
// root: *TrafficClass,
// default_rr_class: *RoundRobinTrafficClass,
Expand Down
52 changes: 30 additions & 22 deletions src/core/traffic_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ const QUANTUM: u32 = 1 << 10;

// Resource types that can be accounted for.
pub enum Resource {
ResourceCount = 0, // Count of how many times scheduled
ResourceCycle, // CPU cycles
ResourcePacket, // Packets set
ResourceBit, // Bits sent
Count = 0, // Count of how many times scheduled
Cycle, // CPU cycles
Packet, // Packets set
Bit, // Bits sent
NumResources, // Sentinel. Also used to indicate "no resource".
}

// An array of counters for all resource types.
// pub type resource_arr_t = [u64; Resource::NUM_RESOURCES as usize];

// The priority of a traffic class.
// typedef uint32_t priority_t;
type priority_t = u32;

// The amount of a resource allocated to a class.
// typedef int32_t resource_share_t;
type resource_share_t = u32;

struct TcStats {
usage: [u64; 4],
Expand Down Expand Up @@ -61,24 +61,26 @@ enum TrafficPolicy {

mod traffic_class_initializer_types {
enum PriorityFakeType {
PRIORITY = 0,
Priority,
}

enum WeightedFairFakeType {
WEIGHTED_FAIR = 0,
WeightedFair,
}
enum RoundRobinFakeType {
ROUND_ROBIN = 0,
RoundRobin,
}
enum RateLimitFakeType {
RATE_LIMIT = 0,
RateLimit,
}
enum LeafFakeType {
LEAF = 0,
Leaf,
}
}

use traffic_class_initializer_types::*;
use std::collections::HashMap;
use once_cell::sync::Lazy;

const TRAFFIC_POLICY_NAME: [&str; TrafficPolicy::NumPolicies as usize] = [
"priority",
Expand All @@ -88,17 +90,23 @@ const TRAFFIC_POLICY_NAME: [&str; TrafficPolicy::NumPolicies as usize] = [
"leaf",
];

// const std::unordered_map<std::string, enum resource_t> ResourceMap = {
// {"count", RESOURCE_COUNT},
// {"cycle", RESOURCE_CYCLE},
// {"packet", RESOURCE_PACKET},
// {"bit", RESOURCE_BIT}};

// const std::unordered_map<int, std::string> ResourceName = {
// {RESOURCE_COUNT, "count"},
// {RESOURCE_CYCLE, "cycle"},
// {RESOURCE_PACKET, "packet"},
// {RESOURCE_BIT, "bit"}};
static RESOURCE_MAP: Lazy<HashMap<&'static str, Resource>> = Lazy::new(|| {
let mut m = HashMap::new();
m.insert("count",Resource::Count);
m.insert("cycle",Resource::Cycle);
m.insert("packet", Resource::Packet);
m.insert("bit",Resource::Bit);
m
});

static RESOURCE_NAME: Lazy<HashMap<Resource, &'static str>> = Lazy::new(|| {
let mut m = HashMap::new();
m.insert(Resource::Count, "count");
m.insert(Resource::Cycle, "cycle");
m.insert(Resource::Packet, "packet");
m.insert(Resource::Bit, "bit");
m
});

/* acc += x */
// #define ACCUMULATE(acc, x) \
Expand Down
1 change: 1 addition & 0 deletions src/core/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod random;
103 changes: 0 additions & 103 deletions src/core/utils/random.h

This file was deleted.

Loading

0 comments on commit 1c99103

Please sign in to comment.