Beispiel #1
0
/*
 *  p r i n t
 */
returnValue Bounds::print( )
{
    if ( n == 0 )
        return SUCCESSFUL_RETURN;

    #ifndef __SUPPRESSANYOUTPUT__

    char myPrintfString[MAX_STRING_LENGTH];

    int_t nFR = getNFR( );
    int_t nFX = getNFX( );

    int_t* FR_idx;
    getFree( )->getNumberArray( &FR_idx );

    int_t* FX_idx;
    getFixed( )->getNumberArray( &FX_idx );

    snprintf( myPrintfString,MAX_STRING_LENGTH,"Bounds object comprising %d variables (%d free, %d fixed):\n",(int)n,(int)nFR,(int)nFX );
    myPrintf( myPrintfString );

    REFER_NAMESPACE_QPOASES print( FR_idx,nFR,"free " );
    REFER_NAMESPACE_QPOASES print( FX_idx,nFX,"fixed" );

    #endif /* __SUPPRESSANYOUTPUT__ */

    return SUCCESSFUL_RETURN;
}
Beispiel #2
0
/*
 *	p r i n t
 */
returnValue Bounds::print( )
{
	if ( n == 0 )
		return SUCCESSFUL_RETURN;

	#ifndef __XPCTARGET__
	#ifndef __DSPACE__
	char myPrintfString[160];

	int nFR = getNFR( );
	int nFX = getNFX( );

	int* FR_idx;
	getFree( )->getNumberArray( &FR_idx );

	int* FX_idx;
	getFixed( )->getNumberArray( &FX_idx );

	snprintf( myPrintfString,160,"Bounds object comprising %d variables (%d free, %d fixed):\n",n,nFR,nFX );
	myPrintf( myPrintfString );

	REFER_NAMESPACE_QPOASES print( FR_idx,nFR,"free " );
	REFER_NAMESPACE_QPOASES print( FX_idx,nFX,"fixed" );

	#endif
	#endif

	return SUCCESSFUL_RETURN;
}
Beispiel #3
0
int _cache_write(int ata, char * msg, int numreads, unsigned int sector){
	int i = 0;
	int cached = 0;
	for( i=0; i<SECTORS; i++ ){
		if( sectors[i].used && sectors[i].index == sector ){
			sectors[i].dirty = 1;
			cached = 1;
			int j = 0;
			for( j=0; j<SECTOR_SIZE; j++ ){
				sectors[i].data[j] = msg[j];
			}
		}
	}
	if( !cached ){
		i = getFree();
		sectors[i].index = sector;
		int j = 0;
		for( j=0; j<SECTOR_SIZE; j++ ){
			sectors[i].data[j] = msg[j];
		}
	//	_disk_write( ata, sectors[i].data, 1, sector);
		sectors[i].used = 1;
		sectors[i].dirty = 1;

	}
	if( numreads == 1 ){
		return 1;
	}
	
	return _cache_write( ata, msg + SECTOR_SIZE, numreads-1, sector+1);
}
Beispiel #4
0
int _cache_read(int ata, char * ans, int numreads, unsigned int sector){
	int i = 0;
	int cached = 0;
	for( i=0; i<SECTORS; i++ ){
		if( sectors[i].used && sectors[i].index == sector ){
			cached = 1;
			int j = 0;
			for( j=0; j<SECTOR_SIZE; j++ ){
				ans[j] = sectors[i].data[j];
			}
		}
	}
	if( !cached ){
		i = getFree();
		sectors[i].index = sector;
		_disk_read( ata, sectors[i].data, 1, sector);
		sectors[i].used = 1;
		sectors[i].dirty = 0;
		int j = 0;
		for( j=0; j<SECTOR_SIZE; j++ ){
			ans[j] = sectors[i].data[j];
		}
	}
	if( numreads == 1 ){
		return 1;
	}
	
	return _cache_read( ata, ans + SECTOR_SIZE, numreads-1, sector+1);
}
void CImageBuffer::calc_sub(int index)
{
    if (image_list[index].sub[4] == 0)
        image_list[index].sub[4] = getFree();
    image_list[index].sub[4]->interH<1>(*image_list[index].sub[0]);

    if (image_list[index].sub[8] == 0)
        image_list[index].sub[8] = getFree();
    image_list[index].sub[8]->interH<2>(*image_list[index].sub[0]);

    if (image_list[index].sub[12] == 0)
        image_list[index].sub[12] = getFree();
    image_list[index].sub[12]->interH<3>(*image_list[index].sub[0]);

    for( int i = 0; i < 16; i += 4) {
        if (image_list[index].sub[i+1] == 0)
            image_list[index].sub[i+1] = getFree();
        image_list[index].sub[i+1]->interV<1>(*image_list[index].sub[i]);

        if (image_list[index].sub[i+2] == 0)
            image_list[index].sub[i+2] = getFree();
        image_list[index].sub[i+2]->interV<2>(*image_list[index].sub[i]);

        if (image_list[index].sub[i+3] == 0)
            image_list[index].sub[i+3] = getFree();
        image_list[index].sub[i+3]->interV<3>(*image_list[index].sub[i]);
    }

    for( int i = 0; i < 16; i++) {
        image_list[index].sub[i]->extend();
    }
}
Beispiel #6
0
        void* Page::find(size_t size, bool aloc)
        {
            //we cant fit it
            if (size >= m_freeSpace)
                return nullptr;
            //now get the next free slot which could fit it
            FreeType* l_prev = nullptr;
            auto l_freePtr = m_free;
            FreeType* l_ret = nullptr;
            while(true)
            {
                //return the position we we sure can fit it
                //without losing any chunks
                if (l_freePtr->getFree() > size + sizeof(FreeType))
                {
                    l_ret = l_freePtr;//safe the spot
                    break;
                }

                if(l_freePtr->getFree() == size)
                {
                    //if it exactly fit we also take the spot
                    l_ret = l_freePtr;
                    break;
                }

                if (l_freePtr->getNext() != 0)
                {
                    //else it does not fit and we need to go to the next

                    l_prev = l_freePtr;//set the previous
                    auto l_temp = RC(char*, l_freePtr);
                    l_temp += l_freePtr->getNext();
                    l_freePtr = RC(FreeType*, l_temp);
                    continue;
                }
                //if we get here we have no space for that!
                return nullptr;
            }
Beispiel #7
0
void mprof::CompactnessAnalysis::build( const struct MprofRecordAlloc * in_record, std::vector<size_t>::const_iterator in_orderBegin, std::vector<size_t>::const_iterator in_orderEnd ) {
    std::list<size_t> retryList;
    size_t lastIndex = *in_orderBegin;
    for( std::vector<size_t>::const_iterator orderItr = in_orderBegin; orderItr != in_orderEnd; ++orderItr ) {

        if( addRecord( in_record, *orderItr ) ) {
            lastIndex = *orderItr;

            //keep retrying--FIXME: handle realloc better( damn you realloc )
            bool progress;
            do {
                progress = false;
                for( std::list<size_t>::iterator retryItr = retryList.begin(); retryItr != retryList.end(); ) {
                    if( addRecord( in_record, *retryItr ) ) {
                        if( olderThan( in_record + *retryItr, in_record + lastIndex ) ) {
                            std::cerr << "Info: mprof::CompactnessAnalysis::build: detected scheduler/timestamp inversion at index '" << *orderItr << "' of " << deltaT( in_record + *retryItr, in_record + lastIndex ) << " microseconds" << std::endl;
                        }
                        lastIndex = *retryItr;
                        retryItr = retryList.erase( retryItr );
                        progress = true;
                    } else {
                        ++retryItr;
                    }
                }
            } while( progress );
        } else {
            if( in_record[ *orderItr ].header.mode == MPROF_MODE_REALLOC ) {
                //std::cerr << "Info: mprof::CompactnessAnalysis::build: realloc record at index '" << *orderItr << "' may have been paritally processed." << std::endl;
            }
            retryList.push_back( *orderItr );
        }
    }

    for( std::list<size_t>::iterator retryItr = retryList.begin(); retryItr != retryList.end(); retryItr = retryList.erase( retryItr ) ) {
        size_t address, size;
        if( getAlloc( in_record + *retryItr, address, size ) ) {
            std::cerr << "Warning: mprof::CompactnessAnalysis::build: found double alloc at index '" << *retryItr << "' for address '" << std::hex << address << std::dec << "'" << std::endl;
        }
        if( getFree( in_record + *retryItr, address ) ) {
            std::cerr << "Warning: mprof::CompactnessAnalysis::build: found unmatched free at index '" << *retryItr << "' for address '" << std::hex << address << std::dec << "'" << std::endl;
        }
    }
}
Beispiel #8
0
int main()
{
    struct master_table mastertable;

    //mark all of the entries in the master table as free
    for (int i = 0; i < 100; i++) {
        mastertable.mem[i].free = 1;
        mastertable.mem[i].base = i * 10;
    }
    srand(time(NULL));
    //initialize our semaphores to 1 and create their queues
    for (int i = 0; i < 10; i++) {
        SEM[i].count = 1;
        SEM[i].sem_queue = pQueueNew();
    }

    //initialize space for n pcbs
    struct pbrain_pcb *pcbMem = (struct pbrain_pcb *)malloc(NUM_PROCESSES * sizeof(struct pbrain_pcb));

    //as well as memory for the entire system (1000 words)
    memBase = (char *)malloc(NUM_PROCESSES * sizeof(char[100][6]));
    mainmem = (char *)malloc(1000 * sizeof(char[100][6]));
    //"zero" out all of the memory we allocated
    memset(memBase, '0', NUM_PROCESSES * sizeof(char[100][6]));
    memset(mainmem, '0', 1000 * sizeof(char[100][6]));

    //assign each process a unique PID
    for (int i = 0; i < NUM_PROCESSES; i++) {
        pcbMem[i].memory = (char (*)[100][6])memBase;
        //set each process's PID to i
        pcbMem[i].pid = i;

        //give the process a random timeslice between 1 and 10
        pcbMem[i].timeSlice = (rand() % 10) + 1;
        pcbMem[i].remaining_quantum = pcbMem[i].timeSlice;

        //load the program into pcb storage
        loadProgramToMem(i, memBase, i);
        
        //set the BAR to 100 * i
        char temp[5];
        sprintf(temp, "%04d", 100 * i);
        memcpy(pcbMem[i].BAR, temp, 4);

        //set the PC to 2 to skip the two parameters
        pcbMem[i].PC = 2;
        pcbMem[i].N = charToInt(pcbMem[i].memory[0][pcbBaseAddress(&pcbMem[i])], 6);
        pcbMem[i].memSize = charToInt(pcbMem[i].memory[0][pcbBaseAddress(&pcbMem[i]) + 1], 6);
        printf("Process %d: N = %d, size = %d\n", i, pcbMem[i].N, pcbMem[i].memSize);
        pcbMem[i].table = (struct page_table *)malloc(sizeof(struct page_table));
        pt_init(pcbMem[i].table);
        
        for (int j = 0; j < 10; j++) {    
            pcbMem[i].table->entries[j].valid = 1;
        }
    }

    struct pqueue *readyQueue = pQueueNew();
    struct pqueue *waitQueue = pQueueNew();

    //load processes into memory until we can't fit any more
    int currentLoaded = 0;
    while (currentLoaded != NUM_PROCESSES && canFit(&pcbMem[currentLoaded], &mastertable)) {
        printf("Process %d can fit (free pages: %d)\n", currentLoaded, freeCount(&mastertable));

        //set up the process's page table
        for (int i = 0; i < getPageSize(&pcbMem[currentLoaded]); i++) {
            struct master_entry *freeEntry = getFree(&mastertable);
            pcbMem[currentLoaded].table->entries[i].baseAddress = freeEntry->base;
            printf("Process %d: table entry %d base set to %d\n", pcbMem[currentLoaded].pid, i, freeEntry->base);
            freeEntry->free = 0;
        }

        for (int i = getPageSize(&pcbMem[currentLoaded]); i < 10; i++) {
            pcbMem[currentLoaded].table->entries[i].valid = 0;
            printf("Process %d: table entry %d set to invalid\n", pcbMem[currentLoaded].pid, i);
        }

        currentLoaded++;
    }
    //load all processes that were placed into memory in the ready queue

    for (int i = 0; i < currentLoaded; i++) {
        printf("Process %d is loaded into memory and placed on the ready queue\n", pcbMem[i].pid);
        pEnqueue(readyQueue, &pcbMem[i]);
    }

    while (currentLoaded != NUM_PROCESSES) {
        pEnqueue(waitQueue, &pcbMem[currentLoaded]);
        printf("Process %d couldn't fit in memory; placed in queue\n", pcbMem[currentLoaded].pid);
        currentLoaded++;
    }

    int numFinished = 0;
    struct pbrain_pcb *current = pDequeue(readyQueue);

    while (numFinished != NUM_PROCESSES) {
        //execute a step
        if (!current->halted) {
            updateEffectiveAddress(current);
            interpretStep(current);
            current->remaining_quantum--;
        }

        //if it made a system call
        if (current->trap) {
            current->trap = false;
            //the cases have braces around them because otherwise we'd have cases in protected scope
            switch (current->syscall) {
            case 0: {//getpid
                printf("Process %d called getpid\n", current->pid);
                current->R0 = current->pid;
                break;
            }

            case 1: { //wait
                int index = current->R0;

                if (index < 0 || index > 9) {
                    current->halted = true;
                    printf("Process %d: attempt to wait on invalid semaphore at index %d\n", current->pid, index);
                    break;
                }

                SEM[index].count--;

                if (SEM[index].count < 0) {
                    pEnqueue(SEM[index].sem_queue, current);
                    printf("Process %d: wait on semaphore %d\n", current->pid, index);
                    current->queueRemoved = true;
                    break;
                } else {
                    printf("Process %d: wait on semaphore %d; continues\n", current->pid, index);
                    break;
                }
                break;
            }

            case 2: { //signal
                int index = current->R0;

                if (index < 0 || index > 9) {
                    current->halted = true;
                    printf("Process %d: attempt to signal invalid semaphore at index %d\n", current->pid, index);
                    continue;
                }

                SEM[index].count++;

                if (SEM[index].count <= 0) {
                    printf("Process %d calls SIGNAL on semaphore %d; ", current->pid, index);
                    struct pbrain_pcb *blocked = pDequeue(SEM[index].sem_queue);
                    pEnqueue(readyQueue, blocked);
                    printf("; process %d was waiting for semaphore %d and moves to the ready queue\n", blocked->pid, index);
                    continue;
                } else {
                    printf("Process %d calls SIGNAL to release semaphore %d. No processes were waiting.\n", current->pid, index);
                    continue;
                }
            }
            } //end switch/case
        } //end if(current->trap)

        if (current->queueRemoved) {
            printf("Process %d is waiting and removed from ready queue\n", current->pid);
            current->queueRemoved = false;

            current = pDequeue(readyQueue);
            if (current == NULL) {
                printf("\nProcesses are deadlocked\n");
                exit(0);
                break;
            }

            printf("Process %d is now executing\n", current->pid);
            current->remaining_quantum = current->timeSlice;
        }

        //if it finished
        if (current->halted) {
            printf("Process %d halted\n", current->pid);
            numFinished++;
            //free the table entries used by that process
            freeEntries(current, &mastertable);
            //see if we can put another process in
            struct pbrain_pcb *potential = pDequeue(waitQueue);
            if (potential != NULL) {
                if (canFit(potential, &mastertable)) {
                    for (int i = 0; i < getPageSize(potential); i++) {
                        struct master_entry *freeEntry = getFree(&mastertable);
                        potential->table->entries[i].baseAddress = freeEntry->base;
                        printf("Process %d: table entry %d base set to %d\n", potential->pid, i, freeEntry->base);
                        freeEntry->free = 0;
                    }

                    for (int i = getPageSize(potential); i < 10; i++) {
                        potential->table->entries[i].valid = 0;
                        printf("Process %d: table entry %d set to invalid\n", potential->pid, i);
                    }

                    printf("Loaded process %d into memory and placed on ready queue\n", potential->pid);
                    pEnqueue(readyQueue, potential);
                } else {
                    pEnqueue(waitQueue, potential);
                }
            }
            struct pbrain_pcb *next = pDequeue(readyQueue);
            

            if (next != NULL) {
                current = next;
                current->remaining_quantum = current->timeSlice;
            }
        }

        if (current == NULL) {
            break; //there are no more processes if we reach this point and this is true
        }

        if (current->remaining_quantum == 0) {
            pEnqueue(readyQueue, current);
            current = pDequeue(readyQueue);

            if (current != NULL) {
                current->remaining_quantum = current->timeSlice;
                continue;
            } else {
                numFinished = NUM_PROCESSES;
            }
        }
    }

    writeMain(pcbMem);
/*
    for (int i = 0; i < NUM_PROCESSES; i++) {
        writeCPU(&pcbMem[i]);
        writeMem(&pcbMem[i]);
    }
*/
    return 0;
}
Beispiel #9
0
bool mprof::CompactnessAnalysis::addRecord( const struct MprofRecordAlloc * in_record, const size_t in_index ) {
    const struct MprofRecordAlloc * const record = in_record + in_index;
    uint64_t size;
    uint64_t address;

    std::map< uint64_t, std::list< std::pair<uint64_t, uint64_t> > >::iterator mapItr;

    bool ret = false;

    bool freed = false;

    do {

        if( getFree( record, address ) && address ) {
            mapItr = allocationMap.find( address );
            //detect out-of-order record
            if( mapItr == allocationMap.end() || mapItr->second.empty() || mapItr->second.back().second != nullIndex ) {
                //std::cerr << "delaying free @ " << std::hex << address << std::dec << " index " << in_index << std::endl;
                break;
            } else {
                mapItr->second.back().second = in_index;
                getAlloc( in_record + mapItr->second.back().first, address, size );
                //adjust client size
                clientSize -= size;

                //mark vmMap
                refPages( address, size, false );
                freed = true;
            }
        }
        if( getAlloc( record, address, size ) && address ) {
            mapItr = allocationMap.find( address );
            //detect out-of-order record
            if( mapItr == allocationMap.end() ) {
                allocationMap[ address ] = std::list< std::pair<uint64_t, uint64_t> >();
                mapItr = allocationMap.find( address );
            } else if( mapItr->second.back().second == nullIndex ) {
                //std::cerr << "delaying alloc @ " << std::hex << address << std::dec << " index " << in_index << std::endl;
                break;
            }
            mapItr->second.push_back( std::pair<uint64_t, uint64_t>( in_index, nullIndex ) );

            //adjust client size
            clientSize += size;
            if( clientSize > clientHighWaterMark ) {
                clientHighWaterMark = clientSize;
            }

            //mark vmMap
            refPages( address, size, true );
        }
        ret = true;
    } while( false );

    if( ret ) {
        setCompactness( clientSize );
    } else if( freed ) {
        //std::cerr << "correcting realloc " << in_index << std::endl;
        getFree( record, address );
        mapItr = allocationMap.find( address );

        mapItr->second.back().second = nullIndex;
        getAlloc( in_record + mapItr->second.back().first, address, size );
        //adjust client size
        clientSize += size;

        //mark vmMap
        refPages( address, size, true );
    }

    return ret;
}