Skip to content

Commit

Permalink
crc32: use ktime_get_ns() for measurement
Browse files Browse the repository at this point in the history
The crc32 test function measures the elapsed time in nanoseconds, but
uses 'struct timespec' for that.  We want to remove timespec from the
kernel for y2038 compatibility, and ktime_get_ns() also helps make the
code simpler here.

It is also slightly better to use monontonic time, as we are only
interested in the time difference.

Link: http://lkml.kernel.org/r/20160617143932.3289626-1-arnd@arndb.de
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: "David S . Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Arnd Bergmann authored and Linus Torvalds committed Aug 2, 2016
1 parent f003a1f commit a9bfd33
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,6 @@ static int __init crc32c_test(void)
int i;
int errors = 0;
int bytes = 0;
struct timespec start, stop;
u64 nsec;
unsigned long flags;

Expand All @@ -999,20 +998,17 @@ static int __init crc32c_test(void)
local_irq_save(flags);
local_irq_disable();

getnstimeofday(&start);
nsec = ktime_get_ns();
for (i = 0; i < 100; i++) {
if (test[i].crc32c_le != __crc32c_le(test[i].crc, test_buf +
test[i].start, test[i].length))
errors++;
}
getnstimeofday(&stop);
nsec = ktime_get_ns() - nsec;

local_irq_restore(flags);
local_irq_enable();

nsec = stop.tv_nsec - start.tv_nsec +
1000000000 * (stop.tv_sec - start.tv_sec);

pr_info("crc32c: CRC_LE_BITS = %d\n", CRC_LE_BITS);

if (errors)
Expand Down Expand Up @@ -1065,7 +1061,6 @@ static int __init crc32_test(void)
int i;
int errors = 0;
int bytes = 0;
struct timespec start, stop;
u64 nsec;
unsigned long flags;

Expand All @@ -1088,7 +1083,7 @@ static int __init crc32_test(void)
local_irq_save(flags);
local_irq_disable();

getnstimeofday(&start);
nsec = ktime_get_ns();
for (i = 0; i < 100; i++) {
if (test[i].crc_le != crc32_le(test[i].crc, test_buf +
test[i].start, test[i].length))
Expand All @@ -1098,14 +1093,11 @@ static int __init crc32_test(void)
test[i].start, test[i].length))
errors++;
}
getnstimeofday(&stop);
nsec = ktime_get_ns() - nsec;

local_irq_restore(flags);
local_irq_enable();

nsec = stop.tv_nsec - start.tv_nsec +
1000000000 * (stop.tv_sec - start.tv_sec);

pr_info("crc32: CRC_LE_BITS = %d, CRC_BE BITS = %d\n",
CRC_LE_BITS, CRC_BE_BITS);

Expand Down

0 comments on commit a9bfd33

Please sign in to comment.