From: Arjun Subject: Strange behavior of simple loop programs in Xen guests. Date: Sat, 15 Apr 2006 02:57:26 -0400 Message-ID: <896ae46a0604142357t447adab7r7701ce00dc359890@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2002189762==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel List-Id: xen-devel@lists.xenproject.org --===============2002189762== Content-Type: multipart/alternative; boundary="----=_Part_4379_31925189.1145084246650" ------=_Part_4379_31925189.1145084246650 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, I'm running some simple C programs in a Xen 3.0 guest. I have a program testprog.c containing simple nested loops (see code below). I run this program and check "sar" and "top" output inside the guest and also xentop on the host. It shows that the running program takes up almost all the CPU time as expected. Now I introduce a sleep(1) statement inside my outer loop. On running the modified program, both "sar" and "top" in the guest VM show 0% and xentop on the host shows about 0.5% Next I start about a 100 instances of my loop program (started at skewed times) inside the guest VM. A check on sar and top still shows 0% CPU, however a check on xentop on the host shows an increase in CPU usage for th= e guest. This changes with the number of instances of the loop program I start (more or less linearly). I don't understand why this is happening. Why are sar and top showing incorrect output in the guest VM. Can anyone explain ? P.S: code for the programs is posted below. Thanks and regards Arjun testprog.c ------------------------------------- nested loops ----------------------------- main() { long long int i =3D 0; int j =3D 0, count =3D 0; do{ i++; for(j=3D0 ; j < 100 ; j++){ count =3D count + 1; } } while (i < 25999999999LL); } ------------------------------ nested loops with sleep ---------------------- main() { long long int i =3D 0; int j =3D 0, count =3D 0; do{ i++; for(j=3D0 ; j < 1000000 ; j++){ count =3D count + 1; } sleep(1); count=3D 0; } while (i < 25999999999LL); } ------------------------------------------------------- ------=_Part_4379_31925189.1145084246650 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi,

I'm running some simple C programs in a Xen 3.0 guest. I have a = program testprog.c containing simple nested loops (see code below).
I ru= n this program and check "sar" and "top" output inside = the guest and also xentop on the host. It shows that the running program
takes up almost all the CPU time as expected.

Now I introduce a = sleep(1) statement inside my outer loop. On running the modified program, b= oth "sar" and "top" in the guest VM show 0% and
xentop on the host shows about 0.5%
Next I start about a 100 instances o= f my loop program (started at skewed times) inside the guest VM. A check on= sar and top still shows 0% CPU,
however a check on xentop on the host s= hows an increase in CPU usage for the guest. This changes with the number o= f instances of the loop program
I start (more or less linearly).

I don't understand why this is = happening. Why are sar and top showing incorrect output in the guest VM. Ca= n anyone explain ?

P.S: code for the programs is posted below.

Thanks and regards
Arjun

testprog.c
----------------------= --------------- nested loops -----------------------------
main()
{        long long int i =3D 0;
&nbs= p;       int j =3D 0, count =3D 0;

        do{
    &= nbsp;     i++;

     &nb= sp;    for(j=3D0 ; j < 100 ; j++){
   &= nbsp;        count =3D count + 1;
&nb= sp;         }


 &nbs= p;     } while (i < 25999999999LL);
}


= ------------------------------ nested loops with sleep --------------------= --
main()
{
        long long int= i =3D 0;
        int j =3D 0, count = =3D 0;

        do{
  = ;        i++;

   &= nbsp;      for(j=3D0 ; j < 1000000 ; j++){
&= nbsp;           count =3D= count + 1;
          }
=           sleep(1);
          count=3D 0;
<= br>       } while (i < 25999999999LL);
= }

-------------------------------------------------------
------=_Part_4379_31925189.1145084246650-- --===============2002189762== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============2002189762==--