Пример #1
0
int _do_vc_lookup_perf(int av_type, int niters, int npeers, int naddrs)
{
	struct gnix_ep_name *addrs;
	fi_addr_t *fi_addrs;
	uint32_t i, ret, inc = npeers / naddrs;
	struct timeval s1, s2;
	int sec, usec;
	double usec_p_lookup;
	struct gnix_vc *vc;
	struct gnix_ep_name tmp_name = ep_name;

	addrs = malloc(ep_name_len * npeers);
	cr_assert(addrs, "failed to malloc addresses");

	fi_addrs = (fi_addr_t *)malloc(sizeof(fi_addr_t) * npeers);
	cr_assert(fi_addrs, "failed to malloc FI addresses");

	for (i = 0; i < npeers; i++) {
		/* insert fake addresses into AV */
		tmp_name.gnix_addr.cdm_id++;
		tmp_name.cm_nic_cdm_id++;
		addrs[i] = tmp_name;
	}

	ret = fi_av_insert(av, (void *)addrs, npeers,
			   (void *)fi_addrs, 0, NULL);
	cr_assert(ret == npeers);

	for (i = 0; i < npeers; i++) {
		/* do warump */
		ret = _gnix_vc_ep_get_vc(gnix_ep, fi_addrs[i],
					 &vc);
		cr_assert(ret == FI_SUCCESS);
	}

	gettimeofday(&s1, 0);
	for (i = 0; i < niters; i++) {
		/* do lookups */
		ret = _gnix_vc_ep_get_vc(gnix_ep, fi_addrs[(i * inc)%npeers],
					 &vc);
		/* cr_assert has ridiculous overhead */
		/* cr_assert(ret == FI_SUCCESS); */
	}
	gettimeofday(&s2, 0);

	calculate_time_difference(&s1, &s2, &sec, &usec);
	usec += sec * 1e6;
	usec_p_lookup = (double)usec;
	usec_p_lookup /= niters;

	fprintf(stderr, "type: %s\tnpeers: %7d naddrs: %7d ns: %f\n",
		av_type == 1 ? "MAP" : "TABLE", npeers, naddrs,
		usec_p_lookup*1000);

	free(fi_addrs);
	free(addrs);

	return 0;
}
void * packet_arrival_thread_function(void * args){
    pthread_sigmask(SIG_BLOCK, &set, 0);
    long local_packet_created_count = 0;
    long local_packet_added_count = 0;
    long local_packet_dropped_count = 0;
    float local_packet_arrival_time = 0.0;
    long local_tokens_needed_for_a_packet = 0;
    float local_packet_service_time = 0.0;
    float local_total_packet_arrival_time = 0.0;
    float local_total_packet_time_in_Q1 = 0.0;
    
    local_packet_arrival_time        = packet_arrival_time;
    local_packet_service_time        = packet_service_time;
    local_tokens_needed_for_a_packet = tokens_needed_for_a_packet;
    
    struct timeval previous_time, current_time;
    struct packet *local_arrival_thread_packet;
    
    int stop_flag = 0;
    
    while(1){
        
        if(is_trace_driven_mode){
            local_packet_arrival_time = **(tsfile_data +
	                                  local_packet_created_count) / 1000.0;

            local_packet_service_time = *(*(tsfile_data +
	                              local_packet_created_count) + 2) / 1000.0;
            local_tokens_needed_for_a_packet = *(*(tsfile_data +
	                                      local_packet_created_count) + 1);
        }
        
        gettimeofday(&previous_time, NULL);
        usleep(local_packet_arrival_time * 1000000.0);
        gettimeofday(&current_time, NULL);
        
        
        local_total_packet_arrival_time = local_total_packet_arrival_time +
	                 calculate_time_difference(current_time,previous_time);
        
        local_packet_created_count++;
        
        /* Create a new packet */
        local_arrival_thread_packet = malloc(sizeof(struct packet));

        local_arrival_thread_packet->id = local_packet_created_count;
        local_arrival_thread_packet->packet_arrival_time =
	                                              local_packet_arrival_time;
        local_arrival_thread_packet->packet_service_time =
	                                              local_packet_service_time;
        local_arrival_thread_packet->tokens_needed =
	                                       local_tokens_needed_for_a_packet;

        gettimeofday(&local_arrival_thread_packet->creation_time, NULL);
        gettimeofday(&local_arrival_thread_packet->updation_time, NULL);
        
        
        /* Lock the mutex */
        pthread_mutex_lock(&mutex);
        
        /*if(cntrl_c_signal){
            stop_flag = 1;
            
        }
        else{*/
	{
            
            
            if(local_tokens_needed_for_a_packet > bucket_capacity){
                
                printf("%012.3fms: p%ld arrives, needs %ld tokens, "
		       "inter-arrival time = %.3fms, dropped\n",
		       calculate_time_difference(current_time,emulation_start_time),
		       local_packet_created_count,local_tokens_needed_for_a_packet,
		       calculate_time_difference(current_time,previous_time));
                
                local_packet_dropped_count++;
                free(local_arrival_thread_packet);
            }
            else {
                
                printf("%012.3fms: p%ld arrives, needs %ld tokens, "
		       "inter-arrival time = %.3fms\n",
		       calculate_time_difference(current_time,emulation_start_time),
		       local_packet_created_count,local_tokens_needed_for_a_packet,
		       calculate_time_difference(current_time,previous_time));
                
                gettimeofday(&previous_time, NULL);
                
                /* Add the packet to Q1 */
                My402ListPrepend(&Q1, local_arrival_thread_packet);
                
                gettimeofday(&current_time, NULL);
                printf("%012.3fms: p%ld enters Q1\n",
		       calculate_time_difference(current_time,emulation_start_time),
		       local_packet_created_count);
                
                local_packet_added_count++;
            }
            
            local_arrival_thread_packet = NULL;
            
            if(!My402ListEmpty(&Q1)){
                My402ListElem * temp_arrival_thread_element = My402ListLast(&Q1);

                struct packet * temp_arrival_thread_packet =
		            (struct packet *)(temp_arrival_thread_element->obj);
                
                /* Move the first packet to q2 if there are enough tokens */
                if(number_of_tokens_in_bucket >=
		                    temp_arrival_thread_packet->tokens_needed){
                    
                    int is_empty = My402ListEmpty(&Q2);
                    
                    number_of_tokens_in_bucket = number_of_tokens_in_bucket -
		                     temp_arrival_thread_packet->tokens_needed;
                    
                    My402ListUnlink(&Q1,temp_arrival_thread_element);
                    
                    gettimeofday(&current_time, NULL);
                    printf("%012.3fms: p%ld leaves Q1, time in Q1 = %.3fms, "
		           "token bucket now has %ld token\n",
			   calculate_time_difference(current_time,
			                             emulation_start_time),
			   temp_arrival_thread_packet->id,
			   calculate_time_difference(current_time,
			            temp_arrival_thread_packet->updation_time),
			   number_of_tokens_in_bucket);
                    printf ("file is %s and function is %s\n", __FILE__,
		                                             __FUNCTION__);
                    
                    local_total_packet_time_in_Q1 =
		                              local_total_packet_time_in_Q1 +
		    calculate_time_difference(current_time,
		                     temp_arrival_thread_packet->updation_time);
                    
                    gettimeofday(&temp_arrival_thread_packet->updation_time,
		                 NULL);
                    My402ListPrepend(&Q2, temp_arrival_thread_packet);
                    
                    gettimeofday(&current_time, NULL);
                    printf("%012.3fms: p%ld enters Q2\n",
		           calculate_time_difference(current_time,
			                             emulation_start_time),
			   temp_arrival_thread_packet->id);
                    
                    if(is_empty){
                        pthread_cond_broadcast(&condition_variable);
                    }
                    
                }
                temp_arrival_thread_element = NULL;
                temp_arrival_thread_packet = NULL;
            }
        }
        pthread_mutex_unlock(&mutex);
        if(stop_flag || (local_packet_created_count == total_number_of_packets)){
            pthread_mutex_lock (&mutex);
            number_of_packets_put_in_Q1 = local_packet_added_count;
            if(local_total_packet_time_in_Q1 != 0.0){
                if(average_number_of_packets_in_Q1 == -1.0){
                    average_number_of_packets_in_Q1 = 0.0;
                }
                average_number_of_packets_in_Q1 = average_number_of_packets_in_Q1 +
		                                  local_total_packet_time_in_Q1;
            }
            if(local_packet_created_count !=0){
                average_packet_inter_arrival_time = local_total_packet_arrival_time / 
		                                    (float)local_packet_created_count;
                packet_drop_probability = (float)local_packet_dropped_count / 
		                          (float)local_packet_created_count;
            }
            packet_arrival_thread_stop = 1;
            pthread_mutex_unlock(&mutex);
            break;
            
        }
        
    }
    pthread_exit(0);
    return NULL;
}
Пример #3
0
void center_based_ES::greedy_schedule(int i){
	vector<int>temp;
	vector<vector<int>>temp_generation = getGeneration_pool();
	temp = temp_generation[i];
	for(int i=0;i<temp.size();i++){
		vector<eachAirplane>temp_eachairplane;//Store each node's flight
		for(int j=0;j<sortedConf.size();j++){
			if(sortedConf.at(j).getEntrancenode()==(i+1)){//Node start from 1
				sortedConf.at(j).setMap(j);
				temp_eachairplane.push_back(sortedConf.at(j));
		}
		}
		double safe_time = 60*15.0/temp[i];
		//cout<<safe_time<<endl;
		int index = 0;//This index is to tag those already arranged flight
		for(int i=0;i<temp_eachairplane.size();i++){
			if(temp_eachairplane.at(i).getEntrancetimeslice()==0){
				double temp_time = temp_eachairplane.at(index).getEntrancetime();
				int temp_map = temp_eachairplane.at(index).getMap();
				setSortedconf(temp_map,temp_time);
				temp_eachairplane.at(index).setSortedentrancetime(temp_time);
				index++;
		}
		}
		for(;index<temp_eachairplane.size();index++){
			double time_difference = calculate_time_difference(temp_eachairplane.at(index-1),temp_eachairplane.at(index),safe_time);
			if (temp_eachairplane.at(index).getEntrancetime()<temp_eachairplane.at(index-1).getSortedentrancetime()){
				double temp_time = temp_eachairplane.at(index-1).getSortedentrancetime()+safe_time/(60.0*100);
				temp_time = ((int)(temp_time*100)+1)/100.0;
				if(temp_time-(int)temp_time>=0.6){
					temp_eachairplane.at(index).setSortedentrancetime(temp_time+0.4);
					int temp_map = temp_eachairplane.at(index).getMap();
				    setSortedconf(temp_map,temp_time+0.4);
				}
				else{
					temp_eachairplane.at(index).setSortedentrancetime(temp_time);
					int temp_map = temp_eachairplane.at(index).getMap();
				    setSortedconf(temp_map,temp_time);
				}
			}
			else{
			if(time_difference>=safe_time){
				double temp_time = temp_eachairplane.at(index).getEntrancetime();
				int temp_map = temp_eachairplane.at(index).getMap();
				setSortedconf(temp_map,temp_time);
				temp_eachairplane.at(index).setSortedentrancetime(temp_time);
			}
			else{
				double temp_time = temp_eachairplane.at(index).getEntrancetime()+(safe_time-time_difference)/(60.0*100);
				temp_time = ((int)(temp_time*100)+1)/100.0;
				if(temp_time-(int)temp_time>=0.6){
					temp_eachairplane.at(index).setSortedentrancetime(temp_time+0.4);
					int temp_map = temp_eachairplane.at(index).getMap();
				    setSortedconf(temp_map,temp_time+0.4);
				}
				else{
					temp_eachairplane.at(index).setSortedentrancetime(temp_time);
					int temp_map = temp_eachairplane.at(index).getMap();
				   setSortedconf(temp_map,temp_time);
				}
			}
		}
		}
		/*for(int i=0;i<temp_eachairplane.size();i++){
			cout<<temp_eachairplane.at(i).getFlightname()<<" "<<temp_eachairplane.at(i).getEntrancetime()<<" "<<temp_eachairplane.at(i).getSortedentrancetime()<<endl;
		}
		system("pause");*/
	}
}
void * server_thread_function(void *args){
    pthread_sigmask(SIG_BLOCK, &set, 0);

    long  local_total_packet_counter               = 0;
    float local_packet_service_time                = packet_service_time;
    float local_total_packet_time_in_S             = 0.0;
    float local_total_packet_time_in_Q2            = 0.0;
    float local_total_packet_service_time          = 0.0;
    float local_total_time_spent_in_system         = 0.0;
    float local_total_time_spent_in_system_squared = 0.0;
    struct timeval previous_time, current_time;

    while(1){
        
        /* Lock the mutex */
        pthread_mutex_lock(&mutex);

        /* wait for the queue-not-empty condition to be signaled */
        while(My402ListEmpty(&Q2) && !cntrl_c_signal){
            pthread_cond_wait(&condition_variable, &mutex);
            if(packet_arrival_thread_stop){
                break;
            }
            
        }
        
        if(!My402ListEmpty(&Q2)){
            My402ListElem * temp_server_thread_element = My402ListLast(&Q2);
            My402ListUnlink(&Q2, temp_server_thread_element);
            struct packet * temp_server_thread_packet =
	                     (struct packet *)(temp_server_thread_element->obj);
            
            if(is_trace_driven_mode){
                local_packet_service_time =
		                 temp_server_thread_packet->packet_service_time;
            }

            gettimeofday(&current_time, NULL);

            printf("%012.3fms: p%ld leaves Q2, time in Q2 = %.3fms, begin "
	           "service at S\n",
		   calculate_time_difference(current_time,emulation_start_time),
		   temp_server_thread_packet->id,
		   calculate_time_difference(current_time,
		                     temp_server_thread_packet->updation_time));
            
            local_total_packet_time_in_Q2 = local_total_packet_time_in_Q2 +
	                                calculate_time_difference(current_time,
				      temp_server_thread_packet->updation_time);
            
            gettimeofday(&temp_server_thread_packet->updation_time, NULL);
            
            /* Unlock the mutex */
            pthread_mutex_unlock(&mutex);
            
            gettimeofday(&previous_time, NULL);
            
            /* Sleep for needed service time */
            usleep(local_packet_service_time * 1000000.0);
            
            gettimeofday(&current_time, NULL);
            
            printf("%012.3fms: p%ld departs from S, service time = %.3fms, "
	           "time in system = %.3fms\n",
		   calculate_time_difference(current_time,emulation_start_time),
		   temp_server_thread_packet->id,
		   calculate_time_difference(current_time, previous_time),
		   calculate_time_difference(current_time,
		                     temp_server_thread_packet->creation_time));
            
            local_total_packet_service_time = local_total_packet_service_time +
	                 calculate_time_difference(current_time, previous_time);
            
            local_total_packet_time_in_S = local_total_packet_time_in_S +
	                 calculate_time_difference(current_time, previous_time);
            
            float temp = calculate_time_difference(current_time,
	                              temp_server_thread_packet->creation_time);
            
            local_total_time_spent_in_system =
	                                local_total_time_spent_in_system + temp;
            
            local_total_time_spent_in_system_squared =
	               local_total_time_spent_in_system_squared + (temp * temp);
            
            free(temp_server_thread_packet);
            local_total_packet_counter++;
        }
        else{
            pthread_mutex_unlock(&mutex);
        }

        //Check this condition
        if(cntrl_c_signal ||
	   (local_total_packet_counter == number_of_packets_put_in_Q1 &&
	                                          packet_arrival_thread_stop)){
            pthread_mutex_lock(&mutex);
            if(local_total_packet_counter !=0){
                average_packet_service_time = local_total_packet_service_time /
		                              (float)local_total_packet_counter;

                average_number_of_packets_in_Q2 = local_total_packet_time_in_Q2;

                average_number_of_packets_at_S = local_total_packet_time_in_S;

                average_time_a_packet_spent_in_system =
		                            local_total_time_spent_in_system /
					    (float)local_total_packet_counter;

                local_total_time_spent_in_system_squared =
		                     local_total_time_spent_in_system_squared /
				              (float)local_total_packet_counter;

                standard_deviation_for_time_spent_in_system =
		              sqrtf(local_total_time_spent_in_system_squared -
			      ( average_time_a_packet_spent_in_system *
			                average_time_a_packet_spent_in_system));
            }
            server_thread_stop = 1;
            pthread_mutex_unlock(&mutex);
            break;
        }
    }
    pthread_exit(0);
    return NULL;
}
Пример #5
0
void * token_depositing_thread_function(void *args){
    pthread_sigmask(SIG_BLOCK, &set, 0);
    long local_token_created_count = 0;
    long local_token_dropped_count = 0;
    float local_total_packet_time_in_Q1 = 0.0;
    int stop_flag = 0;
    struct timeval current_time;
    
    while(1){
        
        
        /* Sleep for needed time */
        usleep(token_arrival_time * 1000000.0);
        
        /* Lock the mutex */
        pthread_mutex_lock(&mutex);
        
        if(cntrl_c_signal){
            stop_flag = 1;
        }
        else{
            local_token_created_count++;
            
            /* Increment token count */
            if(number_of_tokens_in_bucket < bucket_capacity){
                
                number_of_tokens_in_bucket++;
                
                gettimeofday(&current_time, NULL);
                printf("%012.3fms: token t%ld arrives, token bucket now has %ld tokens\n",calculate_time_difference(current_time,emulation_start_time),local_token_created_count,number_of_tokens_in_bucket);
            }
            else {
                
                local_token_dropped_count++;
                
                gettimeofday(&current_time, NULL);
                printf("%012.3fms: token t%ld arrives, dropped\n",calculate_time_difference(current_time,emulation_start_time),local_token_created_count);
            }
            
            if(!My402ListEmpty(&Q1)){
                My402ListElem * temp_arrival_thread_element = My402ListLast(&Q1);
                struct packet * temp_arrival_thread_packet = (struct packet *)(temp_arrival_thread_element->obj);
                
                /* Move the first packet to q2 if there are enough tokens */
                if(number_of_tokens_in_bucket >= temp_arrival_thread_packet->tokens_needed){
                    
                    int is_empty = My402ListEmpty(&Q2);
                    
                    number_of_tokens_in_bucket = number_of_tokens_in_bucket - temp_arrival_thread_packet->tokens_needed;
                    
                    My402ListUnlink(&Q1,temp_arrival_thread_element);
                    
                    gettimeofday(&current_time, NULL);
                    printf("%012.3fms: p%ld leaves Q1, time in Q1 = %.3fms, token bucket now has %ld token\n",calculate_time_difference(current_time,emulation_start_time),temp_arrival_thread_packet->id,calculate_time_difference(current_time, temp_arrival_thread_packet->updation_time),number_of_tokens_in_bucket);
                    
                    local_total_packet_time_in_Q1 = local_total_packet_time_in_Q1 + calculate_time_difference(current_time, temp_arrival_thread_packet->updation_time);
                    
                    gettimeofday(&temp_arrival_thread_packet->updation_time, NULL);
                    My402ListPrepend(&Q2, temp_arrival_thread_packet);
                    
                    gettimeofday(&current_time, NULL);
                    printf("%012.3fms: p%ld enters Q2\n",calculate_time_difference(current_time,emulation_start_time),temp_arrival_thread_packet->id);
                    
                    if(is_empty){
                        pthread_cond_broadcast(&condition_variable);
                    }
                    
                }
                temp_arrival_thread_element = NULL;
                temp_arrival_thread_packet = NULL;
            }
            else {
                if(packet_arrival_thread_stop){
                    stop_flag = 1;
                }
            }
            if(server_thread_stop){
                stop_flag = 1;
            }
        }
        /* Unloack the mutex */
        pthread_mutex_unlock(&mutex);
        if(stop_flag){
            pthread_mutex_lock(&mutex);
            
            if(local_total_packet_time_in_Q1 != 0.0){
                if(average_number_of_packets_in_Q1 == -1.0){
                    average_number_of_packets_in_Q1 = 0.0;
                }
                average_number_of_packets_in_Q1 = average_number_of_packets_in_Q1 + local_total_packet_time_in_Q1;
            }
            average_number_of_packets_in_Q1 = average_number_of_packets_in_Q1 + local_total_packet_time_in_Q1;
            if(local_token_created_count !=0){
                token_drop_probability = (float)local_token_dropped_count / (float)local_token_created_count;
            }
            if(packet_arrival_thread_stop && !server_thread_stop){
                pthread_cond_broadcast(&condition_variable);
            }
            pthread_mutex_unlock(&mutex);
            break;
        }
    }
    pthread_exit(0);
    return NULL;
}