Пример #1
0
int main(int argc, char ** argv)
{
	struct sched_param sp; /* Priorytet procesu */

	/* Zainicjuj obiekty. Ponieważ jest to pierwsze użycie - wykonają sie wszystkie funcje malloc i pliki zostaną otwarte */
	struct controller_t * c = new_controller();
	struct msg_t * msg = new_msg();
	struct io_t * io = new_io();

	/* Ustawianie parametrów planisty */
	sp.sched_priority = MY_PRIORITY;
	if (sched_setscheduler(0, SCHED_FIFO, &sp) == -1)
        {
                log("sched_setscheduler() failed");
        }

	/* Blokowanie pamięci procesu */
	if (mlockall( MCL_CURRENT|MCL_FUTURE ) == -1)
	{
		log("mlockall() failed");
	}

	while (1)
	{
		/* Wykonaj krok automatu */
		do_fsm_step();
	}
	return 0;
}
Пример #2
0
errcode_t write_quota_inode(quota_ctx_t qctx, int qtype)
{
	int		retval, i;
	unsigned long	qf_inums[MAXQUOTAS];
	struct dquot	*dquot;
	dict_t		*dict;
	ext2_filsys	fs;
	struct quota_handle *h;
	int		fmt = QFMT_VFS_V1;

	if (!qctx)
		return;

	fs = qctx->fs;
	h = smalloc(sizeof(struct quota_handle));
	ext2fs_read_bitmaps(fs);

	for (i = 0; i < MAXQUOTAS; i++) {
		if ((qtype != -1) && (i != qtype))
			continue;

		dict = qctx->quota_dict[i];
		if (!dict)
			continue;

		retval = new_io(h, fs, i, fmt);
		if (retval < 0) {
			log_err("Cannot initialize io on quotafile", "");
			continue;
		}

		write_dquots(dict, h);
		retval = end_io(h);
		if (retval < 0) {
			log_err("Cannot finish IO on new quotafile: %s",
				strerror(errno));
			if (h->qh_qf.e2_file)
				ext2fs_file_close(h->qh_qf.e2_file);
			truncate_quota_inode(fs, h->qh_qf.ino);
			continue;
		}

		/* Set quota inode numbers in superblock. */
		set_sb_quota_inum(fs, h->qh_qf.ino, i);
		ext2fs_mark_super_dirty(fs);
		ext2fs_mark_bb_dirty(fs);
		fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
	}

	ext2fs_write_bitmaps(fs);
out:
	free(h);
	return retval;
}
Пример #3
0
int main(int argc, char *argv[])
{
	int time = 10; /* cpu time */
	int t = 0; /* time interval */
	
	READY_QUEUE rq;
	QUEUE wq, oq;
	
	init_q(&wq);
	init_q(&oq);
	init_rq(&rq);

	struct run_task rt;
	rt.status = IDLE;
	rt.set = FALSE;
	rt.rproc = NULL;

	TASK *arr_prog;
	arr_prog = read_prog();

	int t1, t2, t3;
	while(TRUE){
	
		t1 = nex_arr_prog(arr_prog, time);
		t2 = nex_tslice(&rt);
		t3 = next_io(&wq);
		
		assert(t1 >= 0);
		assert(t2 >= 0);
		assert(t3 >= 0);
		t = min(t1, t2, t3);
		
		time += t;
		
		if(rt.status == RUNNING)
			update_run_task(&rt, t);
		update_io_time(&wq, t);
		
		/* after 1ms switch out, put the running process into correct queue */
		if(!rt.set && rt.status == SWITCH_OUT)
			settle_proc(&rt, &rq, &oq, time);

		if(rt.status == IDLE || rt.status == SWITCH_OUT){
			// put process on CPU cost 1 ms
			if(sched_compl_io(&wq))
				handle_compl_io(&rq, &wq, &oq, time);
			while(sched_new_prog(arr_prog, time)){
				push_rq(&rq, arr_prog);
				arr_prog = read_prog();
			}
			
			time += MIN_T;
			update_io_time(&wq, MIN_T);
		
			if(!put_proc_on_cpu(&rt, &rq)){
				rt.status = IDLE;
				if(!peek(&wq) && !arr_prog)
					break;
			}
		}
	
		if(sched_take_out_proc(&rt, &wq, arr_prog, time))
			take_out_proc(&rt);
	
		if(sched_compl_io(&wq))
			handle_compl_io(&rq, &wq, &oq, time);
	
		if(sched_nex_io(&rt))
			new_io(&wq, &rt);
		
		while(sched_new_prog(arr_prog, time)){
			push_rq(&rq, arr_prog);
			arr_prog = read_prog();
		}

	}

	printf("Current Time: %d\n", time);
	TASK *last;
	int num = 0;
	long tot_compl_time = 0;
	int min_compl_time = INF;
	int max_compl_time = 0;
	int tot_cpu_time = 0;
	int tmp_time = 0;
	while(len(&oq)){
		last = dequeue(&oq);
		assert(last->c_io <= 0);
		num++;
		tmp_time = last->t_finish - last->t_arrive;	
		assert(tmp_time > 0);
		tot_compl_time += tmp_time;
		if(tmp_time < min_compl_time)
			min_compl_time = tmp_time;
		if(tmp_time > max_compl_time)
			max_compl_time = tmp_time;
		tot_cpu_time += last->t_exec;
//		printf("Prog Name: %s\n", last->cmd);
//		printf("Finish Time: %d\n", last->t_finish);
	}
	printf("ACT = %f\n", ((double)tot_compl_time) / num);
	printf("Min = %d\n", min_compl_time);
	printf("Max = %d\n", max_compl_time);
	printf("Throughput = %f\n", num / ((double)(time / 1000)));
	printf("Utilization = %f\n",((double)tot_cpu_time) / time); 

	return 1;
}