Skip to content

Commit b75a71a

Browse files
authored
Merge pull request #499 from NetSys/modify-taskresult
Modifies task_result to contain block field.
2 parents 0129500 + 3e1b228 commit b75a71a

12 files changed

Lines changed: 58 additions & 75 deletions

core/module.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515

1616
using bess::gate_idx_t;
1717

18+
#define INVALID_TASK_ID ((task_id_t)-1)
1819
#define MAX_NUMA_NODE 16
20+
#define MAX_TASKS_PER_MODULE 32
1921
#define UNCONSTRAINED_SOCKET ((0x1ull << MAX_NUMA_NODE) - 1)
2022

2123
struct task_result {
22-
uint64_t packets;
24+
bool block;
25+
uint32_t packets;
2326
uint64_t bits;
2427
};
2528

2629
typedef uint16_t task_id_t;
2730
typedef uint64_t placement_constraint;
2831

29-
#define MAX_TASKS_PER_MODULE 32
30-
#define INVALID_TASK_ID ((task_id_t)-1)
3132

3233
using module_cmd_func_t =
3334
pb_func_t<CommandResponse, Module, google::protobuf::Any>;

core/module_bench.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DummySourceModule : public Module {
1313
};
1414

1515
[[gnu::noinline]] struct task_result DummySourceModule::RunTask(void *arg) {
16-
const size_t batch_size = reinterpret_cast<size_t>(arg);
16+
const uint32_t batch_size = reinterpret_cast<size_t>(arg);
1717
bess::PacketBatch batch;
1818

1919
bess::Packet pkts[bess::PacketBatch::kMaxBurst];
@@ -33,7 +33,7 @@ class DummySourceModule : public Module {
3333

3434
RunNextModule(&batch);
3535

36-
return {.packets = static_cast<uint64_t>(batch_size), .bits = 0};
36+
return { .block = false, .packets = batch_size, .bits = 0 };
3737
}
3838

3939
class DummyRelayModule : public Module {

core/modules/drr.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ void DRR::ProcessBatch(bess::PacketBatch* batch) {
116116

117117
struct task_result DRR::RunTask(void*) {
118118
bess::PacketBatch batch;
119-
struct task_result ret;
120119
int err = 0;
121120
batch.clear();
122121
uint32_t total_bytes = 0;
@@ -130,11 +129,9 @@ struct task_result DRR::RunTask(void*) {
130129
}
131130

132131
// the number of bits inserted into the packet batch
133-
uint64_t cnt = batch.cnt();
132+
uint32_t cnt = batch.cnt();
134133
uint64_t bits_retrieved = (total_bytes + cnt * kPacketOverhead) * 8;
135-
ret = (struct task_result){.packets = cnt, .bits = bits_retrieved};
136-
137-
return ret;
134+
return { .block = (cnt == 0), .packets = cnt, .bits = bits_retrieved };
138135
}
139136

140137
uint32_t DRR::GetNextBatch(bess::PacketBatch* batch, int* err) {

core/modules/flowgen.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,21 +479,18 @@ void FlowGen::GeneratePackets(bess::PacketBatch *batch) {
479479
}
480480

481481
struct task_result FlowGen::RunTask(void *) {
482-
bess::PacketBatch batch;
483-
struct task_result ret;
484-
485482
const int pkt_overhead = 24;
483+
bess::PacketBatch batch;
486484

487485
GeneratePackets(&batch);
488486
RunNextModule(&batch);
489487

490-
ret = (struct task_result){
491-
.packets = static_cast<uint64_t>(batch.cnt()),
492-
.bits = static_cast<uint64_t>(
493-
((template_size_ + pkt_overhead) * batch.cnt()) * 8),
488+
uint32_t cnt = batch.cnt();
489+
return {
490+
.block = (cnt == 0),
491+
.packets = cnt,
492+
.bits = ((template_size_ + pkt_overhead) * cnt) * 8
494493
};
495-
496-
return ret;
497494
}
498495

499496
std::string FlowGen::GetDesc() const {

core/modules/noop.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ CommandResponse NoOP::Init(const bess::pb::EmptyArg &) {
1111
}
1212

1313
struct task_result NoOP::RunTask(void *) {
14-
return {
15-
.packets = 0, .bits = 0,
16-
};
14+
return { .block = false, .packets = 0, .bits = 0 };
1715
}
1816

1917
ADD_MODULE(NoOP, "noop", "creates a task that does nothing")

core/modules/port_inc.cc

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,46 +75,41 @@ struct task_result PortInc::RunTask(void *arg) {
7575
const queue_t qid = (queue_t)(uintptr_t)arg;
7676

7777
bess::PacketBatch batch;
78-
struct task_result ret;
79-
8078
uint64_t received_bytes = 0;
8179

8280
const int burst = ACCESS_ONCE(burst_);
8381
const int pkt_overhead = 24;
8482

85-
uint64_t cnt;
8683
batch.set_cnt(p->RecvPackets(qid, batch.pkts(), burst));
87-
cnt = batch.cnt();
88-
84+
uint32_t cnt = batch.cnt();
8985
if (cnt == 0) {
90-
ret.packets = 0;
91-
ret.bits = 0;
92-
return ret;
86+
return { .block = true, .packets = 0, .bits = 0 };
9387
}
9488

95-
/* NOTE: we cannot skip this step since it might be used by scheduler */
89+
// NOTE: we cannot skip this step since it might be used by scheduler.
9690
if (prefetch_) {
97-
for (uint64_t i = 0; i < cnt; i++) {
91+
for (uint32_t i = 0; i < cnt; i++) {
9892
received_bytes += batch.pkts()[i]->total_len();
9993
rte_prefetch0(batch.pkts()[i]->head_data());
10094
}
10195
} else {
102-
for (uint64_t i = 0; i < cnt; i++)
96+
for (uint32_t i = 0; i < cnt; i++) {
10397
received_bytes += batch.pkts()[i]->total_len();
98+
}
10499
}
105100

106-
ret = (struct task_result){
107-
.packets = cnt, .bits = (received_bytes + cnt * pkt_overhead) * 8,
108-
};
109-
110101
if (!(p->GetFlags() & DRIVER_FLAG_SELF_INC_STATS)) {
111102
p->queue_stats[PACKET_DIR_INC][qid].packets += cnt;
112103
p->queue_stats[PACKET_DIR_INC][qid].bytes += received_bytes;
113104
}
114105

115106
RunNextModule(&batch);
116107

117-
return ret;
108+
return {
109+
.block = false,
110+
.packets = cnt,
111+
.bits = (received_bytes + cnt * pkt_overhead) * 8
112+
};
118113
}
119114

120115
CommandResponse PortInc::CommandSetBurst(

core/modules/queue.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,37 @@ void Queue::ProcessBatch(bess::PacketBatch *batch) {
110110
/* to downstream */
111111
struct task_result Queue::RunTask(void *) {
112112
bess::PacketBatch batch;
113-
struct task_result ret;
114113

115114
const int burst = ACCESS_ONCE(burst_);
116115
const int pkt_overhead = 24;
117116

118117
uint64_t total_bytes = 0;
119118

120-
uint64_t cnt = llring_sc_dequeue_burst(queue_, (void **)batch.pkts(), burst);
119+
uint32_t cnt = llring_sc_dequeue_burst(queue_, (void **)batch.pkts(), burst);
121120

122-
if (cnt > 0) {
123-
batch.set_cnt(cnt);
124-
RunNextModule(&batch);
121+
if (cnt == 0) {
122+
return { .block = true, .packets = 0, .bits = 0 };
125123
}
126124

125+
batch.set_cnt(cnt);
126+
RunNextModule(&batch);
127+
127128
if (prefetch_) {
128-
for (uint64_t i = 0; i < cnt; i++) {
129+
for (uint32_t i = 0; i < cnt; i++) {
129130
total_bytes += batch.pkts()[i]->total_len();
130131
rte_prefetch0(batch.pkts()[i]->head_data());
131132
}
132133
} else {
133-
for (uint64_t i = 0; i < cnt; i++)
134+
for (uint32_t i = 0; i < cnt; i++) {
134135
total_bytes += batch.pkts()[i]->total_len();
136+
}
135137
}
136138

137-
ret = (struct task_result){
138-
.packets = cnt, .bits = (total_bytes + cnt * pkt_overhead) * 8,
139+
return {
140+
.block = false,
141+
.packets = cnt,
142+
.bits = (total_bytes + cnt * pkt_overhead) * 8
139143
};
140-
141-
return ret;
142144
}
143145

144146
CommandResponse Queue::CommandSetBurst(

core/modules/queue_inc.cc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,47 +60,43 @@ struct task_result QueueInc::RunTask(void *arg) {
6060
const queue_t qid = (queue_t)(uintptr_t)arg;
6161

6262
bess::PacketBatch batch;
63-
struct task_result ret;
6463

6564
uint64_t received_bytes = 0;
6665

6766
const int burst = ACCESS_ONCE(burst_);
6867
const int pkt_overhead = 24;
6968

70-
uint64_t cnt;
7169
batch.set_cnt(p->RecvPackets(qid, batch.pkts(), burst));
72-
cnt = batch.cnt();
70+
uint32_t cnt = batch.cnt();
7371

7472
if (cnt == 0) {
75-
ret.packets = 0;
76-
ret.bits = 0;
77-
return ret;
73+
return { .block = true, .packets = 0, .bits = 0 };
7874
}
7975

80-
/* NOTE: we cannot skip this step since it might be used by scheduler */
76+
// NOTE: we cannot skip this step since it might be used by scheduler.
8177
if (prefetch_) {
82-
for (uint64_t i = 0; i < cnt; i++) {
78+
for (uint32_t i = 0; i < cnt; i++) {
8379
received_bytes += batch.pkts()[i]->total_len();
8480
rte_prefetch0(batch.pkts()[i]->head_data());
8581
}
8682
} else {
87-
for (uint64_t i = 0; i < cnt; i++) {
83+
for (uint32_t i = 0; i < cnt; i++) {
8884
received_bytes += batch.pkts()[i]->total_len();
8985
}
9086
}
9187

92-
ret = (struct task_result){
93-
.packets = cnt, .bits = (received_bytes + cnt * pkt_overhead) * 8,
94-
};
95-
9688
if (!(p->GetFlags() & DRIVER_FLAG_SELF_INC_STATS)) {
9789
p->queue_stats[PACKET_DIR_INC][qid].packets += cnt;
9890
p->queue_stats[PACKET_DIR_INC][qid].bytes += received_bytes;
9991
}
10092

10193
RunNextModule(&batch);
10294

103-
return ret;
95+
return {
96+
.block = false,
97+
.packets = cnt,
98+
.bits = (received_bytes + cnt * pkt_overhead) * 8
99+
};
104100
}
105101

106102
CommandResponse QueueInc::CommandSetBurst(

core/modules/source.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ struct task_result Source::RunTask(void *) {
5858
const int pkt_size = ACCESS_ONCE(pkt_size_);
5959
const int burst = ACCESS_ONCE(burst_);
6060

61-
int cnt = bess::Packet::Alloc(batch.pkts(), burst, pkt_size);
62-
61+
uint32_t cnt = bess::Packet::Alloc(batch.pkts(), burst, pkt_size);
6362
batch.set_cnt(cnt);
6463
RunNextModule(&batch); // it's fine to call this function with cnt==0
6564

66-
return (struct task_result){
67-
.packets = static_cast<uint64_t>(cnt),
68-
.bits = static_cast<uint64_t>(pkt_size + pkt_overhead) * cnt * 8,
65+
return {
66+
.block = (cnt == 0),
67+
.packets = cnt,
68+
.bits = (pkt_size + pkt_overhead) * cnt * 8
6969
};
7070
}
7171

core/scheduler.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,9 @@ class ExperimentalScheduler : public Scheduler<CallableTask> {
320320
auto ret = leaf->Task()();
321321
now = rdtsc();
322322

323-
if (ret.packets == 0 && ret.bits == 0) {
323+
if (ret.packets == 0 && ret.block) {
324324
constexpr uint64_t kMaxWait = 1ull << 32;
325-
uint64_t wait = leaf->wait_cycles() << 1;
326-
if (wait > kMaxWait) {
327-
wait = kMaxWait;
328-
}
325+
uint64_t wait = std::min(kMaxWait, leaf->wait_cycles() << 1);
329326
leaf->set_wait_cycles(wait);
330327

331328
leaf->blocked_ = true;

0 commit comments

Comments
 (0)