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

Håvard Ostnes <[email protected]> Tue, 24 Apr 2012 15:39:13 +0200
Newsgroups gmane.comp.micro-kernel.l4.l4ka.general
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------000709050507090306060108
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Thank you! This worked! I really appreciate it!

håvard

On 04/24/2012 02:54 PM, Peter Jin wrote:
> Probably because your iter_factorial call got optimized away. Try 
> assigning it to something, like
>
> volatile unsigned f = iter_factorial(1000000001);
>
> Peter
>
>
> On Tue, Apr 24, 2012 at 7:50 AM, Håvard Ostnes 
> <[email protected] <mailto:[email protected]>> 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
>     calculation 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>=1 ? n * recr_factorial(n-1) : 1;
>     }
>
>     unsigned int iter_factorial(int n) {
>        int accu = 1;
>        int i;
>        for(i = 1; i <= n; i++) {
>            accu *= i;
>        }
>        return accu;
>     }
>
>
>     -------- CODE ENDS----------
>
>
>     I really hope someone could take a look at this to help with my
>     problem as 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=         @srcdir@
>     top_srcdir=     @top_srcdir@
>     top_builddir=   @top_builddir@
>
>     include $(top_srcdir)/Mk/l4.base.mk <http://l4.base.mk>
>
>
>     PROGRAM=        cpu_iterative_a
>     PROGRAM_DEPS=   $(top_builddir)/lib/l4/libl4.a \
>                    $(top_builddir)/lib/io/libio.a
>
>     SRCS=           crt0-$(ARCH).S iterative_a.cc
>
>     LIBS+=          -ll4 -lio
>     LDFLAGS+=       -Ttext=$(ROOTTASK_LINKBASE)
>
>     CFLAGS_powerpc+=        -fno-builtin -msoft-float
>     CXXFLAGS_powerpc+=      -fno-rtti
>
>     include $(top_srcdir)/Mk/l4.prog.mk <http://l4.prog.mk>
>
>     ------ MAKEFILE END -------
>
>
>

--------------000709050507090306060108
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thank you! This worked! I really appreciate it!<br>
    <br>
    håvard<br>
    <br>
    On 04/24/2012 02:54 PM, Peter Jin wrote:
    <blockquote
cite="mid:CANn7U_K5mysAiRQV7kx03x0S1XqOQE4h2EK6_3n0gzPgjGZu6Q@mail.gmail.com"
      type="cite">Probably because your iter_factorial call got
      optimized away. Try assigning it to something, like<br>
      <br>
      volatile unsigned f = iter_factorial(1000000001);<br>
      <br clear="all">
      Peter<br>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Tue, Apr 24, 2012 at 7:50 AM, Håvard
          Ostnes <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi!<br>
            <br>
            I have the following code which successfully compiles and
            runs on L4 on Qemu and<br>
            VMware.<br>
            <br>
            The problem is that the calculations seems to finish
            immediately and looking at<br>
            the CPU utilization it doesn't even seem to have performed
            the calculation 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>
             while(1)<br>
               {<br>
                 printf("working\n");<br>
                 iter_factorial(1000000001);<br>
                 printf("Done\n");<br>
                 L4_Sleep(L4_TimePeriod(2000000));<br>
                 //sleep(2);<br>
               }<br>
            }<br>
            <br>
            unsigned int recr_factorial(int n) {<br>
               return n&gt;=1 ? n * recr_factorial(n-1) : 1;<br>
            }<br>
            <br>
            unsigned int iter_factorial(int n) {<br>
               int accu = 1;<br>
               int i;<br>
               for(i = 1; i &lt;= n; i++) {<br>
                   accu *= i;<br>
               }<br>
               return 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 could be<br>
            the problem.<br>
            <br>
            This is my Makefile:<br>
            <br>
            ----- MAKEFILE START ------<br>
            <br>
            <br>
            srcdir=         @srcdir@<br>
            top_srcdir=     @top_srcdir@<br>
            top_builddir=   @top_builddir@<br>
            <br>
            include $(top_srcdir)/Mk/<a moz-do-not-send="true"
              href="http://l4.base.mk" target="_blank">l4.base.mk</a><br>
            <br>
            <br>
            PROGRAM=        cpu_iterative_a<br>
            PROGRAM_DEPS=   $(top_builddir)/lib/l4/libl4.a \<br>
                           $(top_builddir)/lib/io/libio.a<br>
            <br>
            SRCS=           crt0-$(ARCH).S iterative_a.cc<br>
            <br>
            LIBS+=          -ll4 -lio<br>
            LDFLAGS+=       -Ttext=$(ROOTTASK_LINKBASE)<br>
            <br>
            CFLAGS_powerpc+=        -fno-builtin -msoft-float<br>
            CXXFLAGS_powerpc+=      -fno-rtti<br>
            <br>
            include $(top_srcdir)/Mk/<a moz-do-not-send="true"
              href="http://l4.prog.mk" target="_blank">l4.prog.mk</a><br>
            <br>
            ------ MAKEFILE END -------<br>
            <br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
  </body>
</html>

--------------000709050507090306060108--