From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] [RFC][PATCH] kvm: kvmtrace: kvmtrace_format for supporting big_endian Date: Wed, 21 May 2008 12:21:16 +0300 Message-ID: <4833E98C.20202@qumranet.com> References: <08DF4D958216244799FC84F3514D70F0015B1B58@pdsmsx415.ccr.corp.intel.com> <200805141637.03442.hollisb@us.ibm.com> <08DF4D958216244799FC84F3514D70F00164BF05@pdsmsx415.ccr.corp.intel.com> <08DF4D958216244799FC84F3514D70F00164BF20@pdsmsx415.ccr.corp.intel.com> <4832FAD4.2040908@qumranet.com> <08DF4D958216244799FC84F3514D70F00164C4A2@pdsmsx415.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org To: "Tan, Li" Return-path: Received: from bzq-179-150-194.static.bezeqint.net ([212.179.150.194]:45305 "EHLO il.qumranet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753011AbYEUJVU (ORCPT ); Wed, 21 May 2008 05:21:20 -0400 In-Reply-To: <08DF4D958216244799FC84F3514D70F00164C4A2@pdsmsx415.ccr.corp.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: Tan, Li wrote: > -----Original Message----- > From: Avi Kivity [mailto:avi@qumranet.com]=20 > Sent: 2008=C4=EA5=D4=C221=C8=D5 0:23 > To: Tan, Li > Cc: kvm@vger.kernel.org > Subject: Re: [PATCH] [RFC][PATCH] kvm: kvmtrace: kvmtrace_format for = supporting big_endian > > Tan, Li wrote: > =20 >> From 9d39264bdfb00a1a717074e486a948a578547c50 Mon Sep 17 00:00:00 20= 01 >> From: Tan Li >> Date: Tue, 20 May 2008 09:14:41 +0800 >> Subject: [PATCH] [RFC][PATCH] kvm: kvmtrace: kvmtrace_format for >> supporting big_endian >> >> Currently kvmtrace is not portable, and prevent from copying a trace >> file from big-endian target to little-endian workstation for analysi= s. >> >> In the patch, kvmtrace_format reads and checks the magic number from >> trace log. if needed, then change bytes order of all fields in recor= ds >> followed. >> >> =20 >> +def reverse_bytes(origin, bytes_cnt): >> + i =3D 0 >> + rtn =3D 0L >> + while i < bytes_cnt: >> + i =3D i + 1 >> + b =3D origin & 0xff >> + origin =3D origin >> 8 >> + rtn =3D (rtn << 8) + b >> + return rtn >> + >> +def reverse_int(origin): >> + return reverse_bytes(origin, 4) >> + >> +def reverse_qword(origin): >> + return reverse_bytes(origin, 8) >> + >> def sighand(x,y): >> global interrupted >> interrupted =3D 1 >> @@ -100,18 +116,40 @@ D2REC =3D "II" >> D3REC =3D "III" >> D4REC =3D "IIII" >> D5REC =3D "IIIII" >> +KMAGIC =3D "I" >> =20 >> =20 > > The python struct module supports reading big-endian and little-endia= n=20 > data. So you can simply switch the format strings if you have the wr= ong=20 > endianness. > > =20 > [tan] thanks for your comments. Then it looks like: > def reverse_int(origin): > s =3D struct.pack(' return struct.unpack('>I', s) > > def reverse_qword(origin): > s =3D struct.pack(' return struct.unpack('>Q', s) > =20 I meant, you can change the definitions of D3REC, D4REC, etc. and not worry about reversing once you've decoded the magic word. --=20 error compiling committee.c: too many arguments to function