Skip to content

Commit

Permalink
Optimized code omec-project#1
Browse files Browse the repository at this point in the history
  • Loading branch information
JayaramRCDAC committed Apr 4, 2024
1 parent d09895a commit 3ef0643
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 86 deletions.
93 changes: 10 additions & 83 deletions core/task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,27 @@ void Task::Attach(bess::LeafTrafficClass *c) {
c_ = c;
}

/*
struct task_result Task::operator()(Context *ctx) const {
bess::PacketBatch init_batch;
ClearPacketBatch();

// Start from the first module (task module)
struct task_result result = module_->RunTask(ctx, &init_batch, arg_);
// next_gate_: Continuously run if modules are chained
// igates_to_run_ : If next module connection is not chained (merged),
// check priority to choose which module run next
while (next_gate_ || !igates_to_run_.empty()) {
LOG(INFO) << "Inside task_result Task::operator() while loop" ;

while (!igates_to_run_.empty()) {
LOG(INFO) << "Inside task_result Task::operator() while loop";
bess::IGate *igate;
bess::PacketBatch *batch;

// choose igate and batch to run next
if (next_gate_) {
igate = next_gate_;
batch = next_batch_;
next_gate_ = nullptr;
next_batch_ = nullptr;
} else {
auto item = igates_to_run_.top();
igates_to_run_.pop();
auto item = igates_to_run_.top();
igates_to_run_.pop();

igate = item.first;
batch = item.second;
igate = item.first;
batch = item.second;

set_gate_batch(igate, nullptr);
if (!batch) {
// Skip processing empty batches
continue;
}

ctx->current_igate = igate->gate_idx();
Expand All @@ -93,71 +85,6 @@ struct task_result Task::operator()(Context *ctx) const {

return result;
}
*/

struct task_result Task::operator()(Context *ctx) const {
bess::PacketBatch init_batch;
ClearPacketBatch();

// Start from the first module (task module)
struct task_result result = module_->RunTask(ctx, &init_batch, arg_);

// Process initial batch
ProcessModuleAndOGates(ctx, module_, &init_batch);

// Process remaining batches
while (next_gate_ || !igates_to_run_.empty()) {
bess::IGate *igate;
bess::PacketBatch *batch;

// Choose igate and batch to run next
if (next_gate_) {
igate = next_gate_;
batch = next_batch_;
next_gate_ = nullptr;
next_batch_ = nullptr;
} else {
auto item = igates_to_run_.top();
igates_to_run_.pop();

igate = item.first;
batch = item.second;

set_gate_batch(igate, nullptr);
}

ctx->current_igate = igate->gate_idx();

// Process module and output gates
ProcessModuleAndOGates(ctx, igate->module(), batch);
}

// Process any remaining packets
deadend(ctx, &dead_batch_);

return result;
}

void Task::ProcessModuleAndOGates(Context *ctx, Module *module,
bess::PacketBatch *batch) const {
// Retrieve the ingate from the module
bess::IGate *igate = module->igate();

// Check if the ingate is valid before processing
if (!igate) {
// Handle the case where the ingate is not valid
// You may log an error or take appropriate action
return;
}

for (auto &hook : igate->hooks()) {
hook->ProcessBatch(batch);
}

module->ProcessBatch(ctx, batch); // Process module

module->ProcessOGates(ctx); // Process output gates
}

// Compute constraints for the pipeline starting at this task.
placement_constraint Task::GetSocketConstraints() const {
Expand Down
3 changes: 0 additions & 3 deletions core/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ class Task {

struct task_result operator()(Context *ctx) const;

void ProcessModuleAndOGates(Context *ctx, Module *module,
bess::PacketBatch *batch) const;

// Compute constraints for the pipeline starting at this task.
placement_constraint GetSocketConstraints() const;

Expand Down

0 comments on commit 3ef0643

Please sign in to comment.