summaryrefslogtreecommitdiffstats
path: root/lib/crc32.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2016-08-02 17:04:16 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-08-02 19:35:08 -0400
commita9bfd3321713ecec86282dd2bec04212189f91f1 (patch)
tree1c5981e2d274c3d3fb3b340724939fffb7747eb8 /lib/crc32.c
parentf003a1f182bb821f13775338a4bf8711830f927a (diff)
crc32: use ktime_get_ns() for measurement
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>
Diffstat (limited to 'lib/crc32.c')
-rw-r--r--lib/crc32.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/crc32.c b/lib/crc32.c
index 9a907d489d95..7fbd1a112b9d 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -979,7 +979,6 @@ static int __init crc32c_test(void)
979 int i; 979 int i;
980 int errors = 0; 980 int errors = 0;
981 int bytes = 0; 981 int bytes = 0;
982 struct timespec start, stop;
983 u64 nsec; 982 u64 nsec;
984 unsigned long flags; 983 unsigned long flags;
985 984
@@ -999,20 +998,17 @@ static int __init crc32c_test(void)
999 local_irq_save(flags); 998 local_irq_save(flags);
1000 local_irq_disable(); 999 local_irq_disable();
1001 1000
1002 getnstimeofday(&start); 1001 nsec = ktime_get_ns();
1003 for (i = 0; i < 100; i++) { 1002 for (i = 0; i < 100; i++) {
1004 if (test[i].crc32c_le != __crc32c_le(test[i].crc, test_buf + 1003 if (test[i].crc32c_le != __crc32c_le(test[i].crc, test_buf +
1005 test[i].start, test[i].length)) 1004 test[i].start, test[i].length))
1006 errors++; 1005 errors++;
1007 } 1006 }
1008 getnstimeofday(&stop); 1007 nsec = ktime_get_ns() - nsec;
1009 1008
1010 local_irq_restore(flags); 1009 local_irq_restore(flags);
1011 local_irq_enable(); 1010 local_irq_enable();
1012 1011
1013 nsec = stop.tv_nsec - start.tv_nsec +
1014 1000000000 * (stop.tv_sec - start.tv_sec);
1015
1016 pr_info("crc32c: CRC_LE_BITS = %d\n", CRC_LE_BITS); 1012 pr_info("crc32c: CRC_LE_BITS = %d\n", CRC_LE_BITS);
1017 1013
1018 if (errors) 1014 if (errors)
@@ -1065,7 +1061,6 @@ static int __init crc32_test(void)
1065 int i; 1061 int i;
1066 int errors = 0; 1062 int errors = 0;
1067 int bytes = 0; 1063 int bytes = 0;
1068 struct timespec start, stop;
1069 u64 nsec; 1064 u64 nsec;
1070 unsigned long flags; 1065 unsigned long flags;
1071 1066
@@ -1088,7 +1083,7 @@ static int __init crc32_test(void)
1088 local_irq_save(flags); 1083 local_irq_save(flags);
1089 local_irq_disable(); 1084 local_irq_disable();
1090 1085
1091 getnstimeofday(&start); 1086 nsec = ktime_get_ns();
1092 for (i = 0; i < 100; i++) { 1087 for (i = 0; i < 100; i++) {
1093 if (test[i].crc_le != crc32_le(test[i].crc, test_buf + 1088 if (test[i].crc_le != crc32_le(test[i].crc, test_buf +
1094 test[i].start, test[i].length)) 1089 test[i].start, test[i].length))
@@ -1098,14 +1093,11 @@ static int __init crc32_test(void)
1098 test[i].start, test[i].length)) 1093 test[i].start, test[i].length))
1099 errors++; 1094 errors++;
1100 } 1095 }
1101 getnstimeofday(&stop); 1096 nsec = ktime_get_ns() - nsec;
1102 1097
1103 local_irq_restore(flags); 1098 local_irq_restore(flags);
1104 local_irq_enable(); 1099 local_irq_enable();
1105 1100
1106 nsec = stop.tv_nsec - start.tv_nsec +
1107 1000000000 * (stop.tv_sec - start.tv_sec);
1108
1109 pr_info("crc32: CRC_LE_BITS = %d, CRC_BE BITS = %d\n", 1101 pr_info("crc32: CRC_LE_BITS = %d, CRC_BE BITS = %d\n",
1110 CRC_LE_BITS, CRC_BE_BITS); 1102 CRC_LE_BITS, CRC_BE_BITS);
1111 1103