コード例 #1
0
ファイル: tcpip_main.c プロジェクト: yeonsh/Amoeba
void tcpipinit()
{
	prog_name= "kernel TCP/IP";

	mu_init(&mu_generic);
	mu_lock(&mu_generic);

	tcpip_dirinit();

	sr_init_cap_names();
	sr_set_cap_name(ETH_DEV0, "eth");
	sr_set_cap_name(IP_DEV0, "ip");
	sr_set_cap_name(TCP_DEV0, "tcp");
	sr_set_cap_name(UDP_DEV0, "udp");
#if 0
	sr_enable_linger_right();
#endif

	bf_init();
	clck_init();
	sr_init();
	eth_init();
	arp_init();
	ip_init();
	tcp_init();
	udp_init();
	add_default_gws();

	mu_unlock(&mu_generic);
	tcpip_chmod();
}
コード例 #2
0
ファイル: thread.c プロジェクト: yeonsh/Amoeba
static int
thread_doinit()
{
    struct thread_data *td;

    if (thread_initialized)
	return 1;
    mu_lock(&thread_crit);
    if (!thread_initialized)
    {
	td = (struct thread_data *) calloc(sizeof(struct thread_data), 1);
	if (td == NULL) {
	    mu_unlock(&thread_crit);
	    return 0;
	}
	td->td_tab[THREAD_STACK].m_data = (char *) td;
	td->td_tab[THREAD_STACK].m_size = sizeof(struct thread_data);
	_main_local = td;
	thread_initialized = 1;
    }
    mu_unlock(&thread_crit);
    return 1;
}
コード例 #3
0
ファイル: sp_buf.c プロジェクト: yeonsh/Amoeba
union sp_buf *
sp_getbuf()
{
    union sp_buf *buf;

    mu_lock(&sp_buf_mu);
    if (sp_buf_list == NULL) {	/* try to allocate new one */
	buf = (union sp_buf *) malloc(sizeof(union sp_buf));
    } else {			/* reuse previous one */
	buf = sp_buf_list;
	sp_buf_list = sp_buf_list->sp_buf_next;
    }
    mu_unlock(&sp_buf_mu);

    return buf;
}
コード例 #4
0
ファイル: act.c プロジェクト: yeonsh/Amoeba
/*
 *	Return a fresh and locked slot in objs
 */
int
new_obj()
{
    int n;

    for (n = 0; n < MAX_OBJ; ++n) {
	if (!obj_in_use(&objs[n])) {
	    /* Lock it */
	    mu_lock(&objs[n].or_lock);
	    if (!obj_in_use(&objs[n])) {
		(void) memset((_VOIDSTAR) &objs[n].or, 0, sizeof(objs[n].or));
		objs[n].or.or_nextpoll = objs[n].or.or_nextboot = my_gettime();
		return n;
	    }
	    mu_unlock(&objs[n].or_lock);
	}
    }
    MON_EVENT("No free slot in objs[]");
    return -1;
} /* new_obj */
コード例 #5
0
ファイル: bullet_init.c プロジェクト: yeonsh/Amoeba
void
super_free() {
	mu_unlock(&SuperLock) ;
}
コード例 #6
0
ファイル: PNF_orig.hpp プロジェクト: shambakey1/rstm_r5
	virtual void onTransactionCommitted() {
		try{
                    if(param.sched_priority!=PNF_M_PRIO){
                        //increase priority of current thread before locking
                        param.sched_priority=PNF_M_PRIO;
                        sched_setparam(0,&param);
                    }
                    /******************** Debug 3 start **********************/                    
/*
                    clock_gettime(CLOCK_REALTIME, &rec_time);
                    sched_getparam(0, &param);
                    rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "startTxCommitted" << endl;
                    rec.push_back(rec_in.str());
                    rec_in.str("");                    
*/
                    /******************** Debug 3 end **********************/
			//pthread_mutex_lock(&m_set_mutx);
                        mu_lock();
                        if(cur_state!=executing){
                            //current Tx is committing while retrying or checking (it happens
                            //because no other transaction conflicts with it). Current Tx is in 
                            //n_set. Remove it from there
                            n_set.erase(n_set.begin()+nSetPos((void*) this));
                        }
                        else{
                            //Remove accessed objects from m_set
			int acc_obj_size=acc_obj.size();
			int m_set_objs_size=m_set_objs.size();
			for(int j=0;j<acc_obj_size;j++){
				for(int i=0;i<m_set_objs_size;i++){
					if(acc_obj[j]==m_set_objs[i]){
						m_set_objs.erase(m_set_objs.begin()+i);
						m_set_objs_size--;
						break;
					}
				}
			}
                        }
                        
		//Change state of highest priority transaction to "checking" (if it exists), and increase its priority to "RUN_PRIO"
		//So, if processors available, n_set[0] can check itself against m_set.
		//Sequentially, following transactions in n_set can check conflict with m_set in their order in n_set
			if(!n_set.empty()){
				((PNF*)(n_set[(unsigned int) 0]))->cur_state=checking;
			//Increasing priority to "RUN_PRIO" is important. If n_set[0] has a lower priority than other executing tasks
			//then no processor is available to n_set[0]. Otherwise, n_set[0] can preempt the lowest priority thread
			//(lower than Tx itself) if all processors are occupied
				//pthread_setschedprio(*(((PNF*)(n_set[(unsigned int) 0]))->th), RUN_PRIO);
                                param_tmp.sched_priority=PNF_M_PRIO;
                                sched_setparam(((PNF*)(n_set[(unsigned int) 0]))->th, &param_tmp);
                                /******************** Debug 3 start **********************/                           
/*
                                clock_gettime(CLOCK_REALTIME, &rec_time);
                                //pthread_getschedparam((*th), &policy, &param);
                                sched_getparam(0,&param);
                                rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "increase " << (((PNF*)(n_set[(unsigned int) 0]))->th) << " to RUN_PRIO" << endl;
                                rec.push_back(rec_in.str());
                                rec_in.str("");                                 
*/
                                /******************** Debug 3 end **********************/
			}
                        /******************** Debug 3 start **********************/                        
/*
                        clock_gettime(CLOCK_REALTIME, &rec_time);
                        sched_getparam(0, &param);
                        rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "endTxCommitted" << endl;
                        rec.push_back(rec_in.str());
                        rec_in.str(""); 
                        rec_in<<"abort\t"<<total_abort_duration<<endl;
                        rec.push_back(rec_in.str());
                        rec_in.str("");
			//rec_final=rec;
			//rec=vector<string> ();
*/
                        /******************** Debug 3 end **********************/
                        //pthread_mutex_unlock(&m_set_mutx);
                        //Restore default values for m_set and cur_state. Otherwise, the next Tx
                        //will go on with the last values for these variables
			m_set=false;
			cur_state=released;
                        mu_unlock();
                        //Reduce priority of current task to RUN_PRIO because Tx finished
			//pthread_setschedprio(*th,RUN_PRIO);
		}catch(exception e){
			cout << "onTransactionCommitted exception: " << e.what() << endl;
		}
	}
コード例 #7
0
ファイル: PNF_orig.hpp プロジェクト: shambakey1/rstm_r5
	virtual void onBeginTransaction() {
	  try{
                /******************** Debug 3 start **********************/              
/*  
                clock_gettime(CLOCK_REALTIME, &rec_time);
                sched_getparam(0, &param);
                rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "startBeginTx" << endl;
                rec.push_back(rec_in.str());
                rec_in.str("");              
*/
                /******************** Debug 3 end **********************/
		clock_gettime(CLOCK_REALTIME, &stamp);
		if(cur_state==released){
			//Tx newely released
                    param.sched_priority=PNF_M_PRIO;
                    sched_setparam(0,&param);	//Increase priority until checking m
                    /********************* Debug 4 start *****************/
/*
                    rec_in.str("");
                    clock_gettime(CLOCK_REALTIME, &rec_time);
                    sched_getparam(0, &param);
                    rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "released" << endl;
                    rec.push_back(rec_in.str());
                    rec_in.str("");
*/
		    /******************* Debug 4 end ********************************/
                    //pthread_mutex_lock(&m_set_mutx);
                    mu_lock();
                    bool checkMset_st=checkMset(-1);        //-1 is a dummy variable
                    //pthread_mutex_unlock(&m_set_mutx);
                    mu_unlock();
                    if(!checkMset_st){
                        //Tx added to n_set. Reduce priority to lowest value
                        //If Tx becomes executing tx, then leave its priority at PNF_M_PRIO
                        //pthread_setschedprio(*th, PNF_N_PRIO);
                        param.sched_priority=PNF_N_PRIO;
                        sched_setparam(0,&param);
                    }
		}
		else if(cur_state==checking){
			//Tx is in n_set. But an executing tx finished. So, Tx is checking m_set again
			//pthread_setschedprio(*th, PNF_M_PRIO);	//Increase priority until checking m
			if(param.sched_priority!=PNF_M_PRIO){
				//increase priority of current thread before locking
				param.sched_priority=PNF_M_PRIO;
				sched_setparam(0,&param);
			}
                        /********************* Debug 4 start *****************/
/*
                        clock_gettime(CLOCK_REALTIME, &rec_time);
                        sched_getparam(0, &param);
                        rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "checking" << endl;
                        rec.push_back(rec_in.str());
                        rec_in.str("");
*/
                        /******************* Debug 4 end ********************************/

                        //pthread_mutex_lock(&m_set_mutx);
            mu_lock();
			unsigned int next_tx=nSetPos((void*)this)+1;		//Identify what is next Tx. Should be checked before
								//further use. Otherwise, it might exceed n_set size
								//This step should be done before "checkMset". Otherwise, 
								//Tx might be removed from n_set before knowing its previous position
			bool check_mset=checkMset(next_tx-1);	//Store checking result
			if(check_mset){
				//current transaction is not in n_set any more
				//next_tx should be reduced by 1
				next_tx--;
			}
			if(next_tx<n_set.size()){		//Haven't finished n_set yet
			//Prepare the next Tx in n_set for checking
				((PNF*)(n_set[next_tx]))->cur_state=checking;
				//pthread_setschedprio(*(((PNF*)(n_set[next_tx]))->th), RUN_PRIO);
                                param_tmp.sched_priority=PNF_M_PRIO;
                                sched_setparam(((PNF*)(n_set[next_tx]))->th, &param_tmp);
			}
                        //pthread_mutex_unlock(&m_set_mutx);
            mu_unlock();
			if(!check_mset){			//Tx still conflicts with m_set
				//Keep Tx as it is in n_set
				//pthread_setschedprio(*th, PNF_N_PRIO);
				param.sched_priority=PNF_N_PRIO;
				sched_setparam(0,&param);
			}
		}
		else{
			//DO NOTHING. Tx is either executing or retrying
                    /********************* Debug 4 start *****************/
/*
                    clock_gettime(CLOCK_REALTIME, &rec_time);
                    sched_getparam(0, &param);
                    if(cur_state==executing){
                            rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "executing" << endl;
                    }
                    else{
                            rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "retrying" << endl;
                    }
                    rec.push_back(rec_in.str());
                    rec_in.str("");
*/
                    /******************* Debug 4 end ********************************/

		}
		/********************************* Debug 5 start ********************************/
		//tra_start.push_back(stamp);
		/********************************* Debug 5 end ********************************/
                /******************** Debug 3 start **********************/                
/*
                clock_gettime(CLOCK_REALTIME, &rec_time);
                sched_getparam(0, &param);
                rec_in << (rec_time.tv_sec) << "\t" << (rec_time.tv_nsec) << "\t" << th << "\t" << (param.sched_priority) << "\t" << cur_state << "\t" << m_set << "\t" << "endBeginTx" << endl;
                rec.push_back(rec_in.str());
                rec_in.str("");                
*/
                /******************** Debug 3 end **********************/
	    }catch(exception e){
	    	cout << "onBeginTransaction exception: " << e.what() << endl;
	    }
	}
コード例 #8
0
ファイル: grpmain.c プロジェクト: yeonsh/Amoeba
void
sp_end()
{
    mu_unlock(&sp_mutex);
}
コード例 #9
0
ファイル: flip_ip_svr.c プロジェクト: yeonsh/Amoeba
static void flip_ip_svr()
{
	char reqbuf[1024], replbuf[1024];
	char *repl_ptr;
	char *bp, *ep;
	errstat req_size, repl_size;
	am_header_t req_header, repl_header;

	for (;;)
	{
		req_header.h_port= fis_priv_port;
		req_size= rpc_getreq(&req_header, reqbuf, sizeof(reqbuf));
		repl_ptr= replbuf;
		repl_header.h_status= STD_OK;
		if (ERR_STATUS(req_size))
			panic(( "getreq() failed: %s",
				err_why(ERR_CONVERT(req_size)) ));

		switch (req_header.h_command)
		{
		case STD_INFO:
			repl_ptr= bprintf(repl_ptr, replbuf + sizeof(replbuf),
				"flip_ip server");
			break;
		case STD_STATUS:
		{
			int i;

			mu_lock(&mu_flip_ip_inited);
			mu_lock(&mu_generic);

			bp= replbuf;
			ep= replbuf+sizeof(replbuf);
			for (i= 0; i<FIP_PORT_NR; i++)
				bp= print_fip_port(bp, ep, fip_port_table+i);
			repl_ptr= bp;

			mu_unlock(&mu_generic);
			mu_unlock(&mu_flip_ip_inited);

			break;
		}
		case UNREGISTERED_FIRST_COM:
		{
			int proto;
			ipaddr_t host;
			tcpport_t listen_port, connect_port;

			mu_lock(&mu_flip_ip_inited);
			mu_lock(&mu_generic);

			bp= reqbuf;
			ep= bp + req_size;
			bp= buf_get_uint32(bp, ep, &proto);
			bp= buf_get_bytes(bp, ep, &host, sizeof(host));
			bp= buf_get_bytes(bp, ep, &listen_port, 
				sizeof(listen_port));
			bp= buf_get_bytes(bp, ep, &connect_port, 
				sizeof(connect_port));
			if (bp != ep)
			{
				repl_header.h_status= STD_ARGBAD;
				break;
			}
			if (proto != FPNT_TCP)
			{
				repl_header.h_status= STD_ARGBAD;
				break;
			}
			fip_add_tcp_peer (0, host, listen_port, connect_port);

			mu_unlock(&mu_generic);
			mu_unlock(&mu_flip_ip_inited);

			break;
		}
		default:
			repl_header.h_status= STD_COMBAD;
			break;
		}
		if (!repl_ptr)
			repl_size= sizeof(replbuf);
		else
			repl_size= repl_ptr-replbuf;
		repl_header.h_size= repl_size;
		rpc_putrep(&repl_header, replbuf, repl_size);
	}
}