Beispiel #1
0
/*
 * Funkcja przeprowadzajaca pomiary szyfrowania 1 MB danych
 */
void test_wydajnosci_3des_pot()
{
	printf("Test wydajnosci potokowej realizacji szyfratora i deszyfratora Triple DES \n");
	PERF_RESET(PERFORMANCE_COUNTER_0_BASE );
	PERF_START_MEASURING(PERFORMANCE_COUNTER_0_BASE);
	int i=0;
	int j=0;
	PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE ,2); //rozpoczecie pracy 2 licznika mierzacego takty zegara
	while(i<512)
	{
		ciph_3des_pot(&blok_testowy+2048*i,&blok_testowy+1048576+2048*i,2048);


		i++;
	}
	PERF_END(PERFORMANCE_COUNTER_0_BASE ,2); //zakonczenie pracy 2 licznika mierzacego takty zegara
	i=0;
	PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE ,1);//rozpoczecie pracy 1 licznika mierzacego takty zegara
	while(i<512)
	 {
		deciph_3des_pot(&blok_testowy+2048*i,&blok_testowy+1048576+2048*i,2048);
		i++;
	 }
	PERF_STOP_MEASURING(PERFORMANCE_COUNTER_0_BASE); //zakonczenie pracy wszystkich licznikow
	perf_print_formatted_report((void* )PERFORMANCE_COUNTER_0_BASE,
			ALT_CPU_FREQ*2,2,"3Des_pot 1MB szyfr","3Des_pot 1MB deszyfr"); //generacja raportu

}
Beispiel #2
0
/**
 * Funkcja testujaca wydajnosc modulow Triple DES przy wykorzystaniu zapisu i odczytu danych na On-Chip Memory
 */
void test_wydajnosc ()
{
 printf ("Test wydajnosci \n");
	PERF_RESET(PERFORMANCE_COUNTER_0_BASE );
	PERF_START_MEASURING(PERFORMANCE_COUNTER_0_BASE);
	int i=0;
	int j=0;
	PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE ,2); //rozpoczecie pracy 2 licznika mierzacego takty zegara
	while(i<512)
	{
		deciph_3des(dane[2*i],dane[2*i+1]);
		j--;
		j++;
		deciph_3des_read(&wyniki[2*i],&wyniki[2*i+1]);
		i++;
	}
	PERF_END(PERFORMANCE_COUNTER_0_BASE ,2); //zakonczenie pracy 2 licznika mierzacego takty zegara
	i=0;
	PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE ,1);//rozpoczecie pracy 1 licznika mierzacego takty zegara
	while(i<512)
	 {
	ciph_3des(dane[2*i],dane[2*i+1]);
	j--;
	j++;
	ciph_3des_read(&wyniki[2*i],&wyniki[2*i+1]);
	i++;
	 }
	PERF_STOP_MEASURING(PERFORMANCE_COUNTER_0_BASE); //zakonczenie pracy wszystkich licznikow
	perf_print_formatted_report((void* )PERFORMANCE_COUNTER_0_BASE,	ALT_CPU_FREQ*2,2,"3Des 32Kbit szyfr","3Des 32Kbit deszyfr"); //generacja raportu
}
int main()
{
  volatile int i,j,k; //i = row, j = column,
  int count;
  int M1[10][10]={0,0,0,0,0,0,0,0,0,0,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    19,32,33,34,32,32,33,34,32,32,                    
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    19,32,33,34,32,32,33,34,32,32};  

  int M2[10][10]={32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    19,32,33,34,32,32,33,34,32,32,                    
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    32,32,33,34,32,32,33,34,32,32,
                    19,32,33,34,32,32,33,34,32,32};
  int C[10][10]={0};

  PERF_RESET (PERFORMANCE_COUNTER_BASE);            //Reset Performance Counters to 0

  PERF_START_MEASURING (PERFORMANCE_COUNTER_BASE);  //Start the Counter

  PERF_BEGIN (PERFORMANCE_COUNTER_BASE,2);          //Start the overhead counter
    PERF_BEGIN (PERFORMANCE_COUNTER_BASE,1);        //Start the Matrix Multiplication Counter
  PERF_END (PERFORMANCE_COUNTER_BASE,2);            //Stop the overhead counter

  count = 0;
  while(count<100){
  count++;
    for (i=0;i<=9;i++){
      for (j=0;j<=9;j++){
        C[i][j] = 0;
        for (k=0;k<=9;k++){
          C[i][j]+=M1[i][k]*M2[k][j];
        }
        //printf("%f ", C[i][j]);
      }
    }
  }

  PERF_END (PERFORMANCE_COUNTER_BASE,1);            //Stop the Matrix Multiplication Counter
  PERF_STOP_MEASURING (PERFORMANCE_COUNTER_BASE);   //Stop all counters
  
  perf_print_formatted_report((void *)PERFORMANCE_COUNTER_BASE, ALT_CPU_FREQ, 2,
  "100 loops","PC overhead");  
    
  return 0;
}
Beispiel #4
0
/*
 * Test wydajnosci szyfrowania 1MB danych z zapisem i odczytem do pamieci SRAM
 */
void test_wydajnosci_sram()
{
	PERF_RESET(PERFORMANCE_COUNTER_0_BASE );
	PERF_START_MEASURING(PERFORMANCE_COUNTER_0_BASE);
	PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE ,1); //uruchomienie 1 licznia
	przeprowadzenie_szyfrowania_sram();
	PERF_END(PERFORMANCE_COUNTER_0_BASE ,1); //wylaczenie 1 licznika
	PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE ,2); // uruchomienie 2 licznika
	przeprowadzenie_deszyfrowania_sram();
	PERF_STOP_MEASURING(PERFORMANCE_COUNTER_0_BASE); //wylaczenie wszystkich licznikow
	perf_print_formatted_report((void* )PERFORMANCE_COUNTER_0_BASE,	ALT_CPU_FREQ*2,2,"Test szyfr 3DES(1MB)","Test deszyfr 3DES(1MB)");
}
int perf_print_formatted_report (void* perf_base, 
                                 alt_u32 clock_freq_hertz,
                                 int num_sections, ...)
{
  va_list name_args;
  double total_sec;
  alt_u64 total_clocks;
  alt_u64 section_clocks;
  char* section_name;
  int section_num = 1;

  const char* separator = 
    "+---------------+-----+-----------+---------------+-----------+\n";
  const char* column_header = 
    "| Section       |  %  | Time (sec)|  Time (clocks)|Occurrences|\n";

  PERF_STOP_MEASURING (perf_base);

  va_start (name_args, num_sections);

  total_clocks = perf_get_total_time (perf_base);
  total_sec    = ((double)total_clocks) / clock_freq_hertz;

  // Print the total at the top:
  printf ("--Performance Counter Report--\nTotal Time: %3G seconds  (%lld clock-cycles)\n%s%s%s",
          total_sec, total_clocks, separator, column_header, separator);

  section_name = va_arg(name_args, char*);

  for (section_num = 1; section_num <= num_sections; section_num++)
    {
      section_clocks = perf_get_section_time (perf_base, section_num);

      printf ("|%-15s|%5.3g|%11.5f|%15lld|%11u|\n%s",
              section_name,
              ((((double) section_clocks)) * 100) / total_clocks,
              (((double) section_clocks)) / clock_freq_hertz,
              section_clocks,
              (unsigned int) perf_get_num_starts (perf_base, section_num),
              separator
              );

      section_name = va_arg(name_args, char*);
    }

  va_end (name_args);

  return 0;
}
int main(void)
{
    alt_putstr("Hello from Nios II!\n");

    fill_arrays_with_random_values();

    PERF_RESET(PERFORMANCE_COUNTER_0_BASE);
    PERF_START_MEASURING(PERFORMANCE_COUNTER_0_BASE);


    PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, 1);
    shuffle_in_c(array_for_c, ARRAY_SIZE);
    PERF_END(PERFORMANCE_COUNTER_0_BASE, 1);

    PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, 2);
    shuffle_with_custom_instruction(array_for_custom_instr, ARRAY_SIZE);
    PERF_END(PERFORMANCE_COUNTER_0_BASE, 2);

    PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, 3);
    shuffle_with_accelerator(array_for_accelerator, ARRAY_SIZE);
    PERF_END(PERFORMANCE_COUNTER_0_BASE, 3);


    PERF_STOP_MEASURING(PERFORMANCE_COUNTER_0_BASE);
    perf_print_formatted_report((void *) PERFORMANCE_COUNTER_0_BASE, ALT_CPU_FREQ, 3, ""
    		"shuffle_with_c", "shuffle_with_custom_instruction", "shuffle_with_accelerator");

    //verify_arrays();

#ifdef SMALL_ARRAY
    alt_putstr("Shuffle with C:\t\t\t");
    print_array(array_for_c, ARRAY_SIZE);
    alt_putstr("Shuffle with custom instruction:\t");
    print_array(array_for_custom_instr, ARRAY_SIZE);
    alt_putstr("Shuffle with accelerator:\t\t");
    print_array(cache_bypass(array_for_accelerator), ARRAY_SIZE);
#endif

    return 0;
}
Beispiel #7
0
int main()
{ 
	int data_set[ARRAY_SIZE];
	int i;
	
	printf("Generating random data...\n");
	for (i = 0; i < ARRAY_SIZE; i++) {
		data_set[i] = rand() % 65536;
	}
	
	// For performance counter
	PERF_RESET(PERFORMANCE_COUNTER_0_BASE);
	
	// Start the performance counter
	PERF_START_MEASURING(performance_name);
	
	printf("Start sorting...\n");
	
	// Start performance counter
	PERF_BEGIN(performance_name, 1);
	
	bubble_sort(data_set, ARRAY_SIZE);
	
	// Stop performance counter
	PERF_END(performance_name, 1);

	// Start the performance counter
	PERF_STOP_MEASURING(performance_name);
	
	printf("PC: %d\n", perf_get_section_time(performance_name, 1));
	
  /* Event loop never exits. */
  while (1);

  return 0;
}
/*
 * When the small C library is enabled, the printf function does not support
 * floating point format. This function print the time in usec instead of
 * second.
 */
int perf_print_formatted_report (void* perf_base, 
                                 alt_u32 clock_freq_hertz,
                                 int num_sections, ...)
{
    va_list name_args;
    alt_u64 total_usec;
    alt_u64 total_clocks;
    alt_u64 section_clocks;
    char* section_name;
    int section_num = 1;

    const char* separator =
      "+---------------+-----+------------+---------------+------------+\n";
    
    const char* column_header =
      "| Section       |  %  | Time (usec)|  Time (clocks)|Occurrences |\n";

    PERF_STOP_MEASURING (perf_base);

    va_start (name_args, num_sections);

    total_clocks = perf_get_total_time (perf_base);
    total_usec = total_clocks * 1000000 / clock_freq_hertz;

    // Print the total at the top:
    printf("--Performance Counter Report--\n");
    printf("Total Time : %llu usec ", total_usec);            
    printf("(%llu clock-cycles)\n", total_clocks);            
    printf("%s", separator);
    printf("%s", column_header);
    printf("%s", separator);

    section_name = va_arg(name_args, char*);

    for (section_num = 1; section_num <= num_sections; section_num++)
    {
        section_clocks = perf_get_section_time (perf_base, section_num);
        /* section name, small C library does not support left-justify, 
         * uses right-justify instead.
         */
        printf ("|%15s", section_name);

        /* section usage */
        if (total_clocks) 
        {
            printf ("|%4u ", (unsigned int)(section_clocks * 100 / total_clocks));
        }
        else
        {
            printf ("|%4u ", 0);
        }        

        /* section usecs */
        printf ("|%11llu ", (alt_u64)(section_clocks * 1000000 / clock_freq_hertz));

        /* section clocks */
        printf ("|%14u ", (unsigned int)section_clocks);

        /* section occurrences */
        printf ("|%10u  |\n",
        (unsigned int) perf_get_num_starts (perf_base, section_num));

        printf ("%s", separator);

        section_name = va_arg(name_args, char*);
    }

    va_end (name_args);

    return 0;
}