예제 #1
0
int main() {

  test_setup();
  perf_start();

  for (int i = 0; i < NUM_ITER; ++i) {
    test_clear();

    reset_timer();
    start_timer();

    test_run(i);

    stop_timer();

    samples[i] = get_time();
  }

  perf_stop();
  int check = test_check();

  printf("Correct: %d\n", check);
  for (int i = 0; i < NUM_ITER; ++i)
    printf("TS[%d]: %d\n", i, samples[i]);

  perf_print_all();

  return 0;
}
예제 #2
0
int main(void)
{
	int i;

	unsigned char key1[16], key2[16], tinit[16];
	unsigned char *pt, *ct;

	printf("aes_xts_128_enc_perf:\n");

	pt = malloc(TEST_LEN);
	ct = malloc(TEST_LEN);

	if (NULL == pt || NULL == ct) {
		printf("malloc of testsize failed\n");
		return -1;
	}

	mk_rand_data(key1, key2, tinit, pt, TEST_LEN);
	XTS_AES_128_enc(key2, key1, tinit, TEST_LEN, pt, ct);

	struct perf start, stop;

	perf_start(&start);

	for (i = 0; i < TEST_LOOPS; i++) {
		XTS_AES_128_enc(key2, key1, tinit, TEST_LEN, pt, ct);
	}

	perf_stop(&stop);

	printf("aes_xts_128_enc" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * i);

	return 0;
}
예제 #3
0
int main(int argc, char *argv[])
{
	int i;
	void *buf;
	uint16_t crc;
	struct perf start, stop;

	printf("crc16_t10dif_perf:\n");

	if (posix_memalign(&buf, 1024, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}

	printf("Start timed tests\n");
	fflush(0);

	memset(buf, 0, TEST_LEN);
	crc = crc16_t10dif(TEST_SEED, buf, TEST_LEN);
	perf_start(&start);
	for (i = 0; i < TEST_LOOPS; i++) {
		crc = crc16_t10dif(TEST_SEED, buf, TEST_LEN);
	}
	perf_stop(&stop);
	printf("crc16_t10dif" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * i);

	printf("finish 0x%x\n", crc);
	return 0;
}
예제 #4
0
int mac_load(char *name, MFDB *out, GEM_WINDOW *wprog)
{
  FILE   *stream ;
  size_t taille ;
  void   *in ;

  perf_start( PERF_DISK, &PerfInfo ) ;
  stream = fopen(name, "rb") ;
  if (stream == NULL) return(-1) ;
  
  fseek(stream, 0x280, SEEK_SET) ;
  out->fd_nplanes = 1 ;
  out->fd_w       = 576 ; 
  out->fd_h       = 720 ;
  out->fd_stand   = 0 ;
  out->fd_wdwidth = out->fd_w/16 ;
  out->fd_addr    = img_alloc(576, 720, 1) ;
  if (out->fd_addr == NULL)
  {
    fclose(stream) ;
    return(-3) ;
  }

  taille = file_size(name)-sizeof(MACPAINT_HEADER) ;
  in     = malloc(taille) ;
  if (in == NULL)
  {
    fclose(stream) ;
    free(out->fd_addr) ;
    return(-3) ;
  }
  fread(in, taille, 1, stream) ;
  fclose(stream) ;
  perf_stop( PERF_DISK, &PerfInfo ) ;

  perf_start( PERF_COMPRESS, &PerfInfo ) ;
  packbits_dcmps(in, out->fd_addr, out->fd_w, out->fd_h, out->fd_nplanes) ;
  perf_stop( PERF_COMPRESS, &PerfInfo ) ;

  free(in) ;

  return(0) ;
}
예제 #5
0
void
perf_pop (void)
{
  struct perf *prev;
  struct perf *cur;

  prev = get_perf (-2);
  cur = get_perf (-1);

  ASSERT (cur);
  perf_stop (cur);

  if (prev)
    perf_resume (prev);

  pop_perf_index ();
}
예제 #6
0
static void
eval_repeat(heim_dict_t o)
{
    heim_object_t or = heim_dict_get_value(o, HSTR("value"));
    heim_number_t n = heim_dict_get_value(o, HSTR("num"));
    int i, num;
    struct perf perf;

    perf_start(&perf);

    heim_assert(or != NULL, "value missing");
    heim_assert(n != NULL, "num missing");

    num = heim_number_get_int(n);
    heim_assert(num >= 0, "num >= 0");

    for (i = 0; i < num; i++)
	eval_object(or);

    perf_stop(&perf);
}
예제 #7
0
int main(int argc, char *argv[])
{
	int i;
	u8 *buff1, *buff2, gf_const_tbl[64], a = 2;
	struct perf start, stop;

	printf("gf_vect_mul_perf:\n");
	mk_gf_field();
	gf_vect_mul_init(a, gf_const_tbl);

	// Allocate large mem region
	buff1 = (u8*) malloc(TEST_LEN);
	buff2 = (u8*) malloc(TEST_LEN);
	if (NULL == buff1 || NULL == buff2){
		printf("Failed to allocate %dB\n", TEST_LEN);
		return 1;
	}

	memset(buff1, 0, TEST_LEN);
	memset(buff2, 0, TEST_LEN);

	gf_vect_mul(TEST_LEN, gf_const_tbl, buff1, buff2);

	printf("Start timed tests\n"); 
	fflush(0);

	gf_vect_mul(TEST_LEN, gf_const_tbl, buff1, buff2);
	perf_start(&start);
	for(i=0; i<TEST_LOOPS; i++){
		gf_vect_mul_init(a, gf_const_tbl);
		gf_vect_mul(TEST_LEN, gf_const_tbl, buff1, buff2);
	}
	perf_stop(&stop);
	printf("gf_vect_mul" TEST_TYPE_STR ": ");
	perf_print(stop,start,(long long)TEST_LEN*i);


	return 0;
}
int main(int argc, char *argv[])
{
	int i, j;
	void *buf;
	u8 g[TEST_SOURCES], g_tbls[TEST_SOURCES * 32], *dest, *dest_ref;
	u8 *temp_buff, *buffs[TEST_SOURCES];
	struct perf start, stop;

	printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);

	// Allocate the arrays
	for (i = 0; i < TEST_SOURCES; i++) {
		if (posix_memalign(&buf, 64, TEST_LEN)) {
			printf("alloc error: Fail");
			return -1;
		}
		buffs[i] = buf;
	}

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	temp_buff = buf;

	// Performance test
	for (i = 0; i < TEST_SOURCES; i++)
		for (j = 0; j < TEST_LEN; j++)
			buffs[i][j] = rand();

	memset(dest, 0, TEST_LEN);
	memset(temp_buff, 0, TEST_LEN);
	memset(dest_ref, 0, TEST_LEN);
	memset(g, 0, TEST_SOURCES);

	for (i = 0; i < TEST_SOURCES; i++)
		g[i] = rand();

	for (j = 0; j < TEST_SOURCES; j++)
		gf_vect_mul_init(g[j], &g_tbls[j * 32]);

	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);

#ifdef DO_REF_PERF
	perf_start(&start);
	for (i = 0; i < TEST_LOOPS; i++) {
		for (j = 0; j < TEST_SOURCES; j++)
			gf_vect_mul_init(g[j], &g_tbls[j * 32]);

		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
	}
	perf_stop(&stop);
	printf("gf_vect_dot_prod_base" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);
#endif

	FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);

	perf_start(&start);
	for (i = 0; i < TEST_LOOPS; i++) {
		for (j = 0; j < TEST_SOURCES; j++)
			gf_vect_mul_init(g[j], &g_tbls[j * 32]);

		FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
	}
	perf_stop(&stop);
	printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);

	if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
		printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:");
		dump(dest_ref, 25);
		printf("dprod:");
		dump(dest, 25);
		return -1;
	}

	printf("pass perf check\n");
	return 0;
}
예제 #9
0
파일: example.c 프로젝트: d-s-d/FNC14-BST
int main(int argc, char *argv[])
{
    int ret;

    // For a list of valid performance events, see
    //   libpfm/examples/showevtinfo -L
    // or
    //   Intel 64 and IA-32 Architectures Software Developer’s Manual,
    //     Volume 3B: System Programming Guide, Part 2
    
    // Initialize perfmon -------------------------------------------------
    char *events[] = {
        // on Haswell, can use at most 4, otherwise '0' results
        "PERF_COUNT_HW_CPU_CYCLES",
        "CACHE-REFERENCES",
        "CACHE-MISSES",
        "DTLB-LOAD-MISSES",
        NULL
    };

    struct perf_data *data;
    
    ret = perf_init(events, &data);
    if (ret < 0) {
        fprintf(stderr, "Could not initialize perfmon.\n");
        perf_cleanup(data);
        return 0;
    }

    // Example 1: Measure performance for MMM in this file. ---------------

    perf_start(data);

    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            for (int k=0; k<N; ++k) {
                COST_INC_ADD(1); COST_INC_MUL(1);
                C[i*N+j] = A[i*N+k] * B[k*N+j] + C[i*N+j];
            }
        }
    }

    ret = perf_stop(data);
    if (ret < 0) {
        fprintf(stderr, "Error measuring performance.\n");
        perf_cleanup(data);
        return 0;
    }

    // short cycles check
    perf_update_values(data);
    printf("Cycles after example 1: %llu\n", data[0].value);

    // Example 2: Measure external computation ----------------------------

    perf_start(data);    // if desired, do perf_reset() first
    other_computation();
    perf_stop(data);

    // Report results -----------------------------------------------------

    perf_update_values(data);

    printf("Overall results:\n");
    printf("Performance Counters:\n");
    for (struct perf_data *iter = data; iter->name; ++iter) {
        printf("  %-50s : %"PRId64"\n", iter->name, iter->value);
    }

    printf("Cost Model:\n");
    printf("  Add: %"PRI_COST"\n", COST_ADD);
    printf("  Mul: %"PRI_COST"\n", COST_MUL);
    printf("  Div: %"PRI_COST"\n", COST_DIV);
    printf("  Pow: %"PRI_COST"\n", COST_POW);
    printf("  Abs: %"PRI_COST"\n", COST_ABS);

    printf("Derived Results\n");
    double flops      = COST_ADD + COST_MUL + COST_DIV;
    double cycles     = data[0].value; // index as in 'events'
    double cache_load = data[1].value;
    double cache_miss = data[2].value;
    printf("  Flops           : %.0lf\n", flops);
    printf("  Performance     : %.3lf\n", flops/cycles);
    printf("  Cache Miss Rate : %.3lf\n", cache_miss/cache_load);

    // Cleanup ------------------------------------------------------------
    perf_cleanup(data);

    return 0;
}
int main(int argc, char *argv[])
{
	int i,j;
	void *buf;
	u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES];
	u8 g_tbls[3*TEST_SOURCES*32], *dest_ptrs[3], *buffs[TEST_SOURCES];
	u8 *dest1, *dest2, *dest3, *dest_ref1, *dest_ref2, *dest_ref3;
	struct perf start, stop;

	printf("gf_3vect_dot_prod_sse: %dx%d\n", TEST_SOURCES, TEST_LEN);

	mk_gf_field();


	// Allocate the arrays
	for(i=0; i<TEST_SOURCES; i++){
		if (posix_memalign(&buf, 64, TEST_LEN)) {
			printf("alloc error: Fail");
			return -1;
		}
		buffs[i] = buf;
	}

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest1 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest2 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest3 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref1 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref2 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref3 = buf;

	dest_ptrs[0] = dest1;
	dest_ptrs[1] = dest2;
	dest_ptrs[2] = dest3;


	// Performance test
	for(i=0; i<TEST_SOURCES; i++)
		for(j=0; j<TEST_LEN; j++)
			buffs[i][j] = rand();

	memset(dest1, 0, TEST_LEN);
	memset(dest2, 0, TEST_LEN);
	memset(dest_ref1, 0, TEST_LEN);
	memset(dest_ref2, 0, TEST_LEN);

	for (i=0; i<TEST_SOURCES; i++){
		g1[i] = rand();
		g2[i] = rand();
		g3[i] = rand();
	}

	for(j=0; j<TEST_SOURCES; j++){
		gf_vect_mul_init(g1[j], &g_tbls[j*32]);
		gf_vect_mul_init(g2[j], &g_tbls[(32*TEST_SOURCES) + (j*32)]);
		gf_vect_mul_init(g3[j], &g_tbls[(64*TEST_SOURCES) + (j*32)]);
	}

	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32*TEST_SOURCES], buffs, dest_ref2);
	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64*TEST_SOURCES], buffs, dest_ref3);

#ifdef DO_REF_PERF
	perf_start(&start);
	for (i=0; i<TEST_LOOPS/100; i++){
		for (j=0; j<TEST_SOURCES; j++){
			gf_vect_mul_init(g1[j], &g_tbls[j*32]);
			gf_vect_mul_init(g2[j], &g_tbls[(32*TEST_SOURCES) + (j*32)]);
			gf_vect_mul_init(g3[j], &g_tbls[(64*TEST_SOURCES) + (j*32)]);
		}

		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32*TEST_SOURCES], buffs, dest_ref2);
		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64*TEST_SOURCES], buffs, dest_ref3);
	}
	perf_stop(&stop);
	printf("gf_3vect_dot_prod_base" TEST_TYPE_STR ": ");
	perf_print(stop,start,(long long)TEST_LEN*(TEST_SOURCES+3)*i);
#endif

	gf_3vect_dot_prod_sse(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);

	perf_start(&start);
	for (i=0; i<TEST_LOOPS; i++) {
		for (j=0; j<TEST_SOURCES; j++){
			gf_vect_mul_init(g1[j], &g_tbls[j*32]);
			gf_vect_mul_init(g2[j], &g_tbls[(32*TEST_SOURCES) + (j*32)]);
			gf_vect_mul_init(g3[j], &g_tbls[(64*TEST_SOURCES) + (j*32)]);
		}

		gf_3vect_dot_prod_sse(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
	}
	perf_stop(&stop);
	printf("gf_3vect_dot_prod_sse" TEST_TYPE_STR ": ");
	perf_print(stop,start, (long long)TEST_LEN*(TEST_SOURCES+3)*i);

	if (0 != memcmp(dest_ref1, dest1, TEST_LEN)){
		printf("Fail perf vect_dot_prod_sse test1\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:"); 
		dump(dest_ref1, 25);
		printf("dprod_sse:"); 
		dump(dest1, 25);
		return -1;
	}
	if (0 != memcmp(dest_ref2, dest2, TEST_LEN)){
		printf("Fail perf vect_dot_prod_sse test2\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:"); 
		dump(dest_ref2, 25);
		printf("dprod_sse:"); 
		dump(dest2, 25);
		return -1;
	}
	if (0 != memcmp(dest_ref3, dest3, TEST_LEN)){
		printf("Fail perf vect_dot_prod_sse test3\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:"); 
		dump(dest_ref3, 25);
		printf("dprod_sse:"); 
		dump(dest3, 25);
		return -1;
	}

	printf("pass perf check\n");
	return 0;

}
예제 #11
0
int main(int argc, char *argv[])
{
    int i, j, rtest, m, k, nerrs, r, err;
    void *buf;
    u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
    u8 a[MMAX*KMAX], b[MMAX*KMAX], c[MMAX*KMAX], d[MMAX*KMAX];
    u8 g_tbls[KMAX*TEST_SOURCES*32], src_in_err[TEST_SOURCES];
    u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
    struct perf start, stop;

    m = 32;
    k = 28;
    printf("erasure_code_sse_perf: %dx%d ",
           m, (TEST_LEN(m)));


    // Allocate the arrays
    for(i=0; i<TEST_SOURCES; i++) {
        if (posix_memalign(&buf, 64, TEST_LEN(m))) {
            printf("alloc error: Fail");
            return -1;
        }
        buffs[i] = buf;
    }

    for (i=0; i<TEST_SOURCES; i++) {
        if (posix_memalign(&buf, 64, TEST_LEN(m))) {
            printf("alloc error: Fail");
            return -1;
        }
        temp_buffs[i] = buf;
    }

    // Test erasure code by encode and recovery

    // Pick a first test
    if (m > MMAX || k > KMAX)
        return -1;


    // Make random data
    for(i=0; i<k; i++)
        for(j=0; j<(TEST_LEN(m)); j++)
            buffs[i][j] = rand();


    memset(src_in_err, 0, TEST_SOURCES);

    srand(1);
    for (i=0, nerrs=0; i<k && nerrs<m-k; i++) {
        err = 1 & rand();
        src_in_err[i] = err;
        if (err)
            src_err_list[nerrs++] = i;
    }
    if (nerrs == 0) { // should have at least one error
        while ((err = (rand() % KMAX)) >= k) ;
        src_err_list[nerrs++] = err;
        src_in_err[err] = 1;
    }
    printf("Test erase list = ");
    for (i=0; i<nerrs; i++)
        printf(" %d", src_err_list[i]);
    printf("\n");

    perf_start(&start);

    for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
        gf_gen_rs_matrix(a, m, k);

        // Make parity vects
        ec_init_tables(k, m-k, &a[k*k], g_tbls);
        ec_encode_data_sse((TEST_LEN(m)),
                           k, m-k, g_tbls, buffs, &buffs[k]);
    }

    perf_stop(&stop);
    printf("erasure_code_sse_encode" TEST_TYPE_STR ": ");
    perf_print(stop,start,
               (long long)(TEST_LEN(m))*(m)*rtest);

    perf_start(&start);

    for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
        // Construct b by removing error rows
        for(i=0, r=0; i<k; i++, r++) {
            while (src_in_err[r])
                r++;
            for(j=0; j<k; j++)
                b[k*i+j] = a[k*r+j];
        }

        if (gf_invert_matrix(b, d, k) < 0) {
            printf("BAD MATRIX\n");
            return -1;
        }

        for(i=0, r=0; i<k; i++, r++) {
            while (src_in_err[r])
                r++;
            recov[i] = buffs[r];
        }

        for(i=0; i<nerrs; i++) {
            for(j=0; j<k; j++) {
                c[k*i+j]=d[k*src_err_list[i]+j];
            }
        }

        // Recover data
        ec_init_tables(k, nerrs, c, g_tbls);
        ec_encode_data_sse((TEST_LEN(m)),
                           k, nerrs, g_tbls, recov, &temp_buffs[k]);

    }

    perf_stop(&stop);
    for(i=0; i<nerrs; i++) {
        if (0 != memcmp(temp_buffs[k+i], buffs[src_err_list[i]],
                        (TEST_LEN(m)))) {
            printf("Fail error recovery (%d, %d, %d) - ",
                   m, k, nerrs);
            printf(" - erase list = ");
            for (j=0; j<nerrs; j++)
                printf(" %d", src_err_list[j]);
            printf("\na:\n");
            dump_u8xu8((u8*)a, m, k);
            printf("inv b:\n");
            dump_u8xu8((u8*)d, k, k);
            printf("orig data:\n");
            dump_matrix(buffs, m, 25);
            printf("orig   :");
            dump(buffs[src_err_list[i]],25);
            printf("recov %d:",src_err_list[i]);
            dump(temp_buffs[k+i], 25);
            return -1;
        }
    }

    printf("erasure_code_sse_decode" TEST_TYPE_STR ": ");
    perf_print(stop,start,
               (long long)(TEST_LEN(m))*(k+nerrs)*rtest);

    printf("done all: Pass\n");
    return 0;
}
예제 #12
0
int main(void)
{
	int i, j, k;
	u8 s, vec[TEST_SOURCES], dest1[TEST_LEN], dest2[TEST_LEN];
	u8 *matrix[TEST_SOURCES];
	struct perf start, stop;

	mk_gf_field();
	mk_gf_mul_table(gf_mul_table);

	//generate random vector and matrix/data
	for (i = 0; i < TEST_SOURCES; i++) {
		vec[i] = rand();

		if (!(matrix[i] = malloc(TEST_LEN))) {
			fprintf(stderr, "Error failure\n\n");
			return -1;
		}
		for (j = 0; j < TEST_LEN; j++)
			matrix[i][j] = rand();

	}

	gf_vect_dot_prod_ref(TEST_LEN, TEST_SOURCES, vec, matrix, dest1);

	perf_start(&start);
	for (i = 0; i < TEST_LOOPS; i++)
		gf_vect_dot_prod_ref(TEST_LEN, TEST_SOURCES, vec, matrix, dest1);

	perf_stop(&stop);
	printf("gf_vect_dot_prod_2tbl" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);

	// Warm up mult tables
	for (i = 0; i < TEST_LEN; i++) {
		s = 0;
		for (j = 0; j < TEST_SOURCES; j++) {
			s ^= gf_mul_table[vec[j] * 256 + matrix[j][i]];
		}
		dest2[i] = s;
	}

	perf_start(&start);
	for (k = 0; k < TEST_LOOPS; k++) {
		for (i = 0; i < TEST_LEN; i++) {
			s = 0;
			for (j = 0; j < TEST_SOURCES; j++) {
				s ^= gf_mul_table[vec[j] * 256 + matrix[j][i]];
			}
			dest2[i] = s;
		}
	}
	perf_stop(&stop);
	printf("gf_vect_dot_prod_1tbl" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * k);

	// Compare with reference function
	if (0 != memcmp(dest1, dest2, TEST_LEN)) {
		printf("Error, different results!\n\n");
		return -1;
	}

	printf("Pass functional test\n");
	return 0;
}
예제 #13
0
int main(int argc, char *argv[])
{
	int i, j;
	void *buf;
	u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES];
	u8 g4[TEST_SOURCES], g5[TEST_SOURCES], g6[TEST_SOURCES], *g_tbls;
	u8 *dest1, *dest2, *dest3, *dest4, *dest5, *dest6, *dest_ref1;
	u8 *dest_ref2, *dest_ref3, *dest_ref4, *dest_ref5, *dest_ref6;
	u8 *dest_ptrs[6], *buffs[TEST_SOURCES];
	struct perf start, stop;

	printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);

	// Allocate the arrays
	for (i = 0; i < TEST_SOURCES; i++) {
		if (posix_memalign(&buf, 64, TEST_LEN)) {
			printf("alloc error: Fail");
			return -1;
		}
		buffs[i] = buf;
	}

	if (posix_memalign(&buf, 16, 6 * TEST_SOURCES * 32)) {
		printf("alloc error: Fail");
		return -1;
	}
	g_tbls = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest1 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest2 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest3 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest4 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest5 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest6 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref1 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref2 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref3 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref4 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref5 = buf;

	if (posix_memalign(&buf, 64, TEST_LEN)) {
		printf("alloc error: Fail");
		return -1;
	}
	dest_ref6 = buf;

	dest_ptrs[0] = dest1;
	dest_ptrs[1] = dest2;
	dest_ptrs[2] = dest3;
	dest_ptrs[3] = dest4;
	dest_ptrs[4] = dest5;
	dest_ptrs[5] = dest6;

	// Performance test
	for (i = 0; i < TEST_SOURCES; i++)
		for (j = 0; j < TEST_LEN; j++)
			buffs[i][j] = rand();

	memset(dest1, 0, TEST_LEN);
	memset(dest2, 0, TEST_LEN);
	memset(dest3, 0, TEST_LEN);
	memset(dest4, 0, TEST_LEN);
	memset(dest5, 0, TEST_LEN);
	memset(dest6, 0, TEST_LEN);
	memset(dest_ref1, 0, TEST_LEN);
	memset(dest_ref2, 0, TEST_LEN);
	memset(dest_ref3, 0, TEST_LEN);
	memset(dest_ref4, 0, TEST_LEN);
	memset(dest_ref5, 0, TEST_LEN);
	memset(dest_ref6, 0, TEST_LEN);

	for (i = 0; i < TEST_SOURCES; i++) {
		g1[i] = rand();
		g2[i] = rand();
		g3[i] = rand();
		g4[i] = rand();
		g5[i] = rand();
		g6[i] = rand();
	}

	for (j = 0; j < TEST_SOURCES; j++) {
		gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
		gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
		gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
		gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
		gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
		gf_vect_mul_init(g6[j], &g_tbls[(160 * TEST_SOURCES) + (j * 32)]);
	}

	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
			      dest_ref2);
	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs,
			      dest_ref3);
	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES], buffs,
			      dest_ref4);
	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES], buffs,
			      dest_ref5);
	gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[160 * TEST_SOURCES], buffs,
			      dest_ref6);

#ifdef DO_REF_PERF
	perf_start(&start);
	for (i = 0; i < TEST_LOOPS / 20; i++) {
		for (j = 0; j < TEST_SOURCES; j++) {
			gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
			gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g6[j], &g_tbls[(160 * TEST_SOURCES) + (j * 32)]);
		}

		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
				      buffs, dest_ref2);
		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES],
				      buffs, dest_ref3);
		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES],
				      buffs, dest_ref4);
		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES],
				      buffs, dest_ref5);
		gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[160 * TEST_SOURCES],
				      buffs, dest_ref6);
	}
	perf_stop(&stop);
	printf("gf_6vect_dot_prod_base" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 6) * i);
#endif

	FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);

	perf_start(&start);
	for (i = 0; i < TEST_LOOPS; i++) {
		for (j = 0; j < TEST_SOURCES; j++) {
			gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
			gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
			gf_vect_mul_init(g6[j], &g_tbls[(160 * TEST_SOURCES) + (j * 32)]);
		}

		FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
	}
	perf_stop(&stop);
	printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 6) * i);

	if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
		printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:");
		dump(dest_ref1, 25);
		printf("dprod_dut:");
		dump(dest1, 25);
		return -1;
	}
	if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
		printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:");
		dump(dest_ref2, 25);
		printf("dprod_dut:");
		dump(dest2, 25);
		return -1;
	}
	if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) {
		printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test3\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:");
		dump(dest_ref3, 25);
		printf("dprod_dut:");
		dump(dest3, 25);
		return -1;
	}
	if (0 != memcmp(dest_ref4, dest4, TEST_LEN)) {
		printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test4\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:");
		dump(dest_ref4, 25);
		printf("dprod_dut:");
		dump(dest4, 25);
		return -1;
	}
	if (0 != memcmp(dest_ref5, dest5, TEST_LEN)) {
		printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test5\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:");
		dump(dest_ref5, 25);
		printf("dprod_dut:");
		dump(dest5, 25);
		return -1;
	}
	if (0 != memcmp(dest_ref6, dest6, TEST_LEN)) {
		printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test6\n");
		dump_matrix(buffs, 5, TEST_SOURCES);
		printf("dprod_base:");
		dump(dest_ref6, 25);
		printf("dprod_dut:");
		dump(dest6, 25);
		return -1;
	}

	printf("pass perf check\n");
	return 0;

}
예제 #14
0
int main(int argc, char *argv[])
{
        int i, j, rtest, m, k, nerrs, r;
        void *buf;
        u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
        u8 a[MMAX * KMAX], b[MMAX * KMAX], c[MMAX * KMAX], d[MMAX * KMAX];
        u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
        u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
        struct perf start, stop;

        // Pick test parameters
        m = 14;
        k = 10;
        nerrs = 4;
        const u8 err_list[] = {2, 4, 5, 7};

        printf("erasure_code_base_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);

        if (m > MMAX || k > KMAX || nerrs > (m - k)){
                printf(" Input test parameter error\n");
                return -1;
        }

        memcpy(src_err_list, err_list, nerrs);
        memset(src_in_err, 0, TEST_SOURCES);
        for (i = 0; i < nerrs; i++)
                src_in_err[src_err_list[i]] = 1;

        // Allocate the arrays
        for (i = 0; i < m; i++) {
                if (posix_memalign(&buf, 64, TEST_LEN(m))) {
                        printf("alloc error: Fail\n");
                        return -1;
                }
                buffs[i] = buf;
        }

        for (i = 0; i < (m - k); i++) {
                if (posix_memalign(&buf, 64, TEST_LEN(m))) {
                        printf("alloc error: Fail\n");
                        return -1;
                }
                temp_buffs[i] = buf;
        }

        // Make random data
        for (i = 0; i < k; i++)
                for (j = 0; j < TEST_LEN(m); j++)
                        buffs[i][j] = rand();

        gf_gen_rs_matrix(a, m, k);
        ec_init_tables(k, m - k, &a[k * k], g_tbls);
        ec_encode_data_base(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);

        // Start encode test
        perf_start(&start);
        for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
                // Make parity vects
                ec_init_tables(k, m - k, &a[k * k], g_tbls);
                ec_encode_data_base(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);
        }
        perf_stop(&stop);
        printf("erasure_code_base_encode" TEST_TYPE_STR ": ");
        perf_print(stop, start, (long long)(TEST_LEN(m)) * (m) * rtest);

        // Start decode test
        perf_start(&start);
        for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
                // Construct b by removing error rows
                for (i = 0, r = 0; i < k; i++, r++) {
                        while (src_in_err[r])
                                r++;
                        recov[i] = buffs[r];
                        for (j = 0; j < k; j++)
                                b[k * i + j] = a[k * r + j];
                }

                if (gf_invert_matrix(b, d, k) < 0) {
                        printf("BAD MATRIX\n");
                        return -1;
                }

                for (i = 0; i < nerrs; i++)
                        for (j = 0; j < k; j++)
                                c[k * i + j] = d[k * src_err_list[i] + j];

                // Recover data
                ec_init_tables(k, nerrs, c, g_tbls);
                ec_encode_data_base(TEST_LEN(m), k, nerrs, g_tbls, recov, temp_buffs);
        }
        perf_stop(&stop);

        for (i = 0; i < nerrs; i++) {
                if (0 != memcmp(temp_buffs[i], buffs[src_err_list[i]], TEST_LEN(m))) {
                        printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
                        return -1;
                }
        }

        printf("erasure_code_base_decode" TEST_TYPE_STR ": ");
        perf_print(stop, start, (long long)(TEST_LEN(m)) * (k + nerrs) * rtest);

        printf("done all: Pass\n");
        return 0;
}
예제 #15
0
int main(int argc, char *argv[])
{
	FILE *in, *out = NULL;
	unsigned char *inbuf, *outbuf;
	int i, infile_size, iterations, outbuf_size;

	if (argc > 3 || argc < 2) {
		fprintf(stderr, "Usage: igzip_sync_flush_file_perf  infile [outfile]\n"
			"\t - Runs multiple iterations of igzip on a file to get more accurate time results.\n");
		exit(0);
	}
	in = fopen(argv[1], "rb");
	if (!in) {
		fprintf(stderr, "Can't open %s for reading\n", argv[1]);
		exit(0);
	}
	if (argc > 2) {
		out = fopen(argv[2], "wb");
		if (!out) {
			fprintf(stderr, "Can't open %s for writing\n", argv[2]);
			exit(0);
		}
		printf("outfile=%s\n", argv[2]);
	}
	printf("Window Size: %d K\n", HIST_SIZE);
	printf("igzip_sync_flush_file_perf: \n");
	fflush(0);
	/* Allocate space for entire input file and
	 * output (assuming 1:1 max output size)
	 */
	infile_size = get_filesize(in);

	if (infile_size != 0) {
		outbuf_size = infile_size;
		iterations = RUN_MEM_SIZE / infile_size;
	} else {
		outbuf_size = BUF_SIZE;
		iterations = MIN_TEST_LOOPS;
	}
	if (iterations < MIN_TEST_LOOPS)
		iterations = MIN_TEST_LOOPS;

	inbuf = malloc(infile_size);
	if (inbuf == NULL) {
		fprintf(stderr, "Can't allocate input buffer memory\n");
		exit(0);
	}
	outbuf = malloc(outbuf_size);
	if (outbuf == NULL) {
		fprintf(stderr, "Can't allocate output buffer memory\n");
		exit(0);
	}

	printf("igzip_sync_flush_file_perf: %s %d iterations\n", argv[1], iterations);
	/* Read complete input file into buffer */
	stream.avail_in = (uint32_t) fread(inbuf, 1, infile_size, in);
	if (stream.avail_in != infile_size) {
		fprintf(stderr, "Couldn't fit all of input file into buffer\n");
		exit(0);
	}

	struct perf start, stop;
	perf_start(&start);

	for (i = 0; i < iterations; i++) {
		isal_deflate_init(&stream);
		stream.end_of_stream = 0;
		stream.flush = SYNC_FLUSH;
		stream.next_in = inbuf;
		stream.avail_in = infile_size / 2;
		stream.next_out = outbuf;
		stream.avail_out = outbuf_size / 2;
		isal_deflate(&stream);
		if (infile_size == 0)
			continue;
		stream.avail_in = infile_size - infile_size / 2;
		stream.end_of_stream = 1;
		stream.next_in = inbuf + stream.total_in;
		stream.flush = SYNC_FLUSH;
		stream.avail_out = infile_size - outbuf_size / 2;
		stream.next_out = outbuf + stream.total_out;
		isal_deflate(&stream);
		if (stream.avail_in != 0)
			break;
	}
	perf_stop(&stop);

	if (stream.avail_in != 0) {
		fprintf(stderr, "Could not compress all of inbuf\n");
		exit(0);
	}

	printf("  file %s - in_size=%d out_size=%d iter=%d ratio=%3.1f%%\n", argv[1],
	       infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size);

	printf("igzip_file: ");
	perf_print(stop, start, (long long)infile_size * i);

	if (argc > 2 && out) {
		printf("writing %s\n", argv[2]);
		fwrite(outbuf, 1, stream.total_out, out);
		fclose(out);
	}

	fclose(in);
	printf("End of igzip_sync_flush_file_perf\n\n");
	fflush(0);
	return 0;
}
예제 #16
0
int main(void)
{
	int i;

	unsigned char key1[16], key2[16], tinit[16];
	unsigned char *pt, *ct, *refct;
	struct perf start, stop;
	unsigned char keyssl[32];	/* SSL takes both keys together */

	/* Initialise our cipher context, which can use same input vectors */
	EVP_CIPHER_CTX *ctx;
	ctx = EVP_CIPHER_CTX_new();

	printf("aes_xts_128_enc_perf:\n");

	pt = malloc(TEST_LEN);
	ct = malloc(TEST_LEN);
	refct = malloc(TEST_LEN);

	if (NULL == pt || NULL == ct || NULL == refct) {
		printf("malloc of testsize failed\n");
		return -1;
	}

	xts128_mk_rand_data(key1, key2, tinit, pt, TEST_LEN);

	/* Set up key for the SSL engine */
	for (i = 0; i < 16; i++) {
		keyssl[i] = key1[i];
		keyssl[i + 16] = key2[i];
	}

	/* Encrypt and compare output */
	XTS_AES_128_enc(key2, key1, tinit, TEST_LEN, pt, ct);
	openssl_aes_128_xts_enc(ctx, keyssl, tinit, TEST_LEN, pt, refct);
	if (memcmp(ct, refct, TEST_LEN)) {
		printf("ISA-L and OpenSSL results don't match\n");
		return -1;
	}

	/* Time ISA-L encryption */
	perf_start(&start);
	for (i = 0; i < TEST_LOOPS; i++)
		XTS_AES_128_enc(key2, key1, tinit, TEST_LEN, pt, ct);
	perf_stop(&stop);

	printf("aes_xts_128_enc" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * i);

	/* Time OpenSSL encryption */
	perf_start(&start);
	for (i = 0; i < TEST_LOOPS; i++)
		openssl_aes_128_xts_enc(ctx, keyssl, tinit, TEST_LEN, pt, refct);
	perf_stop(&stop);

	printf("aes_xts_128_openssl_enc" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * i);

	EVP_CIPHER_CTX_free(ctx);

	return 0;
}
예제 #17
0
int main(void)
{
	MD5_HASH_CTX_MGR *mgr = NULL;
	MD5_HASH_CTX ctxpool[TEST_BUFS];
	unsigned char *bufs[TEST_BUFS];
	uint32_t i, j, t, fail = 0;
	struct perf start, stop;

	for (i = 0; i < TEST_BUFS; i++) {
		bufs[i] = (unsigned char *)calloc((size_t) TEST_LEN, 1);
		if (bufs[i] == NULL) {
			printf("calloc failed test aborted\n");
			return 1;
		}
		// Init ctx contents
		hash_ctx_init(&ctxpool[i]);
		ctxpool[i].user_data = (void *)((uint64_t) i);
	}

	posix_memalign((void *)&mgr, 16, sizeof(MD5_HASH_CTX_MGR));
	md5_ctx_mgr_init(mgr);

	// Start OpenSSL tests
	perf_start(&start);
	for (t = 0; t < TEST_LOOPS; t++) {
		for (i = 0; i < TEST_BUFS; i++)
			MD5(bufs[i], TEST_LEN, digest_ssl[i]);
	}
	perf_stop(&stop);

	printf("md5_openssl" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * i * t);

	// Start mb tests
	perf_start(&start);
	for (t = 0; t < TEST_LOOPS; t++) {
		for (i = 0; i < TEST_BUFS; i++)
			md5_ctx_mgr_submit(mgr, &ctxpool[i], bufs[i], TEST_LEN, HASH_ENTIRE);

		while (md5_ctx_mgr_flush(mgr)) ;
	}
	perf_stop(&stop);

	printf("multibinary_md5" TEST_TYPE_STR ": ");
	perf_print(stop, start, (long long)TEST_LEN * i * t);

	for (i = 0; i < TEST_BUFS; i++) {
		for (j = 0; j < MD5_DIGEST_NWORDS; j++) {
			if (ctxpool[i].job.result_digest[j] != ((uint32_t *) digest_ssl[i])[j]) {
				fail++;
				printf("Test%d, digest%d fail %08X <=> %08X\n",
				       i, j, ctxpool[i].job.result_digest[j],
				       ((uint32_t *) digest_ssl[i])[j]);
			}
		}
	}

	printf("Multi-buffer md5 test complete %d buffers of %d B with "
	       "%d iterations\n", TEST_BUFS, TEST_LEN, TEST_LOOPS);

	if (fail)
		printf("Test failed function check %d\n", fail);
	else
		printf(" multibinary_md5_ossl_perf: Pass\n");

	return fail;
}