Re: Iterative calculations doesn't work - What could be the problem?

Peter Jin <[email protected]> Tue, 24 Apr 2012 08:54:25 -0400
Newsgroups gmane.comp.micro-kernel.l4.l4ka.general
Message-ID <CANn7U_K5mysAiRQV7kx03x0S1XqOQE4h2EK6_3n0gzPgjGZu6Q@mail.gmail.com>
--20cf307ac89559be7004be6c4394
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Probably because your iter_factorial call got optimized away. Try assigning
it to something, like

volatile unsigned f =3D iter_factorial(1000000001);

Peter


On Tue, Apr 24, 2012 at 7:50 AM, H=C3=A5vard Ostnes <[email protected]=
m>wrote:

> Hi!
>
> I have the following code which successfully compiles and runs on L4 on
> Qemu and
> VMware.
>
> The problem is that the calculations seems to finish immediately and
> looking at
> the CPU utilization it doesn't even seem to have performed the calculatio=
n
> at
> all.
>
>
> -----CODE BEGINS-------
> //LINUX
> //#include <stdio.h>
> //#include <unistd.h>
> //L4
> #include <l4io.h>
> #include <l4/ipc.h>
> //#include <l4/types.h>
>
> unsigned int iter_factorial(int n);
> unsigned int recr_factorial(int n);
>
> int main() {
>  while(1)
>    {
>      printf("working\n");
>      iter_factorial(1000000001);
>      printf("Done\n");
>      L4_Sleep(L4_TimePeriod(2000000));
>      //sleep(2);
>    }
> }
>
> unsigned int recr_factorial(int n) {
>    return n>=3D1 ? n * recr_factorial(n-1) : 1;
> }
>
> unsigned int iter_factorial(int n) {
>    int accu =3D 1;
>    int i;
>    for(i =3D 1; i <=3D n; i++) {
>        accu *=3D i;
>    }
>    return accu;
> }
>
>
> -------- CODE ENDS----------
>
>
> I really hope someone could take a look at this to help with my problem a=
s
> I am
> stuck to the point where I cannot get any further. I have no idea what
> could be
> the problem.
>
> This is my Makefile:
>
> ----- MAKEFILE START ------
>
>
> srcdir=3D         @srcdir@
> top_srcdir=3D     @top_srcdir@
> top_builddir=3D   @top_builddir@
>
> include $(top_srcdir)/Mk/l4.base.mk
>
>
> PROGRAM=3D        cpu_iterative_a
> PROGRAM_DEPS=3D   $(top_builddir)/lib/l4/libl4.a \
>                $(top_builddir)/lib/io/libio.a
>
> SRCS=3D           crt0-$(ARCH).S iterative_a.cc
>
> LIBS+=3D          -ll4 -lio
> LDFLAGS+=3D       -Ttext=3D$(ROOTTASK_LINKBASE)
>
> CFLAGS_powerpc+=3D        -fno-builtin -msoft-float
> CXXFLAGS_powerpc+=3D      -fno-rtti
>
> include $(top_srcdir)/Mk/l4.prog.mk
>
> ------ MAKEFILE END -------
>
>
>

--20cf307ac89559be7004be6c4394
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Probably because your iter_factorial call got optimized away. Try assigning=
 it to something, like<br><br>volatile unsigned f =3D iter_factorial(100000=
0001);<br><br clear=3D"all">Peter<br>
<div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On Tue, Apr 2=
4, 2012 at 7:50 AM, H=C3=A5vard Ostnes <span dir=3D"ltr">&lt;<a href=3D"mai=
lto:[email protected]" target=3D"_blank">[email protected]</a>&=
gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Hi!<br>
<br>
I have the following code which successfully compiles and runs on L4 on Qem=
u and<br>
VMware.<br>
<br>
The problem is that the calculations seems to finish immediately and lookin=
g at<br>
the CPU utilization it doesn&#39;t even seem to have performed the calculat=
ion at<br>
all.<br>
<br>
<br>
-----CODE BEGINS-------<br>
//LINUX<br>
//#include &lt;stdio.h&gt;<br>
//#include &lt;unistd.h&gt;<br>
//L4<br>
#include &lt;l4io.h&gt;<br>
#include &lt;l4/ipc.h&gt;<br>
//#include &lt;l4/types.h&gt;<br>
<br>
unsigned int iter_factorial(int n);<br>
unsigned int recr_factorial(int n);<br>
<br>
int main() {<br>
 =C2=A0while(1)<br>
 =C2=A0 =C2=A0{<br>
 =C2=A0 =C2=A0 =C2=A0printf(&quot;working\n&quot;);<br>
 =C2=A0 =C2=A0 =C2=A0iter_factorial(1000000001);<br>
 =C2=A0 =C2=A0 =C2=A0printf(&quot;Done\n&quot;);<br>
 =C2=A0 =C2=A0 =C2=A0L4_Sleep(L4_TimePeriod(2000000));<br>
 =C2=A0 =C2=A0 =C2=A0//sleep(2);<br>
 =C2=A0 =C2=A0}<br>
}<br>
<br>
unsigned int recr_factorial(int n) {<br>
 =C2=A0 =C2=A0return n&gt;=3D1 ? n * recr_factorial(n-1) : 1;<br>
}<br>
<br>
unsigned int iter_factorial(int n) {<br>
 =C2=A0 =C2=A0int accu =3D 1;<br>
 =C2=A0 =C2=A0int i;<br>
 =C2=A0 =C2=A0for(i =3D 1; i &lt;=3D n; i++) {<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0accu *=3D i;<br>
 =C2=A0 =C2=A0}<br>
 =C2=A0 =C2=A0return accu;<br>
}<br>
<br>
<br>
-------- CODE ENDS----------<br>
<br>
<br>
I really hope someone could take a look at this to help with my problem as =
I am<br>
stuck to the point where I cannot get any further. I have no idea what coul=
d be<br>
the problem.<br>
<br>
This is my Makefile:<br>
<br>
----- MAKEFILE START ------<br>
<br>
<br>
srcdir=3D =C2=A0 =C2=A0 =C2=A0 =C2=A0 @srcdir@<br>
top_srcdir=3D =C2=A0 =C2=A0 @top_srcdir@<br>
top_builddir=3D =C2=A0 @top_builddir@<br>
<br>
include $(top_srcdir)/Mk/<a href=3D"http://l4.base.mk" target=3D"_blank">l4=
.base.mk</a><br>
<br>
<br>
PROGRAM=3D =C2=A0 =C2=A0 =C2=A0 =C2=A0cpu_iterative_a<br>
PROGRAM_DEPS=3D =C2=A0 $(top_builddir)/lib/l4/libl4.a \<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$(top_builddir)/lib=
/io/libio.a<br>
<br>
SRCS=3D =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 crt0-$(ARCH).S iterative_a.cc<br=
>
<br>
LIBS+=3D =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-ll4 -lio<br>
LDFLAGS+=3D =C2=A0 =C2=A0 =C2=A0 -Ttext=3D$(ROOTTASK_LINKBASE)<br>
<br>
CFLAGS_powerpc+=3D =C2=A0 =C2=A0 =C2=A0 =C2=A0-fno-builtin -msoft-float<br>
CXXFLAGS_powerpc+=3D =C2=A0 =C2=A0 =C2=A0-fno-rtti<br>
<br>
include $(top_srcdir)/Mk/<a href=3D"http://l4.prog.mk" target=3D"_blank">l4=
.prog.mk</a><br>
<br>
------ MAKEFILE END -------<br>
<br>
<br>
</blockquote></div><br></div>

--20cf307ac89559be7004be6c4394--