[haiku-appserver] Re: accelerating app_server

  • From: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Sun, 29 Jul 2007 16:47:03 +0200 CEST

Stephan Assmus <superstippi@xxxxxx> wrote:
> Axel Dörfler wrote (2007-07-26, 15:24:15 [+0200]):
> > Stephan Assmus <superstippi@xxxxxx> wrote:
> > > BLooper::check_lock() is definitely a problem (and it pretty much
> > > only
> > > calles find_thread(NULL)), but I am wondering - which version is
> > > used
> > > in the test environment, our's or Dano's?
> > Since we're running on the Dano kernel, and it's an assembler
> > inline for
> > the name==NULL case, we're using Dano's version. Anyway, if you
> > don't
> > mind, I'll try to look into it during the next days.
> No go ahead, I'd be glad if you do that!

I've written a small test app that emulates both versions of
check_loop() - and indeed, I got 0.060 usecs (Haiku) vs. 0.035 (BeOS)
per call.
Looks like even with x86, the cached stack method easily beats
find_thread(NULL) (which is only an assembly inline to return %fs:0).
I'll look into applying that version to our tree soon.

For your reading pleasure, I've attached the test app to this mail.

Bye,
   Axel.

#include <stdio.h>

#include <OS.h>


class Haiku {
        public:
                Haiku()
                {
                        fOwner = find_thread(NULL);
                }

                void
                check_lock()
                {
                        if (fOwner == -1 || fOwner != find_thread(NULL))
                                debugger("Looper must be locked.");
                }

        private:
                thread_id       fOwner;
};

class BeOS {
        public:
                BeOS()
                {
                        fOwner = find_thread(NULL);
                        fCachedStack = (uint32)this & ~(B_PAGE_SIZE - 1);
                }

                void
                check_lock()
                {
                        uint32 stack;
                        if (((uint32)&stack & ~(B_PAGE_SIZE - 1)) == 
fCachedStack
                                || fOwner == find_thread(NULL))
                                return;

                        debugger("Looper must be locked.");
                }

        private:
                thread_id       fOwner;
                uint32          fCachedStack;
};


int
main()
{
        uint32 loops = 10000000;
        Haiku haiku;
        BeOS beos;

        bigtime_t start = system_time();

        for (int i = 0; i < loops; i++) {
        }

        bigtime_t end = system_time();
        bigtime_t loopTime = end - start;

        start = system_time();

        for (int i = 0; i < loops; i++) {
                haiku.check_lock();
        }

        end = system_time();

        printf("Haiku time: %g usec\n", 1.0 * (end - start - loopTime) / loops);

        start = system_time();

        for (int i = 0; i < loops; i++) {
                beos.check_lock();
        }

        end = system_time();

        printf("BeOS time: %g usec\n", 1.0 * (end - start - loopTime) / loops);
        return 0;
}

Other related posts: