Beispiel #1
0
int main(int argc, const char **argv)
{
    poller = new PortalPoller();
    EchoIndication *echoIndication = new EchoIndication(IfcNames_EchoIndication, poller);
    DisplayInd *dispIndication = new DisplayInd(IfcNames_DisplayInd, poller);
    // these use the default poller
    SwallowProxy *swallowProxy = new SwallowProxy(IfcNames_Swallow);
    echoRequestProxy = new EchoRequestProxy(IfcNames_EchoRequest);

    poller->portalExec_init();
    init_thread();
    portalExec_start();

#if 0
    printf("Timer tests\n");
    portalTimerInit();
    for (int i = 0; i < 1000; i++) {
      portalTimerStart(0);
      portalTimerCatch(1);
      portalTimerCatch(2);
      portalTimerCatch(3);
      portalTimerCatch(4);
      portalTimerCatch(5);
      portalTimerCatch(6);
      portalTimerCatch(7);
      portalTimerCatch(8);
    }
    portalTimerPrint(1000);
#endif

    int v = 42;
    fprintf(stderr, "Saying %d\n", v);
    call_say(v);
    call_say(v*5);
    call_say(v*17);
    call_say(v*93);
    printf("[%s:%d] run %d loops\n\n", __FUNCTION__, __LINE__, LOOP_COUNT);
    portalTimerInit();
    portalTimerStart(1);
    for (int i = 0; i < LOOP_COUNT; i++)
        call_say2(v, v*3);
uint64_t elapsed = portalTimerLap(1);
    printf("TEST TYPE: "
#ifndef SEPARATE_EVENT_THREAD
       "INLINE"
#elif defined(USE_MUTEX_SYNC)
       "MUTEX"
#else
       "SEM"
#endif
       "\n");
    portalTimerPrint(LOOP_COUNT);
    printf("call_say: elapsed %g average %g\n", (double) elapsed, (double) elapsed/ (double) LOOP_COUNT);
    echoRequestProxy->setLeds(9);
    poller->portalExec_end();
    portalExec_end();
    return 0;
}
Beispiel #2
0
int main(int argc, const char **argv)
{
    PortalPerfIndication *portalPerfIndication = new PortalPerfIndication(IfcNames_PortalPerfIndication);

    portalPerfRequestProxy = new PortalPerfRequestProxy(IfcNames_PortalPerfRequest);

    portalExec_init();

    printf("Timer tests\n");
    portalTimerInit();
    for (int i = 0; i < 1000; i++) {
      portalTimerStart(0);
      portalTimerCatch(1);
      portalTimerCatch(2);
      portalTimerCatch(3);
      portalTimerCatch(4);
      portalTimerCatch(5);
      portalTimerCatch(6);
      portalTimerCatch(7);
      portalTimerCatch(8);
    }
    printf("Each line 1-8 is one more call to portalTimerCatch()\n");
    portalTimerPrint(1000);

    vl1 = 0xfeed000000000011;
    vl2 = 0xface000000000012;
    vl3 = 0xdead000000000013;
    vl4 = 0xbeef000000000014;
    vd1 = 0xfeed0000000000000021LL;
    vd2 = 0xface0000000000000022LL;
    vd3 = 0xdead0000000000000023LL;
    vd4 = 0xbeef0000000000000024LL;

    dotestout("swallow", call_swallow);
    dotestout("swallowl", call_swallowl);
    dotestout("swallowll", call_swallowll);
    dotestout("swallowlll", call_swallowlll);
    dotestout("swallowllll", call_swallowllll);
    dotestout("swallowd", call_swallowd);
    dotestout("swallowdd", call_swallowdd);
    dotestout("swallowddd", call_swallowddd);
    dotestout("swallowdddd", call_swallowdddd);
    dotestin("spitl", 1);
    dotestin("spit", 0);
    dotestin("spitll", 2);
    dotestin("spitlll", 3);
    dotestin("spitllll", 4);
    dotestin("spitd", 5);
    dotestin("spitdd", 6);
    dotestin("spitddd", 7);
    dotestin("spitdddd", 8);

    portalExec_end();
    return 0;
}
Beispiel #3
0
void dotestout(const char *testname, void (*testfn)(void))
{
  uint64_t elapsed;
  portalTimerInit();
  portalTimerStart(1);
  for (int i = 0; i < LOOP_COUNT; i++) {
    testfn();
  }
  elapsed = portalTimerLap(1);
  printf("test %s: elapsed %g average %g\n", testname, (double) elapsed, (double) elapsed/ (double) LOOP_COUNT);
  portalTimerPrint(LOOP_COUNT);
}
Beispiel #4
0
void dotestin(const char *testname, int which)
{
  uint64_t elapsed;
  heard_count = 0;
  printf("starting test %s, which %d\n", testname, which);
  portalTimerInit();
  portalTimerStart(1);
  portalTimerStart(0);
  portalTimerCatch(0);
  portalPerfRequestProxy->startspit(which, LOOP_COUNT);
  portalTimerCatch(19);
  wait_for(LOOP_COUNT);
  portalTimerCatch(21);
  elapsed = portalTimerLap(1);
  printf("test %s: heard %d elapsed %g average %g\n", testname, heard_count, (double) elapsed, (double) elapsed/ (double) LOOP_COUNT);
  portalTimerPrint(1);
}
int main(int argc, const char **argv)
{
  MaxcommonsubseqRequestProxy *device = 0;
  MaxcommonsubseqIndication *deviceIndication = 0;

  fprintf(stderr, "%s %s\n", __DATE__, __TIME__);
  device = new MaxcommonsubseqRequestProxy(IfcNames_MaxcommonsubseqRequest);
  MemServerRequestProxy *hostMemServerRequest = new MemServerRequestProxy(IfcNames_HostMemServerRequest);
  MMURequestProxy *dmap = new MMURequestProxy(IfcNames_HostMMURequest);
  DmaManager *dma = new DmaManager(dmap);
  MemServerIndication *hostMemServerIndication = new MemServerIndication(hostMemServerRequest, IfcNames_HostMemServerIndication);
  MMUIndication *hostMMUIndication = new MMUIndication(dma, IfcNames_HostMMUIndication);

  deviceIndication = new MaxcommonsubseqIndication(IfcNames_MaxcommonsubseqIndication);

  if(sem_init(&test_sem, 1, 0)){
    fprintf(stderr, "failed to init test_sem\n");
    return -1;
  }

  portalExec_start();

    fprintf(stderr, "simple tests\n");
    int strAAlloc;
    int strBAlloc;
    int fetchAlloc;
    unsigned int alloc_len = 128;
    unsigned int fetch_len = alloc_len * alloc_len;
    int rcA, rcB, rcFetch;
    struct stat statAbuf, statBbuf, statFetchbuf;
    
    fetchAlloc = portalAlloc(fetch_len*sizeof(uint16_t));
    rcFetch = fstat(fetchAlloc, &statFetchbuf);
    if (rcA < 0) perror("fstatFetch");
    int *fetch = (int *)portalMmap(fetchAlloc, fetch_len * sizeof(uint16_t));
    if (fetch == MAP_FAILED) perror("fetch mmap failed");
    assert(fetch != MAP_FAILED);

    strAAlloc = portalAlloc(alloc_len);
    rcA = fstat(strAAlloc, &statAbuf);
    if (rcA < 0) perror("fstatA");
    char *strA = (char *)portalMmap(strAAlloc, alloc_len);
    if (strA == MAP_FAILED) perror("strA mmap failed");
    assert(strA != MAP_FAILED);

    strBAlloc = portalAlloc(alloc_len);
    rcB = fstat(strBAlloc, &statBbuf);
    if (rcA < 0) perror("fstatB");
    char *strB = (char *)portalMmap(strBAlloc, alloc_len);
    if (strB == MAP_FAILED) perror("strB mmap failed");
    assert(strB != MAP_FAILED);

/*
    const char *strA_text = "___a_____b______c____";
    const char *strB_text = "..a........b.c....";
*/
    const char *strA_text = "012a45678b012345c7890";
    const char *strB_text = "ABaDEFGHIJKbMcOPQR";
    
    assert(strlen(strA_text) < alloc_len);
    assert(strlen(strB_text) < alloc_len);

    strncpy(strA, strA_text, alloc_len);
    strncpy(strB, strB_text, alloc_len);

    int strA_len = strlen(strA);
    int strB_len = strlen(strB);
    uint16_t swFetch[fetch_len];

    portalTimerInit();
    portalTimerStart(0);


    fprintf(stderr, "elapsed time (hw cycles): %lld\n", (long long)portalTimerLap(0));
    
    portalDCacheFlushInval(strAAlloc, alloc_len, strA);
    portalDCacheFlushInval(strBAlloc, alloc_len, strB);
    portalDCacheFlushInval(fetchAlloc, fetch_len*sizeof(uint16_t), fetch);

    unsigned int ref_strAAlloc = dma->reference(strAAlloc);
    unsigned int ref_strBAlloc = dma->reference(strBAlloc);
    unsigned int ref_fetchAlloc = dma->reference(fetchAlloc);

    device->setupA(ref_strAAlloc, 0, strA_len);
    sem_wait(&test_sem);

    device->setupB(ref_strBAlloc, 0, strB_len);
    sem_wait(&test_sem);

    uint64_t cycles;
    uint64_t beats;

    fprintf(stderr, "starting algorithm A\n");

    portalTimerInit();
    portalTimerStart(0);

    device->start(0);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    beats = hostMemServerIndication->getMemoryTraffic(ChannelType_Read);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);
    printf("fetch 1 finished \n");
    device->fetch(ref_fetchAlloc, fetch_len, fetch_len / 2, fetch_len / 2);
    sem_wait(&test_sem);
    printf("fetch 2 finished \n");

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4d", j);
    }
    printf("\n");
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4c", strB[j-1]);
    }
    printf("\n");
    for (int i = 0; i <= strA_len; i += 1) {
      printf("%4c%4d", strA[i-1], i);
      for (int j = 0; j <= strB_len; j += 1) {
	printf("%4d", swFetch[(i << 7) + j] & 0xff);
      }
    printf("\n");
    }


    fprintf(stderr, "starting algorithm B, forward\n");
    portalTimerInit();
    portalTimerStart(0);

    device->start(1);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));

    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4d", j);
    }
    printf("\n");
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4c", strB[j-1]);
    }
    printf("\n");
    for (int i = 0; i < 1; i += 1) {
      printf("%4c%4d", strA[i-1], i);
      for (int j = 0; j <= strB_len; j += 1) {
	printf("%4d", swFetch[(i << 7) + j] & 0xff);
      }
    printf("\n");
    }

    /* reverse argument strings */
    for (int i = 0; i < strA_len; i += 1) {
      strA[i] = strA_text[strA_len - i - 1];
    }
    for (int i = 0; i < strB_len; i += 1) {
      strB[i] = strB_text[strB_len - i - 1];
    }
    device->setupA(ref_strAAlloc, 0, strA_len);
    sem_wait(&test_sem);

    device->setupB(ref_strBAlloc, 0, strB_len);
    sem_wait(&test_sem);

    fprintf(stderr, "starting algorithm B, backward\n");



    portalTimerInit();
    portalTimerStart(0);

    device->start(2);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));

    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4d", j);
    }
    printf("\n");
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4c", strB[j-1]);
    }
    printf("\n");
    for (int i = 0; i < 1; i += 1) {
      printf("%4c%4d", strA[i-1], i);
      for (int j = 0; j <= strB_len; j += 1) {
	printf("%4d", swFetch[(i << 7) + j] & 0xff);
      }
    printf("\n");
    }

    /* forward argument strings */
    for (int i = 0; i < strA_len; i += 1) {
      strA[i] = strA_text[i];
    }
    for (int i = 0; i < strB_len; i += 1) {
      strB[i] = strB_text[i];
    }
    device->setupA(ref_strAAlloc, 0, strA_len);
    sem_wait(&test_sem);

    device->setupB(ref_strBAlloc, 0, strB_len);
    sem_wait(&test_sem);


    fprintf(stderr, "starting algorithm C\n");
    portalTimerInit();
    portalTimerStart(0);

    device->start(3);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));

    if (result_length > strB_len) result_length = strB_len;
    
    printf("Algorithm C results\n");
    for (int j = 0; j < result_length; j += 1) {
      char c =  swFetch[j] & 0xff;
      printf(" %02x (%c)", 0xff & c, (isalnum(c) ? c: '_'));
    }
    printf("\n");



    close(strAAlloc);
    close(strBAlloc);
    close(fetchAlloc);
  }