From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:42224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpPQk-0004ys-KL for qemu-devel@nongnu.org; Mon, 23 Jan 2012 14:19:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RpPQj-0002PA-Jx for qemu-devel@nongnu.org; Mon, 23 Jan 2012 14:19:50 -0500 Received: from thoth.sbs.de ([192.35.17.2]:29596) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpPQj-0002P6-9O for qemu-devel@nongnu.org; Mon, 23 Jan 2012 14:19:49 -0500 Message-ID: <4F1DB2D0.9080301@siemens.com> Date: Mon, 23 Jan 2012 20:19:44 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <4F1DA926.4000709@siemens.com> <4F1DB21A.8090607@mail.berlios.de> In-Reply-To: <4F1DB21A.8090607@mail.berlios.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC][PATCH] signrom: Speed up checksum calculation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: Christoph Egger , Anthony Liguori , qemu-devel , Alexander Graf On 2012-01-23 20:16, Stefan Weil wrote: > Am 23.01.2012 19:38, schrieb Jan Kiszka: >> 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 >> --- >> >> 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" >> > > What about replacing the whole script by a python script? > That would save about 6 more forks :-) I think we have no python dependency in the build system yet - while we have for awk. That was also the original reason to go for a shell script. If the situation changed, I would not vote against python, for sure. Jan -- Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux