]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/core/pktgen.c
pktgen: allow faster module unload
[net-next-2.6.git] / net / core / pktgen.c
index 679b797d06b1028888bdc9590a1f741918eece6c..2e57830cbeb2e56a04f0f34449f3eebf31515207 100644 (file)
@@ -378,6 +378,7 @@ struct pktgen_dev {
 
        u16 queue_map_min;
        u16 queue_map_max;
+       __u32 skb_priority;     /* skb priority field */
        int node;               /* Memory node */
 
 #ifdef CONFIG_XFRM
@@ -394,6 +395,8 @@ struct pktgen_hdr {
        __be32 tv_usec;
 };
 
+static bool pktgen_exiting __read_mostly;
+
 struct pktgen_thread {
        spinlock_t if_lock;             /* for list of devices */
        struct list_head if_list;       /* All device here */
@@ -547,6 +550,10 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
                   pkt_dev->queue_map_min,
                   pkt_dev->queue_map_max);
 
+       if (pkt_dev->skb_priority)
+               seq_printf(seq, "     skb_priority: %u\n",
+                          pkt_dev->skb_priority);
+
        if (pkt_dev->flags & F_IPV6) {
                char b1[128], b2[128], b3[128];
                fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
@@ -887,10 +894,11 @@ static ssize_t pktgen_if_write(struct file *file,
        i += len;
 
        if (debug) {
-               char tb[count + 1];
-               if (copy_from_user(tb, user_buffer, count))
+               size_t copy = min_t(size_t, count, 1023);
+               char tb[copy + 1];
+               if (copy_from_user(tb, user_buffer, copy))
                        return -EFAULT;
-               tb[count] = 0;
+               tb[copy] = 0;
                printk(KERN_DEBUG "pktgen: %s,%lu  buffer -:%s:-\n", name,
                       (unsigned long)count, tb);
        }
@@ -1710,6 +1718,18 @@ static ssize_t pktgen_if_write(struct file *file,
                return count;
        }
 
+       if (!strcmp(name, "skb_priority")) {
+               len = num_arg(&user_buffer[i], 9, &value);
+               if (len < 0)
+                       return len;
+
+               i += len;
+               pkt_dev->skb_priority = value;
+               sprintf(pg_result, "OK: skb_priority=%i",
+                       pkt_dev->skb_priority);
+               return count;
+       }
+
        sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
        return -EINVAL;
 }
@@ -2611,8 +2631,8 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
        /* Update any of the values, used when we're incrementing various
         * fields.
         */
-       queue_map = pkt_dev->cur_queue_map;
        mod_cur_headers(pkt_dev);
+       queue_map = pkt_dev->cur_queue_map;
 
        datalen = (odev->hard_header_len + 16) & ~0xf;
 
@@ -2670,6 +2690,8 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
        skb->transport_header = skb->network_header + sizeof(struct iphdr);
        skb_put(skb, sizeof(struct iphdr) + sizeof(struct udphdr));
        skb_set_queue_mapping(skb, queue_map);
+       skb->priority = pkt_dev->skb_priority;
+
        iph = ip_hdr(skb);
        udph = udp_hdr(skb);
 
@@ -2975,8 +2997,8 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        /* Update any of the values, used when we're incrementing various
         * fields.
         */
-       queue_map = pkt_dev->cur_queue_map;
        mod_cur_headers(pkt_dev);
+       queue_map = pkt_dev->cur_queue_map;
 
        skb = __netdev_alloc_skb(odev,
                                 pkt_dev->cur_pkt_size + 64
@@ -3015,6 +3037,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
        skb_put(skb, sizeof(struct ipv6hdr) + sizeof(struct udphdr));
        skb_set_queue_mapping(skb, queue_map);
+       skb->priority = pkt_dev->skb_priority;
        iph = ipv6_hdr(skb);
        udph = udp_hdr(skb);
 
@@ -3430,11 +3453,6 @@ static void pktgen_rem_thread(struct pktgen_thread *t)
 
        remove_proc_entry(t->tsk->comm, pg_proc_dir);
 
-       mutex_lock(&pktgen_thread_lock);
-
-       list_del(&t->th_list);
-
-       mutex_unlock(&pktgen_thread_lock);
 }
 
 static void pktgen_resched(struct pktgen_dev *pkt_dev)
@@ -3581,6 +3599,8 @@ static int pktgen_thread_worker(void *arg)
                pkt_dev = next_to_run(t);
 
                if (unlikely(!pkt_dev && t->control == 0)) {
+                       if (pktgen_exiting)
+                               break;
                        wait_event_interruptible_timeout(t->queue,
                                                         t->control != 0,
                                                         HZ/10);
@@ -3633,6 +3653,13 @@ static int pktgen_thread_worker(void *arg)
        pr_debug("%s removing thread\n", t->tsk->comm);
        pktgen_rem_thread(t);
 
+       /* Wait for kthread_stop */
+       while (!kthread_should_stop()) {
+               set_current_state(TASK_INTERRUPTIBLE);
+               schedule();
+       }
+       __set_current_state(TASK_RUNNING);
+
        return 0;
 }
 
@@ -3907,6 +3934,7 @@ static void __exit pg_cleanup(void)
        struct list_head *q, *n;
 
        /* Stop all interfaces & threads */
+       pktgen_exiting = true;
 
        list_for_each_safe(q, n, &pktgen_threads) {
                t = list_entry(q, struct pktgen_thread, th_list);