Пример #1
0
int border_initialize(char *if_name, const char *ip_addr, const char *tty_dev)
{
    int res, i;
    char command[21 + IPV6_ADDR_LEN + IF_NAME_LEN];
    char ip_addr_cpy[IPV6_ADDR_LEN];
    struct in6_addr parsed_addr;

    strncpy(ip_addr_cpy, ip_addr, IPV6_ADDR_LEN);

    strtok(ip_addr_cpy, "/");

    if ((res = inet_pton(AF_INET6, ip_addr_cpy, &parsed_addr)) != 1) {
        return res;
    }

    if ((res = init_multiplex(tty_dev)) != 0) {
        return res;
    }

    tun_fd = open_tun(if_name, IFF_TUN);

    printf("INFO: ip link set %s up\n", if_name);
    sprintf(command, "ip link set %s up", if_name);

    strncpy(tun_if_name, if_name, IF_NAME_LEN);

    if ((res = system(command)) != 0) {
        return res;
    }

    if ((res = tun_add_addr(ip_addr)) != 0) {
        return res;
    }

    // initialize context cache as empty.
    for (i = 0; i < MAXIMUM_CONTEXTS; i++) {
        context_cache[i].cid = 0xFF;
    }

    pthread_create(&serial_reader, NULL, serial_reader_f, NULL);

    hard_reset_to_user_code();
    flowcontrol_init(&parsed_addr);
    pthread_create(&tun_reader, NULL, tun_reader_f, NULL);

    return 0;
}
Пример #2
0
void event_init(void) {

    int retval;

    // library initialization
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT )
        test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

    // multiplex initialization
    init_multiplex(  );

    // place for initialization in case one makes use of threads
    retval = PAPI_thread_init((unsigned long (*)(void))(pthread_self));
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );

    printf("event_init done \n");


}
Пример #3
0
int main(int argc, char **argv)
{
   PAPI_event_info_t info;
   char name2[PAPI_MAX_STR_LEN];
   int i, j, retval, idx, repeats;
   int iters = NUM_FLOPS;
   double x = 1.1, y, dtmp;
   long long t1, t2;
   long long values[MAXEVENTS], refvals[MAXEVENTS];
   int nsamples[MAXEVENTS], truelist[MAXEVENTS], ntrue;
#ifdef STARTSTOP
   long long dummies[MAXEVENTS];
#endif
   int sleep_time = SLEEPTIME;
   double valsample[MAXEVENTS][REPEATS];
   double valsum[MAXEVENTS];
   double avg[MAXEVENTS];
   double spread[MAXEVENTS];
   int nevents = MAXEVENTS, nev1;
   int eventset = PAPI_NULL;
   int events[MAXEVENTS];
   int eventidx[MAXEVENTS];
   int eventmap[MAXEVENTS];
   int fails;

   events[0] = PAPI_FP_INS;
   events[1] = PAPI_TOT_CYC;
   events[2] = PAPI_TOT_INS;
   events[3] = PAPI_TOT_IIS;
   events[4] = PAPI_INT_INS;
   events[5] = PAPI_STL_CCY;
   events[6] = PAPI_BR_INS;
   events[7] = PAPI_SR_INS;
   events[8] = PAPI_LD_INS;

   for (i = 0; i < MAXEVENTS; i++) {
      values[i] = 0;
      valsum[i] = 0;
      nsamples[i] = 0;
   }

   if (argc > 1) {
      if (!strcmp(argv[1], "TESTS_QUIET"))
         tests_quiet(argc, argv);
      else {
         sleep_time = atoi(argv[1]);
         if (sleep_time <= 0)
            sleep_time = SLEEPTIME;
      }
   }

   if (!TESTS_QUIET) {
      printf("\nFunctional check of multiplexing routines.\n");
      printf("Adding and removing events from an event set.\n\n");
   }

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

#ifdef MPX
   init_multiplex();
#endif
   if ((retval = PAPI_create_eventset(&eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

#ifdef MPX

   /* In Component PAPI, EventSets must be assigned a component index
      before you can fiddle with their internals.
      0 is always the cpu component */
   retval = PAPI_assign_eventset_component(eventset, 0);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval);

   if ((retval = PAPI_set_multiplex(eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval);
#endif

   nevents = MAXEVENTS;
   for (i = 0; i < nevents; i++) {
      if ((retval = PAPI_add_event(eventset, events[i]))) {
         for (j = i; j < MAXEVENTS; j++)
            events[j] = events[j + 1];
         nevents--;
         i--;
      }
   }
   if (nevents < 3)
      test_skip(__FILE__, __LINE__, "Not enough events left...", 0);

   /* Find a reasonable number of iterations (each 
    * event active 20 times) during the measurement
    */
   t2 = 10000 * 20 * nevents;   /* Target: 10000 usec/multiplex, 20 repeats */
   if (t2 > 30e6)
      test_skip(__FILE__, __LINE__, "This test takes too much time", retval);

   /* Measure one run */
   t1 = PAPI_get_real_usec();
   y = dummy3(x, iters);
   t1 = PAPI_get_real_usec() - t1;

   if (t2 > t1)                 /* Scale up execution time to match t2 */
      iters = iters * (int)(t2 / t1);
   else if (t1 > 30e6)          /* Make sure execution time is < 30s per repeated test */
      test_skip(__FILE__, __LINE__, "This test takes too much time", retval);

   j = nevents;
   for (i = 1; i < nevents; i = i + 2)
      eventidx[--j] = i;
   for (i = 0; i < nevents; i = i + 2)
      eventidx[--j] = i;
   assert(j == 0);
   for (i = 0; i < nevents; i++)
      eventmap[i] = i;

   x = 1.0;

   if (!TESTS_QUIET)
      printf("\nReference run:\n");

   t1 = PAPI_get_real_usec();
   if ((retval = PAPI_start(eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);
   y = dummy3(x, iters);
   PAPI_read(eventset, refvals);
   t2 = PAPI_get_real_usec();

   ntrue = nevents;
   PAPI_list_events(eventset, truelist, &ntrue);
   if (!TESTS_QUIET) {
      printf("\tOperations= %.1f Mflop", y * 1e-6);
      printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1)));
      printf("%20s   %16s   %-15s %-15s\n", "PAPI measurement:",
             "Acquired count", "Expected event", "PAPI_list_events");
   }

   if (!TESTS_QUIET) {
      for (j = 0; j < nevents; j++) {
         PAPI_get_event_info(events[j], &info);
         PAPI_event_code_to_name(truelist[j], name2);
         if (!TESTS_QUIET)
            printf("%20s = %16lld   %-15s %-15s %s\n", info.short_descr, refvals[j],
                   info.symbol, name2, strcmp(info.symbol,
                                              name2) ? "*** MISMATCH ***" : "");
      }
      printf("\n");
   }

   nev1 = nevents;
   repeats = nevents * 4;
   for (i = 0; i < repeats; i++) {
      if ((i % nevents) + 1 == nevents)
         continue;

      if (!TESTS_QUIET)
         printf("\nTest %d (of %d):\n", i + 1 - i / nevents, repeats - 4);

      if ((retval = PAPI_stop(eventset, values)))
         test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

      j = eventidx[i % nevents];

      if ((i / nevents) % 2 == 0) {
         PAPI_get_event_info(events[j], &info);
         if (!TESTS_QUIET)
            printf("Removing event[%d]: %s\n", j, info.short_descr);
         if ((retval = PAPI_remove_event(eventset, events[j])))
            test_fail(__FILE__, __LINE__, "PAPI_remove_event", retval);
         nev1--;
         for (idx = 0; eventmap[idx] != j; idx++);
         for (j = idx; j < nev1; j++)
            eventmap[j] = eventmap[j + 1];
      } else {
         PAPI_get_event_info(events[j], &info);
         if (!TESTS_QUIET)
            printf("Adding event[%d]: %s\n", j, info.short_descr);
         if ((retval = PAPI_add_event(eventset, events[j])))
            test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);
         eventmap[nev1] = j;
         nev1++;
      }
      if ((retval = PAPI_start(eventset)))
         test_fail(__FILE__, __LINE__, "PAPI_start", retval);

      x = 1.0;
#ifndef STARTSTOP
      if ((retval = PAPI_reset(eventset)))
         test_fail(__FILE__, __LINE__, "PAPI_reset", retval);
#else
      if ((retval = PAPI_stop(eventset, dummies)))
         test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
      if ((retval = PAPI_start(eventset)))
         test_fail(__FILE__, __LINE__, "PAPI_start", retval);
#endif

      t1 = PAPI_get_real_usec();
      y = dummy3(x, iters);
      PAPI_read(eventset, values);
      t2 = PAPI_get_real_usec();

      if (!TESTS_QUIET) {
         printf("\n(calculated independent of PAPI)\n");
         printf("\tOperations= %.1f Mflop", y * 1e-6);
         printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1)));
         printf("%20s   %16s   %-15s %-15s\n", "PAPI measurement:",
                "Acquired count", "Expected event", "PAPI_list_events");
      }

      ntrue = nev1;
      PAPI_list_events(eventset, truelist, &ntrue);
      for (j = 0; j < nev1; j++) {
         idx = eventmap[j];
         /* printf("Mapping: Counter %d -> slot %d.\n",j,idx); */
         PAPI_get_event_info(events[idx], &info);
         PAPI_event_code_to_name(truelist[j], name2);
         if (!TESTS_QUIET)
            printf("%20s = %16lld   %-15s %-15s %s\n", info.short_descr, values[j],
                   info.symbol, name2, strcmp(info.symbol,
                                              name2) ? "*** MISMATCH ***" : "");
         dtmp = (double) values[j];
         valsum[idx] += dtmp;
         valsample[idx][nsamples[idx]] = dtmp;
         nsamples[idx]++;
      }
      if (!TESTS_QUIET)
         printf("\n");
   }


   if (!TESTS_QUIET) {
      printf("\n\nEstimated variance relative to average counts:\n");
      for (j = 0; j < nev1; j++)
         printf("   Event %.2d", j);
      printf("\n");
   }

   fails = nevents;
   /* Due to limited precision of floating point cannot really use
      typical standard deviation compuation for large numbers with
      very small variations. Instead compute the std devation
      problems with precision.
   */
   for (j = 0; j < nev1; j++) {
      avg[j] = valsum[j] / nsamples[j];
      spread[j] = 0;
      for (i=0; i < nsamples[j]; ++i) {
         double diff = (valsample[j][i] - avg[j]);
         spread[j] += diff * diff;
      }
      spread[j] = sqrt(spread[j] / nsamples[j]) / avg[j];
      if (!TESTS_QUIET)
         printf("%9.2g  ", spread[j]);
      /* Make sure that NaN get counted as errors */
      if (spread[j] < MPX_TOLERANCE)
         fails--;
      else if (values[j] < MINCOUNTS)   /* Neglect inprecise results with low counts */
         fails--;
   }
   if (!TESTS_QUIET) {
      printf("\n\n");
      for (j = 0; j < nev1; j++) {
         PAPI_get_event_info(events[j], &info);
         printf("Event %.2d: mean=%10.0f, sdev/mean=%7.2g nrpt=%2d -- %s\n",
                j, avg[j], spread[j], nsamples[j], info.short_descr);
      }
      printf("\n\n");
   }

   if (fails)
      test_fail(__FILE__, __LINE__, "Values differ from reference", fails);
   else
      test_pass(__FILE__, NULL, 0);

   return 0;
}
Пример #4
0
int main(int argc, char **argv)
{
   PAPI_event_info_t info;
   int i, j, retval;
   int iters = NUM_FLOPS;
   double x = 1.1, y;
   long long t1, t2;
   long long values[MAXEVENTS], refvalues[MAXEVENTS];
   int sleep_time = SLEEPTIME;
   double valsqsum[MAXEVENTS];
   double valsum[MAXEVENTS];
   int nevents = MAXEVENTS;
   int eventset = PAPI_NULL;
   int events[MAXEVENTS];

   events[0] = PAPI_FP_INS;
   events[1] = PAPI_TOT_INS;
   events[2] = PAPI_INT_INS;
   events[3] = PAPI_TOT_CYC;
   events[4] = PAPI_STL_CCY;
   events[5] = PAPI_BR_INS;
   events[6] = PAPI_SR_INS;
   events[7] = PAPI_LD_INS;
   events[8] = PAPI_TOT_IIS;
   events[9] = PAPI_FAD_INS;
   events[10] = PAPI_BR_TKN;
   events[11] = PAPI_BR_MSP;
   events[12] = PAPI_L1_ICA;
   events[13] = PAPI_L1_DCA;

   for (i = 0; i < MAXEVENTS; i++) {
      values[i] = 0;
      valsqsum[i] = 0;
      valsum[i] = 0;
   }

   if (argc > 1) {
      if (!strcmp(argv[1], "TESTS_QUIET"))
         tests_quiet(argc, argv);
      else {
         sleep_time = atoi(argv[1]);
         if (sleep_time <= 0)
            sleep_time = SLEEPTIME;
      }
   }

   if (!TESTS_QUIET) {
      printf("\nAccuracy check of multiplexing routines.\n");
      printf("Comparing a multiplex measurement with separate measurements.\n\n");
   }

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   decide_which_events(events, &nevents);

   init_multiplex();

   /* Find a reasonable number of iterations (each 
    * event active 20 times) during the measurement
    */
   t2 = 10000 * 20 * nevents;   /* Target: 10000 usec/multiplex, 20 repeats */
   if (t2 > 30e6)
      test_skip(__FILE__, __LINE__, "This test takes too much time", retval);

   y = dummy3(x, iters);
   /* Measure one run */
   t1 = PAPI_get_real_usec();
   y = dummy3(x, iters);
   t1 = PAPI_get_real_usec() - t1;

   if (t1 < 1000000)                 /* Scale up execution time to match t2 */
     {
       iters = iters * (1000000/t1);
       printf("Modified iteration count to %d\n\n",iters);
     }

   /* Now loop through the items one at a time */

   ref_measurements(iters, &eventset, events, nevents, refvalues); 

   /* Now check multiplexed */

   if ((retval = PAPI_create_eventset(&eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);


   /* In Component PAPI, EventSets must be assigned a component index
      before you can fiddle with their internals.
      0 is always the cpu component */
   retval = PAPI_assign_eventset_component(eventset, 0);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval);

   if ((retval = PAPI_set_multiplex(eventset)))
     test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval);

   if ((retval = PAPI_add_events(eventset, events, nevents)))
     test_fail(__FILE__, __LINE__, "PAPI_add_events", retval);

   printf("\nPAPI multiplexed measurements:\n");
   x = 1.0;
   t1 = PAPI_get_real_usec();
   if ((retval = PAPI_start(eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);
   y = dummy3(x, iters);
   if ((retval = PAPI_stop(eventset, values)))
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
   t2 = PAPI_get_real_usec();

   for (j = 0; j < nevents; j++) {
      PAPI_get_event_info(events[j], &info);
      if (!TESTS_QUIET) {
         printf("%20s = ", info.short_descr);
         printf(LLDFMT, values[j]);
         printf("\n");
      }
   }

   check_values(eventset, events, nevents, values, refvalues);

   if ((retval = PAPI_remove_events(eventset, events, nevents)))
      test_fail(__FILE__, __LINE__, "PAPI_remove_events", retval);
   if ((retval = PAPI_cleanup_eventset(eventset)))
     test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval);
   if ((retval = PAPI_destroy_eventset(&eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval);
   eventset = PAPI_NULL;

   /* Now loop through the items one at a time */

   ref_measurements(iters, &eventset, events, nevents, refvalues);

   check_values(eventset, events, nevents, values, refvalues);

   test_pass(__FILE__, NULL, 0);

   return 0;
}
Пример #5
0
int main(int argc, char **argv)
{
   PAPI_event_info_t info;
   int i, j, retval;
   int iters = NUM_FLOPS;
   double x = 1.1, y, dtmp;
   long long t1, t2;
   long long values[MAXEVENTS];
   int sleep_time = SLEEPTIME;
#ifdef STARTSTOP
   long long dummies[MAXEVENTS];
#endif
   double valsample[MAXEVENTS][REPEATS];
   double valsum[MAXEVENTS];
   double avg[MAXEVENTS];
   double spread[MAXEVENTS];
   int nevents = MAXEVENTS;
   int eventset = PAPI_NULL;
   int events[MAXEVENTS];
   int fails;

   events[0] = PAPI_FP_INS;
   events[1] = PAPI_TOT_INS;
   events[2] = PAPI_INT_INS;
   events[3] = PAPI_TOT_CYC;
   events[4] = PAPI_STL_CCY;
   events[5] = PAPI_BR_INS;
   events[6] = PAPI_SR_INS;
   events[7] = PAPI_LD_INS;
   events[8] = PAPI_TOT_IIS;

   for (i = 0; i < MAXEVENTS; i++) {
      values[i] = 0;
      valsum[i] = 0;
   }

   if (argc > 1) {
      if (!strcmp(argv[1], "TESTS_QUIET"))
         tests_quiet(argc, argv);
      else {
         sleep_time = atoi(argv[1]);
         if (sleep_time <= 0)
            sleep_time = SLEEPTIME;
      }
   }

   if (!TESTS_QUIET) {
      printf("\nAccuracy check of multiplexing routines.\n");
      printf("Investigating the variance of multiplexed measurements.\n\n");
   }

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

#ifdef MPX
   init_multiplex();
#endif

   if ((retval = PAPI_create_eventset(&eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);
#ifdef MPX

   /* In Component PAPI, EventSets must be assigned a component index
      before you can fiddle with their internals.
      0 is always the cpu component */
   retval = PAPI_assign_eventset_component(eventset, 0);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval);

   if ((retval = PAPI_set_multiplex(eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval);
#endif

   nevents = MAXEVENTS;
   for (i = 0; i < nevents; i++) {
      if ((retval = PAPI_add_event(eventset, events[i]))) {
         for (j = i; j < MAXEVENTS; j++)
            events[j] = events[j + 1];
         nevents--;
         i--;
      }
   }
   if (nevents < 2)
      test_skip(__FILE__, __LINE__, "Not enough events left...", 0);

   /* Find a reasonable number of iterations (each 
    * event active 20 times) during the measurement
    */
   t2 = 10000 * 20 * nevents;   /* Target: 10000 usec/multiplex, 20 repeats */
   if (t2 > 30e6)
      test_skip(__FILE__, __LINE__, "This test takes too much time", retval);

   /* Measure one run */
   t1 = PAPI_get_real_usec();
   y = dummy3(x, iters);
   t1 = PAPI_get_real_usec() - t1;

   if (t2 > t1)                 /* Scale up execution time to match t2 */
      iters = iters * (int)(t2 / t1);
   else if (t1 > 30e6)          /* Make sure execution time is < 30s per repeated test */
      test_skip(__FILE__, __LINE__, "This test takes too much time", retval);

   if ((retval = PAPI_start(eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   for (i = 1; i <= REPEATS; i++) {
      x = 1.0;

#ifndef STARTSTOP
      if ((retval = PAPI_reset(eventset)))
         test_fail(__FILE__, __LINE__, "PAPI_reset", retval);
#else
      if ((retval = PAPI_stop(eventset, dummies)))
         test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
      if ((retval = PAPI_start(eventset)))
         test_fail(__FILE__, __LINE__, "PAPI_start", retval);
#endif

      if (!TESTS_QUIET)
         printf("\nTest %d (of %d):\n", i, REPEATS);
      t1 = PAPI_get_real_usec();
      y = dummy3(x, iters);
      PAPI_read(eventset, values);
      t2 = PAPI_get_real_usec();

      if (!TESTS_QUIET) {
         printf("\n(calculated independent of PAPI)\n");
         printf("\tOperations= %.1f Mflop", y * 1e-6);
         printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1)));
         printf("PAPI measurements:\n");
      }
      for (j = 0; j < nevents; j++) {
         PAPI_get_event_info(events[j], &info);
         if (!TESTS_QUIET) {
            printf("%20s = ", info.short_descr);
            printf(LLDFMT, values[j]);
            printf("\n");
	 }
         dtmp = (double) values[j];
         valsum[j] += dtmp;
         valsample[j][i-1] = dtmp;
      }
      if (!TESTS_QUIET)
         printf("\n");
   }

   if (!TESTS_QUIET) {
      printf("\n\nEstimated variance relative to average counts:\n");
      for (j = 0; j < nevents; j++)
         printf("   Event %.2d", j);
      printf("\n");
   }

   fails = nevents;
   /* Due to limited precision of floating point cannot really use
      typical standard deviation compuation for large numbers with
      very small variations. Instead compute the std devation
      problems with precision.
   */
   for (j = 0; j < nevents; j++) {
      avg[j] = valsum[j] / REPEATS;
      spread[j] = 0;
      for (i=0; i < REPEATS; ++i) {
	double diff = (valsample[j][i] - avg[j]);
	spread[j] += diff * diff;
      }
      spread[j] = sqrt(spread[j] / REPEATS) / avg[j];
      if (!TESTS_QUIET)
         printf("%9.2g  ", spread[j]);
      /* Make sure that NaN get counted as errors */
      if (spread[j] < MPX_TOLERANCE)
         --fails;
      else if (valsum[j] < MINCOUNTS)   /* Neglect inprecise results with low counts */
         --fails;
   }

   if (!TESTS_QUIET) {
      printf("\n\n");
      for (j = 0; j < nevents; j++) {
         PAPI_get_event_info(events[j], &info);
         printf("Event %.2d: mean=%10.0f, sdev/mean=%7.2g nrpt=%2d -- %s\n",
                j, avg[j], spread[j], REPEATS, info.short_descr);
      }
      printf("\n\n");
   }

   if (fails)
      test_fail(__FILE__, __LINE__, "Values outside threshold", fails);
   else
      test_pass(__FILE__, NULL, 0);

   return 0;
}
int case1(void)
{
	int retval, i, EventSet = PAPI_NULL, j = 0, k = 0, allvalid = 1;
	int max_mux, nev, *events;
	long long *values;
	PAPI_event_info_t pset;
	char evname[PAPI_MAX_STR_LEN];

	init_papi();
	init_multiplex();

	retval = PAPI_create_eventset(&EventSet);
	if (retval != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

	/* In Component PAPI, EventSets must be assigned a component index
		before you can fiddle with their internals.
		0 is always the cpu component */
	retval = PAPI_assign_eventset_component(EventSet, 0);
	if (retval != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval);

	retval = PAPI_set_multiplex(EventSet);
	if (retval != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval);

	max_mux = PAPI_get_opt(PAPI_MAX_MPX_CTRS, NULL);
	if (max_mux > 32) max_mux = 32;

	/* Fill up the event set with as many non-derived events as we can */
	printf("\nFilling the event set with as many non-derived events as we can...\n");

	i = PAPI_PRESET_MASK;
	do {
		if (PAPI_get_event_info(i, &pset) == PAPI_OK) 
		{
			if (pset.count && (strcmp(pset.derived,"NOT_DERIVED") == 0))
			{
				retval = PAPI_add_event(EventSet, pset.event_code);
				if (retval != PAPI_OK)
					test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);
				else
				{
					printf("Added %s\n", pset.symbol);
					j++;
				}
			}
		}
	} while ((PAPI_enum_event(&i, PAPI_PRESET_ENUM_AVAIL) == PAPI_OK) && (j < max_mux));

	events = (int *) malloc(j * sizeof(int));
	if (events == NULL)
		test_fail(__FILE__, __LINE__, "malloc events", 0);

	values = (long long *) malloc(j * sizeof(long long));
	if (values == NULL)
		test_fail(__FILE__, __LINE__, "malloc values", 0);

	do_stuff();

	if (PAPI_start(EventSet) != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_start", retval);

	do_stuff();

	retval = PAPI_stop(EventSet, values);
	if (retval != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

	nev =j;
	retval = PAPI_list_events(EventSet, events, &nev);
	if (retval != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_list_events", retval);

	printf("\nEvent Counts:\n");
	for (i = 0, allvalid = 0; i < j; i++) {
		PAPI_event_code_to_name(events[i], evname);
		printf(TAB1, evname, values[i]);
		if (values[i] == 0)
			allvalid++;
	}
	printf("\n");
	if (allvalid){
		printf("Caution: %d counters had zero values\n", allvalid);
	}

	for (i = 0, allvalid = 0; i < j; i++) {
		for (k = i+1; k < j; k++) {
			if ((i != k) && (values[i] == values[k]))
			{
				allvalid++;
				break;
			}
		}
	}

	if (allvalid){
		printf("Caution: %d counter pair(s) had identical values\n", allvalid);
	}

	free(events);
	free(values);

	retval = PAPI_cleanup_eventset(EventSet);
	if (retval != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval);

	retval = PAPI_destroy_eventset(&EventSet);
	if (retval != PAPI_OK)
		test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval);

	return (SUCCESS);
}
Пример #7
0
void
mainloop( int arg )
{
	int allvalid;
	long long *values;
	int EventSet = PAPI_NULL;
	int retval, i, j = 2, skipped_counters=0;
	PAPI_event_info_t pset;

	( void ) arg;

	/* Initialize the library */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	init_multiplex(  );

	retval = PAPI_create_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	/* In Component PAPI, EventSets must be assigned a component index
	   before you can fiddle with their internals.
	   0 is always the cpu component */
	retval = PAPI_assign_eventset_component( EventSet, 0 );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
				   retval );

	retval = PAPI_set_multiplex( EventSet );
        if ( retval == PAPI_ENOSUPP) {
	   test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
	} else if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );

	if ( ( retval =
		   PAPI_thread_init( ( unsigned
							   long ( * )( void ) ) ( pthread_self ) ) ) !=
		 PAPI_OK ) {
		if ( retval == PAPI_ECMP )
			test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
		else
			test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
	}

	retval = PAPI_add_event( EventSet, PAPI_TOT_INS );
	if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( !TESTS_QUIET ) {
		printf( "Added %s\n", "PAPI_TOT_INS" );
	}

	retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
	if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( !TESTS_QUIET ) {
		printf( "Added %s\n", "PAPI_TOT_CYC" );
	}

	values = ( long long * ) malloc( MAX_TO_ADD * sizeof ( long long ) );
	if ( values == NULL )
		test_fail( __FILE__, __LINE__, "malloc", 0 );

	for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
		retval = PAPI_get_event_info( i | PAPI_PRESET_MASK, &pset );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );

		if ( pset.count ) {
			printf( "Adding %s\n", pset.symbol );

			retval = PAPI_add_event( EventSet, ( int ) pset.event_code );
			if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
				test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

			if ( retval == PAPI_OK ) {
				printf( "Added %s\n", pset.symbol );
			} else {
				printf( "Could not add %s\n", pset.symbol );
			}

			do_stuff(  );

			if ( retval == PAPI_OK ) {
				retval = PAPI_start( EventSet );
				if ( retval != PAPI_OK )
					test_fail( __FILE__, __LINE__, "PAPI_start", retval );

				do_stuff(  );

				retval = PAPI_stop( EventSet, values );
				if ( retval != PAPI_OK )
					test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

				if ( values[j] ) {
					if ( ++j >= MAX_TO_ADD )
						break;
				} else {
					retval =
						PAPI_remove_event( EventSet, ( int ) pset.event_code );
					if ( retval == PAPI_OK )
						printf( "Removed %s\n", pset.symbol );
				        /* This added because the test */
				        /* can take a long time if mplexing */
				        /* is broken and all values are 0   */
				        skipped_counters++;
				        if (skipped_counters>MAX_TO_ADD) break;

				}
			}
		}
	}

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_stuff(  );

	retval = PAPI_stop( EventSet, values );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	test_print_event_header( "multiplex3_pthreads:\n", EventSet );
	allvalid = 0;
	for ( i = 0; i < MAX_TO_ADD; i++ ) {
		printf( ONENUM, values[i] );
		if ( values[i] != 0 )
			allvalid++;
	}
	printf( "\n" );
	if ( !allvalid )
		test_fail( __FILE__, __LINE__, "all counter registered no counts", 1 );

	retval = PAPI_cleanup_eventset( EventSet );	/* JT */
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

	free( values );
	PAPI_shutdown(  );
}