Esempio n. 1
0
// Exported hook functions
int my_stat( const char *path, struct my_stat *st )
{
	DISABLE_ERRORS;

	auto tpath = tstr(path);
	int result;

	if(*tpath.get() == 0) {
		/// virtual root
		memset( st, 0, sizeof(struct my_stat) );
		st->st_mode = _S_IFDIR;
		result = 0;
		my_errno = 0;
	} else {
		result = _tstat( MRP(tpath.get()), (struct _stat *)st );
		if(result < 0) {
			my_errno = errno;
		} else {
			my_errno = 0;
		}
	}

	D(bug(TEXT("stat(%s,%s) = %d\n"), tpath.get(), MRP(tpath.get()), result));
	if(result >= 0) dump_stat( st );
	RESTORE_ERRORS;
	return result;
}
static void dump_stats(struct nl_object *obj, void *arg)
{
	int i;
	struct rtnl_link *link = (struct rtnl_link *) obj;

	if (!strcasecmp(gargv[0], "all")) {
		for (i = 0; i < RTNL_LINK_STATS_MAX; i++)
			dump_stat(link, i);
	} else {
		for (i = 0; i < gargc; i++) {
			int id = rtnl_link_str2stat(gargv[i]);

			if (id < 0)
				fprintf(stderr, "Warning: Unknown statistic "
					"\"%s\"\n", gargv[i]);
			else
				dump_stat(link, id);
		}
	}
}
Esempio n. 3
0
int my_fstat( int fd, struct my_stat *st )
{
	DISABLE_ERRORS;
	int result = _fstat( fd, (struct _stat *)st );
	if(result < 0) {
		my_errno = errno;
	} else {
		my_errno = 0;
	}
	D(bug("fstat(%d) = %d\n", fd, result));
	if(result >= 0) dump_stat( st );
	RESTORE_ERRORS;
	return result;
}
Esempio n. 4
0
static void dump_stats(struct nl_object *obj, void *arg)
{
	struct rtnl_link *link = (struct rtnl_link *) obj;
	char **argv = arg;

	if (optind >= gargc) {
		int i;

		for (i = 0; i < RTNL_LINK_STATS_MAX; i++)
			dump_stat(link, i);
	} else {
		while (optind < gargc) {
			int id = rtnl_link_str2stat(argv[optind]);

			if (id < 0)
				fprintf(stderr, "Warning: Unknown statistic "
					"\"%s\"\n", argv[optind]);
			else
				dump_stat(link, id);

			optind++;
		}
	}
}
Esempio n. 5
0
      int CacheStat::dump(const StatDumpFilter* dump_filter)
      {
        int ret = check_init() ? TAIR_RETURN_SUCCESS : TAIR_RETURN_FAILED;

        if (ret != TAIR_RETURN_SUCCESS)
        {
          log_error("dump fail. not init");
        }
        else if (file_->get_file_size() <= RESERVE_SIZE)
        {
          log_error("cache stat contain no data");
        }
        else
        {
          char buf[CACHE_STAT_SIZE * 1024];
          int64_t offset = RESERVE_SIZE;
          int32_t count = 0;
          int32_t read_len;
          cache_stat total_stat, last_stats[TAIR_MAX_AREA_COUNT];
          StatDumpFilter default_filter;
          const StatDumpFilter* filter = (NULL == dump_filter) ? &default_filter : dump_filter;
          bool should_dump = true;

          print_head();
          while (true)
          {
            if ((read_len = file_->pread_file(buf, sizeof(buf), offset)) < 0)
            {
              log_error("read file fail. ret: %d", ret);
              ret = read_len;
              break;
            }
            else if (read_len == 0)
            {
              break;
            }
            else
            {
              count = read_len / CACHE_STAT_SIZE;
              dump_stat(reinterpret_cast<cache_stat*>(buf), count, last_stats, &total_stat, filter, should_dump);
              offset += read_len - read_len % CACHE_STAT_SIZE;
            }
          }
          print_total_stat(&total_stat); // maybe read no sentinel at last
          print_head();
        }
        return ret;
      }
Esempio n. 6
0
/* Clean up after an error. The caller should usually call do_request()
   after this function returns. It can be called from an IRQ handler or the
   normal kernel context. */
void handle_error(const char *from)
{
    u_long flags;
    if(current_req == NULL)
	return;
    save_flags(flags);
    cli();
    kprintf("\nfd: %s (%s): Error (retry number %d)\n",
        from, REQ_FD_DEV(current_req)->name, current_req->retries);
    dump_stat();
    fd_intr = NULL;
    if(current_req->retries++ < MAX_RETRIES)
    {
#if 0
	if((current_req->retries % RESET_FREQ) == 0)
	    reset_pending = TRUE;
#endif
	if((current_req->retries % RECAL_FREQ) == 0)
	    REQ_FD_DEV(current_req)->recalibrate = TRUE;
	/* Retry the current request, this simply means stacking it on the
	   front of the queue and calling do_request(). */
	prepend_node(&fd_reqs, &current_req->node);
	current_req = NULL;
	DB(("fd:handle_error: Retrying request %p\n", current_req));
    }
    else
    {
#if 0
	reset_pending = TRUE;
#endif
	REQ_FD_DEV(current_req)->recalibrate = TRUE;
	DB(("\nfd: handle_error: Request %p has no more retries available.\n",
	    current_req));
	fd_end_request(-1);
    }
    load_flags(flags);
}
Esempio n. 7
0
void* dsfq_proxy_receive_work(void * t_arg)
{
	fprintf(stderr,"hello from receive framework by the proxy\n");
	while (1)
	{
		int i;

		//fprintf(stderr,"starting polling for receiving\n");

		int num_poll=poll(receive_sockets,other_server_count,-1);//poll the whole pool using a wait time of 5 milliseconds at most.
		//fprintf(stderr,"polling returned with %i\n", num_poll);

		if (num_poll>0)
		{
			//Dprintf(D_CALL,"%i detected\n", num_poll);
			for (i=0;i<other_server_count;i++)//iterate through the whole socket pool for returned events
			{
				if (receive_sockets[i].revents & POLLIN)
				{
					//receive whole fix-lengthed message
					//update the queue/resort

					int recv_size = recv(receive_sockets[i].fd, receive_buffer[i]+receive_buffer_size[i], num_apps*sizeof(struct proxy_message)-receive_buffer_size[i], 0);
					//fprintf(stderr, "receive returned %i\n", recv_size);
					if (recv_size!=-1 && recv_size!=0)
					{
						receive_buffer_size[i]+=recv_size;
					}
					else
					{
						fprintf(stderr, "fatal: proxy recv error!\n");
						dump_stat(0);
						//exit(-1);

					}

					if (receive_buffer_size[i]!=num_apps*sizeof(struct proxy_message))
					{
						//fprintf(stderr, "failed to receive the whole message %i\n", receive_buffer_size[i]);
					}
					else
					{
						receive_buffer_size[i]=0;
						int j;

						for (j=0;j<num_apps;j++)
						{
							/*lock queue here!*/

							//fprintf(stderr,"%s: app %i got %i from other server this time\n",log_prefix, receive_buffer[i][j].app_index,receive_buffer[i][j].period_count);
							//receive buffer is per server; however the values are saved per app


							//apply delay function in each poll call
							//re-sort

							/*end locking*/
							pthread_mutex_lock(&dsfq_queue_mutex);
							int app_index = receive_buffer[i][j].app_index;

							dsfq_stats[app_index].dsfq_delay_values+=receive_buffer[i][j].period_count;
							app_stats[app_index].app_throughput+=receive_buffer[i][j].period_count;
							total_throughput+=receive_buffer[i][j].period_count;
						    app_stats[app_index].byte_counter=app_stats[app_index].byte_counter+receive_buffer[i][j].period_count;

							//fprintf(stderr,"%s: app %i got %i from other server in total\n",log_prefix, receive_buffer[i][j].app_index,dsfq_delay_values[receive_buffer[i][j].app_index]);
							pthread_mutex_unlock(&dsfq_queue_mutex);
							//delay values are used locally
						}//eager mode can update the queue here
					}//end receiving a complete message
				}//end processing existing revents
			}//end receiving from every other proxy


		}//end num_poll>0
	}
	pthread_exit(NULL);
}
Esempio n. 8
0
void* dsfq_proxy_broadcast_work(void * t_arg)
{

	fprintf(stderr,"hello from broadcast framework by the proxy\n");
	while (1)
	{
		int i;

		pthread_mutex_lock(&dsfq_broadcast_mutex);

		//if broadcast condition is met, but broadcast
		while (!broadcast_begin)
		{
			//fprintf(stderr, "broadcast worker is waiting on begin signal\n");
			pthread_cond_wait(&dsfq_broadcast_begin_cond, &dsfq_broadcast_mutex);
		}
		//fprintf(stderr,"Broadcast working...\n");


		pthread_mutex_unlock(&dsfq_broadcast_mutex);

		int num_poll=0;
		begin_broadcast:
		//fprintf(stderr,"starting polling for broadcasting\n");
		num_poll=poll(broadcast_sockets,other_server_count,-1);//poll the whole pool using a wait time of 5 milliseconds at most.
		//fprintf(stderr,"polling returned with %i\n", num_poll);
		int total_sent_size=0;
		if (num_poll>0)
		{
			//Dprintf(D_CALL,"%i detected\n", num_poll);
			for (i=0;i<other_server_count;i++)//iterate through the whole socket pool for returned events
			{
				if (broadcast_sockets[i].revents & POLLOUT)
				{
					//Dprintf(L_NOTICE, "processing %ith socket %i for read\n",i,s_pool.poll_list[i].fd);
					int sent_size = send(broadcast_sockets[i].fd, broadcast_buffer[i],broadcast_buffer_size[i], 0);
					if (sent_size!=-1)
					{
						//fprintf(stderr, "send returned %i\n",sent_size);

						if (broadcast_buffer_size[i]!=sent_size)
						{
							memmove(broadcast_buffer[i], broadcast_buffer[i]+sent_size, broadcast_buffer_size[i]-sent_size);
						}
						broadcast_buffer_size[i]-=sent_size;
						total_sent_size+=sent_size;

					}
					else
					{
						fprintf(stderr,"send error!\n");
						dump_stat(0);
					}
					//try to update the queue as soon as possible
				}
			}
		}

		if (total_sent_size>0)
		{
			if (pthread_mutex_lock (&counter_mutex)!=0)
			{
				fprintf(stderr, "error locking when getting counter on throughput\n");
			}
				broadcast_amount+=total_sent_size;
			if (pthread_mutex_unlock (&counter_mutex)!=0)
			{
				fprintf(stderr, "error locking when unlocking counter throughput\n");
			}
		}

		int complete_flag=1;
		for (i=0;i<other_server_count;i++)//broadcast events
		{
			if (broadcast_buffer_size[i]>0)
			{
				complete_flag=0;
				break;
			}

		}

		if (complete_flag)
		{
			pthread_mutex_lock(&dsfq_broadcast_mutex);
			broadcast_begin=0;
			broadcast_complete=1;
			//fprintf(stderr,"broadcast complete signaled\n");
			pthread_cond_signal(&dsfq_broadcast_complete_cond);
			pthread_mutex_unlock(&dsfq_broadcast_mutex);
		}
		else
		{
			goto begin_broadcast;
		}
	}
	pthread_exit(NULL);

}