コード例 #1
0
int add_freq_to_table(int* table, int freq, int fvco, int m, int od, int ext_div)
{
	int ret = 0;
	int k = 0;
	int exist = 0;
	int record = 0;
	int vco = fvco;
	int* f = table;
	int l2,axi,peri,apb;
	int f_cntl,f_latency,f_fvco;
	
	while(f[0]){
		if(f[1]){ 
			record++;
		}

		if(f[0] == freq){
			
			f_cntl = calc_cntl(freq, m, od);
			f_latency = calc_latency(freq,ext_div,&l2,&axi,&peri,&apb);
			f_fvco = fvco;
			
			if(f[1]) // record exist
				exist = 1;
			else{
				f[1] = f_cntl;
				f[2] = f_latency;
				f[3] = f_fvco;
				return 0;
			}
		}
		
		k++;
		f += TABLE_CLM;
	}
	if(k == record)
		return -2; //full
		
	if(exist)
		return -1;
		
	printf("Strange !!!! -- freq: %d, fvco: %d, m: %d, od: %d, ext_div: %d, k: %d , record: %d\n",
			freq, fvco, m, od, ext_div, k, record);
		
	//never go here
	return 0;
}
コード例 #2
0
ファイル: aio-stress.c プロジェクト: Johnfan888/xfstests
/*
 * updates the fields in the io operation struct that belongs to this
 * io unit, and make the io unit reusable again
 */
void finish_io(struct thread_info *t, struct io_unit *io, long result,
		struct timeval *tv_now) {
    struct io_oper *oper = io->io_oper;

    calc_latency(&io->io_start_time, tv_now, &t->io_completion_latency);
    io->res = result;
    io->busy = IO_FREE;
    io->next = t->free_ious;
    t->free_ious = io;
    oper->num_pending--;
    t->num_global_pending--;
    check_finished_io(io);
    if (oper->num_pending == 0 && 
       (oper->started_ios == oper->total_ios || oper->stonewalled)) 
    {
        print_time(oper);
    } 
}
コード例 #3
0
ファイル: aio-stress.c プロジェクト: 1587/ltp
/* starts some io for a given file, returns zero if all went well */
int run_built(struct thread_info *t, int num_ios, struct iocb **my_iocbs)
{
	int ret;
	struct timeval start_time;
	struct timeval stop_time;

resubmit:
	gettimeofday(&start_time, NULL);
	ret = io_submit(t->io_ctx, num_ios, my_iocbs);
	gettimeofday(&stop_time, NULL);
	calc_latency(&start_time, &stop_time, &t->io_submit_latency);

	if (ret != num_ios) {
		/* some I/O got through */
		if (ret > 0) {
			update_iou_counters(my_iocbs, ret, &stop_time);
			my_iocbs += ret;
			t->num_global_pending += ret;
			num_ios -= ret;
		}
		/*
		 * we've used all the requests allocated in aio_init, wait and
		 * retry
		 */
		if (ret > 0 || ret == -EAGAIN) {
			int old_ret = ret;
			if ((ret = read_some_events(t) > 0)) {
				goto resubmit;
			} else {
				fprintf(stderr, "ret was %d and now is %d\n",
					ret, old_ret);
				abort();
			}
		}

		fprintf(stderr, "ret %d (%s) on io_submit\n", ret,
			strerror(-ret));
		return -1;
	}
	update_iou_counters(my_iocbs, ret, &stop_time);
	t->num_global_pending += ret;
	return 0;
}
コード例 #4
0
ファイル: thread.c プロジェクト: coperd/sio
/* create a read/write thread according to arg->is_read */
void *rw_iothread(void *arg)
{
    int i;
    void *buf;
    struct timespec rstart, rend;

    struct thread_info *tinfo = (struct thread_info *)arg;
    int fd = tinfo->fd;
    int iosize = tinfo->iosize;
    int *retlist = tinfo->ret;
    int *latencylist = tinfo->latencylist;
    int *errlist = tinfo->errlist;
    off_t *oftlist = tinfo->oftlist;

    sio_memalign(&buf, ALIGNMENT, iosize); /* STRIPE size alignment */
    memset(buf, 0, iosize);

    srand(time(NULL));

    int nb_thread_rw = tinfo->nb_rw;

#if 0
    struct timespec rts, wts;
    rts.tv_sec = 0;
    rts.tv_nsec = 1000000;

    wts.tv_sec = 0;
    wts.tv_nsec = 1500000; // 40ms
#endif

    if (tinfo->is_read) {   /* create read threads */
        for (i = 0; i < nb_thread_rw; i++) {
            //printf("%d\n", i+1);
            off_t randoffset = rand() % RBLK_RANGE;
            clock_gettime(CLOCK_REALTIME, &rstart);
            //printf("READ: fd=%d,iosize=%d\n", fd, iosize);
            int ret = pread(fd, buf, iosize, randoffset*BLK_SZ);
            //int ret = syscall(548, fd, buf, iosize, randoffset*BLK_SZ);
            clock_gettime(CLOCK_REALTIME, &rend);
            if (ret == -1) {
                errlist[i] = errno;
                handle_error("pread");
            } else {
                errlist[i] = 0;
            }
            oftlist[i] = randoffset*CHUNK_SZ/512;
            retlist[i] = ret;
            latencylist[i] = calc_latency(rstart, rend);

            if (vflag) {
                printf("pread  %-6d ret: %-6d errno: %-2d offset: %-8ld\n", 
                        ++read_cnt, ret, errlist[i], randoffset*CHUNK_SZ/512);
            }
            //ssleep(&rts);
        }
    } else {                /* create write threads */
        for (i = 0; i < nb_thread_rw; i++) {
            off_t randoffset = rand() % WBLK_RANGE;
            clock_gettime(CLOCK_REALTIME, &rstart);
            int ret = pwrite(fd, buf, iosize, randoffset*BLK_SZ);
            clock_gettime(CLOCK_REALTIME, &rend);
            if (ret == -1) {
                handle_error("pwrite");
                errlist[i] = errno;
            } else {
                errlist[i] = 0;
            }
            oftlist[i] = randoffset*CHUNK_SZ/512;
            retlist[i] = ret;
            latencylist[i] = calc_latency(rstart, rend);

            if (vflag) {
                printf("pwrite %-6d ret: %-6d errno: %-2d offset: %-8ld\n", 
                        ++write_cnt, ret, errlist[i], randoffset*CHUNK_SZ/512);
            }

            //ssleep(&wts);

        }
    }

    return NULL;
}
コード例 #5
0
ファイル: thread.c プロジェクト: coperd/sio
void rw_thrd_main(int argc, char **argv)
{

    struct timespec start, end;
    struct thread_info *warmup_args = malloc(sizeof(struct thread_info));
    struct thread_info *wargs = malloc(sizeof(struct thread_info)*NB_WTHRD);
    struct thread_info *rargs = malloc(sizeof(struct thread_info)*NB_RTHRD);
    int *tr_latencylist = calloc(NB_READ, sizeof(int));
    int *tr_retlist = calloc(NB_READ, sizeof(int));
    int *tr_errlist = calloc(NB_READ, sizeof(int));
    off_t *tr_oftlist = calloc(NB_READ, sizeof(off_t));

    int *tw_latencylist = calloc(NB_WRITE, sizeof(int));
    int *tw_retlist = calloc(NB_WRITE, sizeof(int));
    int *tw_errlist = calloc(NB_WRITE, sizeof(int));
    off_t *tw_oftlist = calloc(NB_WRITE, sizeof(off_t));

    int i, j, ret;

#ifdef DEBUG
    printf("dev: %s\n", dev);
#endif

    if (NB_WARMUP > 0) {

        warmup_args->fd = FD;
        warmup_args->iosize = BLK_SZ;
        warmup_args->is_read = false;
        warmup_args->nb_rw = NB_WARMUP;

        printf("creating warmup thread..\n");
        ret = pthread_create(&warmup_args->tid, NULL, warmup_thread, 
                (void *)warmup_args);

        if (ret != 0) {
            handle_error("pthread_create");
        }

        printf("joining warmup thread.., warmup_args->tid=%ld\n", warmup_args->tid);
        ret = pthread_join(warmup_args->tid, NULL);
        if (ret != 0) {
            handle_error("pthread_join");
        }


        printf("sleeping here .. \n");
    }

    clock_gettime(CLOCK_REALTIME, &start);

    /* init write threads */
    if (NB_WTHRD > 0 && NB_WRITE > 0) {
#ifdef DEBUG
        printf("creating write threads...\n");
#endif

        for (i = 0; i < NB_WTHRD; i++) {
            wargs[i].fd = FD;
            wargs[i].iosize = BLK_SZ;
            wargs[i].nb_rw = NB_WRITE/NB_WTHRD;
            wargs[i].is_read = false;
            wargs[i].ret = calloc(wargs[i].nb_rw, sizeof(int));
            wargs[i].latencylist = calloc(wargs[i].nb_rw, sizeof(int));
            wargs[i].errlist = calloc(wargs[i].nb_rw, sizeof(int));
            wargs[i].oftlist = calloc(wargs[i].nb_rw, sizeof(off_t));

            ret = pthread_create(&wargs[i].tid, NULL, rw_iothread, 
                    (void *)&wargs[i]);

            if (ret != 0) {
                handle_error("pthread_create");
                exit(1);
            }

        }
    }

    /* init read threads */
    if (NB_RTHRD > 0 && NB_READ > 0) {
#ifdef DEBUG
        printf("crating read threads...\n");
#endif

        for (i = 0; i < NB_RTHRD; i++) {
            rargs[i].fd = FD;
            rargs[i].iosize = BLK_SZ;
            rargs[i].nb_rw = NB_READ/NB_RTHRD;
            rargs[i].is_read = true; /* read thread */
            rargs[i].ret = calloc(rargs[i].nb_rw, sizeof(int));
            rargs[i].latencylist = calloc(rargs[i].nb_rw, sizeof(int));
            rargs[i].errlist = calloc(rargs[i].nb_rw, sizeof(int));
            rargs[i].oftlist = calloc(rargs[i].nb_rw, sizeof(off_t));

            ret = pthread_create(&rargs[i].tid, NULL, rw_iothread, 
                    (void *)&rargs[i]);

            if (ret != 0) {
                handle_error("pthread_create");
                exit(1);
            }
        }

        /* wait for all read threads to finish */
        for (i = 0; i < NB_RTHRD; i++) {
            pthread_join(rargs[i].tid, NULL);
        }
    }
    
    if (NB_WTHRD > 0 && NB_WRITE > 0) {
        /* wait for all write thread to finish, if any */
        for (i = 0; i < NB_WTHRD; i++) {
            pthread_join(wargs[i].tid, NULL);
        }
    }

    if (vflag)
        printf("=====================End TRACE====================\n");

    clock_gettime(CLOCK_REALTIME, &end);

    int cnt = 0;
    for (i = 0; i < NB_RTHRD; i++) {
        for (j = 0; j < NB_READ/NB_RTHRD; j++) {
            tr_latencylist[cnt] = rargs[i].latencylist[j];
            tr_retlist[cnt] = rargs[i].ret[j];
            tr_errlist[cnt] = rargs[i].errlist[j];
            tr_oftlist[cnt] = rargs[i].oftlist[j];
            cnt++;
        }
    }

    cnt = 0;
    for (i = 0; i < NB_WTHRD; i++) {
        for (j = 0; j < NB_WRITE/NB_WTHRD; j++) {
            tw_latencylist[cnt] = wargs[i].latencylist[j];
            tw_retlist[cnt] = wargs[i].ret[j];
            tw_errlist[cnt] = wargs[i].errlist[j];
            tw_oftlist[cnt] = wargs[i].oftlist[j];
            cnt++;
        }
    }

    if (sflag) {
        qsort(tr_latencylist, NB_READ, sizeof(int), cmp);
        qsort(tw_latencylist, NB_WRITE, sizeof(int), cmp);
    }

    FILE *fp = NULL;
    if (rstfile[0] == '\0') {
        fp = stdout;
    } else {
        fp = fopen(rstfile, "w");
        if (fp == NULL)
            fp = stdout;
    }

    if (NB_RTHRD > 0) {
        for (i = 0; i < NB_READ; i++) {
            fprintf(fp, "%ld, %d, %d, %d\n", tr_oftlist[i], tr_latencylist[i], 
                    tr_retlist[i], tr_errlist[i]);
        }
    }

    if (NB_WTHRD > 0) {
        for (i = 0; i < NB_WRITE; i++) {
            fprintf(fp, "%ld,%d,%d,%d\n", tw_oftlist[i], tw_latencylist[i], 
                    tw_retlist[i], tw_errlist[i]);
        }
    }

    if ((NB_RTHRD > 0 && NB_READ > 0) || (NB_WTHRD > 0 && NB_WRITE > 0)) {
        printf("Total Latency: %" PRId64 " us\n", calc_latency(start, end));
    }
}