[Qemu-devel] Re: [Autotest] [RFC PATCH 05/14] KVM-test: Add a subtest jumbo

2010-08-10 Thread Amos Kong
On Tue, Jul 27, 2010 at 10:13 PM, Lucas Meneghel Rodrigues
 wrote:
> On Tue, 2010-07-20 at 09:35 +0800, Amos Kong wrote:
>> According to different nic model set different MTU for it. And ping from 
>> guest
>> to host, to see whether tested size can be received by host.
>>
>> Signed-off-by: Jason Wang 
>> Signed-off-by: Amos Kong 
>> ---
>>  0 files changed, 0 insertions(+), 0 deletions(-)
>>
>> diff --git a/client/tests/kvm/tests/jumbo.py 
>> b/client/tests/kvm/tests/jumbo.py
>> new file mode 100644
>> index 000..9f56a87
>> --- /dev/null
>> +++ b/client/tests/kvm/tests/jumbo.py
>> @@ -0,0 +1,133 @@
>> +import os, re, logging, commands, time, random
>> +from autotest_lib.client.common_lib import error
>> +import kvm_subprocess, kvm_test_utils, kvm_utils, kvm_net_utils
>> +
>> +def run_jumbo(test, params, env):
>> +    """
>> +    Test the RX jumbo frame function of vnics:
>> +    1) boot the vm
>> +    2) change the MTU of guest nics and host taps depends on the nic model
>
> ^ I think you meant 'depending on the nic model'
>
>> +    3) add the static arp entry for guest nic
>> +    4) wait for the MTU ok
>> +    5) verify the patch mtu using ping
>> +    6) ping the guest with large frames
>> +    7) increament size ping
>
> ^ typo, increment
>
>> +    8) flood ping the guest with large frames
>> +    9) verify the path mtu
>> +    10) revocer the mtu
>
> ^ maybe a typo, restore?
>
>> +
>> +   �...@param test: kvm test object
>> +   �...@param params: Dictionary with the test parameters
>> +   �...@param env: Dictionary with test environment.
>> +    """
>> +
>> +    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
>> +    session = kvm_test_utils.wait_for_login(vm)
>> +    mtu = params.get("mtu", "1500")
>> +    flood_time = params.get("flood_time", "300")
>> +    max_icmp_pkt_size = int(mtu) - 28
>> +
>> +    ifname = vm.get_ifname(0)
>> +    ip = vm.get_address(0)
>> +    if ip is None:
>> +        raise error.TestError("Could not get the ip address")
>> +
>> +    try:
>> +        # Environment preparartion
>
> ^ typo, preparation
>
>> +        ethname = kvm_net_utils.get_linux_ifname(session, vm.get_macaddr(0))
>> +
>> +        logging.info("Changing the mtu of guest ...")
>> +        guest_mtu_cmd = "ifconfig %s mtu %s" % (ethname , mtu)
>> +        s, o = session.get_command_status_output(guest_mtu_cmd)
>> +        if s != 0:
>> +            logging.error(o)
>> +            raise error.TestError("Fail to set the mtu of guest nic: %s"
>> +                                  % ethname)
>> +
>> +        logging.info("Chaning the mtu of host tap ...")
>> +        host_mtu_cmd = "ifconfig %s mtu %s" % (ifname, mtu)
>> +        s, o = commands.getstatusoutput(host_mtu_cmd)
>> +        if s != 0:
>> +            raise error.TestError("Fail to set the mtu of %s" % ifname)
>> +
>> +        logging.info("Add a temporary static arp entry ...")
>> +        arp_add_cmd = "arp -s %s %s -i %s" % (ip, vm.get_macaddr(0), ifname)
>> +        s, o = commands.getstatusoutput(arp_add_cmd)
>> +        if s != 0 :
>> +            raise error.TestError("Fail to add temporary arp entry")
>> +
>> +        def is_mtu_ok():
>> +            s, o = kvm_net_utils.ping(ip, 1, interface = ifname,
>> +                                      packetsize = max_icmp_pkt_size,
>> +                                      hint = "do", timeout = 2)
>
> ^ please fix the default argument attribution, here and all subsequent
> calls
>
>> +            if s != 0:
>> +                return False
>> +            else:
>> +                return True
>
> ^ Here you could simple use return s != 0
>
>> +
>> +        def verify_mtu():
>> +            logging.info("Verify the path mtu")
>> +            s, o = kvm_net_utils.ping(ip, 10, interface = ifname,
>> +                                      packetsize = max_icmp_pkt_size,
>> +                                      hint = "do", timeout = 15)
>> +            if s != 0 :
>> +                logging.error(o)
>> +                raise error.TestFail("Path MTU is not as expected")
>> +            if kvm_net_utils.get_loss_ratio(o) != 0:
>> +                logging.error(o)
>> +                raise error.TestFail("Packet loss ratio during mtu 
>> verification"
>> +                                     " is not zero")
>> +
>> +        def flood_ping():
>> +            logging.info("Flood with large frames")
>> +            kvm_net_utils.ping(ip, interface = ifname,
>> +                               packetsize = max_icmp_pkt_size,
>> +                               flood = True, timeout = float(flood_time))
>> +
>> +        def large_frame_ping(count = 100):
>> +            logging.info("Large frame ping")
>> +            s, o = kvm_net_utils.ping(ip, count, interface = ifname,
>> +                                      packetsize = max_icmp_pkt_size,
>> +                                      timeout = float(count) * 2)
>> +            ratio = kvm_net_utils.get_loss_ratio(o)
>> +            if 

[Qemu-devel] Rehabilitering

2010-08-10 Thread DokuMera Nyhetsbrev
Om du har problem med att läsa detta e-postmeddelande, klicka här 
(http://www.anp.se/newsletterweb/822531/444059437941455D4B7142445C43) för en 
webb-version.

Vårt nyhetsbrev skickas automatiskt till våra kunder och intressenter. Vill du 
inte ha detta nyhetsbrev framöver, klicka här för att avprenumerera 
(http://www.anp.se/oa/822531/444059437941455D4B7142445C43).


Nyhetsbrev 32/2010Detta nyhetsbrev är skickat till: qemu-devel@nongnu.org

(http://www.dokumera.se/newsletter_redirect.asp?to=http://www.dokumera.se&from=172191075&prefix=dm)
 (http://www.anp.se/taf/822531/444059437941455D4B7142445C43)  
(http://www.dokumera.se/newsletter_redirect.asp?to=http://www.dokumera.se/out_newsletters.asp&from=172191075&prefix=dm)
  
(http://www.anp.se/newsletter.asp?sqid=822531&sid=444059437941455D4B7142445C43&print=true)


Arbetsgivarens rehabiliteringsansvar

Arbetsgivaren har ett ansvar att göra en utredning angående behovet av 
rehabiliteringsinsatser i de fall då en anställd är sjuk ofta eller under en 
längre period. En anställd kan även själv kräva att en utredning skall göras. 
Rehabiliteringen kan bestå av medicinska, psykologiska, sociala och 
arbetslivsinriktade åtgärder som sätts in för att främja den anställdes 
återgång i arbete.

Som arbetsgivare har du inte enbart ett utredningsansvar. Du ansvarar även, 
tillsammans med den anställde, för att rehabiliteringsåtgärderna genomförs.

Rehabilitering kan ske genom exempelvis:
. Arbetsplatsanpassning
. Arbetshjälpmedel
. Ändrade arbetsuppgifter
. Omplacering
. Arbetsträning
. Utbildning

Med DokuMeras Företagspaket 
(http://www.dokumera.se/visa-kategorier.asp?id=1321) får du tillgång till fler 
än 1300 avtal, checklistor, policys, expertsvar och mycket annat som 
underlättar och juridiskt säkerställer arbetet i ditt företag. 


Veckans dokument 

Arbetsmiljöpolicy >> (http://www.dokumera.se/arbetsmiljopolicy_2060_dd.html)

Informationsblad rehabilitering >> 
(http://www.dokumera.se/informationsblad_rehabilitering_4383_dd.html) Ny !

Checklista rehabilitering >> 
(http://www.dokumera.se/checklista_rehabilitering_4382_dd.html) Ny !

Rehabiliteringspolicy >> 
(http://www.dokumera.se/rehabiliteringspolicy_4292_dd.html)

Rehabutredning och rehabplan >> 
(http://www.dokumera.se/rehabutredning_och_rehabplan_4384_dd.html) Ny !

Rehabdokumentation >> (http://www.dokumera.se/rehabdokumentation_4385_dd.html) 
Ny !


Expertsvar

Vilket ansvar har arbetsgivare för arbets-tagare som uvecklat sjukdom i 
arbetet? >> 
(http://www.dokumera.se/expertsvar/vilket_ansvar_har_arbetsgivare_for_arbetstagare_som_uvecklat_sjukdom_i_arbetet_1203_ad.html)

När ska behovet av rehabilitering klar-läggas? >> 
(http://www.dokumera.se/expertsvar/nar_ska_behovet_av_rehabilitering_klarlaggas_1264_ad.html)

Vad är rehabiliteringsutredning och rehabiliteringsplan? >> 
(http://www.dokumera.se/expertsvar/vad_ar_rehabiliteringsutredning_och_rehabiliteringsplan_1262_ad.html)

Går det att neka löneökning till för sjuk-skrivna? >> 
(http://www.dokumera.se/expertsvar/gar_det_att_neka_loneokning_till_for_sjukskrivna_1238_ad.html)


(http://www.dokumera.se/newsletter_redirect.asp?to=http://www.dokumera.se/foretagspaketet_1321_dc.html&from=172191075&prefix=dm)
 
(http://www.dokumera.se/newsletter_redirect.asp?to=http://www.dokumera.se/out_atq_ppdviewer.asp&from=172191075&prefix=dm)
 
(http://www.dokumera.se/newsletter_redirect.asp?to=http://www.dokumera.se/styckvisa_dokumentmallar_1330_dc.html&from=172191075&prefix=dm)

(http://www.dokumera.se/newsletter_redirect.asp?to=http://www.dokumera.se/out_contactusmessage.asp&from=172191075&prefix=dm)

För en kostnadsfri exklusiv presentation av hur DokuMera kan spara tiotusentals 
kronor åt just mitt företag.
Givetvis är du varmt välkommen att ringa oss på 08-664 04 50.

Innehållet i nyhetsbrev ska inte tolkas som ett åtagande från DokuMeras sida. 
Informationen sänds ut i befintligt skick, utan garantier och digitala 
signaturer.

[Qemu-devel] Re: [Autotest] [RFC PATCH 14/14] KVM-test: Add subtest of testing offload by ethtool

2010-08-10 Thread Amos Kong
On Tue, Aug 3, 2010 at 3:10 AM, Lucas Meneghel Rodrigues  
wrote:
> On Tue, 2010-07-20 at 09:36 +0800, Amos Kong wrote:
>> The latest case contains TX/RX/SG/TSO/GSO/GRO/LRO test. RTL8139 NIC doesn't
>> support TSO, LRO, it's too old, so drop offload test from rtl8139. LRO, GRO
>> are only supported by latest kernel, virtio nic doesn't support receive
>> offloading function.
>> Initialize the callbacks first and execute all the sub tests one by one, all
>> the result will be check at the end.
>> When execute this test, vhost should be enabled, then most of new feature can
>> be used. Vhost doestn't support VIRTIO_NET_F_MRG_RXBUF, so do not check large
>> packets in received offload test.
>> Transfer files by scp between host and guest, match new opened TCP port by
>> netstat. Capture the packages info by tcpdump, it contains package length.
>
> This test is heavily dependent on ethtool, so we need to make sure the
> package is going to be installed on linux guests. The default package
> selection for Fedora 13 does not include it for example. So, we need to
> modify linux guest kickstarts/XMLs to add ethtool to the default package
> selection.

OK.

>> Signed-off-by: Amos Kong 
>> ---
>>  0 files changed, 0 insertions(+), 0 deletions(-)
>>
>> diff --git a/client/tests/kvm/tests/ethtool.py 
>> b/client/tests/kvm/tests/ethtool.py
>> new file mode 100644
>> index 000..7274eae
>> --- /dev/null
>> +++ b/client/tests/kvm/tests/ethtool.py
>> @@ -0,0 +1,205 @@
>> +import time, os, logging, commands, re
>> +from autotest_lib.client.common_lib import error
>> +from autotest_lib.client.bin import utils
>> +import kvm_test_utils, kvm_utils, kvm_net_utils
>> +
>> +def run_ethtool(test, params, env):
>> +    """
>> +    Test offload functions of ethernet device by ethtool
>> +
>> +    1) Log into a guest
>> +    2) Initialize the callback of sub functions
>> +    3) Enable/disable sub function of NIC
>> +    4) Execute callback function
>> +    5) Check the return value
>> +    6) Restore original configuration
>> +
>> +   �...@param test: Kvm test object
>> +   �...@param params: Dictionary with the test parameters.
>> +   �...@param env: Dictionary with test environment.
>> +    """
>> +    def ethtool_get(type):
>> +        feature_pattern = {
>> +            'tx':  'tx.*checksumming',
>> +            'rx':  'rx.*checksumming',
>> +            'sg':  'scatter.*gather',
>> +            'tso': 'tcp.*segmentation.*offload',
>> +            'gso': 'generic.*segmentation.*offload',
>> +            'gro': 'generic.*receive.*offload',
>> +            'lro': 'large.*receive.*offload',
>> +            }
>> +        s, o = session.get_command_status_output("ethtool -k %s" % ethname)
>> +        try:
>> +            return re.findall("%s: (.*)" % feature_pattern.get(type), o)[0]
>> +        except IndexError:
>> +            logging.debug("Could not get %s status" % type)
>> +
>> +    def ethtool_set(type, status):
>> +        """
>> +        Set ethernet device offload status
>> +
>> +       �...@param type: Offload type name
>> +       �...@param status: New status will be changed to
>> +        """
>> +        logging.info("Try to set %s %s" % (type, status))
>> +        if status not in ["off", "on"]:
>> +            return False
>> +        cmd = "ethtool -K %s %s %s" % (ethname, type, status)
>> +        if ethtool_get(type) != status:
>> +            return session.get_command_status(cmd) == 0
>> +        if ethtool_get(type) != status:
>> +            logging.error("Fail to set %s %s" % (type, status))
>> +            return False
>> +        return True
>> +
>> +    def ethtool_save_params():
>> +        logging.info("Save ethtool configuration")
>> +        for i in supported_features:
>> +            feature_status[i] = ethtool_get(i)
>> +
>> +    def ethtool_restore_params():
>> +        logging.info("Restore ethtool configuration")
>> +        for i in supported_features:
>> +            ethtool_set(i, feature_status[i])
>> +
>> +    def compare_md5sum(name):
>> +        logging.info("Compare md5sum of the files on guest and host")
>> +        host_result = utils.hash_file(name, method="md5")
>> +        try:
>> +            o = session.get_command_output("md5sum %s" % name)
>> +            guest_result = re.findall("\w+", o)[0]
>> +        except IndexError:
>> +            logging.error("Could not get file md5sum in guest")
>> +            return False
>> +        logging.debug("md5sum: guest(%s), host(%s)" % (guest_result,
>> +                                                   host_result))
>> +        return guest_result == host_result
>> +
>> +    def transfer_file(src="guest"):
>> +        """
>> +        Transfer file by scp, use tcpdump to capture packets, then check the
>> +        return string.
>> +
>> +       �...@param src: Source host of transfer file
>> +       �...@return: Tuple (status, error msg/tcpdump result)
>> +        """
>> +        session2.get_command_status("rm -rf %s" % filename)
>> +

[Qemu-devel] [PATCH] vmstate: fix vmstate_load_state for subsections

2010-08-10 Thread TeLeMan
If one vmstate includes subsections and its last field flag is
VMS_STRUCT, vmstate_load_state will be always failed when the
subsections exist. This fix is not perfect because if the last field
includes subsections too, vmstate_load_state will maybe be failed when
not all of the subsections exist. I think vmstate subsections needs to
be redesigned.

Signed-off-by: TeLeMan 
---
 savevm.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/savevm.c b/savevm.c
index 2082b8c..feca8fa 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1286,9 +1286,11 @@ int vmstate_load_state(QEMUFile *f, const
VMStateDescription *vmsd,
 }
 field++;
 }
-ret = vmstate_subsection_load(f, vmsd, opaque);
-if (ret != 0) {
-return ret;
+if (vmsd->subsections) {
+ret = vmstate_subsection_load(f, vmsd, opaque);
+if (ret != 0) {
+return ret;
+}
 }
 if (vmsd->post_load) {
 return vmsd->post_load(opaque, version_id);
-- 
1.6.5.1.1367.gcd48

--
SUN OF A BEACH



Re: [Autotest] [Qemu-devel] [RFC PATCH 06/14] KVM-test: Add basic file transfer test

2010-08-10 Thread Amos Kong
On Tue, Jul 27, 2010 at 10:36 PM, Lucas Meneghel Rodrigues
 wrote:
> On Tue, 2010-07-20 at 09:35 +0800, Amos Kong wrote:
>> This test is the basic test of transfering file between host and guest. Try 
>> to
>> transfer a large file from host to guest, and transfer it back to host, then
>> compare the files by diff command.
>> The default file size is 4000M, scp timeout is 1000s. It means if the average
>> speed is less than 4M/s, this test will be fail.
>
> ^ About this average 4MB/s throughput, is there some sort of
> agreement/standard I'm not aware of?

Also an 'experimental' standard.
The most important purpose is not check the transfer result, but catch
the bug during file transfer.
If case fail of transfer timeout, we need try to augment the timeout,
and compare the test result.

>> We can extend this test by using another disk later, then we can transfer 
>> larger
>> files without the limit of first disk size.
>>
>> Signed-off-by: Amos Kong 
>> ---
>>  0 files changed, 0 insertions(+), 0 deletions(-)
>>
>> diff --git a/client/tests/kvm/tests/file_transfer.py 
>> b/client/tests/kvm/tests/file_transfer.py
>> new file mode 100644
>> index 000..a20e62e
>> --- /dev/null
>> +++ b/client/tests/kvm/tests/file_transfer.py
>> @@ -0,0 +1,54 @@
>> +import logging, commands
>> +from autotest_lib.client.common_lib import error
>> +import kvm_utils, kvm_test_utils
>> +
>> +def run_file_transfer(test, params, env):
>> +    """
>> +    Test ethrnet device function by ethtool
>> +
>> +    1) Boot up a virtual machine
>> +    2) Create a large file by dd on host
>> +    3) Copy this file from host to guest
>> +    4) Copy this file from guest to host
>> +    5) Check if file transfers good
>> +
>> +   �...@param test: Kvm test object
>> +   �...@param params: Dictionary with the test parameters.
>> +   �...@param env: Dictionary with test environment.
>> +    """
>> +    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
>> +    timeout=int(params.get("login_timeout", 360))
>> +    logging.info("Trying to log into guest '%s' by serial", vm.name)
>> +    session = kvm_utils.wait_for(lambda: vm.serial_login(),
>> +                                 timeout, 0, step=2)
>
> ^ I assume the serial session is being used here to avoid interfering
> with the bandwidth required for the test to complete as little as
> possible, right?

Just want to split the control connection and data connection, if
network is down, some clean work would not be done.
But there is only one serial console session per VM, when we use
serial_login, serial console log would be disabled.

>> +    if not session:
>> +        raise error.TestFail("Could not log into guest '%s'" % vm.name)
>> +
>> +    dir = test.tmpdir
>> +    scp_timeout = int(params.get("scp_timeout"))
>> +    cmd = "dd if=/dev/urandom of=%s/a.out bs=1M count=%d" %  (dir, int(
>> +                                         params.get("filesize", 4000)))
>> +    try:
>> +        logging.info("Create file by dd command on host, cmd: %s" % cmd)
>> +        s, o = commands.getstatusoutput(cmd)
>> +        if s != 0:
>> +            raise error.TestError("Fail to create file, output:%s" % o)
>
> ^ I've seen this throughout the patchseries, the use of functions
> present on commands rather than utils.system, or utils.run. The former
> are preferable on autotest tests, that's important to have in mind.
> Would you consider changing those calls to the autotest API functions?

ok, I will try to use autotest API.

>> +        logging.info("Transfer file from host to guest")
>> +        if not vm.copy_files_to("%s/a.out" % dir, "/tmp/b.out",
>> +                                                        
>> timeout=scp_timeout):
>> +            raise error.TestFail("Fail to transfer file from host to guest")
>> +
>> +        logging.info("Transfer file from guest to host")
>> +        if not vm.copy_files_from("/tmp/b.out", "%s/c.out" % dir,
>> +                                                        
>> timeout=scp_timeout):
>> +            raise error.TestFail("Fail to transfer file from guest to host")
>> +
>> +        logging.debug(commands.getoutput("ls -l %s/[ac].out" % dir))
>> +        s, o = commands.getstatusoutput("diff %s/a.out %s/c.out" % (dir, 
>> dir))
>> +        if s != 0:
>> +            raise error.TestFail("File changed after transfer. Output:%s" % 
>> o)
>
> ^ It seems faster to use md5 or sha1 to verify the integrity of the
> files rather than diff. Unless there's a good reason to use diff, I'd
> like you to change it to one of the programs mentioned above.

I would change it to md5.

>> +    finally:
>> +        session.get_command_status("rm -f /tmp/b.out")
>> +        commands.getoutput("rm -f %s/[ac].out" % dir)
>> +        session.close()
>> diff --git a/client/tests/kvm/tests_base.cfg.sample 
>> b/client/tests/kvm/tests_base.cfg.sample
>> index 7f7b56a..872674e 100644
>> --- a/client/tests/kvm/tests_base.cfg.sample
>> +++ b/client/tests/kvm/tests_base.cfg.sa

[Qemu-devel] [Bug 586175] Re: Windows XP/2003 doesn't boot

2010-08-10 Thread Michael Tokarev
This appears to be fixed in 0.13-tobe by this patch:
http://lists.gnu.org/archive/html/qemu-devel/2010-07/msg00152.html
(hence it's "fix released" in debian which now has 0.13 in experimental).

** Bug watch added: Debian Bug tracker #588739
   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588739

-- 
Windows XP/2003 doesn't boot
https://bugs.launchpad.net/bugs/586175
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Incomplete
Status in “qemu-kvm” package in Ubuntu: New
Status in Debian GNU/Linux: Fix Released
Status in Fedora: Unknown

Bug description:
Hello everyone,

my qemu doesn't boot any Windows XP/2003 installations if I try to boot the 
image.
If I boot the install cd first, it's boot manager counts down and triggers the 
boot on it's own. That's kinda stupid.

I'm using libvirt, but even by a simple
> qemu-kvm -drive file=image.img,media=disk,if=ide,boot=on
it won't boot. Qemu hangs at the message "Booting from Hard Disk..."

I'm using qemu-kvm-0.12.4 with SeaBIOS 0.5.1 on Gentoo (No-Multilib and AMD64). 
It's a server, that means I'm using VNC as the primary graphic output but i 
don't think it should be an issue.





[Qemu-devel] [Bug 586175] Re: Windows XP/2003 doesn't boot

2010-08-10 Thread Michael Tokarev
(and it is also filed agains debian qemu-kvm package, not just qemu --
http://bugs.debian.org/588739 )

-- 
Windows XP/2003 doesn't boot
https://bugs.launchpad.net/bugs/586175
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Incomplete
Status in “qemu-kvm” package in Ubuntu: New
Status in Debian GNU/Linux: Fix Released
Status in Fedora: Unknown

Bug description:
Hello everyone,

my qemu doesn't boot any Windows XP/2003 installations if I try to boot the 
image.
If I boot the install cd first, it's boot manager counts down and triggers the 
boot on it's own. That's kinda stupid.

I'm using libvirt, but even by a simple
> qemu-kvm -drive file=image.img,media=disk,if=ide,boot=on
it won't boot. Qemu hangs at the message "Booting from Hard Disk..."

I'm using qemu-kvm-0.12.4 with SeaBIOS 0.5.1 on Gentoo (No-Multilib and AMD64). 
It's a server, that means I'm using VNC as the primary graphic output but i 
don't think it should be an issue.





Re: [Qemu-devel] about qemu

2010-08-10 Thread Mulyadi Santosa
On Tue, Aug 10, 2010 at 12:17, chandra shekar
 wrote:
> can any one suggest any study materials for start learning  qemu and its
> internals
> i have already read the documentation in this qemu web page other than that
> any
> other materials,thanks
>

I am afraid, the other thing left to try is just read the code and
explore them. Running qemu under gdb (i mean qemu itself) might
help...

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com



[Qemu-devel] [PATCH 0/2] [PULL] qemu-kvm.git uq/master queue

2010-08-10 Thread Marcelo Tosatti
The following changes since commit 748a4ee311b8353292e85851034cb917906aac14:
  Blue Swirl (1):
sparc32: use FW_CFG_CMDLINE_SIZE

are available in the git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Alex Williamson (1):
  kvm: Don't walk memory_size == 0 slots in kvm_client_migration_log

Gleb Natapov (1):
  kvm: remove guest triggerable abort()

 kvm-all.c |   19 +++
 1 files changed, 7 insertions(+), 12 deletions(-)



[Qemu-devel] [PATCH 1/2] kvm: Don't walk memory_size == 0 slots in kvm_client_migration_log

2010-08-10 Thread Marcelo Tosatti
From: Alex Williamson 

If we've unregistered a memory area, we should avoid calling
qemu_get_ram_ptr() on the left over phys_offset cruft in the
slot array.  Now that we support removing ramblocks, the
phys_offset ram_addr_t can go away and cause a lookup fault
and abort.

Signed-off-by: Alex Williamson 
Signed-off-by: Marcelo Tosatti 
---
 kvm-all.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 7635f2f..736c516 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -274,6 +274,9 @@ static int kvm_set_migration_log(int enable)
 for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
 mem = &s->slots[i];
 
+if (!mem->memory_size) {
+continue;
+}
 if (!!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) == enable) {
 continue;
 }
-- 
1.6.6.1




[Qemu-devel] [PATCH 2/2] kvm: remove guest triggerable abort()

2010-08-10 Thread Marcelo Tosatti
From: Gleb Natapov 

This abort() condition is easily triggerable by a guest if it configures
pci bar with unaligned address that overlaps main memory.

Signed-off-by: Gleb Natapov 
Signed-off-by: Marcelo Tosatti 
---
 kvm-all.c |   16 
 1 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 736c516..85f2e58 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -432,18 +432,10 @@ static void kvm_set_phys_mem(target_phys_addr_t 
start_addr,
 KVMSlot *mem, old;
 int err;
 
-if (start_addr & ~TARGET_PAGE_MASK) {
-if (flags >= IO_MEM_UNASSIGNED) {
-if (!kvm_lookup_overlapping_slot(s, start_addr,
- start_addr + size)) {
-return;
-}
-fprintf(stderr, "Unaligned split of a KVM memory slot\n");
-} else {
-fprintf(stderr, "Only page-aligned memory slots supported\n");
-}
-abort();
-}
+/* kvm works in page size chunks, but the function may be called
+   with sub-page size and unaligned start address. */
+size = TARGET_PAGE_ALIGN(size);
+start_addr = TARGET_PAGE_ALIGN(start_addr);
 
 /* KVM does not support read-only slots */
 phys_offset &= ~IO_MEM_ROM;
-- 
1.6.6.1




Re: [Qemu-devel] [PATCH 00/12 v4] Clean up linux-user/elfload.c

2010-08-10 Thread Richard Henderson
On 08/09/2010 09:52 AM, Jan-Simon Möller wrote:
>> A re-based and re-tested version of a patch series I
>> posted back in April and May.  These cleanups prepare
>> elfload.c for loading the VDSO for x86_64.
> 
> Do you have a repo where i could pull these from ?

Which, the vdso loading bits?

  git://repo.or.cz/qemu/rth.git elfload-vdso

I still haven't worked out how to fix the makefile, and
there's still the question of how to load the vdso from
the build tree (as opposed to the install tree).


r~



Re: [Qemu-devel] [PATCH v8 1/5] Add qemu_ram_alloc_from_ptr function

2010-08-10 Thread Anthony Liguori

On 07/26/2010 07:10 PM, Cam Macdonell wrote:

Provide a function to add an allocated region of memory to the qemu RAM.

This patch is copied from Marcelo's qemu_ram_map() in qemu-kvm and given the
clearer name qemu_ram_alloc_from_ptr().

Signed-off-by: Cam Macdonell
   


Applied all.  Thanks.

Regards,

Anthony Liguori


---
  cpu-common.h |2 ++
  exec.c   |   43 +++
  2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/cpu-common.h b/cpu-common.h
index 71e7933..0426bc8 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -40,6 +40,8 @@ static inline void 
cpu_register_physical_memory(target_phys_addr_t start_addr,
  }

  ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
+ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
+ram_addr_t size, void *host);
  ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t 
size);
  void qemu_ram_free(ram_addr_t addr);
  /* This should only be used for ram local to a device.  */
diff --git a/exec.c b/exec.c
index 868cd7f..8636316 100644
--- a/exec.c
+++ b/exec.c
@@ -2808,6 +2808,49 @@ static ram_addr_t last_ram_offset(void)
  return last;
  }

+ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
+ram_addr_t size, void *host)
+{
+RAMBlock *new_block, *block;
+
+size = TARGET_PAGE_ALIGN(size);
+new_block = qemu_mallocz(sizeof(*new_block));
+
+if (dev&&  dev->parent_bus&&  dev->parent_bus->info->get_dev_path) {
+char *id = dev->parent_bus->info->get_dev_path(dev);
+if (id) {
+snprintf(new_block->idstr, sizeof(new_block->idstr), "%s/", id);
+qemu_free(id);
+}
+}
+pstrcat(new_block->idstr, sizeof(new_block->idstr), name);
+
+QLIST_FOREACH(block,&ram_list.blocks, next) {
+if (!strcmp(block->idstr, new_block->idstr)) {
+fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n",
+new_block->idstr);
+abort();
+}
+}
+
+new_block->host = host;
+
+new_block->offset = find_ram_offset(size);
+new_block->length = size;
+
+QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
+
+ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty,
+   last_ram_offset()>>  TARGET_PAGE_BITS);
+memset(ram_list.phys_dirty + (new_block->offset>>  TARGET_PAGE_BITS),
+   0xff, size>>  TARGET_PAGE_BITS);
+
+if (kvm_enabled())
+kvm_setup_guest_memory(new_block->host, size);
+
+return new_block->offset;
+}
+
  ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size)
  {
  RAMBlock *new_block, *block;
   





[Qemu-devel] Re: [Autotest] [RFC PATCH 08/14] KVM-test: Add a subtest of nic promisc

2010-08-10 Thread Amos Kong
On Thu, Jul 29, 2010 at 5:35 AM, Lucas Meneghel Rodrigues
 wrote:
> On Tue, 2010-07-20 at 09:35 +0800, Amos Kong wrote:
>> This test mainly covers TCP sent from host to guest and from guest to host
>> with repeatedly turn on/off NIC promiscuous mode.
>>
>> Signed-off-by: Amos Kong 
>> ---
>>  0 files changed, 0 insertions(+), 0 deletions(-)
>>
>> diff --git a/client/tests/kvm/tests/nic_promisc.py 
>> b/client/tests/kvm/tests/nic_promisc.py
>> new file mode 100644
>> index 000..9a0c979
>> --- /dev/null
>> +++ b/client/tests/kvm/tests/nic_promisc.py
>> @@ -0,0 +1,87 @@
>> +import logging, commands
>> +from autotest_lib.client.common_lib import error
>> +import kvm_utils, kvm_test_utils, kvm_net_utils
>> +
>> +def run_nic_promisc(test, params, env):
>> +    """
>> +    Test nic driver in promisc mode:
>> +
>> +    1) Boot up a guest
>> +    2) Repeatedly enable/disable promiscuous mode in guest
>> +    3) TCP data transmission from host to guest, and from guest to host,
>> +       with 1/1460/65000/1 bytes payloads
>> +    4) Clean temporary files
>> +    5) Stop enable/disable promiscuous mode change
>> +
>> +   �...@param test: kvm test object
>> +   �...@param params: Dictionary with the test parameters
>> +   �...@param env: Dictionary with test environment
>> +    """
>> +    timeout = int(params.get("login_timeout", 360))
>> +    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
>> +    session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
>> +    logging.info("Trying to log into guest '%s' by serial", vm.name)
>> +    session2 = kvm_utils.wait_for(lambda: vm.serial_login(),
>> +                                  timeout, 0, step=2)
>> +    if not session2:
>> +        raise error.TestFail("Could not log into guest '%s'" % vm.name)
>> +
>> +    def compare(filename):
>> +        cmd = "md5sum %s" % filename
>> +        s1, ret_host = commands.getstatusoutput(cmd)
>> +        s2, ret_guest = session.get_command_status_output(cmd)
>> +        if s1 != 0 or s2 != 0:
>> +            logging.debug("ret_host:%s, ret_guest:%s" % (ret_host, 
>> ret_guest))
>> +            logging.error("Could not get md5, cmd:%s" % cmd)
>> +            return False
>> +        if ret_host.strip() != ret_guest.strip():
>> +            logging.debug("ret_host :%s, ret_guest:%s" % (ret_host, 
>> ret_guest))
>> +            logging.error("Files' md5sum mismatch" % (receiver))
>> +            return False
>
> ^ The above debug messages will be confusing when looked by someone who
> is not familiar with the test code, so we should make their lives
> easier:
>
>    def compare(filename):
>        cmd = "md5sum %s" % filename
>        rc_host, md5_host = commands.getstatusoutput(cmd)
>        rc_guest, md5_guest = session.get_command_status_output(cmd)
>        if rc_host:
>            logging.debug('Could not get MD5 hash for file %s on host, output: 
> %s', filename, md5_host)
>            return False
>        if rc_guest:
>            logging.debug('Could not get MD5 hash for file %s on guest, 
> output: %s', filename, md5_guest)
>            return False
>        md5host = md5host.strip()
>        md5guest = md5guest.strip()
>        if md5host != md5guest:
>            logging.error('MD5 hash mismatch between file %s present on guest 
> and on host', filename)
>            logging.error('MD5 hash for file on guest: %s, MD5 hash for file 
> on host: %s', md5_host, md5_guest)
>            return False
>        return True
>
>
>> +        return True
>> +
>> +    ethname = kvm_net_utils.get_linux_ifname(session, vm.get_macaddr(0))
>> +    set_promisc_cmd = "ip link set %s promisc on; sleep 0.01;" % ethname
>> +    set_promisc_cmd += "ip link set %s promisc off; sleep 0.01" % ethname
>
> ^ You could do the above on a single attribution, see comment on patch 7
> of the patchseries.
>
>> +    logging.info("Set promisc change repeatedly in guest")
>> +    session2.sendline("while true; do %s; done" % set_promisc_cmd)
>> +
>> +    dd_cmd = "dd if=/dev/urandom of=%s bs=%d count=1"
>> +    filename = "/tmp/nic_promisc_file"
>> +    file_size = params.get("file_size", "1, 1460, 65000, 
>> 1").split(",")
>> +    try:
>> +        for size in file_size:
>> +            logging.info("Create %s bytes file on host" % size)
>> +            s, o = commands.getstatusoutput(dd_cmd % (filename, int(size)))
>> +            if s != 0:
>> +                logging.debug("Output: %s"% o)
>> +                raise error.TestFail("Create file on host failed")
>> +
>> +            logging.info("Transfer file from host to guest")
>> +            if not vm.copy_files_to(filename, filename):
>> +                raise error.TestFail("File transfer failed")
>> +            if not compare(filename):
>> +                raise error.TestFail("Compare file failed")
>
> ^ It'd be better if we don't abruptly fail the whole test if we get a
> failure for a single size, what about having a global failure counter,
> and increment it if

[Qemu-devel] [qemu-kvm] build fail on i386 RHEL5u4

2010-08-10 Thread Hao, Xudong
Hi, 
Recently I build qemu-kvm on 32bit RHEL5u4/RHEL5u5, it will fail on fuction 
"vhost_dev_sync_region". But RHEL5u1 system is fine to build.
Did anyone meet similar issue?

qemu-kvm commit: 59d71ddb432db04b57ee2658ce50a3e35d7db97e

build error:
...
  CCx86_64-softmmu/i8254.o
  CCx86_64-softmmu/i8254-kvm.o
  CCx86_64-softmmu/device-assignment.o
  LINK  x86_64-softmmu/qemu-system-x86_64
vhost.o: In function `vhost_dev_sync_region':
/home/source/qemu-kvm/hw/vhost.c:47: undefined reference to 
`__sync_fetch_and_and_4'
collect2: ld returned 1 exit status
make[1]: *** [qemu-system-x86_64] Error 1
make: *** [subdir-x86_64-softmmu] Error 2


Best Regards,
Xudong Hao



[Qemu-devel] [PATCH 01/15] vnc: don't set the quality if lossy encoding are disabled

2010-08-10 Thread Corentin Chary
This should not change the current behavior, but if any new
encoding try to use the tight quality, it will always be set
to -1 when lossy encodings are disabled.

Signed-off-by: Corentin Chary 
---
 ui/vnc.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 7fc40ac..3086d95 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1776,7 +1776,9 @@ static void set_encodings(VncState *vs, int32_t 
*encodings, size_t n_encodings)
 vs->tight.compression = (enc & 0x0F);
 break;
 case VNC_ENCODING_QUALITYLEVEL0 ... VNC_ENCODING_QUALITYLEVEL0 + 9:
-vs->tight.quality = (enc & 0x0F);
+if (vs->vd->lossy) {
+vs->tight.quality = (enc & 0x0F);
+}
 break;
 default:
 VNC_DEBUG("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc);
-- 
1.7.1




[Qemu-devel] [PATCH 02/15] vnc: add a way to get the update frequency for a given region

2010-08-10 Thread Corentin Chary
This patch compute the update frequency (in Hz) for each 64x64 rects.
Any adaptive encoding can get this value using vnc_update_freq(), and
switch to a lossy encoding if the value is too high.

The frequency is pre-calculated every 500ms, based on the last 10
updates per 64x64 rect.

If a 64x64 rect was not updated in the last 2 second, then the frequency
became 0, and all the stored timestamp are reseted.

Signed-off-by: Corentin Chary 
---
 ui/vnc.c |  101 ++
 ui/vnc.h |   19 +++
 2 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 3086d95..5c3a760 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -35,6 +35,8 @@
 #define VNC_REFRESH_INTERVAL_BASE 30
 #define VNC_REFRESH_INTERVAL_INC  50
 #define VNC_REFRESH_INTERVAL_MAX  2000
+static const struct timeval VNC_REFRESH_STATS = { 0, 50 };
+static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 };
 
 #include "vnc_keysym.h"
 #include "d3des.h"
@@ -2253,6 +2255,99 @@ static int protocol_version(VncState *vs, uint8_t 
*version, size_t len)
 return 0;
 }
 
+static VncRectStat *vnc_stat_rect(VncDisplay *vd, int x, int y)
+{
+struct VncSurface *vs = &vd->guest;
+
+return &vs->stats[y / VNC_STAT_RECT][x / VNC_STAT_RECT];
+}
+
+static void vnc_update_stats(VncDisplay *vd,  struct timeval * tv)
+{
+int x, y;
+struct timeval res;
+
+for (y = 0; y < vd->guest.ds->height; y += VNC_STAT_RECT) {
+for (x = 0; x < vd->guest.ds->width; x += VNC_STAT_RECT) {
+VncRectStat *rect = vnc_stat_rect(vd, x, y);
+
+rect->updated = false;
+}
+}
+
+timersub(tv, &VNC_REFRESH_STATS, &res);
+
+if (timercmp(&vd->guest.last_freq_check, &res, >)) {
+return ;
+}
+vd->guest.last_freq_check = *tv;
+
+for (y = 0; y < vd->guest.ds->height; y += VNC_STAT_RECT) {
+for (x = 0; x < vd->guest.ds->width; x += VNC_STAT_RECT) {
+VncRectStat *rect= vnc_stat_rect(vd, x, y);
+int count = ARRAY_SIZE(rect->times);
+struct timeval min, max;
+
+if (!timerisset(&rect->times[count - 1])) {
+continue ;
+}
+
+max = rect->times[(rect->idx + count - 1) % count];
+timersub(tv, &max, &res);
+
+if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {
+rect->freq = 0;
+memset(rect->times, 0, sizeof (rect->times));
+continue ;
+}
+
+min = rect->times[rect->idx];
+max = rect->times[(rect->idx + count - 1) % count];
+timersub(&max, &min, &res);
+
+rect->freq = res.tv_sec + res.tv_usec / 100.;
+rect->freq /= count;
+rect->freq = 1. / rect->freq;
+}
+}
+}
+
+double vnc_update_freq(VncState *vs, int x, int y, int w, int h)
+{
+int i, j;
+double total = 0;
+int num = 0;
+
+x =  (x / VNC_STAT_RECT) * VNC_STAT_RECT;
+y =  (y / VNC_STAT_RECT) * VNC_STAT_RECT;
+
+for (j = y; j <= y + h; j += VNC_STAT_RECT) {
+for (i = x; i <= x + w; i += VNC_STAT_RECT) {
+total += vnc_stat_rect(vs->vd, i, j)->freq;
+num++;
+}
+}
+
+if (num) {
+return total / num;
+} else {
+return 0;
+}
+}
+
+static void vnc_rect_updated(VncDisplay *vd, int x, int y, struct timeval * tv)
+{
+VncRectStat *rect;
+
+rect = vnc_stat_rect(vd, x, y);
+if (rect->updated) {
+return ;
+}
+rect->times[rect->idx] = *tv;
+rect->idx = (rect->idx + 1) % ARRAY_SIZE(rect->times);
+rect->updated = true;
+}
+
 static int vnc_refresh_server_surface(VncDisplay *vd)
 {
 int y;
@@ -2263,6 +2358,11 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
 VncState *vs;
 int has_dirty = 0;
 
+struct timeval tv;
+
+gettimeofday(&tv, NULL);
+vnc_update_stats(vd, &tv);
+
 /*
  * Walk through the guest dirty map.
  * Check and copy modified bits from guest to server surface.
@@ -2289,6 +2389,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
 if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
 continue;
 memcpy(server_ptr, guest_ptr, cmp_bytes);
+vnc_rect_updated(vd, x, y, &tv);
 QTAILQ_FOREACH(vs, &vd->clients, next) {
 vnc_set_bit(vs->dirty[y], (x / 16));
 }
diff --git a/ui/vnc.h b/ui/vnc.h
index 9619b24..f10fa3c 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -80,6 +80,10 @@ typedef void VncSendHextileTile(VncState *vs,
 #define VNC_MAX_HEIGHT 2048
 #define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32))
 
+#define VNC_STAT_RECT  64
+#define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
+#define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
+
 #define VNC_AUTH_CHALLENGE_SIZE 16
 
 typedef struct VncDisplay VncDisplay;
@@ -92,9 +96,23 @@ typedef struct VncDisplay VncD

[Qemu-devel] [PATCH 00/15] vnc: adapative tight, zrle, zywrle, and bitmap module

2010-08-10 Thread Corentin Chary
Hi,

In this series you'll find:
 - Adaptive Tight Encoding: send lossy or lossless updates depending on the
 update frequency of the screen region. If a lossy update is forced, then
 it will be refreshed with a lossless update as soon as the update frequency
 goes back to 0.

 - ZRLE/ZYWRLE Encodings: ZYWRLE use less bandwidth than tight, but the result
 is also probably more lossy. I wanted to make ZRLE/ZYWRLE adaptive, but this
 is not possible because most of the vnc clients can't switch between ZRLE and
 ZYWRLE. But a possible solution is to use another encoding for lossless 
updates,
 like zlib or tight.

 - Bitmap module: create bitmap.h and bitops.h, and remove duplicate code
 from vnc.c

This is probably my last series in the GSoC 2010 context, but I'll probably
continue to work on the VNC server for some time :).

Thanks,

Corentin Chary (15):
  vnc: don't set the quality if lossy encoding are disabled
  vnc: add a way to get the update frequency for a given region
  vnc: refresh lossy rect after a given timeout
  vnc: tight: use the update frequency to choose between lossy and
lossless
  vnc: palette: use a pool to reduce memory allocations
  vnc: palette: add palette_init calls
  vnc: palette: and fill and color calls.
  vnc: Add ZRLE and ZYWRLE encodings.
  vnc: fix uint8_t comparisons with negative values
  vnc: fix lossy rect refreshing
  bitmap: add a generic bitmap and bitops library
  vnc: use the new generic bitmap functions
  vnc: don't try to send bigger updates that client height
  vnc: tight: tweak adaptive tight settings
  vnc: add a non-adaptive option

 Makefile.objs|2 +
 bitmap.c |  255 
 bitmap.h |  222 ++
 bitops.c |  142 +
 bitops.h |  272 ++
 osdep.h  |4 +
 qemu-options.hx  |9 +
 qemu-thread.c|1 +
 ui/vnc-enc-tight.c   |   75 -
 ui/vnc-enc-zrle-template.c   |  275 ++
 ui/vnc-enc-zrle.c|  390 +
 ui/vnc-enc-zrle.h|   40 +++
 ui/vnc-enc-zywrle-template.c |  170 +++
 ui/vnc-enc-zywrle.h  |  652 ++
 ui/vnc-jobs-async.c  |4 +
 ui/vnc-palette.c |   59 +++--
 ui/vnc-palette.h |7 +-
 ui/vnc.c |  283 ++-
 ui/vnc.h |   57 -
 19 files changed, 2811 insertions(+), 108 deletions(-)
 create mode 100644 bitmap.c
 create mode 100644 bitmap.h
 create mode 100644 bitops.c
 create mode 100644 bitops.h
 create mode 100644 ui/vnc-enc-zrle-template.c
 create mode 100644 ui/vnc-enc-zrle.c
 create mode 100644 ui/vnc-enc-zrle.h
 create mode 100644 ui/vnc-enc-zywrle-template.c
 create mode 100644 ui/vnc-enc-zywrle.h




[Qemu-devel] [PATCH 04/15] vnc: tight: use the update frequency to choose between lossy and lossless

2010-08-10 Thread Corentin Chary
Use the new update frequency infrastructure to use jpeg for regions with
high update frequency.

Signed-off-by: Corentin Chary 
---
 ui/vnc-enc-tight.c |   75 +++-
 1 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index 8ca5570..5ca4342 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -72,6 +72,26 @@ static const struct {
 static int tight_send_framebuffer_update(VncState *vs, int x, int y,
  int w, int h);
 
+#ifdef CONFIG_VNC_JPEG
+static const struct {
+double jpeg_freq_min;   /* Don't send JPEG if the freq is bellow */
+double jpeg_freq_threshold; /* Always send JPEG if the freq is above */
+int jpeg_idx;   /* Allow indexed JPEG */
+int jpeg_full;  /* Allow full color JPEG */
+} tight_jpeg_conf[] = {
+{ 0,   4,  1, 1 },
+{ 0,   4,  1, 1 },
+{ 0,   4,  1, 1 },
+{ 0,   4,  1, 1 },
+{ 0,   4,  0, 1 },
+{ 0.1, 4,  0, 1 },
+{ 0.2, 4,  0, 1 },
+{ 0.3, 6,  0, 0 },
+{ 0.4, 8,  0, 0 },
+{ 0.5, 10, 0, 0 },
+};
+#endif
+
 #ifdef CONFIG_VNC_PNG
 static const struct {
 int png_zlib_level, png_filters;
@@ -1478,12 +1498,13 @@ static int send_sub_rect_nojpeg(VncState *vs, int x, 
int y, int w, int h,
 #ifdef CONFIG_VNC_JPEG
 static int send_sub_rect_jpeg(VncState *vs, int x, int y, int w, int h,
   int bg, int fg, int colors,
-  VncPalette *palette)
+  VncPalette *palette, bool force)
 {
 int ret;
 
 if (colors == 0) {
-if (tight_detect_smooth_image(vs, w, h)) {
+if (force || (tight_jpeg_conf[vs->tight.quality].jpeg_full &&
+  tight_detect_smooth_image(vs, w, h))) {
 int quality = tight_conf[vs->tight.quality].jpeg_quality;
 
 ret = send_jpeg_rect(vs, x, y, w, h, quality);
@@ -1495,8 +1516,9 @@ static int send_sub_rect_jpeg(VncState *vs, int x, int y, 
int w, int h,
 } else if (colors == 2) {
 ret = send_mono_rect(vs, x, y, w, h, bg, fg);
 } else if (colors <= 256) {
-if (colors > 96 &&
-tight_detect_smooth_image(vs, w, h)) {
+if (force || (colors > 96 &&
+  tight_jpeg_conf[vs->tight.quality].jpeg_idx &&
+  tight_detect_smooth_image(vs, w, h))) {
 int quality = tight_conf[vs->tight.quality].jpeg_quality;
 
 ret = send_jpeg_rect(vs, x, y, w, h, quality);
@@ -1514,6 +1536,8 @@ static int send_sub_rect(VncState *vs, int x, int y, int 
w, int h)
 uint32_t bg = 0, fg = 0;
 int colors;
 int ret = 0;
+bool force_jpeg = false;
+bool allow_jpeg = true;
 
 vnc_framebuffer_update(vs, x, y, w, h, vs->tight.type);
 
@@ -1521,11 +1545,26 @@ static int send_sub_rect(VncState *vs, int x, int y, 
int w, int h)
 vnc_raw_send_framebuffer_update(vs, x, y, w, h);
 vnc_tight_stop(vs);
 
+#ifdef CONFIG_VNC_JPEG
+if (vs->tight.quality != -1) {
+double freq = vnc_update_freq(vs, x, y, w, h);
+
+if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) {
+allow_jpeg = false;
+}
+if (freq >= tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold) {
+force_jpeg = true;
+vnc_sent_lossy_rect(vs, x, y, w, h);
+}
+}
+#endif
+
 colors = tight_fill_palette(vs, x, y, w * h, &fg, &bg, &palette);
 
 #ifdef CONFIG_VNC_JPEG
-if (vs->tight.quality != -1) {
-ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette);
+if (allow_jpeg && vs->tight.quality != -1) {
+ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette,
+ force_jpeg);
 } else {
 ret = send_sub_rect_nojpeg(vs, x, y, w, h, bg, fg, colors, palette);
 }
@@ -1548,7 +1587,8 @@ static int send_sub_rect_solid(VncState *vs, int x, int 
y, int w, int h)
 return send_solid_rect(vs);
 }
 
-static int send_rect_simple(VncState *vs, int x, int y, int w, int h)
+static int send_rect_simple(VncState *vs, int x, int y, int w, int h,
+bool split)
 {
 int max_size, max_width;
 int max_sub_width, max_sub_height;
@@ -1559,7 +1599,7 @@ static int send_rect_simple(VncState *vs, int x, int y, 
int w, int h)
 max_size = tight_conf[vs->tight.compression].max_rect_size;
 max_width = tight_conf[vs->tight.compression].max_rect_width;
 
-if (w > max_width || w * h > max_size) {
+if (split && (w > max_width || w * h > max_size)) {
 max_sub_width = (w > max_width) ? max_width : w;
 max_sub_height = max_size / max_sub_width;
 
@@ -1590,7 +1630,7 @@ static int find_large_solid_color_rect(VncState *vs, int 
x, int y,
 /* If a rectangle becomes too large, send its upper part now. */
 
 if (dy - y >= max_rows) {
-n += send_rect_s

[Qemu-devel] [PATCH 05/15] vnc: palette: use a pool to reduce memory allocations

2010-08-10 Thread Corentin Chary
We now that the palette will never have more than 256
elements. Let's use a pool to reduce malloc calls.

Signed-off-by: Corentin Chary 
---
 ui/vnc-palette.c |   18 ++
 ui/vnc-palette.h |3 ++-
 2 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index bff6445..c47420b 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -63,23 +63,9 @@ VncPalette *palette_new(size_t max, int bpp)
 
 void palette_destroy(VncPalette *palette)
 {
-int i;
-
 if (palette == NULL) {
-return ;
+qemu_free(palette);
 }
-
-for (i = 0; i < VNC_PALETTE_HASH_SIZE; i++) {
-VncPaletteEntry *entry = QLIST_FIRST(&palette->table[i]);
-while (entry) {
-VncPaletteEntry *tmp = QLIST_NEXT(entry, next);
-QLIST_REMOVE(entry, next);
-qemu_free(entry);
-entry = tmp;
-}
-}
-
-qemu_free(palette);
 }
 
 int palette_put(VncPalette *palette, uint32_t color)
@@ -97,7 +83,7 @@ int palette_put(VncPalette *palette, uint32_t color)
 if (!entry) {
 VncPaletteEntry *entry;
 
-entry = qemu_mallocz(sizeof(*entry));
+entry = &palette->pool[palette->size];
 entry->color = color;
 entry->idx = idx;
 QLIST_INSERT_HEAD(&palette->table[hash], entry, next);
diff --git a/ui/vnc-palette.h b/ui/vnc-palette.h
index d0645eb..f57d0e7 100644
--- a/ui/vnc-palette.h
+++ b/ui/vnc-palette.h
@@ -34,6 +34,7 @@
 #include 
 
 #define VNC_PALETTE_HASH_SIZE 256
+#define VNC_PALETTE_MAX_SIZE  256
 
 typedef struct VncPaletteEntry {
 int idx;
@@ -42,7 +43,7 @@ typedef struct VncPaletteEntry {
 } VncPaletteEntry;
 
 typedef struct VncPalette {
-QObject_HEAD;
+VncPaletteEntry pool[VNC_PALETTE_MAX_SIZE];
 size_t size;
 size_t max;
 int bpp;
-- 
1.7.1




[Qemu-devel] [PATCH 06/15] vnc: palette: add palette_init calls

2010-08-10 Thread Corentin Chary
This allow to use palette on the stack instead of always
allocating them.

Signed-off-by: Corentin Chary 
---
 ui/vnc-palette.c |8 +++-
 ui/vnc-palette.h |1 +
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index c47420b..f93250b 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -56,9 +56,15 @@ VncPalette *palette_new(size_t max, int bpp)
 VncPalette *palette;
 
 palette = qemu_mallocz(sizeof(*palette));
+palette_init(palette, max, bpp);
+return palette;
+}
+
+void palette_init(VncPalette *palette, size_t max, int bpp)
+{
+memset(palette, 0, sizeof (*palette));
 palette->max = max;
 palette->bpp = bpp;
-return palette;
 }
 
 void palette_destroy(VncPalette *palette)
diff --git a/ui/vnc-palette.h b/ui/vnc-palette.h
index f57d0e7..c646e4d 100644
--- a/ui/vnc-palette.h
+++ b/ui/vnc-palette.h
@@ -51,6 +51,7 @@ typedef struct VncPalette {
 } VncPalette;
 
 VncPalette *palette_new(size_t max, int bpp);
+void palette_init(VncPalette *palette, size_t max, int bpp);
 void palette_destroy(VncPalette *palette);
 
 int palette_put(VncPalette *palette, uint32_t color);
-- 
1.7.1




[Qemu-devel] [PATCH 03/15] vnc: refresh lossy rect after a given timeout

2010-08-10 Thread Corentin Chary
If an adaptive encoding has choosen to send a lossy update
based on the result of vnc_update_freq(), then it should advertise
it with vnc_sent_lossy_rect(). This will allow to automatically refresh
this rect once it's static again.

Signed-off-by: Corentin Chary 
---
 ui/vnc-jobs-async.c |2 +
 ui/vnc.c|   67 +++---
 ui/vnc.h|3 ++
 3 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c
index 6e9cf08..31f8436 100644
--- a/ui/vnc-jobs-async.c
+++ b/ui/vnc-jobs-async.c
@@ -166,6 +166,7 @@ static void vnc_async_encoding_start(VncState *orig, 
VncState *local)
 local->features = orig->features;
 local->ds = orig->ds;
 local->vd = orig->vd;
+local->lossy_rect = orig->lossy_rect;
 local->write_pixels = orig->write_pixels;
 local->clientds = orig->clientds;
 local->tight = orig->tight;
@@ -182,6 +183,7 @@ static void vnc_async_encoding_end(VncState *orig, VncState 
*local)
 orig->tight = local->tight;
 orig->zlib = local->zlib;
 orig->hextile = local->hextile;
+orig->lossy_rect = local->lossy_rect;
 }
 
 static int vnc_worker_thread_loop(VncJobQueue *queue)
diff --git a/ui/vnc.c b/ui/vnc.c
index 5c3a760..f7a43e5 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1010,6 +1010,8 @@ static void vnc_disconnect_start(VncState *vs)
 
 static void vnc_disconnect_finish(VncState *vs)
 {
+int i;
+
 vnc_jobs_join(vs); /* Wait encoding jobs */
 
 vnc_lock_output(vs);
@@ -1046,7 +1048,11 @@ static void vnc_disconnect_finish(VncState *vs)
 #ifdef CONFIG_VNC_THREAD
 qemu_mutex_destroy(&vs->output_mutex);
 #endif
-qemu_free(vs);
+for (i = 0; i < VNC_STAT_ROWS; ++i) {
+qemu_free(vs->lossy_rect[i]);
+}
+qemu_free(vs->lossy_rect);
+   qemu_free(vs);
 }
 
 int vnc_client_io_error(VncState *vs, int ret, int last_errno)
@@ -2262,10 +2268,55 @@ static VncRectStat *vnc_stat_rect(VncDisplay *vd, int 
x, int y)
 return &vs->stats[y / VNC_STAT_RECT][x / VNC_STAT_RECT];
 }
 
-static void vnc_update_stats(VncDisplay *vd,  struct timeval * tv)
+void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h)
+{
+int i, j;
+
+w = (x + w) / VNC_STAT_RECT;
+h = (y + h) / VNC_STAT_RECT;
+x /= VNC_STAT_RECT;
+y /= VNC_STAT_RECT;
+
+for (j = y; j <= y + h; j++) {
+for (i = x; i <= x + w; i++) {
+vs->lossy_rect[j][i] = 1;
+}
+}
+}
+
+static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y)
+{
+VncState *vs;
+int sty = y / VNC_STAT_RECT;
+int stx = x / VNC_STAT_RECT;
+int has_dirty = 0;
+
+y = y / VNC_STAT_RECT * VNC_STAT_RECT;
+x = x / VNC_STAT_RECT * VNC_STAT_RECT;
+
+QTAILQ_FOREACH(vs, &vd->clients, next) {
+int j ;
+
+/* kernel send buffers are full -> refresh later */
+if (vs->output.offset)
+continue ;
+
+if (!vs->lossy_rect[sty][stx])
+continue ;
+vs->lossy_rect[sty][stx] = 0;
+for (j = 0; j < VNC_STAT_RECT; ++j) {
+vnc_set_bits(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16);
+}
+has_dirty++;
+}
+return has_dirty;
+}
+
+static int vnc_update_stats(VncDisplay *vd,  struct timeval * tv)
 {
 int x, y;
 struct timeval res;
+int has_dirty = 0;
 
 for (y = 0; y < vd->guest.ds->height; y += VNC_STAT_RECT) {
 for (x = 0; x < vd->guest.ds->width; x += VNC_STAT_RECT) {
@@ -2278,7 +2329,7 @@ static void vnc_update_stats(VncDisplay *vd,  struct 
timeval * tv)
 timersub(tv, &VNC_REFRESH_STATS, &res);
 
 if (timercmp(&vd->guest.last_freq_check, &res, >)) {
-return ;
+return has_dirty;
 }
 vd->guest.last_freq_check = *tv;
 
@@ -2297,6 +2348,7 @@ static void vnc_update_stats(VncDisplay *vd,  struct 
timeval * tv)
 
 if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {
 rect->freq = 0;
+has_dirty += vnc_refresh_lossy_rect(vd, x, y);
 memset(rect->times, 0, sizeof (rect->times));
 continue ;
 }
@@ -2310,6 +2362,7 @@ static void vnc_update_stats(VncDisplay *vd,  struct 
timeval * tv)
 rect->freq = 1. / rect->freq;
 }
 }
+return has_dirty;
 }
 
 double vnc_update_freq(VncState *vs, int x, int y, int w, int h)
@@ -2361,7 +2414,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
 struct timeval tv;
 
 gettimeofday(&tv, NULL);
-vnc_update_stats(vd, &tv);
+has_dirty = vnc_update_stats(vd, &tv);
 
 /*
  * Walk through the guest dirty map.
@@ -2463,7 +2516,13 @@ static void vnc_remove_timer(VncDisplay *vd)
 static void vnc_connect(VncDisplay *vd, int csock)
 {
 VncState *vs = qemu_mallocz(sizeof(VncState));
+int i;
+
 vs->csock = csock;
+vs->lossy_rect = qemu_mallocz(VNC_STAT_ROWS * sizeof (*vs->lossy_rect));
+for (i = 0; i < VNC_STAT_ROWS; ++i) {
+vs->l

[Qemu-devel] [PATCH 07/15] vnc: palette: and fill and color calls.

2010-08-10 Thread Corentin Chary
These two helpers are needed for zrle and zywrle.

Signed-off-by: Corentin Chary 
---
 ui/vnc-palette.c |   33 +
 ui/vnc-palette.h |3 +++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index f93250b..d691a0c 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -126,3 +126,36 @@ void palette_iter(const VncPalette *palette,
 }
 }
 }
+
+uint32_t palette_color(const VncPalette *palette, int idx, bool *found)
+{
+int i;
+VncPaletteEntry *entry;
+
+for (i = 0; i < VNC_PALETTE_HASH_SIZE; i++) {
+QLIST_FOREACH(entry, &palette->table[i], next) {
+if (entry->idx == idx) {
+*found = true;
+return entry->color;
+}
+}
+}
+
+*found = false;
+return -1;
+}
+
+static void palette_fill_cb(int idx, uint32_t color, void *opaque)
+{
+uint32_t *colors = opaque;
+
+colors[idx] = color;
+}
+
+size_t palette_fill(const VncPalette *palette,
+uint32_t colors[VNC_PALETTE_MAX_SIZE])
+{
+palette_iter(palette, palette_fill_cb, colors);
+return palette_size(palette);
+}
+
diff --git a/ui/vnc-palette.h b/ui/vnc-palette.h
index c646e4d..3260885 100644
--- a/ui/vnc-palette.h
+++ b/ui/vnc-palette.h
@@ -61,5 +61,8 @@ size_t palette_size(const VncPalette *palette);
 void palette_iter(const VncPalette *palette,
   void (*iter)(int idx, uint32_t color, void *opaque),
   void *opaque);
+uint32_t palette_color(const VncPalette *palette, int idx, bool *found);
+size_t palette_fill(const VncPalette *palette,
+uint32_t colors[VNC_PALETTE_MAX_SIZE]);
 
 #endif /* VNC_PALETTE_H */
-- 
1.7.1




[Qemu-devel] [PATCH 11/15] bitmap: add a generic bitmap and bitops library

2010-08-10 Thread Corentin Chary
Add most used bitmap and bitops functions into bitmap.c and bitops.c.
Theses functions are mostly copied from Linux kernel source.

Some of these functions are already redefined in the VNC server. Some
of them could be used for some block stuff. The yet yo be submitted
NUMA work also need bitmaps.

Signed-off-by: Corentin Chary 
---
 Makefile.objs |1 +
 bitmap.c  |  255 +
 bitmap.h  |  222 ++
 bitops.c  |  142 ++
 bitops.h  |  272 +
 osdep.h   |4 +
 6 files changed, 896 insertions(+), 0 deletions(-)
 create mode 100644 bitmap.c
 create mode 100644 bitmap.h
 create mode 100644 bitops.c
 create mode 100644 bitops.h

diff --git a/Makefile.objs b/Makefile.objs
index a6dd2ab..d4afde8 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -83,6 +83,7 @@ common-obj-y += qemu-char.o savevm.o #aio.o
 common-obj-y += msmouse.o ps2.o
 common-obj-y += qdev.o qdev-properties.o
 common-obj-y += block-migration.o
+common-obj-y += bitmap.c bitops.c
 
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
diff --git a/bitmap.c b/bitmap.c
new file mode 100644
index 000..eaafbea
--- /dev/null
+++ b/bitmap.c
@@ -0,0 +1,255 @@
+/*
+ * Bitmap Module
+ *
+ * Stolen from linux/src/lib/bitmap.c
+ *
+ * Copyright (C) 2010 Corentin Chary
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.
+ */
+
+#include "bitops.h"
+#include "bitmap.h"
+
+/*
+ * bitmaps provide an array of bits, implemented using an an
+ * array of unsigned longs.  The number of valid bits in a
+ * given bitmap does _not_ need to be an exact multiple of
+ * BITS_PER_LONG.
+ *
+ * The possible unused bits in the last, partially used word
+ * of a bitmap are 'don't care'.  The implementation makes
+ * no particular effort to keep them zero.  It ensures that
+ * their value will not affect the results of any operation.
+ * The bitmap operations that return Boolean (bitmap_empty,
+ * for example) or scalar (bitmap_weight, for example) results
+ * carefully filter out these unused bits from impacting their
+ * results.
+ *
+ * These operations actually hold to a slightly stronger rule:
+ * if you don't input any bitmaps to these ops that have some
+ * unused bits set, then they won't output any set unused bits
+ * in output bitmaps.
+ *
+ * The byte ordering of bitmaps is more natural on little
+ * endian architectures.
+ */
+
+int __bitmap_empty(const unsigned long *bitmap, int bits)
+{
+int k, lim = bits/BITS_PER_LONG;
+
+for (k = 0; k < lim; ++k) {
+if (bitmap[k]) {
+return 0;
+}
+}
+if (bits % BITS_PER_LONG) {
+if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) {
+return 0;
+}
+}
+
+return 1;
+}
+
+int __bitmap_full(const unsigned long *bitmap, int bits)
+{
+int k, lim = bits/BITS_PER_LONG;
+
+for (k = 0; k < lim; ++k) {
+if (~bitmap[k]) {
+return 0;
+}
+}
+
+if (bits % BITS_PER_LONG) {
+if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits)) {
+return 0;
+}
+}
+
+return 1;
+}
+
+int __bitmap_equal(const unsigned long *bitmap1,
+   const unsigned long *bitmap2, int bits)
+{
+int k, lim = bits/BITS_PER_LONG;
+
+for (k = 0; k < lim; ++k) {
+if (bitmap1[k] != bitmap2[k]) {
+return 0;
+}
+}
+
+if (bits % BITS_PER_LONG) {
+if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) {
+return 0;
+}
+}
+
+return 1;
+}
+
+void __bitmap_complement(unsigned long *dst, const unsigned long *src, int 
bits)
+{
+int k, lim = bits/BITS_PER_LONG;
+
+for (k = 0; k < lim; ++k) {
+dst[k] = ~src[k];
+}
+
+if (bits % BITS_PER_LONG) {
+dst[k] = ~src[k] & BITMAP_LAST_WORD_MASK(bits);
+}
+}
+
+int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2, int bits)
+{
+int k;
+int nr = BITS_TO_LONGS(bits);
+unsigned long result = 0;
+
+for (k = 0; k < nr; k++) {
+result |= (dst[k] = bitmap1[k] & bitmap2[k]);
+}
+return result != 0;
+}
+
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+   const unsigned long *bitmap2, int bits)
+{
+int k;
+int nr = BITS_TO_LONGS(bits);
+
+for (k = 0; k < nr; k++) {
+dst[k] = bitmap1[k] | bitmap2[k];
+}
+}
+
+void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
+   const unsigned long *bitmap2, int bits)
+{
+int k;
+int nr = BITS_TO_LONGS(bits);
+
+for (k = 0; k < nr; k++) {
+dst[k] = bitmap1[k] ^ bitmap2[k];
+}
+}
+
+int __bitmap_andnot(unsigned long *dst, const unsig

Re: [Qemu-devel] [PATCH] trace: Make trace record fields 64-bit

2010-08-10 Thread Prerna Saxena

On 08/09/2010 07:05 PM, Stefan Hajnoczi wrote:

Explicitly use 64-bit fields in trace records so that timestamps and
magic numbers work for 32-bit host builds.

Signed-off-by: Stefan Hajnoczi
---
  simpletrace.c  |   31 +--
  simpletrace.h  |   11 ++-
  simpletrace.py |2 +-
  tracetool  |6 +++---
  4 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/simpletrace.c b/simpletrace.c
index 954cc4e..01acfc5 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -9,18 +9,29 @@
   */

  #include
+#include
  #include
  #include
  #include "trace.h"

+/** Trace file header event ID */
+#define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with 
TraceEventIDs */
+
+/** Trace file magic number */
+#define HEADER_MAGIC 0xf2b177cb0aa429b4ULL
+
+/** Trace file version number, bump if format changes */
+#define HEADER_VERSION 0
+
+/** Trace buffer entry */
  typedef struct {
-unsigned long event;
-unsigned long timestamp_ns;
-unsigned long x1;
-unsigned long x2;
-unsigned long x3;
-unsigned long x4;
-unsigned long x5;
+uint64_t event;
+uint64_t timestamp_ns;
+uint64_t x1;
+uint64_t x2;
+uint64_t x3;
+uint64_t x4;
+uint64_t x5;
  } TraceRecord;

  enum {
@@ -42,9 +53,9 @@ void st_print_trace_file_status(FILE *stream, int 
(*stream_printf)(FILE *stream,
  static bool write_header(FILE *fp)
  {
  TraceRecord header = {
-.event = -1UL, /* max avoids conflicting with TraceEventIDs */
-.timestamp_ns = 0xf2b177cb0aa429b4, /* magic number */
-.x1 = 0, /* bump this version number if file format changes */
+.event = HEADER_EVENT_ID,
+.timestamp_ns = HEADER_MAGIC,
+.x1 = HEADER_VERSION,
  };

  return fwrite(&header, sizeof header, 1, fp) == 1;
diff --git a/simpletrace.h b/simpletrace.h
index 6a2b8d9..f81aa8e 100644
--- a/simpletrace.h
+++ b/simpletrace.h
@@ -10,6 +10,7 @@
  #define SIMPLETRACE_H

  #include
+#include
  #include

  typedef unsigned int TraceEventID;


It would be useful to have :

typedef uint64_t TraceEventID;

This ensures that the maximum number of trace events available on both 
32 and 64 bit builds is same.



@@ -20,11 +21,11 @@ typedef struct {
  } TraceEvent;

  void trace0(TraceEventID event);
-void trace1(TraceEventID event, unsigned long x1);
-void trace2(TraceEventID event, unsigned long x1, unsigned long x2);
-void trace3(TraceEventID event, unsigned long x1, unsigned long x2, unsigned 
long x3);
-void trace4(TraceEventID event, unsigned long x1, unsigned long x2, unsigned 
long x3, unsigned long x4);
-void trace5(TraceEventID event, unsigned long x1, unsigned long x2, unsigned 
long x3, unsigned long x4, unsigned long x5);
+void trace1(TraceEventID event, uint64_t x1);
+void trace2(TraceEventID event, uint64_t x1, uint64_t x2);
+void trace3(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3);
+void trace4(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, 
uint64_t x4);
+void trace5(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, 
uint64_t x4, uint64_t x5);
  void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream, const 
char *fmt, ...));
  void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, 
const char *fmt, ...));
  void st_change_trace_event_state(const char *tname, bool tstate);
diff --git a/simpletrace.py b/simpletrace.py
index 979d911..fdf0eb5 100755
--- a/simpletrace.py
+++ b/simpletrace.py
@@ -17,7 +17,7 @@ header_event_id = 0x
  header_magic= 0xf2b177cb0aa429b4
  header_version  = 0

-trace_fmt = 'LLL'
+trace_fmt = '=QQQ'
  trace_len = struct.calcsize(trace_fmt)
  event_re  = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\)\s+"([^"]*)"')

diff --git a/tracetool b/tracetool
index c5a5bdc..b78cd97 100755
--- a/tracetool
+++ b/tracetool
@@ -151,11 +151,11 @@ EOF
  simple_event_num=0
  }

-cast_args_to_ulong()
+cast_args_to_uint64_t()
  {
  local arg
  for arg in $(get_argnames "$1"); do
-echo -n "(unsigned long)$arg"
+echo -n "(uint64_t)$arg"


Tested this on a 32 bit host. It throws up some warnings, and we need :
echo -n "(uint64_t)(uintptr_t)$arg"


  done
  }

@@ -173,7 +173,7 @@ linetoh_simple()
  trace_args="$simple_event_num"
  if [ "$argc" -gt 0 ]
  then
-trace_args="$trace_args, $(cast_args_to_ulong "$1")"
+trace_args="$trace_args, $(cast_args_to_uint64_t "$1")"
  fi

  cat<


--
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India



[Qemu-devel] [PATCH 09/15] vnc: fix uint8_t comparisons with negative values

2010-08-10 Thread Corentin Chary
Signed-off-by: Corentin Chary 
---
 ui/vnc-enc-tight.c |6 +++---
 ui/vnc-enc-zrle.c  |3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index 5ca4342..9f83235 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -1546,7 +1546,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int 
w, int h)
 vnc_tight_stop(vs);
 
 #ifdef CONFIG_VNC_JPEG
-if (vs->tight.quality != -1) {
+if (vs->tight.quality != (uint8_t)-1) {
 double freq = vnc_update_freq(vs, x, y, w, h);
 
 if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) {
@@ -1562,7 +1562,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int 
w, int h)
 colors = tight_fill_palette(vs, x, y, w * h, &fg, &bg, &palette);
 
 #ifdef CONFIG_VNC_JPEG
-if (allow_jpeg && vs->tight.quality != -1) {
+if (allow_jpeg && vs->tight.quality != (uint8_t)-1) {
 ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette,
  force_jpeg);
 } else {
@@ -1711,7 +1711,7 @@ static int tight_send_framebuffer_update(VncState *vs, 
int x, int y,
 vs->tight.pixel24 = false;
 }
 
-if (vs->tight.quality != -1) {
+if (vs->tight.quality != (uint8_t)-1) {
 double freq = vnc_update_freq(vs, x, y, w, h);
 
 if (freq > tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold) {
diff --git a/ui/vnc-enc-zrle.c b/ui/vnc-enc-zrle.c
index 4460890..b5a245a 100644
--- a/ui/vnc-enc-zrle.c
+++ b/ui/vnc-enc-zrle.c
@@ -284,7 +284,8 @@ static int zrle_send_framebuffer_update(VncState *vs, int 
x, int y,
   int zywrle_level;
 
   if (vs->zrle.type == VNC_ENCODING_ZYWRLE) {
-  if (!vs->vd->lossy || vs->tight.quality < 0 || vs->tight.quality == 9) {
+  if (!vs->vd->lossy || vs->tight.quality == (uint8_t)-1
+  || vs->tight.quality == 9) {
   zywrle_level = 0;
   vs->zrle.type = VNC_ENCODING_ZRLE;
   } else if (vs->tight.quality < 3) {
-- 
1.7.1




[Qemu-devel] [PATCH 14/15] vnc: tight: tweak adaptive tight settings

2010-08-10 Thread Corentin Chary
The force_jpeg threshold was too low.

Signed-off-by: Corentin Chary 
---
 qemu-thread.c  |1 +
 ui/vnc-enc-tight.c |   20 ++--
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/qemu-thread.c b/qemu-thread.c
index fbc78fe..4094c51 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -22,6 +22,7 @@
 static void error_exit(int err, const char *msg)
 {
 fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
+char *p = NULL; *p = 1;
 exit(1);
 }
 
diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index 9f83235..b0181ff 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -79,16 +79,16 @@ static const struct {
 int jpeg_idx;   /* Allow indexed JPEG */
 int jpeg_full;  /* Allow full color JPEG */
 } tight_jpeg_conf[] = {
-{ 0,   4,  1, 1 },
-{ 0,   4,  1, 1 },
-{ 0,   4,  1, 1 },
-{ 0,   4,  1, 1 },
-{ 0,   4,  0, 1 },
-{ 0.1, 4,  0, 1 },
-{ 0.2, 4,  0, 1 },
-{ 0.3, 6,  0, 0 },
-{ 0.4, 8,  0, 0 },
-{ 0.5, 10, 0, 0 },
+{ 0,   8,  1, 1 },
+{ 0,   8,  1, 1 },
+{ 0,   8,  1, 1 },
+{ 0,   8,  1, 1 },
+{ 0,   10, 1, 1 },
+{ 0.1, 10, 1, 1 },
+{ 0.2, 10, 1, 1 },
+{ 0.3, 12, 0, 0 },
+{ 0.4, 14, 0, 0 },
+{ 0.5, 16, 0, 0 },
 };
 #endif
 
-- 
1.7.1




[Qemu-devel] [PATCH 10/15] vnc: fix lossy rect refreshing

2010-08-10 Thread Corentin Chary
The for loop in send_lossy_rect was totally wrong, and we can't
call vnc_set_bits() because it does not really do what it should.
Use vnc_set_bit() directly instead.

Signed-off-by: Corentin Chary 
---
 ui/vnc.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 27263dc..5038863 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2292,8 +2292,8 @@ void vnc_sent_lossy_rect(VncState *vs, int x, int y, int 
w, int h)
 x /= VNC_STAT_RECT;
 y /= VNC_STAT_RECT;
 
-for (j = y; j <= y + h; j++) {
-for (i = x; i <= x + w; i++) {
+for (j = y; j <= h; j++) {
+for (i = x; i <= w; i++) {
 vs->lossy_rect[j][i] = 1;
 }
 }
@@ -2310,7 +2310,7 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, 
int y)
 x = x / VNC_STAT_RECT * VNC_STAT_RECT;
 
 QTAILQ_FOREACH(vs, &vd->clients, next) {
-int j ;
+int j, i;
 
 /* kernel send buffers are full -> refresh later */
 if (vs->output.offset)
@@ -2318,12 +2318,16 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int 
x, int y)
 
 if (!vs->lossy_rect[sty][stx])
 continue ;
+
 vs->lossy_rect[sty][stx] = 0;
 for (j = 0; j < VNC_STAT_RECT; ++j) {
-vnc_set_bits(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16);
+for (i = x / 16; i < VNC_STAT_RECT / 16 + x / 16; ++i) {
+vnc_set_bit(vs->dirty[y + j], i);
+}
 }
 has_dirty++;
 }
+
 return has_dirty;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 13/15] vnc: don't try to send bigger updates that client height

2010-08-10 Thread Corentin Chary
Respect client size if it doesn't not support desktop resizing.

Signed-off-by: Corentin Chary 
---
 ui/vnc.c |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 0adab4a..dffb4aa 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -791,12 +791,11 @@ static void vnc_dpy_cursor_define(QEMUCursor *c)
 }
 
 static int find_and_clear_dirty_height(struct VncState *vs,
-   int y, int last_x, int x)
+   int y, int last_x, int x, int height)
 {
 int h;
-VncDisplay *vd = vs->vd;
 
-for (h = 1; h < (vd->server->height - y); h++) {
+for (h = 1; h < (height - y); h++) {
 int tmp_x;
 if (!test_bit(last_x, vs->dirty[y + h])) {
 break;
@@ -861,7 +860,8 @@ static int vnc_update_client(VncState *vs, int has_dirty)
 }
 } else {
 if (last_x != -1) {
-int h = find_and_clear_dirty_height(vs, y, last_x, x);
+int h = find_and_clear_dirty_height(vs, y, last_x, x,
+height);
 
 n += vnc_job_add_rect(job, last_x * 16, y,
   (x - last_x) * 16, h);
@@ -870,7 +870,7 @@ static int vnc_update_client(VncState *vs, int has_dirty)
 }
 }
 if (last_x != -1) {
-int h = find_and_clear_dirty_height(vs, y, last_x, x);
+int h = find_and_clear_dirty_height(vs, y, last_x, x, height);
 n += vnc_job_add_rect(job, last_x * 16, y,
   (x - last_x) * 16, h);
 }
-- 
1.7.1




[Qemu-devel] [PATCH 15/15] vnc: add a non-adaptive option

2010-08-10 Thread Corentin Chary
This option allow to disable adaptive behaviors in some encodings.

Signed-off-by: Corentin Chary 
---
 qemu-options.hx|9 +
 ui/vnc-enc-tight.c |2 +-
 ui/vnc.c   |   13 +
 ui/vnc.h   |1 +
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 40cee70..e158101 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -842,6 +842,15 @@ option is set, VNC client may receive lossy framebuffer 
updates
 depending on its encoding settings. Enabling this option can save
 a lot of bandwidth at the expense of quality.
 
+...@item non-adaptive
+
+Disable adaptive encodings. Adaptive encodings are enabled by default.
+An adaptive encoding will try to detect frequently updated screen regions,
+and send updates in these regions using a lossy encoding (like JPEG).
+This can be really helpfull to save bandwidth when playing videos. Disabling
+adaptive encodings allow to restore the original static behavior of encodings
+like Tight.
+
 @end table
 ETEXI
 
diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index b0181ff..534745e 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -1546,7 +1546,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int 
w, int h)
 vnc_tight_stop(vs);
 
 #ifdef CONFIG_VNC_JPEG
-if (vs->tight.quality != (uint8_t)-1) {
+if (!vs->vd->non_adaptive && vs->tight.quality != (uint8_t)-1) {
 double freq = vnc_update_freq(vs, x, y, w, h);
 
 if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) {
diff --git a/ui/vnc.c b/ui/vnc.c
index dffb4aa..cb37a75 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2380,10 +2380,12 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
 VncState *vs;
 int has_dirty = 0;
 
-struct timeval tv;
+struct timeval tv = { 0, 0 };
 
-gettimeofday(&tv, NULL);
-has_dirty = vnc_update_stats(vd, &tv);
+if (!vd->non_adaptive) {
+gettimeofday(&tv, NULL);
+has_dirty = vnc_update_stats(vd, &tv);
+}
 
 /*
  * Walk through the guest dirty map.
@@ -2412,7 +2414,8 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
 if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
 continue;
 memcpy(server_ptr, guest_ptr, cmp_bytes);
-vnc_rect_updated(vd, x, y, &tv);
+if (!vd->non_adaptive)
+vnc_rect_updated(vd, x, y, &tv);
 QTAILQ_FOREACH(vs, &vd->clients, next) {
 set_bit((x / 16), vs->dirty[y]);
 }
@@ -2717,6 +2720,8 @@ int vnc_display_open(DisplayState *ds, const char 
*display)
 acl = 1;
 } else if (strncmp(options, "lossy", 5) == 0) {
 vs->lossy = true;
+} else if (strncmp(options, "non-adapative", 13) == 0) {
+vs->non_adaptive = true;
 }
 }
 
diff --git a/ui/vnc.h b/ui/vnc.h
index 979467b..f502690 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -143,6 +143,7 @@ struct VncDisplay
 char *password;
 int auth;
 bool lossy;
+bool non_adaptive;
 #ifdef CONFIG_VNC_TLS
 int subauth; /* Used by VeNCrypt */
 VncDisplayTLS tls;
-- 
1.7.1




[Qemu-devel] [PATCH 12/15] vnc: use the new generic bitmap functions

2010-08-10 Thread Corentin Chary
Switch to bitmap.h and bitops.h instead of redefining our own bitmap
helpers.

Signed-off-by: Corentin Chary 
---
 ui/vnc.c |   91 ++---
 ui/vnc.h |7 +++--
 2 files changed, 25 insertions(+), 73 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 5038863..0adab4a 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -41,13 +41,6 @@ static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 };
 #include "vnc_keysym.h"
 #include "d3des.h"
 
-#define count_bits(c, v) { \
-for (c = 0; v; v >>= 1) \
-{ \
-c += v & 1; \
-} \
-}
-
 static VncDisplay *vnc_display; /* needed for info vnc */
 static DisplayChangeListener *dcl;
 
@@ -374,47 +367,6 @@ static void framebuffer_update_request(VncState *vs, int 
incremental,
 static void vnc_refresh(void *opaque);
 static int vnc_refresh_server_surface(VncDisplay *vd);
 
-static inline void vnc_set_bit(uint32_t *d, int k)
-{
-d[k >> 5] |= 1 << (k & 0x1f);
-}
-
-static inline void vnc_clear_bit(uint32_t *d, int k)
-{
-d[k >> 5] &= ~(1 << (k & 0x1f));
-}
-
-static inline void vnc_set_bits(uint32_t *d, int n, int nb_words)
-{
-int j;
-
-j = 0;
-while (n >= 32) {
-d[j++] = -1;
-n -= 32;
-}
-if (n > 0)
-d[j++] = (1 << n) - 1;
-while (j < nb_words)
-d[j++] = 0;
-}
-
-static inline int vnc_get_bit(const uint32_t *d, int k)
-{
-return (d[k >> 5] >> (k & 0x1f)) & 1;
-}
-
-static inline int vnc_and_bits(const uint32_t *d1, const uint32_t *d2,
-   int nb_words)
-{
-int i;
-for(i = 0; i < nb_words; i++) {
-if ((d1[i] & d2[i]) != 0)
-return 1;
-}
-return 0;
-}
-
 static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
 {
 int i;
@@ -437,7 +389,7 @@ static void vnc_dpy_update(DisplayState *ds, int x, int y, 
int w, int h)
 
 for (; y < h; y++)
 for (i = 0; i < w; i += 16)
-vnc_set_bit(s->dirty[y], (x + i) / 16);
+set_bit((x + i) / 16, s->dirty[y]);
 }
 
 void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
@@ -776,7 +728,7 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int 
src_y, int dst_x, int
 memmove(dst_row, src_row, cmp_bytes);
 QTAILQ_FOREACH(vs, &vd->clients, next) {
 if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
-vnc_set_bit(vs->dirty[y], ((x + dst_x) / 16));
+set_bit(((x + dst_x) / 16), vs->dirty[y]);
 }
 }
 }
@@ -846,10 +798,12 @@ static int find_and_clear_dirty_height(struct VncState 
*vs,
 
 for (h = 1; h < (vd->server->height - y); h++) {
 int tmp_x;
-if (!vnc_get_bit(vs->dirty[y + h], last_x))
+if (!test_bit(last_x, vs->dirty[y + h])) {
 break;
-for (tmp_x = last_x; tmp_x < x; tmp_x++)
-vnc_clear_bit(vs->dirty[y + h], tmp_x);
+}
+for (tmp_x = last_x; tmp_x < x; tmp_x++) {
+clear_bit(tmp_x, vs->dirty[y + h]);
+}
 }
 
 return h;
@@ -901,11 +855,10 @@ static int vnc_update_client(VncState *vs, int has_dirty)
 int x;
 int last_x = -1;
 for (x = 0; x < width / 16; x++) {
-if (vnc_get_bit(vs->dirty[y], x)) {
+if (test_and_clear_bit(x, vs->dirty[y])) {
 if (last_x == -1) {
 last_x = x;
 }
-vnc_clear_bit(vs->dirty[y], x);
 } else {
 if (last_x != -1) {
 int h = find_and_clear_dirty_height(vs, y, last_x, x);
@@ -1698,8 +1651,7 @@ static void framebuffer_update_request(VncState *vs, int 
incremental,
 if (!incremental) {
 vs->force_update = 1;
 for (i = 0; i < h; i++) {
-vnc_set_bits(vs->dirty[y_position + i],
- (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS);
+bitmap_set(vs->dirty[y_position + i], x_position / 16, w / 16);
 }
 }
 }
@@ -1838,15 +1790,15 @@ static void set_pixel_format(VncState *vs,
 
 vs->clientds = *(vs->vd->guest.ds);
 vs->clientds.pf.rmax = red_max;
-count_bits(vs->clientds.pf.rbits, red_max);
+vs->clientds.pf.rbits = hweight_long(red_max);
 vs->clientds.pf.rshift = red_shift;
 vs->clientds.pf.rmask = red_max << red_shift;
 vs->clientds.pf.gmax = green_max;
-count_bits(vs->clientds.pf.gbits, green_max);
+vs->clientds.pf.gbits = hweight_long(green_max);
 vs->clientds.pf.gshift = green_shift;
 vs->clientds.pf.gmask = green_max << green_shift;
 vs->clientds.pf.bmax = blue_max;
-count_bits(vs->clientds.pf.bbits, blue_max);
+vs->clientds.pf.bbits = hweight_long(blue_max);
 vs->clientds.pf.bshift = blue_shift;
 vs->clientds.pf.bmask = blue_max << blue_shift;
 vs->clientds.pf.bits_per_pixel = bits_per_pixel;
@@ -2310,7 +226