Esempio n. 1
0
//function used by heap to compare between two elements
int sfqdfull_packet_cmp(struct heap_node* _a, struct heap_node* _b)
{
	struct generic_queue_item *g_a, *g_b;
	struct sfqdfull_queue_item *a, *b;

	g_a = (struct generic_queue_item*) heap_node_value(_a);
	g_b = (struct generic_queue_item*) heap_node_value(_b);
	a = (struct sfqdfull_queue_item *)g_a->embedded_queue_item;
	b = (struct sfqdfull_queue_item *)g_b->embedded_queue_item;


	if (a->start_tag < b->start_tag)
	{
		return 1;
	}
	else if (a->start_tag == b->start_tag)
	{
		return g_a->item_id < g_b->item_id;//to ensure that the order in which the requests are received are dispatched the same way.
	}
	else
	{
		return 0;
	}

}
Esempio n. 2
0
struct generic_queue_item * sfqdfull_dequeue(struct dequeue_reason r)
{

	//int last_io_type = r.complete_size;
	struct generic_queue_item * next;//for heap and list
	//free up current item
	struct generic_queue_item * next_item = NULL; //for actual list item removal
	struct sfqdfull_queue_item *next_queue_item;

	int found=0;
	next_retry:

	if (SFQD_FULL_USE_HEAP_QUEUE==1 && !heap_empty(sfqdfull_heap_queue))
	{
		struct heap_node * hn  = heap_take(sfqd_packet_cmp, sfqdfull_heap_queue);
		next_item  = heap_node_value(hn);
		next_queue_item = (struct sfqdfull_queue_item *)(next_item->embedded_queue_item);
		found=1;
	}

	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);

	//fprintf(stderr,"%s %s, finished %i complete recv %i, completefwd %i\n",	bptr, log_prefix, finished[0], completerecv[0], completefwd[0]);
	if (SFQD_FULL_USE_HEAP_QUEUE==0)
	{
		/*if (sfqdfull_sorted==0)
		{
			sfqdfull_llist_queue = PINT_llist_sort(sfqdfull_llist_queue,list_sfqd_sort_comp);
			sfqdfull_sorted=1;
		}*/

		int i;
		fprintf(stderr,"%s %s ",bptr,log_prefix);
		for (i=0;i<num_apps;i++)
		{
			fprintf(stderr,"app%i:%i,", i, sfqdfull_list_queue_count[i]);
		}
		fprintf(stderr,"\n");

		next  = (struct generic_queue_item *)PINT_llist_head(sfqdfull_llist_queue);
		if (next!=NULL)
		{
			next_item = (struct generic_queue_item *)PINT_llist_rem(sfqdfull_llist_queue, (void*)next->item_id,  list_req_comp);

		}
		if (next_item!=NULL)
		{
			next_queue_item = (struct sfqdfull_queue_item *)(next_item->embedded_queue_item);
			sfqdfull_list_queue_count[next_queue_item->app_index]--;
			found=1;
			fprintf(stderr," meta dispatching \n");
			int app_index=next_queue_item->app_index;
			if (next_queue_item->app_index==1 && sfqdfull_list_queue_count[0]==0){
				fprintf(stderr,"%s %s, ********************************************** warning app 0 has no item left in the queue\n", bptr, log_prefix);

			}
		}

	}

	if (found==1)
	{
		//current_node = hn;
		sfqdfull_virtual_time=next_queue_item->start_tag;

		fprintf(depthtrack,"%s %s dispatching tag %i app%i on %s\n", bptr, log_prefix, next_queue_item->socket_tag, next_queue_item->app_index,
				s_pool.socket_state_list[next_queue_item->request_socket_index].ip);

		int app_index=next_item->socket_data->app_index;;
		app_stats[app_index].req_go+=1;

		app_stats[app_index].dispatched_requests+=1;

		struct timeval dispatch_time, diff;
		gettimeofday(&dispatch_time, 0);
		next_queue_item->dispatchtime = dispatch_time;
		double ratio = ((float)(app_stats[0].dispatched_requests))/((float)app_stats[1].dispatched_requests);
		fprintf(stderr,"%s %s $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ instant ratio is %d/%d=%f\n",
				bptr, log_prefix, app_stats[0].dispatched_requests, app_stats[1].dispatched_requests, ratio);
		return next_item;
	}
	else
	{
		sfqdfull_current_depth--;
		return NULL;
	}
}
Esempio n. 3
0
int main(int argc, char** argv)
{
    unsigned int count;
    struct heap *h;
    struct heap_node *hn, *first = NULL;
    u64 time;
    struct st_event_record *rec;
    int find_release = 0;
    int show_count = 0;
    int use_first_nonzero = 0;
    int opt;

    while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
        switch (opt) {
        case 'r':
            find_release = 1;
            break;
        case 'c':
            show_count = 1;
            break;
        case 'f':
            use_first_nonzero = 1;
            break;
        case 'h':
            usage(NULL);
            break;
        case ':':
            usage("Argument missing.");
            break;
        case '?':
        default:
            usage("Bad argument.");
            break;
        }
    }


    h = load(argv + optind, argc - optind, &count);
    if (!h)
        return 1;
    if (show_count)
        printf("Loaded %u events.\n", count);
    while ((hn = heap_take(earlier_event, h))) {
        time =  event_time(heap_node_value(hn));
        if (time != 0 && !first)
            first = hn;
        time /= 1000000; /* convert to milliseconds */
        if (!find_release) {
            printf("[%10llu] ", (unsigned long long) time);
            print_event(heap_node_value(hn));
        } else {
            rec = heap_node_value(hn);
            if (rec->hdr.type == ST_SYS_RELEASE) {
                printf("%6.2fms\n", rec->data.raw[1] / 1000000.0);
                find_release = 0;
                break;
            }
        }
    }
    if (find_release && use_first_nonzero && first) {
        rec = heap_node_value(first);
        printf("%6.2fms\n", event_time(rec) / 1000000.0);
    }

    return 0;
}