Skip to contentSkip to conversation

: PSCHED_TADD() and PSCHED_TADD2() can result,tv_usec >= 1000000

PKT_SCHED David Miller 2 participants 5 messages Jun 20, 2006 – Jun 28, 2006 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

David Miller

author maintainer
#1 lore raw

From: Shuya MAEDA <[email protected]>
Date: Mon, 19 Jun 2006 14:36:46 +0900

Quoted 8 lines

#define PSCHED_TADD2(tv, delta, tv_res) \
({ \

(quoted diff) +2 -4
-          int __delta = (tv).tv_usec + (delta); \
-          (tv_res).tv_sec = (tv).tv_sec; \
-          if (__delta > USEC_PER_SEC) { (tv_res).tv_sec++; __delta -= USEC_PER_SEC; } \
-          (tv_res).tv_usec = __delta; \
+          int __delta = (delta); \
+          (tv_res) = (tv); \

Review

Quoted 10 lines
(quoted diff) +9 -0
+          if((delta) > USEC_PER_SEC) { \
+                (tv_res).tv_sec += (delta) / USEC_PER_SEC; \
+                __delta -= (delta) % USEC_PER_SEC; \
+          } \
+          (tv_res).tv_usec += __delta; \
+          if((tv_res).tv_usec >= USEC_PER_SEC) { \
+                (tv_res).tv_sec++; \
+                (tv_res).tv_usec -= USEC_PER_SEC; \
+          } \
 })

Divide and modulus can be extremely expensive on some systems, so let's try to avoid using them.

It is probably sufficient to adjust the passed in delta only once if it is >= USEC_PER_SEC, but if you feel that is an unsafe assumption then please use a simply loop like this:

	while (__delta >= USEC_PER_SEC) {
		(tv_res).tv_sec++;
		__delta -= USEC_PER_SEC;
	}

And please provide a proper "Signed-off-by: " line in your next patch submission.

Thank you very much.

#2 lore raw

Thank you for the comment.
I made the patch that used the loop instead of the divide and modulus. Are there any comments?

Quoted 34 lines · David Miller

From: Shuya MAEDA <[email protected]>
Date: Mon, 19 Jun 2006 14:36:46 +0900

Quoted 8 lines

#define PSCHED_TADD2(tv, delta, tv_res) \
({ \

(quoted diff) +2 -4
-          int __delta = (tv).tv_usec + (delta); \
-          (tv_res).tv_sec = (tv).tv_sec; \
-          if (__delta > USEC_PER_SEC) { (tv_res).tv_sec++; __delta -= USEC_PER_SEC; } \
-          (tv_res).tv_usec = __delta; \
+          int __delta = (delta); \
+          (tv_res) = (tv); \

Review

Quoted 10 lines
(quoted diff) +9 -0
+          if((delta) > USEC_PER_SEC) { \
+                (tv_res).tv_sec += (delta) / USEC_PER_SEC; \
+                __delta -= (delta) % USEC_PER_SEC; \
+          } \
+          (tv_res).tv_usec += __delta; \
+          if((tv_res).tv_usec >= USEC_PER_SEC) { \
+                (tv_res).tv_sec++; \
+                (tv_res).tv_usec -= USEC_PER_SEC; \
+          } \
 })

Divide and modulus can be extremely expensive on some systems, so let's try to avoid using them.

It is probably sufficient to adjust the passed in delta only once if it is >= USEC_PER_SEC, but if you feel that is an unsafe assumption then please use a simply loop like this:

	while (__delta >= USEC_PER_SEC) {
		(tv_res).tv_sec++;
		__delta -= USEC_PER_SEC;
	}
Quoted 4 lines

And please provide a proper "Signed-off-by: " line in your next patch submission.

Thank you very much.

include/net/pkt_sched.h 2006-06-20 17:17:34.000000000 +0900 renamed from include/net/pkt_sched.h 2006-06-18 10:49:35.000000000 +0900 +12 -6
diff -Nur linux-2.6.17.orig/include/net/pkt_sched.h linux-2.6.17.mypatch/include/net/pkt_sched.h
@@ -169,17 +169,23 @@
 
 #define PSCHED_TADD2(tv, delta, tv_res) \
 ({ \
-          int __delta = (tv).tv_usec + (delta); \
-          (tv_res).tv_sec = (tv).tv_sec; \
-          if (__delta > USEC_PER_SEC) { (tv_res).tv_sec++; __delta -= USEC_PER_SEC; } \
+          int __delta = (delta); \
+          (tv_res) = (tv); \
+          while(__delta >= USEC_PER_SEC){ \
+                (tv_res).tv_sec++; \
+                __delta -= USEC_PER_SEC; \
+          } \
           (tv_res).tv_usec = __delta; \
 })
 
 #define PSCHED_TADD(tv, delta) \
 ({ \
-          (tv).tv_usec += (delta); \
-          if ((tv).tv_usec > USEC_PER_SEC) { (tv).tv_sec++; \
-                (tv).tv_usec -= USEC_PER_SEC; } \
+          int __delta = (delta); \
+          while(__delta >= USEC_PER_SEC){ \
+                (tv).tv_sec++; \
+                __delta -= USEC_PER_SEC; \
+          } \
+          (tv).tv_usec = __delta; \
 })
 
 /* Set/check that time is in the "past perfect";
Signature · 1 line
Shuya MAEDA
author maintainer
#3 lore raw

From: Shuya MAEDA <[email protected]>
Date: Wed, 21 Jun 2006 09:16:03 +0900

Quoted 3 lines

Thank you for the comment.
I made the patch that used the loop instead of the divide and modulus. Are there any comments?

Your email client has corrupted the patch, turning tab characters into spaces, and also turning lines containing only spaces into empty lines.

Therefore, I cannot apply your patch, please send your patch properly so that I may apply it.

Thank you.

#4 lore raw

Excuse me for the corrupted patch. I will send the patch as an attachment this time.

Thank you very much.

Quoted 11 lines · David Miller

From: Shuya MAEDA <[email protected]>
Date: Wed, 21 Jun 2006 09:16:03 +0900

Quoted 3 lines

Thank you for the comment.
I made the patch that used the loop instead of the divide and modulus. Are there any comments?

Your email client has corrupted the patch, turning tab characters into spaces, and also turning lines containing only spaces into empty lines.

Quoted 50 lines

Therefore, I cannot apply your patch, please send your patch properly so that I may apply it.

Thank you.

Quoted 44 lines · Shuya MAEDA

Thank you for the comment.
I made the patch that used the loop instead of the divide and modulus. Are there any comments?

Quoted 39 lines · David Miller

From: Shuya MAEDA <[email protected]>
Date: Mon, 19 Jun 2006 14:36:46 +0900

Quoted 9 lines

#define PSCHED_TADD2(tv, delta, tv_res) \
({ \

(quoted diff) +2 -5
-          int __delta = (tv).tv_usec + (delta); \
-          (tv_res).tv_sec = (tv).tv_sec; \
-          if (__delta > USEC_PER_SEC) { (tv_res).tv_sec++; __delta
-= USEC_PER_SEC; } \
-          (tv_res).tv_usec = __delta; \
+          int __delta = (delta); \
+          (tv_res) = (tv); \

Review

Quoted 10 lines
(quoted diff) +9 -0
+          if((delta) > USEC_PER_SEC) { \
+                (tv_res).tv_sec += (delta) / USEC_PER_SEC; \
+                __delta -= (delta) % USEC_PER_SEC; \
+          } \
+          (tv_res).tv_usec += __delta; \
+          if((tv_res).tv_usec >= USEC_PER_SEC) { \
+                (tv_res).tv_sec++; \
+                (tv_res).tv_usec -= USEC_PER_SEC; \
+          } \
 })

Divide and modulus can be extremely expensive on some systems, so let's try to avoid using them.

It is probably sufficient to adjust the passed in delta only once if it is >= USEC_PER_SEC, but if you feel that is an unsafe assumption then please use a simply loop like this:

    while (__delta >= USEC_PER_SEC) {
        (tv_res).tv_sec++;
        __delta -= USEC_PER_SEC;
    }

And please provide a proper "Signed-off-by: " line in your next patch submission.

Thank you very much.

--
Shuya MAEDA

include/net/pkt_sched.h +12 -6
diff -Nur linux-2.6.17.orig/include/net/pkt_sched.h linux-2.6.17.mypatch/include/net/pkt_sched.h
@@ -169,17 +169,23 @@
 
 #define PSCHED_TADD2(tv, delta, tv_res) \
 ({ \
-	   int __delta = (tv).tv_usec + (delta); \
-	   (tv_res).tv_sec = (tv).tv_sec; \
-	   if (__delta > USEC_PER_SEC) { (tv_res).tv_sec++; __delta -= USEC_PER_SEC; } \
+	   int __delta = (delta); \
+	   (tv_res) = (tv); \
+	   while(__delta >= USEC_PER_SEC){ \
+		 (tv_res).tv_sec++; \
+		 __delta -= USEC_PER_SEC; \
+	   } \
 	   (tv_res).tv_usec = __delta; \
 })
 
 #define PSCHED_TADD(tv, delta) \
 ({ \
-	   (tv).tv_usec += (delta); \
-	   if ((tv).tv_usec > USEC_PER_SEC) { (tv).tv_sec++; \
-		 (tv).tv_usec -= USEC_PER_SEC; } \
+	   int __delta = (delta); \
+	   while(__delta >= USEC_PER_SEC){ \
+		 (tv).tv_sec++; \
+		 __delta -= USEC_PER_SEC; \
+	   } \
+	   (tv).tv_usec = __delta; \
 })
 
 /* Set/check that time is in the "past perfect";
author maintainer
#5 lore raw

From: Shuya MAEDA <[email protected]>
Date: Wed, 28 Jun 2006 17:38:56 +0900

Quoted 4 lines

Excuse me for the corrupted patch. I will send the patch as an attachment this time.

Thank you very much.

Patch applied, thanks a lot.