Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-for-linus-2.6
[cascardo/linux.git] / net / core / pktgen.c
index c57b06b..ef430b1 100644 (file)
 #include <asm/timex.h>
 
 
-#define VERSION  "pktgen v2.61: Packet Generator for packet performance testing.\n"
+#define VERSION  "pktgen v2.62: Packet Generator for packet performance testing.\n"
 
 /* #define PG_DEBUG(a) a */
 #define PG_DEBUG(a) 
@@ -363,7 +363,7 @@ struct pktgen_thread {
  * All Rights Reserved.
  *
  */
-inline static s64 divremdi3(s64 x, s64 y, int type) 
+static inline s64 divremdi3(s64 x, s64 y, int type)
 {
         u64 a = (x < 0) ? -x : x;
         u64 b = (y < 0) ? -y : y;
@@ -503,7 +503,7 @@ static int pg_delay_d = 0;
 static int pg_clone_skb_d = 0;
 static int debug = 0;
 
-static spinlock_t _thread_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(_thread_lock);
 static struct pktgen_thread *pktgen_threads = NULL;
 
 static char module_fname[128];
@@ -1452,8 +1452,7 @@ static int proc_thread_write(struct file *file, const char __user *user_buffer,
                thread_lock();
                t->control |= T_REMDEV;
                thread_unlock();
-               current->state = TASK_INTERRUPTIBLE;
-               schedule_timeout(HZ/8);  /* Propagate thread->control  */
+               schedule_timeout_interruptible(msecs_to_jiffies(125));  /* Propagate thread->control  */
                ret = count;
                 sprintf(pg_result, "OK: rem_device_all");
                goto out;
@@ -1716,10 +1715,9 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
        printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now));
        while (now < spin_until_us) {
                /* TODO: optimise sleeping behavior */
-               if (spin_until_us - now > (1000000/HZ)+1) {
-                       current->state = TASK_INTERRUPTIBLE;
-                       schedule_timeout(1);
-               } else if (spin_until_us - now > 100) {
+               if (spin_until_us - now > jiffies_to_usecs(1)+1)
+                       schedule_timeout_interruptible(1);
+               else if (spin_until_us - now > 100) {
                        do_softirq();
                        if (!pkt_dev->running)
                                return;
@@ -1921,6 +1919,11 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
        struct iphdr *iph;
         struct pktgen_hdr *pgh = NULL;
         
+       /* Update any of the values, used when we're incrementing various
+        * fields.
+        */
+       mod_cur_headers(pkt_dev);
+
        skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16, GFP_ATOMIC);
        if (!skb) {
                sprintf(pkt_dev->result, "No memory");
@@ -1934,11 +1937,6 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
        iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
        udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
 
-        /* Update any of the values, used when we're incrementing various
-         * fields.
-         */
-        mod_cur_headers(pkt_dev);
-
        memcpy(eth, pkt_dev->hh, 12);
        *(u16*)&eth[12] = __constant_htons(ETH_P_IP);
 
@@ -2192,7 +2190,12 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        int datalen;
        struct ipv6hdr *iph;
         struct pktgen_hdr *pgh = NULL;
-        
+
+       /* Update any of the values, used when we're incrementing various
+        * fields.
+        */
+       mod_cur_headers(pkt_dev);
+
        skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16, GFP_ATOMIC);
        if (!skb) {
                sprintf(pkt_dev->result, "No memory");
@@ -2206,17 +2209,9 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        iph = (struct ipv6hdr *)skb_put(skb, sizeof(struct ipv6hdr));
        udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
 
-
-        /* Update any of the values, used when we're incrementing various
-         * fields.
-         */
-       mod_cur_headers(pkt_dev);
-
-       
        memcpy(eth, pkt_dev->hh, 12);
        *(u16*)&eth[12] = __constant_htons(ETH_P_IPV6);
-       
-        
+
        datalen = pkt_dev->cur_pkt_size-14- 
                sizeof(struct ipv6hdr)-sizeof(struct udphdr); /* Eth + IPh + UDPh */
 
@@ -2452,8 +2447,7 @@ static void pktgen_run_all_threads(void)
        }
        thread_unlock();
 
-       current->state = TASK_INTERRUPTIBLE;
-       schedule_timeout(HZ/8);  /* Propagate thread->control  */
+       schedule_timeout_interruptible(msecs_to_jiffies(125));  /* Propagate thread->control  */
                        
        pktgen_wait_all_threads_run();
 }