Skip to contentSkip to conversation

trace: Use 64-bit timekeeping

PATCH In review Tina Ruchandani 3 participants 4 messages Jan 28, 2015 – Jan 29, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 trace: Use 64-bit timekeeping

The ring_buffer_producer uses 'struct timeval' to measure its start and end times. 'struct timeval' on 32-bit systems will have its tv_sec value overflow in year 2038 and beyond. This patch replaces struct timeval with 'ktime_t' which uses 64-bit representation for nanoseconds.

---
Changes in v4:
- Fix typo in commit message.
- Avoid typecast to 'long long' by defining RUN_TIME as '10ULL' instead of '10'.
Changes in v3:
- Use a more efficient way to compute condition for exiting loop.
- Fix variable naming - all caps is only for macros.
Changes in v2:
- Use ktime_t instead of timespec64 for efficiency reasons.

---
 kernel/trace/ring_buffer_benchmark.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
kernel/trace/ring_buffer_benchmark.c +8 -10
index 3f9e328..13d945c 100644
@@ -7,7 +7,7 @@
 #include <linux/completion.h>
 #include <linux/kthread.h>
 #include <linux/module.h>
-#include <linux/time.h>
+#include <linux/ktime.h>
 #include <asm/local.h>
 
 struct rb_page {
@@ -17,7 +17,7 @@ struct rb_page {
 };
 
 /* run time and sleep time in seconds */
-#define RUN_TIME	10
+#define RUN_TIME	10ULL
 #define SLEEP_TIME	10
 
 /* number of events for writer to wake up the reader */
@@ -212,8 +212,7 @@ static void ring_buffer_consumer(void)
 
 static void ring_buffer_producer(void)
 {
-	struct timeval start_tv;
-	struct timeval end_tv;
+	ktime_t start_time, end_time, timeout;
 	unsigned long long time;
 	unsigned long long entries;
 	unsigned long long overruns;
@@ -227,7 +226,8 @@ static void ring_buffer_producer(void)
 	 * make the system stall)
 	 */
 	trace_printk("Starting ring buffer hammer\n");
-	do_gettimeofday(&start_tv);
+	start_time = ktime_get();
+	timeout = ktime_add_ns(start_time, RUN_TIME * NSEC_PER_SEC);
 	do {
 		struct ring_buffer_event *event;
 		int *entry;
@@ -244,7 +244,7 @@ static void ring_buffer_producer(void)
 				ring_buffer_unlock_commit(buffer, event);
 			}
 		}
-		do_gettimeofday(&end_tv);
+		end_time = ktime_get();
 
 		cnt++;
 		if (consumer && !(cnt % wakeup_interval))
@@ -264,7 +264,7 @@ static void ring_buffer_producer(void)
 			cond_resched();
 #endif
 
-	} while (end_tv.tv_sec < (start_tv.tv_sec + RUN_TIME) && !kill_test);
+	} while (ktime_before(end_time, timeout) && !kill_test);
 	trace_printk("End ring buffer hammer\n");
 
 	if (consumer) {
@@ -280,9 +280,7 @@ static void ring_buffer_producer(void)
 		wait_for_completion(&read_done);
 	}
 
-	time = end_tv.tv_sec - start_tv.tv_sec;
-	time *= USEC_PER_SEC;
-	time += (long long)((long)end_tv.tv_usec - (long)start_tv.tv_usec);
+	time = ktime_us_delta(end_time, start_time);
 
 	entries = ring_buffer_entries(buffer);
 	overruns = ring_buffer_overruns(buffer);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
maintainer
#1 lore raw
Quoted 6 lines · On Wed, 28 Jan 2015 19:46:11 +0530 Tina Ruchandani <[email protected]>…

The ring_buffer_producer uses 'struct timeval' to measure its start and end times. 'struct timeval' on 32-bit systems will have its tv_sec value overflow in year 2038 and beyond. This patch replaces struct timeval with 'ktime_t' which uses 64-bit representation for nanoseconds.

Quoted 8 lines

---
Changes in v4:
- Fix typo in commit message.
- Avoid typecast to 'long long' by defining RUN_TIME as '10ULL' instead of '10'.

Although I have not tested this, this patch looks fine to me. Is this going to go through some cleanup tree or should I just pull it?

-- Steve

Quoted 5 lines

Changes in v3:
- Use a more efficient way to compute condition for exiting loop.
- Fix variable naming - all caps is only for macros.
Changes in v2:
- Use ktime_t instead of timespec64 for efficiency reasons.

#2 lore raw
Quoted 18 lines · On Wednesday 28 January 2015 09:53:49 Steven Rostedt wrote:
Quoted 6 lines · On Wed, 28 Jan 2015 19:46:11 +0530 Tina Ruchandani <[email protected]>…

The ring_buffer_producer uses 'struct timeval' to measure its start and end times. 'struct timeval' on 32-bit systems will have its tv_sec value overflow in year 2038 and beyond. This patch replaces struct timeval with 'ktime_t' which uses 64-bit representation for nanoseconds.

Quoted 8 lines

---
Changes in v4:
- Fix typo in commit message.
- Avoid typecast to 'long long' by defining RUN_TIME as '10ULL' instead of '10'.

Quoted 3 lines

Although I have not tested this, this patch looks fine to me. Is this going to go through some cleanup tree or should I just pull it?

Please apply it to your tree.

Arnd

maintainer
#3 lore raw
Quoted 1 line · On Wed, 28 Jan 2015 15:55:39 +0100 Arnd Bergmann <[email protected]> wrote:

Please apply it to your tree.

Will do.

Thanks,

-- Steve