Exemple #1
0
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();
}
Exemple #2
0
static struct thd_info *
enter()
{
    /* Flag to avoid recursion while getting the thread id: */
    static int Prof_getting_id = 0;
    static int ident;
    register int *thread_id;
    register struct thd_info *thdp;

    if (!Prof_initialized) {
	prof_init();
    }

    if (Prof_getting_id) {
	return NULL;
    }
    Prof_getting_id = 1;
    thread_id = (int *) thread_alloc(&ident, sizeof(int));
    Prof_getting_id = 0;

    /* When initialized, the glocal variable referred to by `ident'
     * contains the thread number plus one.
     */
    if (*thread_id == 0) {
	/* first time called within this thread */
	if (Prof_nthreads < MAXTHREADS) {
	    *thread_id = ++Prof_nthreads;

	    /* initialize thread info structure */
	    thdp = &thread_info[*thread_id - 1];
	    thdp->thd_here = 0;
	    thdp->thd_funcs = NULL;
	    thdp->thd_stack = NULL;
	    mu_init(&thdp->thd_mu);
	} else {
	    thdp = NULL;
	}
    } else {
	thdp = &thread_info[*thread_id - 1];
    }

    if (thdp != NULL) {
	if (!thdp->thd_here) {
	    thdp->thd_here = 1;
	    mu_lock(&thdp->thd_mu);
	} else {
	    thdp = NULL;
	}
    }

    return thdp;
}
Exemple #3
0
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;
}
Exemple #4
0
/*
 *	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 */
Exemple #5
0
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;
}
Exemple #6
0
void
super_lock() {
	mu_lock(&SuperLock) ;
}
Exemple #7
0
	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;
		}
	}
Exemple #8
0
	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;
	    }
	}
Exemple #9
0
void
sp_begin()
{
    mu_lock(&sp_mutex);
}
Exemple #10
0
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);
	}
}
Exemple #11
0
void init_pool_sems ()
{
	mu_init (&sleep_till_free_thread);
	mu_lock (&sleep_till_free_thread);
}