next up previous
Next: Reset Up: Queuing Disciplines Previous: Drop

Init

The init function of a queuing discipline is used to initialize and configure the parameters of a queuing discipline when it is created. The init function can be passed the arguments that will used to configure the queuing discipline. Each of the queuing disciplines need different sets of parameters during the process of the initial configuration. These parameters will be discussed in detail during the discussion on the usage of the traffic control features in linux. All the scheduler related files, for example, sch_cbq.c, sch_tbf.c etc. contain the scheduler data structure, that is the parameters that will used by the scheduler to determine the packet that needs to be sent next. This data structure can be very simple for certain queuing disciplines, for example, priority FIFO, or it can really very complicated for certain queuing disciplines, for example CBQ.

The scheduler data structure, for a simple FIFO (in net/sched/sch_fifo.c) is shown below:

struct fifo_sched_data
{
    unsigned limit;
};

The only parameter that a FIFO scheduler needs is the maximum length of the queue. The above structure shows the limit argument which indicates the maximum length of the queue, beyond which packets are dropped. In the fifo_init function (in net/sched/sch_fifo.c), the following portion of code demonstrates the initialization and configuration that is done in general, in the init function of a queuing discipline.

static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
{
 struct fifo_sched_data *q = (void*)sch->data;
 if (opt == NULL) {
   q->limit = sch->dev->tx_queue_len;
   if (sch->ops == &bfifo_qdisc_ops)
       q->limit *= sch->dev->mtu;
 }
 else
 {
    struct tc_fifo_qopt *ctl = RTA_DATA(opt);
    if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
       return -EINVAL;
    q->limit = ctl->limit;
  }
  return 0;
}

In the above function, if the limit argument is specified, the init function sets the limit to the specifies value. If this is not specified, it defaults the limit to the MTU of the device.


next up previous
Next: Reset Up: Queuing Disciplines Previous: Drop
Saravanan Radhakrishnan
1999-09-30