]> err.no Git - linux-2.6/blobdiff - net/sched/sch_generic.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[linux-2.6] / net / sched / sch_generic.c
index efa418a1b34e64cd0d2983c7e13bfab3abd796ae..9c9cd4d94890d1b1c5fb7d582af730f37248cfc0 100644 (file)
 /* Main transmission queue. */
 
 /* Modifications to data participating in scheduling must be protected with
- * queue->lock spinlock.
+ * qdisc_root_lock(qdisc) spinlock.
  *
  * The idea is the following:
- * - enqueue, dequeue are serialized via top level device
- *   spinlock queue->lock.
- * - ingress filtering is serialized via top level device
- *   spinlock dev->rx_queue.lock.
+ * - enqueue, dequeue are serialized via qdisc root lock
+ * - ingress filtering is also serialized via qdisc root lock
  * - updates to tree and tree walking are only done under the rtnl mutex.
  */
 
-void qdisc_lock_tree(struct net_device *dev)
-       __acquires(dev->rx_queue.lock)
-{
-       unsigned int i;
-
-       local_bh_disable();
-       for (i = 0; i < dev->num_tx_queues; i++) {
-               struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
-               spin_lock(&txq->lock);
-       }
-       spin_lock(&dev->rx_queue.lock);
-}
-EXPORT_SYMBOL(qdisc_lock_tree);
-
-void qdisc_unlock_tree(struct net_device *dev)
-       __releases(dev->rx_queue.lock)
-{
-       unsigned int i;
-
-       spin_unlock(&dev->rx_queue.lock);
-       for (i = 0; i < dev->num_tx_queues; i++) {
-               struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
-               spin_unlock(&txq->lock);
-       }
-       local_bh_enable();
-}
-EXPORT_SYMBOL(qdisc_unlock_tree);
-
 static inline int qdisc_qlen(struct Qdisc *q)
 {
        return q->q.qlen;
@@ -126,15 +96,15 @@ static inline int handle_dev_cpu_collision(struct sk_buff *skb,
 }
 
 /*
- * NOTE: Called under queue->lock with locally disabled BH.
+ * NOTE: Called under qdisc_lock(q) with locally disabled BH.
  *
  * __QDISC_STATE_RUNNING guarantees only one CPU can process
- * this qdisc at a time. queue->lock serializes queue accesses for
- * this queue AND txq->qdisc pointer itself.
+ * this qdisc at a time. qdisc_lock(q) serializes queue accesses for
+ * this queue.
  *
  *  netif_tx_lock serializes accesses to device driver.
  *
- *  queue->lock and netif_tx_lock are mutually exclusive,
+ *  qdisc_lock(q) and netif_tx_lock are mutually exclusive,
  *  if one is grabbed, another must be free.
  *
  * Note, that this procedure can be called by a watchdog timer
@@ -165,7 +135,8 @@ static inline int qdisc_restart(struct Qdisc *q)
        txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
 
        HARD_TX_LOCK(dev, txq, smp_processor_id());
-       if (!netif_subqueue_stopped(dev, skb))
+       if (!netif_tx_queue_stopped(txq) &&
+           !netif_tx_queue_frozen(txq))
                ret = dev_hard_start_xmit(skb, dev, txq);
        HARD_TX_UNLOCK(dev, txq);
 
@@ -192,7 +163,8 @@ static inline int qdisc_restart(struct Qdisc *q)
                break;
        }
 
-       if (ret && netif_tx_queue_stopped(txq))
+       if (ret && (netif_tx_queue_stopped(txq) ||
+                   netif_tx_queue_frozen(txq)))
                ret = 0;
 
        return ret;
@@ -242,9 +214,9 @@ static void dev_watchdog(unsigned long arg)
                        if (some_queue_stopped &&
                            time_after(jiffies, (dev->trans_start +
                                                 dev->watchdog_timeo))) {
-                               printk(KERN_INFO "NETDEV WATCHDOG: %s: "
-                                      "transmit timed out\n",
-                                      dev->name);
+                               char drivername[64];
+                               printk(KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit timed out\n",
+                                      dev->name, netdev_drivername(dev, drivername, 64));
                                dev->tx_timeout(dev);
                                WARN_ON_ONCE(1);
                        }
@@ -347,7 +319,6 @@ struct Qdisc_ops noop_qdisc_ops __read_mostly = {
 };
 
 static struct netdev_queue noop_netdev_queue = {
-       .lock           =       __SPIN_LOCK_UNLOCKED(noop_netdev_queue.lock),
        .qdisc          =       &noop_qdisc,
 };
 
@@ -357,6 +328,7 @@ struct Qdisc noop_qdisc = {
        .flags          =       TCQ_F_BUILTIN,
        .ops            =       &noop_qdisc_ops,
        .list           =       LIST_HEAD_INIT(noop_qdisc.list),
+       .q.lock         =       __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock),
        .dev_queue      =       &noop_netdev_queue,
 };
 EXPORT_SYMBOL(noop_qdisc);
@@ -370,12 +342,19 @@ static struct Qdisc_ops noqueue_qdisc_ops __read_mostly = {
        .owner          =       THIS_MODULE,
 };
 
+static struct Qdisc noqueue_qdisc;
+static struct netdev_queue noqueue_netdev_queue = {
+       .qdisc          =       &noqueue_qdisc,
+};
+
 static struct Qdisc noqueue_qdisc = {
        .enqueue        =       NULL,
        .dequeue        =       noop_dequeue,
        .flags          =       TCQ_F_BUILTIN,
        .ops            =       &noqueue_qdisc_ops,
        .list           =       LIST_HEAD_INIT(noqueue_qdisc.list),
+       .q.lock         =       __SPIN_LOCK_UNLOCKED(noqueue_qdisc.q.lock),
+       .dev_queue      =       &noqueue_netdev_queue,
 };
 
 
@@ -528,7 +507,7 @@ errout:
 }
 EXPORT_SYMBOL(qdisc_create_dflt);
 
-/* Under queue->lock and BH! */
+/* Under qdisc_root_lock(qdisc) and BH! */
 
 void qdisc_reset(struct Qdisc *qdisc)
 {
@@ -547,6 +526,9 @@ static void __qdisc_destroy(struct rcu_head *head)
        struct Qdisc *qdisc = container_of(head, struct Qdisc, q_rcu);
        const struct Qdisc_ops  *ops = qdisc->ops;
 
+#ifdef CONFIG_NET_SCHED
+       qdisc_put_stab(qdisc->stab);
+#endif
        gen_kill_estimator(&qdisc->bstats, &qdisc->rate_est);
        if (ops->reset)
                ops->reset(qdisc);
@@ -556,10 +538,12 @@ static void __qdisc_destroy(struct rcu_head *head)
        module_put(ops->owner);
        dev_put(qdisc_dev(qdisc));
 
+       kfree_skb(qdisc->gso_skb);
+
        kfree((char *) qdisc - qdisc->padded);
 }
 
-/* Under queue->lock and BH! */
+/* Under qdisc_root_lock(qdisc) and BH! */
 
 void qdisc_destroy(struct Qdisc *qdisc)
 {
@@ -567,7 +551,8 @@ void qdisc_destroy(struct Qdisc *qdisc)
            !atomic_dec_and_test(&qdisc->refcnt))
                return;
 
-       list_del(&qdisc->list);
+       if (qdisc->parent)
+               list_del(&qdisc->list);
 
        call_rcu(&qdisc->q_rcu, __qdisc_destroy);
 }
@@ -599,7 +584,6 @@ static void attach_one_default_qdisc(struct net_device *dev,
                        printk(KERN_INFO "%s: activation failed\n", dev->name);
                        return;
                }
-               list_add_tail(&qdisc->list, &dev_queue->qdisc_list);
        } else {
                qdisc =  &noqueue_qdisc;
        }
@@ -610,13 +594,12 @@ static void transition_one_qdisc(struct net_device *dev,
                                 struct netdev_queue *dev_queue,
                                 void *_need_watchdog)
 {
+       struct Qdisc *new_qdisc = dev_queue->qdisc_sleeping;
        int *need_watchdog_p = _need_watchdog;
 
-       spin_lock_bh(&dev_queue->lock);
-       rcu_assign_pointer(dev_queue->qdisc, dev_queue->qdisc_sleeping);
-       if (dev_queue->qdisc != &noqueue_qdisc)
+       rcu_assign_pointer(dev_queue->qdisc, new_qdisc);
+       if (need_watchdog_p && new_qdisc != &noqueue_qdisc)
                *need_watchdog_p = 1;
-       spin_unlock_bh(&dev_queue->lock);
 }
 
 void dev_activate(struct net_device *dev)
@@ -638,6 +621,7 @@ void dev_activate(struct net_device *dev)
 
        need_watchdog = 0;
        netdev_for_each_tx_queue(dev, transition_one_qdisc, &need_watchdog);
+       transition_one_qdisc(dev, &dev->rx_queue, NULL);
 
        if (need_watchdog) {
                dev->trans_start = jiffies;
@@ -650,23 +634,17 @@ static void dev_deactivate_queue(struct net_device *dev,
                                 void *_qdisc_default)
 {
        struct Qdisc *qdisc_default = _qdisc_default;
-       struct sk_buff *skb = NULL;
        struct Qdisc *qdisc;
 
-       spin_lock_bh(&dev_queue->lock);
-
        qdisc = dev_queue->qdisc;
        if (qdisc) {
+               spin_lock_bh(qdisc_lock(qdisc));
+
                dev_queue->qdisc = qdisc_default;
                qdisc_reset(qdisc);
 
-               skb = qdisc->gso_skb;
-               qdisc->gso_skb = NULL;
+               spin_unlock_bh(qdisc_lock(qdisc));
        }
-
-       spin_unlock_bh(&dev_queue->lock);
-
-       kfree_skb(skb);
 }
 
 static bool some_qdisc_is_running(struct net_device *dev, int lock)
@@ -702,6 +680,7 @@ void dev_deactivate(struct net_device *dev)
        bool running;
 
        netdev_for_each_tx_queue(dev, dev_deactivate_queue, &noop_qdisc);
+       dev_deactivate_queue(dev, &dev->rx_queue, &noop_qdisc);
 
        dev_watchdog_down(dev);
 
@@ -738,13 +717,12 @@ static void dev_init_scheduler_queue(struct net_device *dev,
 
        dev_queue->qdisc = qdisc;
        dev_queue->qdisc_sleeping = qdisc;
-       INIT_LIST_HEAD(&dev_queue->qdisc_list);
 }
 
 void dev_init_scheduler(struct net_device *dev)
 {
        netdev_for_each_tx_queue(dev, dev_init_scheduler_queue, &noop_qdisc);
-       dev_init_scheduler_queue(dev, &dev->rx_queue, NULL);
+       dev_init_scheduler_queue(dev, &dev->rx_queue, &noop_qdisc);
 
        setup_timer(&dev->watchdog_timer, dev_watchdog, (unsigned long)dev);
 }
@@ -762,15 +740,15 @@ static void shutdown_scheduler_queue(struct net_device *dev,
                dev_queue->qdisc = qdisc_default;
                dev_queue->qdisc_sleeping = qdisc_default;
 
-               spin_lock(root_lock);
+               spin_lock_bh(root_lock);
                qdisc_destroy(qdisc);
-               spin_unlock(root_lock);
+               spin_unlock_bh(root_lock);
        }
 }
 
 void dev_shutdown(struct net_device *dev)
 {
        netdev_for_each_tx_queue(dev, shutdown_scheduler_queue, &noop_qdisc);
-       shutdown_scheduler_queue(dev, &dev->rx_queue, NULL);
-       BUG_TRAP(!timer_pending(&dev->watchdog_timer));
+       shutdown_scheduler_queue(dev, &dev->rx_queue, &noop_qdisc);
+       WARN_ON(timer_pending(&dev->watchdog_timer));
 }