From: Christoph Egger <Christoph.Egger@amd.com>
To: Stefan Weil <weil@mail.berlios.de>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
Anthony Liguori <aliguori@us.ibm.com>,
qemu-devel <qemu-devel@nongnu.org>,
Alexander Graf <agraf@suse.de>
Subject: Re: [Qemu-devel] [RFC][PATCH] signrom: Speed up checksum calculation
Date: Tue, 24 Jan 2012 11:18:30 +0100 [thread overview]
Message-ID: <4F1E8576.3060502@amd.com> (raw)
In-Reply-To: <4F1DB21A.8090607@mail.berlios.de>
On 01/23/12 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<jan.kiszka@siemens.com>
>> ---
>>
>> That "remaining portable" is an unproven claim. So please check that
>> problematic NetBSD and also mingw. Thanks!
The "unproven claim" is actually what SuSv3 spec
(http://pubs.opengroup.org/onlinepubs/009695399/utilities/od.html)
says:
"and the output from each of the transformations shall be separated by
one or more <blank>s."
The actual problem is that the programmer expects the behaviour
of either GNU od(1) or AT&T UNIX od(1) rather the SuSv3 spec.
NetBSD has AT&T UNIX od(1).
Christoph
>>
>> 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'd prefer if we could get rid of all AWK dependencies in QEMU
> and focus on as few scripting languages as reasonable.
>
> Regards,
> Stefan W.
>
>
--
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
next prev parent reply other threads:[~2012-01-24 11:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2012-01-24 8:39 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F1E8576.3060502@amd.com \
--to=christoph.egger@amd.com \
--cc=agraf@suse.de \
--cc=aliguori@us.ibm.com \
--cc=jan.kiszka@siemens.com \
--cc=qemu-devel@nongnu.org \
--cc=weil@mail.berlios.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.