int sfqdfull_add_item_to_queue(struct generic_queue_item* item) { int dispatched=0; if (SFQD_FULL_USE_HEAP_QUEUE==1) { struct heap_node* hn = malloc(sizeof(struct heap_node)); heap_node_init(hn, item); heap_insert(sfqdfull_packet_cmp, sfqdfull_heap_queue, hn); } else { if (PINT_llist_add_to_tail( sfqdfull_llist_queue, item)) { fprintf(stderr,"sfqd_full queue insertion error!\n"); exit(-1); } } return dispatched; }
/* PINT_create_extent_list() * * Return an extent llist based on extent string input * * Parameters: * extent_str - pointer to string * * Returns an extent list matching structure of * the input extent_str on success; returns NULL * the extent_str is invalid, or an error occurs * */ PINT_llist *PINT_create_extent_list(char *extent_str) { PVFS_handle_extent cur_extent, *new_extent = NULL; PINT_llist *extent_list = NULL; int status = 0; if (extent_str) { extent_list = PINT_llist_new(); assert(extent_list); while(PINT_parse_handle_ranges(extent_str,&cur_extent,&status)) { new_extent = malloc(sizeof(PVFS_handle_extent)); assert(new_extent); new_extent->first = cur_extent.first; new_extent->last = cur_extent.last; PINT_llist_add_to_tail(extent_list,(void *)new_extent); } } return extent_list; }
int dsfq_enqueue(struct socket_info * si, struct pvfs_info* pi) { app_stats[si->app_index].received_requests+=1; int r_socket_index, d_socket_index, length, tag, io_type, req_size; char* request = si->buffer; r_socket_index = si->request_socket; d_socket_index = si->data_socket; length = pi->current_data_size; tag= pi->tag; io_type= pi->io_type; req_size=pi->req_size; char* ip = s_pool.socket_state_list[d_socket_index].ip; int port= s_pool.socket_state_list[d_socket_index].port; int d_socket=s_pool.socket_state_list[d_socket_index].socket; int socket_tag = tag; int app_index= s_pool.socket_state_list[r_socket_index].app_index; //Dprintf(D_CACHE, "app_index is %i for ip %s\n", app_index, ip); int weight = s_pool.socket_state_list[r_socket_index].weight; struct dsfq_queue_item * item = (struct dsfq_queue_item * )malloc(sizeof(struct dsfq_queue_item)); //Dprintf(D_CACHE,"weight got from request socket is %i,ip %s\n",weight,ip); pthread_mutex_lock(&dsfq_broadcast_mutex); dsfq_stats[app_index].request_receive_queue+=length; dsfq_current_io_counter+=length; if (dsfq_current_io_counter>=dsfq_threshold) { //fprintf(stderr,"%s: counter reached %i > %i\n", log_prefix, dsfq_current_io_counter, dsfq_threshold); threshold_ready=1; pthread_cond_signal(&dsfq_threshold_cond); } pthread_mutex_unlock(&dsfq_broadcast_mutex); pthread_mutex_lock(&dsfq_queue_mutex); item->delay_value=dsfq_stats[app_index].dsfq_delay_values; dsfq_stats[app_index].dsfq_delay_values=0; //fprintf(stderr,"%s: setting app %i value to zero\n", log_prefix, app_index); item->weight=s_pool.socket_state_list[r_socket_index].weight; item->delay_value/=(item->weight * (REDUCER)); //fprintf(stderr,"%s: app %i delay value applied is %i value to zero\n", log_prefix, app_index, item->delay_value); int start_tag=MAX(dsfq_virtual_time,dsfq_last_finish_tags[app_index]+item->delay_value);//work-conserving //fprintf(stderr,"%s: virtual time: %i, finish tag: %i, delay value: %i , taken value: %i\n",log_prefix, dsfq_virtual_time,dsfq_last_finish_tags[app_index], item->delay_value, start_tag); //int start_tag=last_finish_tags[app_index];//non-work-conserving //item->last_finish_tag=dsfq_last_finish_tags[app_index]; //item->virtual_time=dsfq_virtual_time; int cost; if (dsfq_purecost) { cost=length; } else { cost=length;//*(dsfq_current_depth+1); } int finish_tag = start_tag+cost/weight/REDUCER; dsfq_last_finish_tags[app_index]=finish_tag; //Dprintf(D_CACHE, "my previous finish tag is updated to %i, weight %i\n",finish_tag,s_pool.socket_state_list[r_socket_index].weight); item->start_tag=start_tag; item->finish_tag=finish_tag; /* * the section deals with the queueing delay of requests...from the moment it is queued to when it is released * in the later section we will deal with the response time of requests from the moment it is released until when it is completed * char bptr[20]; struct timeval tv; time_t tp; gettimeofday(&tv, 0); tp = tv.tv_sec; strftime(bptr, 10, "[%H:%M:%S", localtime(&tp)); sprintf(bptr+9, ".%06ld]", (long)tv.tv_usec); s_pool.socket_state_list[r_socket_index].last_work_time=tv;*/ //Dprintf(D_CACHE, "%s adding start_tag:%i finish_tag:%i weight:%i app:%i ip:%s\n",bptr, start_tag, finish_tag, weight,s_pool.socket_state_list[r_socket_index].app_index+1,s_pool.socket_state_list[r_socket_index].ip); //Dprintf(D_CACHE, "adding to %ith socket %i\n",r_socket_index, s_pool.socket_state_list[r_socket_index].socket); item->data_port=port; item->data_ip=ip; item->task_size=length; item->data_socket=d_socket; item->socket_tag=socket_tag; item->app_index=app_index; item->stream_id=app_stats[app_index].stream_id++; item->got_size=0; item->request_socket=s_pool.socket_state_list[r_socket_index].socket; item->io_type=io_type; item->buffer=request; item->buffer_size=req_size; struct generic_queue_item * generic_item = (struct generic_queue_item *) malloc(sizeof(struct generic_queue_item)); //Dprintf(D_CACHE, "[INITIALIZE]ip:%s port:%i tag:%i\n", item->data_ip, item->data_port, item->socket_tag); generic_item->embedded_queue_item=item; generic_item->item_id=dsfq_item_id++; generic_item->socket_data=si; if (PINT_llist_add_to_tail( dsfq_llist_queue, generic_item)) { fprintf(stderr,"queue insertion error!\n"); exit(-1); } //PINT_llist_doall(dsfq_llist_queue,list_pmsg_print_all); int dispatched=0; if (dsfq_current_depth<dsfq_depth)//meaning the queue must be empty before this insertion { dispatched=1; dsfq_current_depth++; //this means the queue is empty before adding item to it. } dsfq_queue_size++; dsfq_new_item_added=1; if (dispatched) { //fprintf(stderr, "current_depth increased to %i\n",dsfq_current_depth); //fprintf(stderr, "dispatched immeidately\n"); } else { //fprintf(stderr,"sorting after adding new item...\n"); //fprintf(stderr,"service delayed\n"); //dsfq_llist_queue = PINT_llist_dsfq_sort(dsfq_llist_queue);//sort } pthread_mutex_unlock(&dsfq_queue_mutex); return dispatched; }
int dsfq_parse_server_config() { char myhost[100]; fprintf(stderr, "host name returned %i\n",gethostname(myhost, 100)); FILE * server_config = fopen(pvfs_config,"r"); if (!server_config) { fprintf(stderr, "opening %s error\n", pvfs_config); return -1; } char line[10000]; int ret=0; if (ret=fread(line, 1, 9999, server_config)) { fprintf(stderr,"returning %i\n",ret); line[ret]='\0'; } char * begin = strtok(line, "\n"); char * alias, * alias2; other_server_names = PINT_llist_new(); while (begin) { if (alias=strstr(begin, "Alias ")) { alias2 = strstr(alias+6, " "); char * tmp = (char*)malloc((alias2-alias-6+1)*sizeof (char)); tmp[alias2-alias-6]='\0'; memcpy(tmp,alias+6,alias2-alias-6); if (!strcmp(myhost, tmp)) { fprintf(stderr,"excluding same host name from server config: %s\n", myhost); } else { PINT_llist_add_to_tail(other_server_names, tmp); other_server_count++; } } begin = strtok(NULL, "\n"); } other_server_ips = (struct sockaddr_in **)malloc(sizeof(struct sockaddr_in *)*other_server_count); other_server_address = (char**)malloc(sizeof(char*)*other_server_count); PINT_llist_doall(other_server_names, dsfq_fill_ip); fclose(server_config); return 0; //read server names //use resolve to resolve ip address }