示例#1
0
void *test_latency(void *data)
{
    thread_data_t *d = (thread_data_t *)data;
#ifndef NO_SET_CPU
  int phys_id = the_cores[d->id];
  set_cpu(phys_id);
#endif
    int rand_max;
#if defined(TEST_CTR)
    data_type old_data;
    data_type new_data;
#endif
    volatile uint64_t res;

    seeds = seed_rand();
    rand_max = num_entries - 1;

    unsigned long do_not_measure=0;
    int entry=0;
    ticks t1 = 0, t2 = 0;
    barrier_cross(d->barrier);

    while (stop == 0) {
        if (num_entries>1) {
            entry =(int) my_random(&(seeds[0]),&(seeds[1]),&(seeds[2])) & rand_max;
        }
        do_not_measure=(d->num_operations) & 0x1f; 
#ifdef TEST_CAS
        if ((d->num_operations)&1) { 
            res = CAS_U8(&(the_data[entry].data),1,0);
        } else {
            if (!do_not_measure) {
                t1=getticks();
#  ifdef __tile__
                MEM_BARRIER;
#  endif
                res = CAS_U8(&(the_data[entry].data),0,1);
#  ifdef __tile__
                MEM_BARRIER;
#  endif
                t2=getticks();

            } else {
                res = CAS_U8(&(the_data[entry].data),0,1);
            }
        }
#elif defined(TEST_SWAP)
        if ((d->num_operations)&1) {
            res = SWAP_U8(&(the_data[entry].data),0);
        } else {
            if (do_not_measure) {
                res = SWAP_U8(&(the_data[entry].data),1);
            } else {
                t1=getticks(); 
#  ifdef __tile__
                MEM_BARRIER;
#  endif
               res = SWAP_U8(&(the_data[entry].data),1);
#  ifdef __tile__
                MEM_BARRIER;
#  endif

                t2=getticks();
            }
        }
#elif defined(TEST_CTR)
        if (do_not_measure) {
            do {
                old_data=the_data[entry].data;
                new_data=old_data+1;
            } while (CAS_U8(&(the_data[entry].data),old_data,new_data)!=old_data);
        } else {
            t1=getticks();
#  ifdef __tile__
                MEM_BARRIER;
#  endif
            do {
                old_data=the_data[entry].data;
                new_data=old_data+1;
            } while (CAS_U8(&(the_data[entry].data),old_data,new_data)!=old_data);
#  ifdef __tile__
                MEM_BARRIER;
#  endif
            t2=getticks();
        }
#elif defined(TEST_TAS)
        if (do_not_measure) {
            res = TAS_U8(&(the_data[entry].data));
        } else {
            t1=getticks();
#  ifdef __tile__
                MEM_BARRIER;
#  endif
            res = TAS_U8(&(the_data[entry].data));
#  ifdef __tile__
                MEM_BARRIER;
#  endif
            t2=getticks();
        }
        if (res==0) {
            the_data[entry].data = 0;
        }
#elif defined(TEST_FAI)
        if (do_not_measure) {
            FAI_U8(&(the_data[entry].data));
        } else {
            t1=getticks();
#  ifdef __tile__
                MEM_BARRIER;
#  endif
            FAI_U8(&(the_data[entry].data));
#  ifdef __tile__
                MEM_BARRIER;
#  endif
            t2=getticks();
        }
#else
        perror("No test primitive specified");
#endif 
        if (!do_not_measure) {
            d->num_measured++;
            d->total_time+=t2-t1-correction;
        }
        d->num_operations++;
        if (op_pause>0) {
            cpause(op_pause);
        }
    }
    
     /* avoid warning of unused var*/
    if (res == 12345654)
      {
	printf("%d", (int) res);
      }

    return NULL;
}
示例#2
0
void *test_throughput(void *data)
{
    thread_data_t *d = (thread_data_t *)data;
#ifndef NO_SET_CPU
  int phys_id = the_cores[d->id];
  set_cpu(phys_id);
#endif
    int rand_max;
#if defined(TEST_CTR)
    data_type old_data;
    data_type new_data;
#endif
    volatile uint64_t res;

    seeds = seed_rand();
    rand_max = num_entries - 1;

    barrier_cross(d->barrier);
    int entry=0;
    while (stop == 0) {
        if (num_entries>1) {
            entry =(int) my_random(&(seeds[0]),&(seeds[1]),&(seeds[2])) & rand_max;
        }
#ifdef TEST_CAS
        if ((d->num_operations)&1) {
            res = CAS_U8(&(the_data[entry].data),1,0);
        } else {
            res = CAS_U8(&(the_data[entry].data),0,1);
        }
#elif defined(TEST_SWAP)
#  ifdef __sparc__
        if ((d->num_operations)&1) {
            res = SWAP_U32(&(the_data[entry].data),0);
        } else {
            res = SWAP_U32(&(the_data[entry].data),1);
        }

#  else
        if ((d->num_operations)&1) {
            res = SWAP_U8(&(the_data[entry].data),0);
        } else {
            res = SWAP_U8(&(the_data[entry].data),1);
        }
#  endif
#elif defined(TEST_CTR)
        do {
            old_data=the_data[entry].data;
            new_data=old_data+1;
        } while (CAS_U8(&(the_data[entry].data),old_data,new_data)!=old_data);
#elif defined(TEST_TAS)
        res = TAS_U8(&(the_data[entry].data));
        if (res==0) {
            the_data[entry].data = 0;
        }
#elif defined(TEST_FAI)
        FAI_U8(&(the_data[entry].data));
#else
        perror("No test primitive specified");
#endif 
        d->num_operations++;
        if (op_pause>0) {
            cpause(op_pause);
        }
    }

     /* avoid warning of unused var*/
    if (res == 12345654)
      {
	printf("%d", (int) res);
      }

    return NULL;
}
void *test(void *data)
{
    thread_data_t *d = (thread_data_t *)data;
    phys_id = the_cores[d->id];
    set_cpu(phys_id);
    int rand_max;
    data_type old_data;
    data_type new_data;
    uint64_t res;

    seeds = seed_rand();
    rand_max = num_entries - 1;

    /* Init of local data if necessary */
    unsigned long do_not_measure=0;
    int entry;
    ticks t1,t2;
    /* Wait on barrier */
    barrier_cross(d->barrier);

    while (stop == 0) {
        if (num_entries==1) {
            entry=0;
        } else {
            entry =(int) my_random(&(seeds[0]),&(seeds[1]),&(seeds[2])) & rand_max;
        }
        do_not_measure=(d->num_operations) & 0x1f; 
        //   entry = (int)(erand48(seed) * rand_max) + rand_min;
#ifdef TEST_CAS
        //    do {
        if ((d->num_operations)&1) { 
            res = CAS_U8(&(the_data[entry].data),1,0);
        } else {
            if (!do_not_measure) {
                t1=getticks();
                res = CAS_U8(&(the_data[entry].data),0,1);
                t2=getticks();

            } else {
                res = CAS_U8(&(the_data[entry].data),0,1);
            }
        }
        //    MEM_BARRIER;
        //    } while(res!=0);
#elif defined(TEST_SWAP)
        //    do {
        if ((d->num_operations)&1) {
            res = SWAP_U8(&(the_data[entry].data),0);
        } else {
            if (do_not_measure) {
                res = SWAP_U8(&(the_data[entry].data),1);
            } else {
                t1=getticks(); 
                res = SWAP_U8(&(the_data[entry].data),1);
                t2=getticks();
            }
        }
        //MEM_BARRIER;
        //    } while(res!=0);
#elif defined(TEST_CTR)
        if (do_not_measure) {
            do {
                old_data=the_data[entry].data;
                new_data=old_data+1;
            } while (CAS_U8(&(the_data[entry].data),old_data,new_data)!=old_data);
        } else {
            t1=getticks();
            do {
                old_data=the_data[entry].data;
                new_data=old_data+1;
            } while (CAS_U8(&(the_data[entry].data),old_data,new_data)!=old_data);
            t2=getticks();

        }
        // MEM_BARRIER;
#elif defined(TEST_TAS)
        //    do {
        if (do_not_measure) {
            res = TAS_U8(&(the_data[entry].data));
        } else {
            t1=getticks();
            res = TAS_U8(&(the_data[entry].data));
            t2=getticks();
        }
        if (res==0) {
            //            MEM_BARRIER;
            the_data[entry].data = 0;
        }

        //    } while (res!=0);
#elif defined(TEST_FAI)
        if (do_not_measure) {
            FAI_U8(&(the_data[entry].data));
        } else {
            t1=getticks();
            FAI_U8(&(the_data[entry].data));
            t2=getticks();
        }
        //        MEM_BARRIER;
#else
        perror("No test primitive specified");
#endif 
        //#ifdef XEON
        //MEM_BARRIER;
        //__sync_synchronize();
        //#endif
        if (!do_not_measure) {
            d->num_measured++;
            d->total_time+=t2-t1-correction;
        }
        d->num_operations++;
        if (op_pause>0) {
            cpause(op_pause);
            //cdelay(op_pause);
        }
    }

    /* Free any local data if necessary */ 

    return NULL;
}