Ejemplo n.º 1
0
Archivo: RR.c Proyecto: Reiuiji/ProcSim
int RR(PROCESS Proc[], SIMULATION *Sim)
{
  printf("/***********  Round-Robin Algorithm (time quantum 3)  ***********/\n");

  Sim->Schedule = "RR";

  RoundRobin(Proc,Sim, 3);
}
Ejemplo n.º 2
0
int TestMain () {
    for( int p=MinThread; p<=MaxThread; ++p ) {
        REMARK("testing with %d threads\n", p );
        CyclicCounter = 0;
        Quit = false;
        NativeParallelFor( long(p), RoundRobin(p) );
    }
    return Harness::Done;
}
Ejemplo n.º 3
0
void *FilePriorite ()
{
	for ( ; ; )
	{
		NbOrdonnancement = 0;
		
		// Si le premier processus n'a pas encore été soumis
		if (NbProc == 0)
		{
			usleep (100);
			continue;
		}
		
		// Applique round robin à la file la plus prioritaire non vide
		for (int i = 0; ; ++i)
		{
			if (1 == NouveauProc)
			{
				pthread_mutex_lock (&mutex);
				fprintf (SortieAffichage, "! Process(es) %sconsidered.\n", ListeNouveauProc);
				sprintf (ListeNouveauProc, "");
				NouveauProc = 0;
				pthread_mutex_unlock (&mutex);
				i = -1;
				continue;
			}

			int FileContientElement = 0;

			for (int j = 0; j < 256; ++j)
				if (NULL != ListePriorite [i][j])
					FileContientElement = 1;

			// Si la liste est non vide, on Round Robin
			if (FileContientElement)
			{
				RoundRobin (i);
				if (10 == NbOrdonnancement)
					break;

				// on remet à 0 au cas où l'on ait ajouté un proc dans RoundRobin
				i = -1;
			}

			if (4 == i)
				i = -1;

		}

		for (int i = 0; i < 5; ++i)
			CursFileAttente[i] = 0;

		fprintf(SortieAffichage, "\n...Calculating new priorities...\n\n");
		RecalculerPriorite ();
	}

} // FilePriorite ()
Ejemplo n.º 4
0
// Project Entry Point
// main
// no parameters taken
// expects input via STDIN (redirect or direct entry)
//  input shall conform to 3 integers per line, spaced with whitespace
void main()
{
	ProcessTable pTable;
	initializeTable(&pTable);
	
	//int j;
	//for (j=0; j<pTable.size; j++)
	//	printf("PID: %d\n", pTable.pid[j]);
	
	// do fcfs
	FirstCome(pTable);
	// do shortest job
	ShortestJob(pTable);
	// do shortest remaining job
	ShortestRemaining(pTable);
	// do round robin
	RoundRobin(pTable, 0);
	RoundRobin(pTable, 0.4);
}
Ejemplo n.º 5
0
int main( int argc, char* argv[] ) {
    // Set defaults
    MaxThread = MinThread = 3;
    ParseCommandLine( argc, argv );
    for( int p=MinThread; p<=MaxThread; ++p ) {
        if( Verbose ) printf("testing with %d threads\n", p );
        CyclicCounter = 0;
        Quit = false;
        NativeParallelFor( tbb::blocked_range<long>(0,p,1), RoundRobin(p) );
    }
    printf("done\n");
    return 0;
}
Ejemplo n.º 6
0
/*============================== PROCESSO =====================================*/
void *Processo(void *a) {
	int* id1 = (int*) a;
	int id = (*id1);

	if(numEscalonamento == 1 || numEscalonamento == 2) {
		FCFS_SJF(id, tabelaProcessos[id].dt, tabelaProcessos[id].deadline);
	}
	else if(numEscalonamento == 3) {
		SRTN(id, tabelaProcessos[id].deadline);
	}
	else if(numEscalonamento == 4) {
		RoundRobin(id, tabelaProcessos[id].deadline);
	}

	return NULL;
}
Ejemplo n.º 7
0
int main()
{
	char input[MAX_INPUT_LEN];
	int arrPid[MAX_INPUT_LEN];
	int arrArrival[MAX_INPUT_LEN];
	int arrService[MAX_INPUT_LEN];

	// Read data from stdin
	while(fgets(input, MAX_INPUT_LEN, stdin) != 0)
	{
		InputToArray(input, arrPid, arrArrival, arrService);
	}
	// Call function to print the 3 arrays
	FirstCome(arrPid, arrArrival, arrService, _pidIndex);
	ShortestJobFirst( arrPid, arrArrival, arrService, _pidIndex );
	ShortestNext(arrPid, arrArrival, arrService, _pidIndex);
	RoundRobin( arrPid, arrArrival, arrService, _pidIndex );
	return 0;
}
Ejemplo n.º 8
0
//MAIN/////////////////////////////////////////////////////////
int main(){

	//init globals
	init();

	//read file and store into queues
	read_and_store();

	//based off of alg.name, determine which functino to call
	if(alg.name.compare("PR_noPREMP") == 0) PriorityNoPre(); 
	else if(alg.name.compare("PR_withPREMP") == 0) PriorityWithPre(); 
	else if(alg.name.compare("RR") == 0) RoundRobin(); 
	else if(alg.name.compare("SJF") == 0) ShortestJobFirst(); 
	else std::cout << "ERROR: algorithm name not recognized" << std::endl; 
	
	in.close();
	out.close();

	return 0;
}
HARNESS_EXPORT
int main(int argc, char* argv[]) {
    argC=argc;
    argV=argv;
    MaxThread = MinThread = 1;
    Tmalloc=scalable_malloc;
    Trealloc=scalable_realloc;
    Tcalloc=scalable_calloc;
    Tfree=scalable_free;
    Rposix_memalign=scalable_posix_memalign;
    Raligned_malloc=scalable_aligned_malloc;
    Raligned_realloc=scalable_aligned_realloc;
    Taligned_free=scalable_aligned_free;

    // check if we were called to test standard behavior
    for (int i=1; i< argc; i++) {
        if (strcmp((char*)*(argv+i),"-s")==0)
        {
            setSystemAllocs();
            argC--;
            break;
        }
    }

    ParseCommandLine( argC, argV );
#if __linux__
    /* According to man pthreads
       "NPTL threads do not share resource limits (fixed in kernel 2.6.10)".
       Use per-threads limits for affected systems.
     */
    if ( LinuxKernelVersion() < 2*1000000 + 6*1000 + 10)
        perProcessLimits = false;
#endif
    //-------------------------------------
#if __APPLE__
    /* Skip due to lack of memory limit enforcing under OS X*. */
#else
    limitMem(200);
    ReallocParam();
    limitMem(0);
#endif

//for linux and dynamic runtime errno is used to check allocator functions
//check if library compiled with /MD(d) and we can use errno
#if _MSC_VER
#if defined(_MT) && defined(_DLL) //check errno if test itself compiled with /MD(d) only
    char*  version_info_block = NULL;
    int version_info_block_size;
    LPVOID comments_block = NULL;
    UINT comments_block_size;
#ifdef _DEBUG
#define __TBBMALLOCDLL "tbbmalloc_debug.dll"
#else  //_DEBUG
#define __TBBMALLOCDLL "tbbmalloc.dll"
#endif //_DEBUG
    version_info_block_size = GetFileVersionInfoSize( __TBBMALLOCDLL, (LPDWORD)&version_info_block_size );
    if( version_info_block_size
        && ((version_info_block = (char*)malloc(version_info_block_size)) != NULL)
        && GetFileVersionInfo(  __TBBMALLOCDLL, NULL, version_info_block_size, version_info_block )
        && VerQueryValue( version_info_block, "\\StringFileInfo\\000004b0\\Comments", &comments_block, &comments_block_size )
        && strstr( (char*)comments_block, "/MD" )
        ){
            __tbb_test_errno = true;
     }
     if( version_info_block ) free( version_info_block );
#endif // defined(_MT) && defined(_DLL)
#else  // _MSC_VER
    __tbb_test_errno = true;
#endif // _MSC_VER

    for( int p=MaxThread; p>=MinThread; --p ) {
        REMARK("testing with %d threads\n", p );
        Harness::SpinBarrier *barrier = new Harness::SpinBarrier(p);
        NativeParallelFor( p, RoundRobin(p, barrier, Verbose) );
        delete barrier;
    }
    if( !error_occurred )
        REPORT("done\n");
    return 0;
}
Ejemplo n.º 10
0
HARNESS_EXPORT
int main(int argc, char* argv[]) {
    argC=argc;
    argV=argv;
    MaxThread = MinThread = 1;
    Rmalloc=scalable_malloc;
    Rrealloc=scalable_realloc;
    Rcalloc=scalable_calloc;
    Tfree=scalable_free;
    Rposix_memalign=scalable_posix_memalign;
    Raligned_malloc=scalable_aligned_malloc;
    Raligned_realloc=scalable_aligned_realloc;
    Taligned_free=scalable_aligned_free;

    // check if we were called to test standard behavior
    for (int i=1; i< argc; i++) {
        if (strcmp((char*)*(argv+i),"-s")==0)
        {
#if __INTEL_COMPILER == 1400 && __linux__
            // Workaround for Intel(R) C++ Compiler XE, version 14.0.0.080:
            // unable to call setSystemAllocs() in such configuration.
            REPORT("Known issue: Standard allocator testing is not supported.\n");
            REPORT( "skip\n" );
            return 0;
#else
            setSystemAllocs();
            argC--;
            break;
#endif
        }
    }

    ParseCommandLine( argC, argV );
#if __linux__
    /* According to man pthreads
       "NPTL threads do not share resource limits (fixed in kernel 2.6.10)".
       Use per-threads limits for affected systems.
     */
    if ( LinuxKernelVersion() < 2*1000000 + 6*1000 + 10)
        perProcessLimits = false;
#endif
    //-------------------------------------
#if __APPLE__
    /* Skip due to lack of memory limit enforcing under macOS. */
#else
    limitMem(200);
    ReallocParam();
    limitMem(0);
#endif

//for linux and dynamic runtime errno is used to check allocator functions
//check if library compiled with /MD(d) and we can use errno
#if _MSC_VER
#if defined(_MT) && defined(_DLL) //check errno if test itself compiled with /MD(d) only
    char*  version_info_block = NULL;
    int version_info_block_size;
    LPVOID comments_block = NULL;
    UINT comments_block_size;
#ifdef _DEBUG
#define __TBBMALLOCDLL "tbbmalloc_debug.dll"
#else  //_DEBUG
#define __TBBMALLOCDLL "tbbmalloc.dll"
#endif //_DEBUG
    version_info_block_size = GetFileVersionInfoSize( __TBBMALLOCDLL, (LPDWORD)&version_info_block_size );
    if( version_info_block_size
        && ((version_info_block = (char*)malloc(version_info_block_size)) != NULL)
        && GetFileVersionInfo(  __TBBMALLOCDLL, NULL, version_info_block_size, version_info_block )
        && VerQueryValue( version_info_block, "\\StringFileInfo\\000004b0\\Comments", &comments_block, &comments_block_size )
        && strstr( (char*)comments_block, "/MD" )
        ){
            __tbb_test_errno = true;
     }
     if( version_info_block ) free( version_info_block );
#endif // defined(_MT) && defined(_DLL)
#else  // _MSC_VER
    __tbb_test_errno = true;
#endif // _MSC_VER

    CheckArgumentsOverflow();
    CheckReallocLeak();
    for( int p=MaxThread; p>=MinThread; --p ) {
        REMARK("testing with %d threads\n", p );
        for (int limit=0; limit<2; limit++) {
            int ret = scalable_allocation_mode(TBBMALLOC_SET_SOFT_HEAP_LIMIT,
                                               16*1024*limit);
            ASSERT(ret==TBBMALLOC_OK, NULL);
            Harness::SpinBarrier *barrier = new Harness::SpinBarrier(p);
            NativeParallelFor( p, RoundRobin(p, barrier, Verbose) );
            delete barrier;
        }
    }
    int ret = scalable_allocation_mode(TBBMALLOC_SET_SOFT_HEAP_LIMIT, 0);
    ASSERT(ret==TBBMALLOC_OK, NULL);
    if( !error_occurred )
        REPORT("done\n");
    return 0;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[]) {
	int tempo_total = 0, shmID_1, shmID_2, status;
	float tempo_medio = 0;
	long pid_filho1, pid_filho2;
	key_t key_1 = 567194, key_2 = 567192;

	
	input = fopen(argv[2], "r");
	n_processos = tamanho_alloc();			//numero de processos a serem simulados
	fclose(input);
		
	
	//compartilhar tarefa e instante entre os processos
	instante = (int*) malloc (sizeof(int));
	shmID_2 = shmget(key_2, sizeof(int), IPC_CREAT | 0666);
	instante = shmat(shmID_2, NULL, 0);
	*instante = 0;
	
	tarefas_input = criar_tarefas(tarefas_input, n_processos);		//armazena entrada do arquivo

	tarefa = (Tarefa*) malloc(sizeof(Tarefa));
	if ( (shmID_1 = shmget(key_1, sizeof(Tarefa), IPC_CREAT | 0666)) < 0 ){
		perror("shmget error");
		exit(1);
	}
	if( (tarefa = shmat(shmID_1, NULL, 0)) == (Tarefa*) -1){
		perror("shmat error");
		exit(1);
	}
	
	
	
	mutex  = mmap(NULL,sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
	mutex2 = mmap(NULL,sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
	
	if(!mutex || !mutex2)
		perror("mmap error");
		
		
	//iniciados em 0 e 1
	sem_init(mutex, 1, 0);
	sem_init(mutex2, 1, 1);
	
	
	pid_filho2 = fork();
	if(pid_filho2 != 0){
		pid_filho1 = fork();
		wait(&status);
	}
	
	
	//processo CPU
	 if(pid_filho1 == 0){
		fprintf(stderr, "[Processo CPU]...\n");
		 int i;
		 tarefas_output = (Tarefa*) calloc(n_processos, sizeof(Tarefa));
		 for(i=0; i < n_processos; i++){
			tarefas_output[i].dados[0] = i;
			tarefas_output[i].dados[1] = -1;
		}
		 while(1){
			 fprintf(stderr, "[Processo CPU] Tempo: %d\n", tempo_total);
			 sem_wait(mutex);
			 if(tarefa==NULL){
				 fprintf(stderr, "Tarefa null no instante %d\n", *instante);
				break;
			}
			 fprintf(stderr, "[Processo CPU] Executando Tarefa {%d;%d;%d;%d,%d}...\n", tarefa->dados[0], tarefa->dados[1], tarefa->dados[2], tarefa->dados[3], tarefa->dados[4]);
			 sleep(QUANTUM);
			 tarefa->dados[2] -= QUANTUM;		//tempo restante de execucao
			
			 tempo_total += QUANTUM;
			
			 if(tarefas_output[ tarefa->dados[0] ].dados[1] == -1)
				 tarefas_output[ tarefa->dados[0] ].dados[1] = (*instante);
			 else
			 	tarefas_output[ tarefa->dados[0] ].dados[2] += QUANTUM;
			
			 sem_post(mutex2);
		 }
		 
		 //salvar saida
		 output = fopen(argv[3], "w");
		 for(i=0; i < n_processos; i++)
			fprintf(stderr, "%d;%d;%d;\n", tarefas_output[i].dados[0], tarefas_output[i].dados[1], tarefas_output[i].dados[2]);
			//output 
		 fprintf(stderr, "Tempo Total: %d\nTempo medio: %f", tempo_total, tempo_medio);
		 fclose(output);
		 exit(0);
		 
	 }
	 
	 
	 //processo escalonador
	 if(pid_filho2 == 0){
		 fprintf(stderr, "\n[Processo Escalonador]...\n");
		 input = fopen(argv[2], "r");
			 			
		 lerEntradasArquivo();
		 
		 //fprinTest(tarefas_input);
			 
				 
		 if(!strcmp(argv[1], "FCFS"))
			 FirstComeFirstServed();
		 else if(!strcmp(argv[1], "RR"))
			 RoundRobin();
		 else if(!strcmp(argv[1], "SJF"))
			 ShortestJobFirst();

		 fclose(input);
		 exit(0);
	 }
	 
	 
	 sem_destroy(mutex);
	munmap(mutex, sizeof(sem_t));
	sem_destroy(mutex2);
	munmap(mutex2, sizeof(sem_t));

		

	
	return EXIT_SUCCESS;
}
Ejemplo n.º 12
0
int main (int argc, const char * argv[]) {

    FILE   *fp;                                  /* Pointer to the file */
    int    quantum = 0;                /* Quantum value for Round Robin */
    int    parameters[NUMVAL];        /* Process parameters in the line */
    int    i;                    /* Number of parameters in the process */
    
    /* Check if the parameters in the main function are not empty */
    if (argc < NUMPARAMS){
        printf("Need a file with the process information\n\n");
        printf("Abnormal termination\n");
        return (EXIT_FAILURE);
    }
    else {
        
        /* Open the file and check that it exists */
        fp = fopen (argv[1],"r");       /* Open file for read operation */
        if (!fp)                            /* The file does not exists */
            ErrorMsg("'main'","Filename does not exist or is corrupted\n");
        
        else {
            
            /* The first number in the file is the quantum */
            quantum = GetInt(fp);
        
            if (quantum == EXIT_FAILURE)
                ErrorMsg("'main'","The quantum was not found");
            
            else {
                /* Read the process information until the end of file 
                is reached */
                while (!feof(fp)){
                    
                    /* For every four parameters create a new process */
                    for (i = 0; ((i < NUMVAL) && (!feof(fp))); i++) {
                        parameters[i] = GetInt(fp);
                    }
                    
                    /* Do we have only four parameters? */
                    if (i == NUMVAL) {
                        
                        /* Create a new process with its information */
                        CreateProcessList(parameters[0], parameters[1], parameters[2], parameters[3]);
                    }
                }
                
                /* Start by sorting the processes by arrival time */
                SortProcessList(ARRIVALTIME);
                
                /* Apply all the scheduling algorithms and print the results */
                 FirstComeFS();
                 NonPreemptive(CPUBURST);
                 NonPreemptive(PRIORITY);
                 Preemptive(CPUBURST);
                 Preemptive(PRIORITY);
                 RoundRobin(quantum);
                
            }
        }
        
    }
}
Ejemplo n.º 13
0
int main(void)
{
    int preemtive(int line_number,struct proc process[MAXPROC]);
    int nonpreemtive(int line_number,struct proc process[MAXPROC]);
    int FCFS(int line_number,struct proc process[MAXPROC]);
    int RoundRobin(int line_number,struct proc process[MAXPROC]);
    int choice;
    int loop=4;
    while(1)
    {
        int i;
        for(i=0; i<MAXSIZE; i++)
            q[i]=-2;
        char *inname = "test.txt";
        FILE *infile;
        char line_buffer[50][BUFSIZ]; /* BUFSIZ is defined if you include stdio.h */
        int length;

        infile = fopen(inname, "r");
        if (!infile)
        {
            printf("Couldn't open file %s for reading.\n", inname);
            return 0;
        }
        char space=' ';
        printf("Opened file %s for reading.\n", inname);

        line_number = 0;
        struct proc process[MAXPROC];
        while (fgets(line_buffer[line_number], sizeof(line_buffer[line_number]), infile))
        {


            /* note that the newline is in the buffer */
            length = strlen(line_buffer[line_number]);
            if (line_buffer[line_number][length - 1] == '\n')
                line_buffer[line_number][length - 1] = '\0';
            printf("%4d: %s\n", line_number, line_buffer[line_number]);
            int i=0;
            int c=0;

            {
                /* data */
            };
            int ar=0;
            while(1)
            {
                if(i==length)
                    break;
                if(line_buffer[line_number][i]==space && ar==1)
                {
                    process[line_number].cpu[c]=atoi(&line_buffer[line_number][i+1]);
                    c++;
                }
                if(line_buffer[line_number][i]==space && ar==0)
                {
                    process[line_number].arrival=atoi(&line_buffer[line_number][i+1]);
                    ar=1;
                }
                i++;
            }
            process[line_number].max=c;
            process[line_number].pointer=0;
            process[line_number].number=atoi(&line_buffer[line_number][0]);
            process[line_number].cpuf=true;

            ++line_number;
        }
        fclose(infile);
        printf("1. Pre-emptive\n");
        printf("2. Non-emptive\n");
        printf("3. FCFS\n");
        printf("4. Round Robin\n");
        printf("5. To exit\n");
        scanf("%d",&choice);
        switch(choice)
        {
        case 1:
            preemtive(line_number,process);
            break;
        case 2:
            nonpreemtive(line_number,process);
            break;
        case 3:
            FCFS(line_number,process);
            break;
        case 4:
            RoundRobin(line_number,process);
            break;
        case 5:
            return 0;
        default:
            printf("Wrong Choice\n");
        }
    }
    printf("\nTotal number of lines = %d\n", line_number);

    return 0;
}
Ejemplo n.º 14
0
int main(){
	Queue *ready_queue;
	Queue *FCFS_queue, *RR_queue, *MRR_queue, *MHRR_queue;
	Queue *FCFS_pool, *RR_pool, *MRR_pool, *MHRR_pool;
	ready_queue = createQueue(MAX_SIZE_QUEUE);

	createJobPool();
	int i = 0;
	FILE *f;
	f = fopen("job_pool.txt", "r");

	// Copy the job pool data into another queue for each scheduling
    	// method and copy the queue of elements into another queue for
    	// each scheduling method
	printf("%s\n", "Generating jobs.");
    	FCFS_pool = createQueue(JOB_POOL_SIZE);
    	RR_pool = createQueue(JOB_POOL_SIZE);
    	MRR_pool = createQueue(JOB_POOL_SIZE);
    	MHRR_pool = createQueue(JOB_POOL_SIZE);

    	FCFS_queue = createQueue(MAX_SIZE_QUEUE);
    	RR_queue = createQueue(MAX_SIZE_QUEUE);
    	MRR_queue = createQueue(MAX_SIZE_QUEUE);
    	MHRR_queue = createQueue(MAX_SIZE_QUEUE);

    	for (i = 0; i < JOB_POOL_SIZE; i++){
    	    int quanta;
    	    fscanf(f, "%i", &quanta);
    	    enqueue(FCFS_pool, quanta);
    	    enqueue(RR_pool, quanta);
    	    enqueue(MRR_pool, quanta);
    	    enqueue(MHRR_pool, quanta);
    	}
	
    	// Transfer jobs to reach the steady state.
	printf("%s\n", "Transferring elements to reach the steady state.");
    	transfer(FCFS_queue, FCFS_pool, STEADY_STATE);
    	transfer(RR_queue, RR_pool, STEADY_STATE);
    	transfer(MRR_queue, MRR_pool, STEADY_STATE);
    	transfer(MHRR_queue, MHRR_pool, STEADY_STATE);
	
	srand(time(NULL));
	
    	// Now run each of the processes on the same exact data
	printf("%s\n", "Starting FCFS.");
    	FCFS(FCFS_queue, FCFS_pool);
	printf("%s\n", "Starting Round Robin");
    	RoundRobin(RR_queue, RR_pool);
	printf("%s\n", "Starting Modified Round Robin");
    	ModifiedRoundRobin(MRR_queue, MRR_pool);
	printf("%s\n", "Modified Half Round Robin");
    	ModifiedHalfedRoundRobin(MHRR_queue, MHRR_pool);

	printf("%s\n", "Freeing allocated memory.");
	// Free all allocated memory
	free(ready_queue);
	free(FCFS_queue);
	free(RR_queue);
	free(MRR_queue);
	free(MHRR_queue);
	free(FCFS_pool);
	free(RR_pool);
	free(MRR_pool);
	free(MHRR_pool);
	
	return 0;
}