qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC][PATCH] signrom: Speed up checksum calculation
@ 2012-01-23 18:38 Jan Kiszka
  2012-01-23 19:16 ` Stefan Weil
  2012-01-24  8:39 ` Paolo Bonzini
  0 siblings, 2 replies; 12+ messages in thread
From: Jan Kiszka @ 2012-01-23 18:38 UTC (permalink / raw)
  To: qemu-devel, Anthony Liguori; +Cc: Stefan Weil, Christoph Egger, Alexander Graf

Forking an expr process for every byte of the input data slows down the
checksum calculation massively. Fix this while still remaining portable
by implementing the algorithm in awk.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

That "remaining portable" is an unproven claim. So please check that
problematic NetBSD and also mingw. Thanks!

 scripts/signrom.sh |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/scripts/signrom.sh b/scripts/signrom.sh
index 9dc5c63..f0f460e 100755
--- a/scripts/signrom.sh
+++ b/scripts/signrom.sh
@@ -23,22 +23,20 @@
 # did we get proper arguments?
 test "$1" -a "$2" || exit 1
 
-sum=0
-
 # find out the file size
 x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n`
-#size=`expr $x \* 512 - 1`
 size=$(( $x * 512 - 1 ))
 
 # now get the checksum
 nums=`od -A n -t u1 -v -N $size "$1"`
-for i in ${nums}; do
-    # add each byte's value to sum
-    sum=`expr \( $sum + $i \) % 256`
-done
-
-sum=$(( (256 - $sum) % 256 ))
-sum_octal=$( printf "%o" $sum )
+sum_octal=`echo $nums | awk 'BEGIN {
+    getline data_str;
+    sum = 0;
+    n = split(data_str, data, " ");
+    for (i = 1; i <= n; i++)
+        sum = ( sum + data[i] ) % 256;
+    printf "%o", (256 - sum) % 256;
+}'`
 
 # and write the output file
 cp "$1" "$2"
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-01-24 11:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-23 18:38 [Qemu-devel] [RFC][PATCH] signrom: Speed up checksum calculation Jan Kiszka
2012-01-23 19:16 ` Stefan Weil
2012-01-23 19:19   ` Jan Kiszka
2012-01-23 19:25     ` Stefan Weil
2012-01-23 20:08       ` Anthony Liguori
2012-01-23 20:32         ` Jan Kiszka
2012-01-23 20:37           ` Anthony Liguori
2012-01-23 21:32             ` Stefan Weil
2012-01-24  9:43             ` Andreas Färber
2012-01-24  8:18         ` Paolo Bonzini
2012-01-24 10:18   ` Christoph Egger
2012-01-24  8:39 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).