Example #1
0
    internal static long GetUtcTimeInterruptsDisabled()
    {
        CompilerIntrinsics.Cli(); // TODO: superfluous
        long tsc = NucleusCalls.Rdtsc();

        return(unchecked (tsc >> 8));
    }
Example #2
0
 internal static long Rdtsc()
 {
     try
     {
         CompilerIntrinsics.Cli();
         return(NucleusCalls.Rdtsc());
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Example #3
0
    public override void Run()
    {
        int nIter = 1048576;

        if (me == 0)
        {
            myId = Kernel.CurrentThread;
            Thread otherT  = kernel.NewThread(other);
            uint   otherId = otherT.id;
            kernel.Yield();
            try
            {
                CompilerIntrinsics.Cli();
                NucleusCalls.DebugPrintHex(50, 0);
                long t1 = NucleusCalls.Rdtsc();
                for (int i = 0; i < nIter; i++)
                {
                    NucleusCalls.YieldTo(otherId);
                }
                long t2   = NucleusCalls.Rdtsc();
                uint diff = (uint)((t2 - t1) >> 20);
                NucleusCalls.DebugPrintHex(50, diff);
            }
            finally
            {
                CompilerIntrinsics.Sti();
            }
            doneSemaphore.Signal();
        }
        else
        {
            uint otherId = other.myId;
            kernel.Yield();
            try
            {
                CompilerIntrinsics.Cli();
                for (int i = 0; i < nIter; i++)
                {
                    NucleusCalls.YieldTo(otherId);
                }
            }
            finally
            {
                CompilerIntrinsics.Sti();
            }
        }
    }
Example #4
0
    internal void ScheduleNextThread()
    {
        Thread t = readyQueue.Dequeue();

        if (t == null)
        {
            if (collectionRequested)
            {
                CompilerIntrinsics.Cli(); // TODO: superfluous
                NucleusCalls.DebugPrintHex(70, ++gcCount);
                NucleusCalls.DebugPrintHex(60, 0);
                long t1 = NucleusCalls.Rdtsc();

                // No ready threads.
                // Make anyone waiting for GC ready:
                while (true)
                {
                    t = collectionQueue.Dequeue();
                    if (t == null)
                    {
                        break;
                    }
                    readyQueue.Enqueue(t);
                }

                t = readyQueue.Dequeue();

                // Garbage collect, then we're ready to go.
                CompilerIntrinsics.Sti();
                System.DebugStub.Print("GarbageCollecting. ");
                CompilerIntrinsics.Cli();
                NucleusCalls.GarbageCollect();
                collectionRequested = false;

                long t2   = NucleusCalls.Rdtsc();
                uint diff = (uint)((t2 - t1) >> 10);
                NucleusCalls.DebugPrintHex(60, diff);
            }

            while (t == null)
            {
                // TODO: let the CPU sleep here
                // TODO: enable interrupts
                CompilerIntrinsics.Cli(); // TODO: superfluous
                if (!CheckWakeUp())
                {
                    // No threads to run.  The system is finished.
                    CompilerIntrinsics.Cli(); // TODO: superfluous
                    NucleusCalls.DebugPrintHex(0, 0x76543210);
                    while (true)
                    {
                    }
                }

                t = readyQueue.Dequeue();
                CompilerIntrinsics.Cli(); // TODO: superfluous
            }
        }

        // Go to t.
        RunThread(t);

        // We're back.  Somebody (not necessarily t) yielded to us.
    }