Hi,
because my nsclick simulations took a long time to complete, I analysed
them using a profiler, and i discovered that the main problem was that
the run_task of the tosimdevice whas called a lot, and that it tried to
pull upstream, even if there were no elements available in the queues
before it.
So i added a notifier to the tosimdevice (like in a unqueue), so that
the task will only be scheduled if there is a packet available upstream.
First results where very promising, simulations were performed five
times faster then before. I have included the changed tosimdevice
sources in attachment, maybe some more people could test this code and
verify if this speeds up their simulations, and if the simulation
results are still the same.
Kind regards,
Wim
/*
* tosimdevice.{cc,hh} -- writes packets to simulated network devices
*
*/
/*****************************************************************************
* Copyright 2002, Univerity of Colorado at Boulder *
* Copyright (c) 2006 Regents of the University of California *
* *
* All Rights Reserved *
* *
* Permission to use, copy, modify, and distribute this software and its *
* documentation for any purpose other than its incorporation into a *
* commercial product is hereby granted without fee, provided that the *
* above copyright notice appear in all copies and that both that *
* copyright notice and this permission notice appear in supporting *
* documentation, and that the name of the University not be used in *
* advertising or publicity pertaining to distribution of the software *
* without specific, written prior permission. *
* *
* UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS *
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND *
* FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY *
* OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL *
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA *
* OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER *
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR *
* PERFORMANCE OF THIS SOFTWARE. *
* *
****************************************************************************/
#include <click/config.h>
#include "fromsimdevice.hh"
#include "tosimdevice.hh"
#include <click/error.hh>
#include <click/etheraddress.hh>
#include <click/confparse.hh>
#include <click/router.hh>
#include <click/standard/scheduleinfo.hh>
#include <stdio.h>
#include <unistd.h>
CLICK_DECLS
ToSimDevice::ToSimDevice()
: _fd(-1), _my_fd(false), _task(this), _encap_type(SIMCLICK_PTYPE_ETHER),_signals(0)
{
}
ToSimDevice::~ToSimDevice()
{
uninitialize();
}
int
ToSimDevice::configure(Vector<String> &conf, ErrorHandler *errh)
{
String encap_type;
if (cp_va_parse(conf, this, errh,
cpString, "interface name", &_ifname,
cpOptional,
cpWord, "encapsulation type", &encap_type,
cpKeywords,
"ENCAP", cpWord, "encapsulation type", &encap_type,
cpEnd) < 0)
return -1;
if (!_ifname)
return errh->error("interface not set");
if (!encap_type || encap_type == "ETHER")
_encap_type = SIMCLICK_PTYPE_ETHER;
else if (encap_type == "IP")
_encap_type = SIMCLICK_PTYPE_IP;
else if (encap_type == "UNKNOWN")
_encap_type = SIMCLICK_PTYPE_UNKNOWN;
else
return errh->error("bad encapsulation type");
return 0;
}
int
ToSimDevice::initialize(ErrorHandler *errh)
{
_fd = -1;
if (!_ifname)
return errh->error("interface not set");
// Get the simulator ifid
Router* myrouter = router();
_fd = myrouter->sim_get_ifid(_ifname.c_str());
if (_fd < 0) return -1;
_my_fd = true;
if (input_is_pull(0))
ScheduleInfo::join_scheduler(this, &_task, errh);
//initialize the scheduler element so that run_task will only pull a packet if there is one available in a non-empty queue
if (!(_signals = new NotifierSignal[ninputs()]))
return errh->error("out of memory!");
for (int i = 0; i < ninputs(); i++)
_signals[i] = Notifier::upstream_empty_signal(this, i, &_task); //the pointer to _task makes sure that the task wel be schedulled if a pakket becomes available in an upstream queue
return 0;
}
void
ToSimDevice::uninitialize()
{
_task.unschedule();
delete[] _signals;
}
void
ToSimDevice::send_packet(Packet *p)
{
Router* myrouter = router();
int retval;
// We send out either ethernet or IP
retval = myrouter->sim_write(_fd,_encap_type,p->data(),p->length(),
p->get_sim_packetinfo());
p->kill();
}
void
ToSimDevice::push(int, Packet *p)
{
assert(p->length() >= 14);
//fprintf(stderr,"Hey!!! Pushing!!!\n");
send_packet(p);
}
bool
ToSimDevice::run_task()
{
// XXX reduce tickets when idle
bool active = false;
if (router()->sim_if_ready(_fd)) {
//fprintf(stderr,"Hey!!! Pulling ready!!!\n");
if (Packet *p = input(0).pull()) {
//fprintf(stderr,"Hey!!! Sending a packet!!!\n");
send_packet(p);
active = true;
}
}
//if there are no packets available in the queues upstream, do not reschedule
if(!_signals[0]){
return active;
}
_task.fast_reschedule();
return active;
}
void
ToSimDevice::add_handlers()
{
if (input_is_pull(0))
add_task_handlers(&_task);
}
CLICK_ENDDECLS
ELEMENT_REQUIRES(FromSimDevice ns)
EXPORT_ELEMENT(ToSimDevice)
#ifndef CLICK_TOSIMDEVICE_HH
#define CLICK_TOSIMDEVICE_HH
#include <click/element.hh>
#include <click/string.hh>
#include <click/task.hh>
#include <click/notifier.hh>
CLICK_DECLS
/*****************************************************************************
* Copyright 2002, Univerity of Colorado at Boulder. *
* *
* All Rights Reserved *
* *
* Permission to use, copy, modify, and distribute this software and its *
* documentation for any purpose other than its incorporation into a *
* commercial product is hereby granted without fee, provided that the *
* above copyright notice appear in all copies and that both that *
* copyright notice and this permission notice appear in supporting *
* documentation, and that the name of the University not be used in *
* advertising or publicity pertaining to distribution of the software *
* without specific, written prior permission. *
* *
* UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS *
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND *
* FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY *
* OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL *
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA *
* OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER *
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR *
* PERFORMANCE OF THIS SOFTWARE. *
* *
****************************************************************************/
/*
* =title ToSimDevice.u
* =c
* ToSimDevice(DEVNAME [, ENCAP])
* =s netdevices
* sends packets to simulated network device
* =d
*
* This manual page describes the ToSimDevice element.
*
* This element will only work with the click simulator interface.
*
* Keyword arguments are:
*
* =over 8
*
* =item ENCAP
*
* Word. The interface's encapsulation type. Options are ETHER, IP, and
* UNKNOWN; default is ETHER.
*
* =back
*
* =a
* FromSimDevice.u */
/*
* Write packets to a simulated network interface.
* Expects packets that already have an ether header.
* Can push or pull.
*/
class ToSimDevice : public Element { public:
ToSimDevice();
~ToSimDevice();
const char *class_name() const { return "ToSimDevice"; }
const char *port_count() const { return PORTS_1_0; }
const char *processing() const { return AGNOSTIC; }
//const char *flags() const { return "S2"; }
int configure_phase() const { return CONFIGURE_PHASE_LAST; }//wim vdb : makes
sure that all upstream elements are initialised first, so that all upstream
notifiers can be found
int configure(Vector<String> &, ErrorHandler *);
int initialize(ErrorHandler *);
void uninitialize();
void add_handlers();
String ifname() const { return _ifname; }
int fd() const { return _fd; }
void push(int port, Packet *);
bool run_task();
private:
String _ifname;
int _fd;
bool _my_fd;
Task _task;
int _encap_type;
void send_packet(Packet *);
NotifierSignal *_signals; //used for a smarter rescheduling, no rescheduling
if there is no packet available upstream
};
CLICK_ENDDECLS
#endif
begin:vcard
fn:Wim Vandenberghe
n:Vandenberghe;Wim
org:Ghent University - IBBT - IMEC;Department of Information Technology (INTEC)
adr:;;Gaston Crommenlaan 8;Ghent;;9050;Belgium
email;internet:[EMAIL PROTECTED]
title:Junior researcher
url:http://www.intec.ugent.be/
version:2.1
end:vcard
_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click