Skip to content

Commit

Permalink
FromHost: add a BURST option similar to FromDevice
Browse files Browse the repository at this point in the history
If traffic goes through a FromDevice, to a ToHost, and then back
through a FromHost, then when run_task is round robining between
FromDevice and FromHost, the FromDevice will get to send multiple
packets for every single packet that FromHost sends.  Adding a BURST
option to FromHost allows management of the load between the two
elements.
  • Loading branch information
Jim Roewe committed Jul 20, 2012
1 parent 9f65e55 commit 5643ab5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
35 changes: 25 additions & 10 deletions elements/linuxmodule/fromhost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ FromHost::configure(Vector<String> &conf, ErrorHandler *errh)
_destaddr = IPAddress();
_destmask = IPAddress();
_clear_anno = true;
_burst = 8;

if (Args(conf, this, errh)
.read_mp("DEVNAME", _devname)
Expand All @@ -182,6 +183,7 @@ FromHost::configure(Vector<String> &conf, ErrorHandler *errh)
.read("MTU", mtu)
.read("CAPACITY", _capacity)
.read("CLEAR_ANNO", _clear_anno)
.read("BURST", BoundedIntArg(1, 1000000), _burst)
.complete() < 0)
return -1;

Expand Down Expand Up @@ -498,11 +500,11 @@ FromHost::fl_tx(struct sk_buff *skb, net_device *dev)
bool
FromHost::run_task(Task *)
{
if (!_nonfull_signal)
if (!_nonfull_signal || unlikely(empty()))
return false;

if (likely(!empty())) {
Packet * volatile *q = queue();
Packet * volatile *q = queue();
for (int count = 0; count < _burst && !empty(); ++count) {
Packet *p = q[_head];
packet_memory_barrier(q[_head], _head);
_head = next_i(_head);
Expand All @@ -527,18 +529,16 @@ FromHost::run_task(Task *)
bad:
_ninvalid++;
checked_output_push(1, p);
goto done;
continue;
}
}

output(0).push(p);
}

done:
if (!empty())
_task.fast_reschedule();
return true;
} else
return false;
if (!empty())
_task.fast_reschedule();
return true;
}

String
Expand All @@ -548,13 +548,28 @@ FromHost::read_handler(Element *e, void *)
return String(fh->size());
}

int FromHost::write_handler(const String &str, Element *e, void *thunk, ErrorHandler *errh)
{
FromHost *fh = static_cast<FromHost *>(e);
switch (reinterpret_cast<intptr_t>(thunk)) {
case h_burst:
if (!BoundedIntArg(1, 1000000).parse(str, fh->_burst))
return errh->error("burst parameter must be integer between 1 and 1000000");
return 0;
default:
return 0;
}
}

void
FromHost::add_handlers()
{
add_task_handlers(&_task);
add_read_handler("length", read_handler, h_length);
add_data_handlers("capacity", Handler::OP_READ, &_capacity);
add_data_handlers("drops", Handler::OP_READ, &_drops);
add_data_handlers("burst", Handler::OP_READ, &_burst);
add_write_handler("burst", write_handler, h_burst);
}

ELEMENT_REQUIRES(AnyDevice linuxmodule)
Expand Down
11 changes: 9 additions & 2 deletions elements/linuxmodule/fromhost.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ If false, this area is left as it was received from Linux.
(Note that the packet type, device, and header annotations are left as is.)
Defaults to true.
=item BURST
Integer. Sets the BURST parameter affecting how many packets are
emitted per task execution. BURST is 8 by default.
=back
=n
Expand Down Expand Up @@ -156,6 +161,8 @@ class FromHost : public AnyDevice, public Storage { public:
net_device_stats _stats;
#endif

int _burst;

Task _task;
Timer _wakeup_timer;

Expand Down Expand Up @@ -184,9 +191,9 @@ class FromHost : public AnyDevice, public Storage { public:
static net_device_stats *fl_stats(net_device *dev);
#endif

enum { h_length };
enum { h_length, h_burst };
static String read_handler(Element *e, void *thunk);

static int write_handler(const String &, Element *, void *, ErrorHandler *);
};

#endif

0 comments on commit 5643ab5

Please sign in to comment.