Ejemplo n.º 1
0
        public bool Run()
        {
            Console.WriteLine("JAVA - DEOS\n");

            theTimer         = new NewTimer();
            thePeriodicClock = new PeriodicClock(Registry.uSecsInFastestPeriod);
            systemClock      = new Clock(thePeriodicClock, theTimer);

            DEOSKernel.ColdStartKernel();

            int result = DEOSKernel.CreateThreadK("user1", 0, 21, 1);

            logger.Info("{threadName}|{result}", "user1", result);

            result = DEOSKernel.CreateThreadK("user2", 0, 21, 1);
            logger.Info("{threadName}|{result}", "user2", result);

            int tickResult = Clock.NOINTERRUPTS;

            for (int i = 0; i < 1000; i++)
            {
                DEOS.println("****************************");
                DEOS.println("Current time: " + DEOS.systemClock.GetCurrentTime());

                DEOS.println(Scheduler.CurrentThread().ToString() + " is the current thread");

                tickResult = DEOS.systemClock.Ticks();

                Scheduler.CurrentThread().GetBody().Run(tickResult);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void Run(int tickResult)
        {
            DEOS.Inc();

            if (tickResult == Clock.NOTIMECHANGE)
            {
                DEOS.println("No interrupts!");
                DEOS.println(thread.ToString() + " waiting until next period");
                DEOSKernel.WaitUntilNextPeriodK(thread); //yieldCPU();
            }
            else
            {
                if (DEOS.RandBool())
                {
                    DEOS.println("---Choice 0 of main---");
                    DEOS.println(thread.ToString() + " waiting until next period");
                    DEOSKernel.WaitUntilNextPeriodK(thread);
                }
                else
                {
                    DEOS.println("---Choice 1 of main---");

                    GetInterrupted(tickResult);
                }
            }
        }
Ejemplo n.º 3
0
        public DEOSThread(Thread th)
        {
            thread = th;
            isIdle = thread.IsIdle();
            isMain = thread.IsMain();

            DEOS.println(thread.ToString() + " created");
        }
Ejemplo n.º 4
0
 public void GetInterrupted(int tickResult)
 {
     if (tickResult == Clock.SYSTEMINTERRUPT)
     {
         DEOS.println(thread.ToString() + " interrupted by system tick");
         DEOS.thePeriodicClock.ResetUsedTime();
         Scheduler.HandleSystemTickInterrupt();
     }
     else if (tickResult == Clock.TIMEOUT)
     {
         DEOS.println(thread.ToString() + " interrupted by timer");
         Scheduler.HandleTimerInterrupt();
     }
     else
     {
         DEOS.println(thread.ToString() + " waiting for time to pass");
     }
 }
Ejemplo n.º 5
0
        public static bool Run()
        {
            DEOS deos = new DEOS();

            return(deos.Run());
        }
Ejemplo n.º 6
0
        public void Run(int tickResult)
        {
            //Verify.assertTrue(Timer.timer || Timer.tick);
            DEOS.Inc();

            if (tickResult == Clock.NOTIMECHANGE)
            {
                if (DEOS.RandBool())
                {
                    //System.out.println("Thread: " + thread + " - Depth: " + depth);
                    DEOS.println("No interrupt - Choice 0:");
                    DEOS.println(thread.ToString() + " waiting until next period");
                    DEOSKernel.WaitUntilNextPeriodK(thread);

                    //yieldCPU();
                }
                else
                {
                    //System.out.println("Thread: " + thread + " - Depth: " + depth);
                    DEOS.println("No interrupt - Choice 1:");
                    DEOS.println(thread.ToString() + " deleting");
                    int result = DEOSKernel.DeleteThreadK(thread); //deleteThread();
                    logger.Info("{threadName}|{result}", thread.ToString(), result);
                }
            }
            else
            {
                Random rand = new Random();
                switch (rand.Next(2))
                {
                case 0:

                    //System.out.println("Thread: " + thread + " - Depth: " + depth);
                    DEOS.println("Choice 0:");
                    DEOS.println(thread.ToString() + " waiting until next period");
                    DEOSKernel.WaitUntilNextPeriodK(thread);

                    //yieldCPU();
                    break;

                case 2:

                    //System.out.println("Thread: " + thread + " - Depth: " + depth);
                    DEOS.println("Choice 2:");
                    DEOS.println(thread.ToString() + " deleting");
                    int result = DEOSKernel.DeleteThreadK(thread);
                    logger.Info("{threadName}|{result}", thread.ToString(), result);

                    //deleteThread();
                    break;

                case 1:

                    //System.out.println("Thread: " + thread + " - Depth: " + depth);
                    DEOS.println("Choice 1: ");
                    GetInterrupted(tickResult);

                    break;
                }
            }
        }
Ejemplo n.º 7
0
        public int Ticks()
        {
            ClearInterrupts();

            int delta;

            if (!DEOS.abstraction)
            {
                delta = 1;
            }
            else
            {
                int timeToEOP     = (clockToNotify.GetTimeToEOP());
                int timeOutTime   = (timerToNotify.GetStoppingTime());
                int timeToTimeOut = (timeOutTime - currentTime);

                if (DEOS.RandBool())
                {
                    delta = 0;
                }
                else
                {
                    if (timeToEOP <= timeToTimeOut)
                    {
                        delta = timeToEOP;
                    }
                    else
                    {
                        delta = timeToTimeOut;
                    }
                }
            }

            if (delta == 0)
            {
                return(NOTIMECHANGE);
            }
            else
            {
                if ((currentTime + delta) > TIME_CONSTRAINT)
                {
                    return(NOTIMECHANGE);
                }

                currentTime = (currentTime + delta);
                clockToNotify.ClockTicks(currentTime);
                timerToNotify.ClockTicks(currentTime);

                if (clockToNotify.IsInterrupted())
                {
                    timerToNotify.InterruptTimer();

                    return(SYSTEMINTERRUPT);
                }
                else if (timerToNotify.IsTimeOut())
                {
                    return(TIMEOUT);
                }
                else
                {
                    return(NOINTERRUPTS);
                }
            }
        }
Ejemplo n.º 8
0
        public static bool Check()
        {
            total_time[0] = 0;
            total_time[1] = 0;

            Thread current;

            for (int i = 0; i < num_entries; i++)
            {
                current = allThreads[i];

                if (current != Scheduler.IdleThread())
                {
                    int cp = current.itsPeriodicEvent.CurrentPeriod();

                    if ((current.itsLastExecution == cp) &&
                        (current.itsLastCompletion != cp))
                    {
                        total_time[1] += current.itsCurrentBudget.RemainingBudgetInUsec();

                        if (current.itsPeriodIndex == 0)
                        {
                            total_time[0] += current.itsCurrentBudget.RemainingBudgetInUsec();
                        }
                    }
                    else if (current.itsLastExecution != cp)
                    {
                        total_time[1] += current.itsCurrentBudget.TotalBudgetInUsec();

                        if (current.itsPeriodIndex == 0)
                        {
                            total_time[0] += current.itsCurrentBudget.TotalBudgetInUsec();
                        }
                    }

                    if (current.itsPeriodIndex == 0)
                    {
                        int tmp = (current.itsCurrentBudget.TotalBudgetInUsec()) * (StartOfPeriodEvent.EventForPeriodIndex(1).countDown - 1);
                        total_time[1] += tmp;
                    }
                }
            }

            int period_count = StartOfPeriodEvent.EventForPeriodIndex(1).countDown - 1;

            int current_period = StartOfPeriodEvent.EventForPeriodIndex(1).CurrentPeriod();

            if (Scheduler.CurrentThread() != Scheduler.IdleThread())
            {
                int remaining = ((Registry.uSecsInFastestPeriod * period_count) +
                                 Registry.uSecsInFastestPeriod) -
                                DEOS.thePeriodicClock.GetUsedTime();

                if (total_time[1] > remaining)
                {
                    DEOS.println("Ooops: Time wanted " + total_time[1] + " > " + remaining);
                    throw new Exception("error found");
                }
                else
                {
                }
            }

            total_time[0] = 0;
            total_time[1] = 0;

            return(true);
        }