Fwd: [Click] When run_task function starts to run in element
- Beyers Cronje
- 2015-06-04 @ 21:22
I highly recommend the following two sources of information:
The main click paper that covers all the core concepts like Elements, Push
vs Pull paths etc:
And then a bit more low-lever documentation in the "Click Under the Hood"
The above under the hood document goes into more details on how Click
implements scheduling, multithreading etc.
To answer some of your questions now, not every element has a task, or in
turn a run_task function. In fact *most* elements do not implement a Click
task. In Click there are two main schedulable units, namely Task and Timer.
Tasks are used when an element needs to frequently initiates a push or pull
chain, where Timers are used for less frequent operations. Click maintains
a task and timer queue and will schedule these tasks using a stride
scheduling algorithm. When Click runs an element's task, it calls the
element's run_task() method. It is the element's responsibility to add
itself to the task queue, this is fast_reschedule() comes into play, it
adds the element's task back onto the task queue. Note there are rules when
you are permitted to call fast_reschedule() vs reschedule(), see the Task
API documentation http://read.cs.ucla.edu/click/doxygen/class_task.html
However, most elements are never placed on the task queue. They are
implicitly scheduled when their push or pull methods are called. Once an
element is scheduled, either explicitly or implicitly, it can initiate an
arbitrary sequence of push and pull requests, thus implicitly scheduling
The main Click loop where all the task scheduling happens is inside Click's
RouterThread, specifically driver(). Start Click kicks off the following
for the current implementation of driver(). It processes the task and timer
queues as well as other OS specific scheduling.
Multithreaded Click implements multiple RouterThreads, each managing their
own task queue.
I hope this helps a bit. Keep digging into the documentation and source and
it will all become clear in time.
On Thu, Jan 16, 2014 at 12:28 AM, 张伟 <email@example.com> wrote:
> Hi all,
> I starts to learn click router recently. I have a question that make me
> confused. Does anybody give me some advices. I will be appreciated.
> In each element, there is a function named run_task. I can not understand
> when this run_task function will be executed.
> If my following understanding is not correct, please help to point them
> >From the document, it seems that there is a kernel thread. Whether this
> thread will manage a queue, in this queue, the tasks in this queue are the
> run_tasks tasks. When I learn the code, I want to find where the run_task
> function will be called, however I can not find the places. There are many
> places that call the function _task.fast_reschedule(). What is the function
> and aim for this function _task.fast_reschedule()? Whether does it have
> some relation with the task queue? Where is the code for task scheduling?
> I do not know where they are.
> I am looking forward to anybody's reply.
> click mailing list