Example #1
0
// called when current proc neeeds reschedule is true
static struct proc_struct *
MY_pick_next(struct run_queue *rq) {
    if (heap_empty(heap))
    	panic("sched_MY.c pick_next: heap is empty!\n");
	// heap part
	heap_entry_t elm = heap_gettop(heap);
	struct proc_struct *heapNext = (struct proc_struct *)elm.proc;
    return heapNext;
}
Example #2
0
bool heap_exist_earlier_deadline(process_heap_t *heap, int deadline) {
	heap_entry_t elm = heap_gettop(heap);
	return (elm.x < deadline) ? TRUE : FALSE;
}
Example #3
0
    int feedback(int nVerts, int nArcs, t_edge* graph, int* order)
    {
        Arc = (PARC) malloc(sizeof(ARC) * 2 * nArcs) ;
        DeltaCost = (int*) malloc(sizeof(int) * nVerts);
        ArcStart = (PARC*) malloc(sizeof(PARC*) * nVerts);
        Zero = (int*) malloc(sizeof(int) * nVerts);
        Ordered = (int*) malloc(sizeof(int) * nVerts);
        ArcCount = (int*) malloc(sizeof(int) * nVerts);
        OutDegree = (int*) malloc(sizeof(int) * nVerts);
        InDegree = (int*) malloc(sizeof(int) * nVerts);

        CHECK_OUT_OF_MEMORY(Arc);
        CHECK_OUT_OF_MEMORY(DeltaCost);
        CHECK_OUT_OF_MEMORY(ArcStart);
        CHECK_OUT_OF_MEMORY(Zero);
        CHECK_OUT_OF_MEMORY(Ordered);
        CHECK_OUT_OF_MEMORY(ArcCount);
        CHECK_OUT_OF_MEMORY(OutDegree);
        CHECK_OUT_OF_MEMORY(InDegree);

        memset(Arc, 0, sizeof(int) * 2 * nArcs);
        memset(DeltaCost, 0, sizeof(int) * nVerts);
        memset(ArcCount, 0, sizeof(int) * nVerts);
        memset(OutDegree, 0, sizeof(int) * nVerts);
        memset(InDegree, 0, sizeof(int) * nVerts);

        PARC pArc = Arc;

        for (int a = 0; a < nArcs; a++)
        {
            int i, j, c;
            i = graph[a].from;
            j = graph[a].to;
            c = graph[a].cost;
            //printf("edge: %i %i %i\n", i, j, c);
            ArcCount[i]++; ArcCount[j]++;
            DeltaCost[i] -= c; DeltaCost[j] += c;
            InDegree[j]++; OutDegree[i]++;
            pArc->i = i; pArc->j = j; pArc->c = c;
            pArc++;
            pArc->i = j; pArc->j = i; pArc->c = -c;
            pArc++;
        }

        // Make sure edges are sorted by vertex index
        qsort(Arc, 2 * nArcs, sizeof(ARC), cmp);

        // Find start of each vertex's section in edge list
        memset(ArcStart, 0, sizeof(PARC*) * nVerts);
        pArc = Arc;

        for (int i = 0; i < nVerts; i++)
        {
            if (ArcCount[i] > 0)
            {
                ArcStart[i] = pArc;
                pArc += ArcCount[i];
            }
        }

        // Allocate and initialize heap
        if (!heap_create(Heap, nVerts))
        {
            errorf(("Out of memory."));
            return 1;
        }

        for (int i = 0; i < nVerts; i++)
        {
            heap_insert(Heap, i, -abs(DeltaCost[i]));
        }

        //  initialize stack of zero degree vertices
        nZero = 0;

        for (int i = 0; i < nVerts; i++)
        {
            if (InDegree[i] == 0 || OutDegree[i] == 0)
            {
                Zero[nZero++] = i;
            }
        }

        memset(Ordered, 0, sizeof(int) * nVerts);

        // While there are vertices to be output
        iFirst = 0;
        iLast = nVerts - 1;

        while (1)
        {
            // Output vertices with zero degree
            while (nZero > 0)
            {
                int v = Zero[--nZero];
                Output(v);
            }

            if (iFirst > iLast) { break; }

            Output((int)heap_gettop(Heap, NULL));

            if (iFirst > iLast) { break; }
        }

        // Output results
        //for (i = 0; i < nVerts; i++)
        //    printf("%d\n", Ordered[i]);
        memcpy(order, Ordered, sizeof(int) * nVerts);

        // clean up
        free(Arc);
        free(DeltaCost);
        free(ArcCount);
        free(OutDegree);
        free(InDegree);
        free(ArcStart);
        free(Zero);
        free(Ordered);
        heap_destroy(Heap);

        return 1;
    }