示例#1
0
        //Return Task Set after loading from
        //File is formatted like
        //0     T1
        //1     T1
        //2     T2
        //...
        public CTaskExecutionTrace ParseTaskExecutionTrace(string
                                                           FileContents)
        {
            string[] sArray, sArray_1;

            long  time;
            CTask task;
            CTaskExecutionTrace et = new CTaskExecutionTrace();

            try
            {
                sArray = FileContents.Split('\n');

                foreach (string s in sArray)
                {
                    sArray_1 = s.Split('\t');
                    time     = Convert.ToInt32(sArray_1[0]);
                    task     = new CTask(sArray_1[1], 0, 0, 0, 0, 0);
                    et.Add(time, task);
                }
                return(et);
            }
            catch (Exception e)
            {
                _message = e.Message;
                return(null);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="L"></param>
        /// <returns></returns>
        private long findResponseTime(SortedList eventSet, int priorityOfEvent, long L)
        {
            ArrayList  Q = new ArrayList();
            SortedList G = new SortedList();

            //Reverse Priority Order, Such that task with lowest Priority is at index 0
            long  t;
            int   ii;
            int   Gap = 0;
            int   Ci = 0;
            int   retVal, lowestPriorityIndex;
            CTask hPriority, tmpE;
            int   stepsInternal;

            long currentTime;
            int  noOfInterferencesLowestPriority;


            if (priorityOfEvent > 0)
            {
                lowestPriorityIndex = priorityOfEvent;
            }
            else
            {
                lowestPriorityIndex = 0;
            }



            //Add all higher priority events
            for (ii = getIndexofHighestPriority(eventSet); ii > getIndex(lowestPriorityIndex); ii--)
            {
                tmpE = (CTask)eventSet[ii];
                tmpE.dExecutedSteps = 0; //Important to do this
                G.Add(tmpE.iPriority, tmpE);
            }

            if (priorityOfEvent > 0) //Lowest priority can be 1
            {
                tmpE = (CTask)eventSet[priorityOfEvent];
                Ci   = (int)tmpE.ExecutionTime;
            }
            else
            {
                Ci = -1;
            }


            _stepsTotal = 0;
            noOfInterferencesLowestPriority = 0;
            _interferenceCount = 0;


            for (t = 0; t < L; t++)
            {
                _lastDiscreteTimeValue = t;
                System.Windows.Forms.Application.DoEvents();


                currentTime = t; //Maintain Current Time
                retVal      = putEventInQ(t, G, Q);
                if (retVal < 0)
                {
                    return(retVal);
                }

                _stepsTotal++;

                //Execute task in Queue
                if (Q.Count > 0)
                {
                    hPriority     = (CTask)Q[Q.Count - 1]; // Last task
                    stepsInternal = 0;
                    foreach (CTask T in Q)
                    {
                        stepsInternal++;
                        if (T.iPriority >= hPriority.iPriority)
                        {
                            hPriority = T;
                        }
                    }
                    if (stepsInternal == 0)
                    {
                        _stepsTotal++;
                    }
                    else
                    {
                        _stepsTotal += stepsInternal;
                    }

                    if (Gap > 0)
                    {
                        noOfInterferencesLowestPriority++;
                        _interferenceCount++;
                    }
                    Gap = 0;

                    //Execute task hPriority
                    hPriority.dExecutedSteps++;
                    if (hPriority.dExecutedSteps == hPriority.ExecutionTime)
                    {
                        Q.Remove(hPriority);
                        hPriority.dExecutedSteps = 0;
                    }



                    _executionTrace.Add(t, hPriority);

                    //Reset all other executed steps to 0
                    stepsInternal = 0;
                    foreach (CTask T in Q)
                    {
                        stepsInternal++;
                        if (T.iPriority != hPriority.iPriority)
                        {
                            if (T.dExecutedSteps > 0)
                            {
                                _interferenceCount++;
                            }
                            //T.dExecutedSteps = 0; //Dont do this for Preemptive
                        }
                    }
                    if (stepsInternal == 0)
                    {
                        _stepsTotal++;
                    }
                    else
                    {
                        _stepsTotal += stepsInternal;
                    }
                }
                else
                {
                    Gap++;
                    _executionTrace.Add(t, null);
                    if (Gap == Ci)     // && t >= Ci * G.Count) //Gap found
                    {
                        return(t + 1); //If Ci is -ve this will never be reached
                    }
                }
            }
            if (priorityOfEvent > 0)
            {
                return(-1);                     //No gap was found
            }
            else
            {
                return(0); // All events were schedulable
            }
        }