Beispiel #1
0
int vt_convert_PLST_write(struct vt_options* opt, vaht_resource* res, char* path)
{
    vaht_plst* plst = vaht_plst_open(res);
    if (plst == NULL)
    {
        vt_error(opt, "PLST resource could not be converted: %04i", vaht_resource_id(res));
        return 1;
    }
    
    FILE* fp = fopen(path, "w");
    if (!fp)
    {
        vt_error(opt, "cannot open path: %s", path);
        vaht_plst_close(plst);
        return 1;
    }
    
    /* do the conversion */
    fprintf(fp, "#\ttBMP\t-- L\tR\tT\tB\n");
    uint16_t count = vaht_plst_records(plst);
    uint16_t i;
    for (i = 1; i <= count; i++)
    {
        uint16_t bitmap_id = vaht_plst_bitmap_id(plst, i);
        uint16_t left, right, top, bottom;
        vaht_plst_rect(plst, i, &left, &right, &top, &bottom);
        
        fprintf(fp, "%i\t%i\t-- %i\t%i\t%i\t%i\n", i, bitmap_id, left, right, top, bottom);
    }

    fclose(fp);
    vaht_plst_close(plst);
    
    return 0;
}
Beispiel #2
0
void
vt_cleanup (vt_thread_pool_t *workers, vt_context_t *context, int async)
{
  int ret;
  pthread_t thread;
  vt_cleanup_arg_t *arg;

  arg = NULL;
  if (! async)
    goto failure;
  if (! (arg = calloc (1, sizeof (vt_cleanup_arg_t)))) {
    vt_error ("%s: calloc: %s", __func__, strerror (errno));
    goto failure;
    
  }

  arg->context = context;
  arg->workers = workers;

  if ((ret = pthread_create (&thread, NULL, vt_cleanup_worker, (void *)arg)) < 0) {
    vt_error ("%s: pthread_create: %s", __func__, strerror (ret));
    goto failure;
  }

  return;
failure:
  if (arg)
    free (arg);
  // fine... need to do it ourselves
  // handle errors
}
Beispiel #3
0
int vt_convert_tMOV_write(struct vt_options* opt, vaht_resource* res, char* path)
{
    vaht_mov* mov = vaht_mov_open(res);
    if (mov == NULL)
    {
        vt_error(opt, "tMOV resource could not be converted: %04i", vaht_resource_id(res));
        return 1;
    }
    
    FILE* fp = fopen(path, "wb");
    if (!fp)
    {
        vt_error(opt, "cannot open path: %s", path);
        vaht_mov_close(mov);
        return 1;
    }
    
    uint32_t bufsize = 1024;
    uint8_t* buffer = malloc(sizeof(uint8_t) * bufsize);
    while (1)
    {
        uint32_t read = vaht_mov_read(mov, bufsize, buffer);
        uint32_t written = fwrite(buffer, sizeof(uint8_t), read, fp);
        if (read != written || read != bufsize)
            break;
    }
    
    free(buffer);
    
    fclose(fp);
    vaht_mov_close(mov);
    
    return 0;
}
Beispiel #4
0
void VTThrd_createMutex(VTThrdMutex** mutex)
{
  jvmtiError error;

  vt_assert(mutexInitMutex != NULL);

  error = (*jvmti)->RawMonitorEnter(jvmti, mutexInitMutex);
  vt_java_check_error(jvmti, error, "RawMonitorEnter");
  if (*mutex == NULL)
  {
    static uint8_t rawmon_id = 0;
    char rawmon_name[10];

    *mutex = (VTThrdMutex*)malloc(sizeof(VTThrdMutex));
    if (*mutex == NULL)
      vt_error();

    snprintf(rawmon_name, sizeof(rawmon_name) - 1, "rawmon%d", rawmon_id++);

    error = (*jvmti)->CreateRawMonitor(jvmti, rawmon_name,
                                       &((*mutex)->m));
    vt_java_check_error(jvmti, error, "CreateRawMonitor");
  }
  error = (*jvmti)->RawMonitorExit(jvmti, mutexInitMutex);
  vt_java_check_error(jvmti, error, "RawMonitorExit");
}
static void idle_tid_list_push_back(uint32_t ptid, uint32_t tid)
{
  IdleThreadIdListEntryT* idle_tid;

  vt_libassert(ptid < VTThrdMaxNum);

  /* create new list entry */
  idle_tid = (IdleThreadIdListEntryT*)calloc(1,
               sizeof(IdleThreadIdListEntryT));
  if (idle_tid == NULL)
    vt_error();

  idle_tid->tid = tid;

  /* append new entry to list */
  if (idleThreadIds[ptid].last)
  {
    idleThreadIds[ptid].last->next = idle_tid;
    idleThreadIds[ptid].last = idle_tid;
  }
  else
  {
    idleThreadIds[ptid].first = idleThreadIds[ptid].last = idle_tid;
  }

  /* increment size of list */
  idleThreadIds[ptid].size++;
}
Beispiel #6
0
void VTThrd_init()
{
  /* get the maximum number of threads */
  VTThrdMaxNum = (uint32_t)vt_env_max_threads();

  /* create vector of the thread objects */
  VTThrdv = (VTThrd**)calloc(VTThrdMaxNum, sizeof(VTThrd*));
  if ( VTThrdv == NULL )
    vt_error();

#if (defined(VT_MT) || defined (VT_HYB) || defined(VT_JAVA))

  /* initialize thread-type specifics */
# if defined(VT_THRD_PTHREAD)
    VTThrd_initPthread();
# elif defined(VT_THRD_OMP)
    VTThrd_initOmp();
# elif defined(VT_JAVA)
    VTThrd_initJava();
# endif /* VT_THRD_[PTHREAD|OMP] || VT_JAVA */

  /* create mutexes for locking */
  VTThrd_createMutex(&VTThrdMutexEnv);
  VTThrd_createMutex(&VTThrdMutexIds);

#endif /* VT_MT || VT_HYB || VT_JAVA */

  /* create object for master thread
     (for Java this will be done in VTThrd_initJava(),
      'cause it gets the read thread name) */
#if !defined(VT_JAVA)
  VTThrd_create(0, 0, NULL, 0);
  VTThrd_open(0);
#endif /* VT_JAVA */
}
VT_DECLDEF(int VT_pthread_create__(pthread_t* thread,
                                   const pthread_attr_t* attr,
                                   void *(*start_routine)(void*), void* arg))
{
  int rc;
  uint64_t time;
  struct vt_pthread_pack_struct* pack;

  if (vt_init)
  {
    vt_init = 0;
    vt_open();
  }

  time = vt_pform_wtime();
  vt_enter(VT_CURRENT_THREAD, &time, vt_pthread_regid[VT__PTHREAD_CREATE]);

  pack = (struct vt_pthread_pack_struct*)malloc(
           sizeof(struct vt_pthread_pack_struct));
  if (pack == NULL)
    vt_error();

  pack->start_routine = start_routine;
  pack->arg = arg;
  pack->ptid = VTThrd_getThreadId();

  rc = pthread_create(thread, attr, vt_pthread_function, (void*)pack);

  time = vt_pform_wtime();
  vt_exit(VT_CURRENT_THREAD, &time);

  return rc;
}
static void hash_put_region(const char* name, const char* file, int lno,
                            uint32_t rid)
{
  uint32_t idx;
  HN_RegionT* add;

  /* -- get hash index -- */
  idx = vt_hash(name, strlen(name), 0);
  if ( file )
  {
    idx = vt_hash(file, strlen(file), idx);
    idx = vt_hashtriple(lno, 0, 0, idx);
  }
  idx &= (REGION_HASH_MAX - 1);

  /* -- allocate/initialize new hash entry -- */
  add = (HN_RegionT*)calloc(1, sizeof(HN_RegionT));
  if ( add == NULL )
    vt_error();

  add->name = strdup(name);
  if ( file )
  {
    add->file = strdup(file);
    add->lno = lno;
  }
  add->rid = rid;

  /* -- insert new hash entry at calculated hash index -- */
  add->next = htab_region[idx];
  htab_region[idx] = add;
}
void vt_rusage_init()
{
  uint32_t gid;
  uint32_t i;

  /* allocate vector of counter ids */
  vt_rusage_cidv = (uint32_t*)calloc(ru_active_cntrn, sizeof(uint32_t));
  if ( vt_rusage_cidv == NULL )
    vt_error();

  /* write counter group name definition */
  gid = vt_def_counter_group(VT_CURRENT_THREAD, "Resources");

  /* write counter definition for active counters */
  for ( i = 0; i < ru_active_cntrn; i++ )
  {
    vt_rusage_cidv[i] =
      vt_def_counter(VT_CURRENT_THREAD,
		     ru_active_cntrv[i]->name,
		     ru_active_cntrv[i]->unit,
		     ru_active_cntrv[i]->prop,
		     gid,
		     0);
  }
}
Beispiel #10
0
struct vt_metv* vt_metric_create()
{
    struct vt_metv* metv;
    int retval, i;

    if ( nmetrics == 0 )
        return NULL;

    metv = (struct vt_metv*)malloc(sizeof(struct vt_metv));
    if ( metv == NULL )
        vt_error();

    /* create event set */
    metv->EventSet = PAPI_NULL;
    retval = PAPI_create_eventset(&metv->EventSet);
    if ( retval != PAPI_OK)
        vt_metric_error(retval, "PAPI_create_eventset");

    for ( i = 0; i < nmetrics; i++ )
    {
        /* add event to event set */
        retval = PAPI_add_event(metv->EventSet, metricv[i]->papi_code);
        if ( retval != PAPI_OK )
            vt_metric_error(retval, "PAPI_add_event");
    }

    retval = PAPI_start(metv->EventSet);
    if ( retval != PAPI_OK )
        vt_metric_error(retval, "PAPI_start");
    /*vt_cntl_msg("Counters started");*/

    return metv;
}
Beispiel #11
0
void VTThrd_registerThread(jthread thread, const char* tname)
{
  jvmtiError error;
  uint32_t *tid;

  /* check whether an ID is already created for this thread */
  error = (*jvmti)->GetThreadLocalStorage(jvmti, thread, (void**)&tid);
  vt_java_check_error(jvmti, error, "GetThreadLocalStorage");
  if (tid == NULL)
  {
    /* create new thread-ID */
    tid = (uint32_t*)malloc(sizeof(uint32_t));
    if (tid == NULL) vt_error();

    /* increment number of threads */
    *tid = VTThrd_createNewThreadId();

    /* put new ID to thread-specific data */
    error = (*jvmti)->SetThreadLocalStorage(jvmti, thread, (void*)tid);
    vt_java_check_error(jvmti, error, "SetThreadLocalStorage");

    /* create new thread object */
    vt_cntl_msg(2, "Dynamic thread creation. Thread #%d (%s)",
                *tid, tname ? tname : "unnamed");
    VTThrd_create(*tid, 0, tname, 0);
    VTThrd_open(*tid);
  }
}
Beispiel #12
0
static void esync_master(VT_MPI_INT slave, MPI_Comm comm, VT_MPI_INT masterid)
{
  int i;
   
  uint64_t tsend, trecv, tslave;
  uint64_t t1, t2, t3, t4;
   
  MPI_Status stat;
  MPI_Request req;
  Sync_TsPerPhase* temp;
   
  /* exchange LOOP_COUNT ping pong messages with the communication partner */
   
  t1 = vt_pform_wtime();
  PMPI_Isend( &t1, 1, MPI_LONG_LONG_INT, slave, 0, comm, &req );
  PMPI_Recv( &t2, 1, MPI_LONG_LONG_INT, slave, 0, comm, &stat );
  t4 = vt_pform_wtime();
  t3 = t2;
  PMPI_Waitall( 1, &req, &stat );
   
  for( i = 1; i < LOOP_COUNT; i++ )
  {
    tsend = vt_pform_wtime();
      
    /* message exchange */

    PMPI_Isend(&tsend, 1, MPI_LONG_LONG_INT, slave, i, comm, &req);
    PMPI_Recv(&tslave, 1, MPI_LONG_LONG_INT, slave, i, comm, &stat);
    trecv = vt_pform_wtime();
      
    PMPI_Waitall(1, &req, &stat);

    /* select timestamps with minimum message delay in each direction */

    if ( ( (int64_t)tslave - (int64_t)tsend ) < ( (int64_t)t2 - (int64_t)t1 ) )
    {
      t1 = tsend;
      t2 = tslave;
    }
    if ( ( (int64_t)trecv - (int64_t)tslave ) < ( (int64_t)t4 - (int64_t)t3 ) )
    {
      t3 = tslave;
      t4 = trecv;
    }
  }

  /* save synchronization measurement data into internal data structure */

  temp = (Sync_TsPerPhase*)malloc(sizeof(Sync_TsPerPhase));
  if (!temp) vt_error();
  temp->id1  = masterid;
  temp->id2  = slave;
  temp->t1   = t1;
  temp->t2   = t2;
  temp->t3   = t3;
  temp->t4   = t4;
  temp->next = SyncTsPerRunLast->sync_phase;
  SyncTsPerRunLast->sync_phase = temp;
}
static void childv_add(pid_t pid)
{
  childv = (pid_t*)realloc(childv, (nchilds+1) * sizeof(pid_t));
  if (childv == NULL )
    vt_error();

  childv[nchilds++] = pid;
}
Beispiel #14
0
int vt_mode_extract(struct vt_options* opt)
{
    int error = 0;
    
    unsigned int input_file;
    for (input_file = 0; input_file < opt->input_files_count; input_file++)
    {
        vaht_archive* archive = vaht_archive_open(opt->input_files[input_file]);
        
        if (archive == NULL)
        {
            vt_error(opt, "file \"%s\" is not a valid MHK archive", opt->input_files[input_file]);
            return 1;
        }
        
        vt_log(opt, "extracting %s ...", opt->input_files[input_file]);
        
        char* out = opt->output;
        if (out == NULL)
        {
            out = ".";
        }
        
        /* create "out" */
        if (create_directory(opt, out))
            return 1;
        
        /* special handling if output provided, only one archive */
        if (opt->output != NULL && opt->input_files_count == 1)
        {
            if (create_directory(opt, out))
            {
                vaht_archive_close(archive);
                return 1;
            }
            
            error = extract_archive(opt, archive, out);
        } else {
            char* newout = construct_output_path(opt, out, opt->input_files[input_file]);
            if (create_directory(opt, newout))
            {
                free(newout);
                vaht_archive_close(archive);
                return 1;
            }
            
            error = extract_archive(opt, archive, newout);
            free(newout);
        }
        
        vaht_archive_close(archive);
        
        if (error)
            break;
    }

    return error;
}
Beispiel #15
0
void *
vt_cleanup_worker (void *arg)
{
  vt_context_t *context;
  vt_thread_pool_t *workers;

  assert (arg);

  context = ((vt_cleanup_arg_t *)arg)->context;
  workers = ((vt_cleanup_arg_t *)arg)->workers;
vt_error ("%s:%d: ", __func__, __LINE__);
  free (arg);
vt_error ("%s:%d: ", __func__, __LINE__);
  (void)vt_thread_pool_destroy (workers, NULL);
vt_error ("%s:%d: ", __func__, __LINE__);
  (void)vt_context_destroy (context, NULL);
vt_error ("%s:%d: ", __func__, __LINE__);
  return NULL;
}
void vt_comm_init()
{
  VT_MPI_INT i;

  if ( !comm_initialized )
  {
    comm_initialized = 1;

    groups = (struct VTGroup*)calloc(max_groups, sizeof(struct VTGroup));
    if ( !groups )
      vt_error();

    comms = (struct VTComm*)calloc(max_comms, sizeof(struct VTComm));
    if ( !comms )
      vt_error();

#if defined(HAVE_MPI2_1SIDED) && HAVE_MPI2_1SIDED
    wins = (struct VTWin*)calloc(max_wins, sizeof(struct VTWin));
    if ( !wins )
      vt_error();
#endif /* HAVE_MPI2_1SIDED */

    PMPI_Comm_group(MPI_COMM_WORLD, &vt_mpi_comm_world_group);
    PMPI_Comm_group(MPI_COMM_SELF, &vt_mpi_comm_self_group);

    world.group = vt_mpi_comm_world_group;
    PMPI_Group_size(world.group, &world.size);
    world.size_grpv = world.size / 8 + (world.size % 8 ? 1 : 0);

    world.ranks  = (VT_MPI_INT*)calloc(world.size, sizeof(VT_MPI_INT));
    if ( !world.ranks )
      vt_error();

    for (i = 0; i < world.size; i++)
      world.ranks[i] = i;

    ranks  = (VT_MPI_INT*)calloc(world.size, sizeof(VT_MPI_INT));
    grpv = (uint8_t*)calloc(world.size_grpv, sizeof(uint8_t));

    vt_comm_create(MPI_COMM_WORLD);
    vt_comm_create(MPI_COMM_SELF);
  }
}
struct vt_rusage* vt_rusage_create()
{
  struct vt_rusage* rusage;

  rusage = (struct vt_rusage*)malloc(sizeof(struct vt_rusage));
  if ( rusage == NULL )
    vt_error();

  return rusage;
}
Beispiel #18
0
static int create_directory(struct vt_options* opt, char* name)
{
    /* we set all permissions, umask will handle the rest */
    if (mkdir(name, S_IRWXU | S_IRWXG | S_IRWXO) == -1 && errno != EEXIST)
    {
        vt_error(opt, "could not make directory: %s", name);
        return 1;
    }
    return 0;
}
void VTThrd_registerThread(uint32_t ptid)
{
  uint32_t *tid;
  uint8_t tid_reuse = 0;

  if (!vt_is_alive) return;

  /* check whether an ID is already created for this thread */
  tid = (uint32_t*)pthread_getspecific(pthreadKey);
  if (tid == NULL)
  {
    tid = (uint32_t*)malloc(sizeof(uint32_t));
    if (tid == NULL) vt_error();

    /* try to get idle thread-ID for reuse, if desired */
    if (reuseThreadIds)
    {
      pthread_mutex_lock(&threadReuseMutex);
      if (idle_tid_list_size(ptid) > 0)
      {
        *tid = idle_tid_list_pop_front(ptid);
        tid_reuse = 1;
      }
      pthread_mutex_unlock(&threadReuseMutex);
    }

    /* create new thread-ID, if not reusing */
    if (!tid_reuse)
      *tid = VTThrd_create(NULL, ptid, 0);

    /* put (new) thread-ID to thread-specific data */
    pthread_setspecific(pthreadKey, tid);

    /* open thread associated trace file, if new thread object was created */
    if (!tid_reuse )
    {
      VTThrd_open(*tid);
    }
    /* otherwise, re-create metrics for reused thread object */
    else
    {
#if defined(VT_METR)
      if (vt_metric_num() > 0 && !VTThrdv[*tid]->metv)
        VTThrdv[*tid]->metv = vt_metric_create();
#endif /* VT_METR */

#if defined(VT_PLUGIN_CNTR)
      /* if we really use plugins and this thread also uses some */
      if (vt_plugin_cntr_used && VTThrdv[*tid]->plugin_cntr_defines)
        vt_plugin_cntr_thread_enable_counters(VTThrdv[*tid]);
#endif /* VT_PLUGIN_CNTR */
    }
  }
}
Beispiel #20
0
void VT_Dyn_start(uint32_t index, const char* name, const char* fname,
                  uint32_t lno, uint32_t loop)
{
  uint64_t time;
  uint32_t* rid;

  vt_libassert(index < VT_MAX_DYNINST_REGIONS);

  /* Ignore events if VT is initializing */
  if( !dyn_init && !vt_is_alive ) return;

  /* If not yet initialized, initialize VampirTrace */
  if ( dyn_init )
  {
    VT_MEMHOOKS_OFF();
    dyn_init = 0;
    rtab = (uint32_t*)calloc(VT_MAX_DYNINST_REGIONS, sizeof(uint32_t));
    if ( rtab == NULL )
      vt_error();
    vt_open();
    vt_comp_finalize = VT_Dyn_finalize;
    VT_MEMHOOKS_ON();
  }

  /* If VampirTrace already finalized, return */
  if ( !vt_is_alive ) return;

  VT_MEMHOOKS_OFF();

  time = vt_pform_wtime();

  /* Get region identifier
   */
  rid = &(rtab[index]);
  if ( *rid == 0 )
  {
    /* If region entered the first time, register region
     */
#if (defined(VT_MT) || defined(VT_HYB))
    VTTHRD_LOCK_IDS();
    if ( *rid == 0 )
      *rid = register_region(name, fname, lno, loop);
    VTTHRD_UNLOCK_IDS();
#else /* VT_MT || VT_HYB */
    *rid = register_region(name, fname, lno, loop);
#endif /* VT_MT || VT_HYB */
  }

  /* Write enter record */
  vt_enter(VT_CURRENT_THREAD, &time, *rid);

  VT_MEMHOOKS_ON();
}
char* vt_fork_get_trcid_filename()
{
  char* filename;

  vt_libassert(trcid_filename[0] != '\0');

  filename = strdup(trcid_filename);
  if ( filename == NULL )
    vt_error();

  return filename;
}
Beispiel #22
0
static int write_resource(struct vt_options* opt, vaht_resource* res, char* path)
{
    if (opt->convert)
    {
        const char* type = vaht_resource_type(res);
        
        vt_inform(opt, " %s", path);
        
        if (strcmp("tBMP", type) == 0)
            return vt_convert_tBMP_write(opt, res, path);
        if (strcmp("tMOV", type) == 0)
            return vt_convert_tMOV_write(opt, res, path);
        if (strcmp("tWAV", type) == 0)
            return vt_convert_tWAV_write(opt, res, path);
        if (strcmp("NAME", type) == 0)
            return vt_convert_NAME_write(opt, res, path);
        if (strcmp("CARD", type) == 0)
            return vt_convert_CARD_write(opt, res, path);
        if (strcmp("PLST", type) == 0)
            return vt_convert_PLST_write(opt, res, path);
        if (strcmp("BLST", type) == 0)
            return vt_convert_BLST_write(opt, res, path);
        if (strcmp("HSPT", type) == 0)
            return vt_convert_HSPT_write(opt, res, path);
        if (strcmp("RMAP", type) == 0)
            return vt_convert_RMAP_write(opt, res, path);
        if (strcmp("SLST", type) == 0)
            return vt_convert_SLST_write(opt, res, path);
        return 0;
    }
    
    FILE* f = fopen(path, "wb");
    if (f == NULL)
    {
        vt_error(opt, "cannot open path: %s", path);
        return 1;
    }
    
    vt_inform(opt, " %s", path);
    
    uint32_t bufsize = 1024;
    uint8_t* buffer = malloc(sizeof(uint8_t) * bufsize);
    while (1)
    {
        uint32_t read = vaht_resource_read(res, bufsize, buffer);
        uint32_t written = fwrite(buffer, sizeof(uint8_t), read, f);
        if (read != written || read != bufsize)
            break;
    }
    
    fclose(f);
    return 0;
}
void VTThrd_createMutex(VTThrdMutex** mutex)
{
# pragma omp critical (mutexInitMutex)
  {
    if (*mutex == NULL)
    {
      *mutex = (VTThrdMutex*)malloc(sizeof(VTThrdMutex));
      if (*mutex == NULL)
        vt_error();
      omp_init_lock(&((*mutex)->m));
    }
  }
}
void VTThrd_initPthread()
{
  static uint8_t initflag = 1;

  if (initflag)
  {
    uint32_t* master_tid;
    initflag = 0;

    /* reuse thread IDs of terminated threads? */
    if ((reuseThreadIds = (uint8_t)vt_env_pthread_reuse()))
    {
      /* create lists for idle thread-IDs */
      idleThreadIds = (IdleThreadIdListT*)calloc(VTThrdMaxNum,
                        sizeof(IdleThreadIdListT));
      if (idleThreadIds == NULL)
        vt_error();
    }

    /* create thread-specific data key for all threads */
    if (pthread_key_create(&pthreadKey, pthread_key_destructor) != 0)
      vt_error();

    /* create ID for master thread (=0) */
    master_tid = (uint32_t*)calloc(1, sizeof(uint32_t));
    if (master_tid == NULL)
      vt_error();

    /* put master thread-ID to thread-specific data */
    if (pthread_setspecific(pthreadKey, master_tid) != 0)
      vt_error();

#if defined(VT_METR)
    if (vt_metric_num() > 0)
      vt_metric_thread_init((long (*)(void))(pthread_self));
#endif /* VT_METR */
  }
}
void *
vt_return_node(xmlNodePtr node, struct vtest *test)
{
    int exp_ret;

    exp_ret = strtoul(node->content, NULL, 0);
    if (exp_ret != test->vtest_return) {
        printf("Expected return %d. Actual return %d\n",
                exp_ret, test->vtest_return);
        vt_error(RETURN, test, -EINVAL);
        return NULL;
    }

    return NULL;
}
void VTThrd_initJava()
{
  static uint8_t initflag = 1;

  if (initflag)
  {
    jvmtiError error;
    char tname[VT_MAX_THREAD_NAME_LEN];
    uint32_t* tid;

    initflag = 0;

    /* store pointer to JVMTI's environment */
    jvmti = vt_jvmti_agent->jvmti;

    /* create ID for first thread (=0) */
    tid = (uint32_t*)malloc(sizeof(uint32_t));
    if (tid == NULL)
      vt_error();
    *tid = 0;

    /* put thread-ID to thread-specific data */
    error = (*jvmti)->SetThreadLocalStorage(jvmti, NULL, (void*)tid);
    vt_java_check_error(jvmti, error, "SetThreadLocalStorage");

    /* create raw monitor for thread count */
    error = (*jvmti)->CreateRawMonitor(jvmti, "thread count",
                                       &threadCountMutex);
    vt_java_check_error(jvmti, error, "CreateRawMonitor[thread count]");

    /* create raw monitor for mutex init */
    error = (*jvmti)->CreateRawMonitor(jvmti, "mutex init",
                                       &mutexInitMutex);
    vt_java_check_error(jvmti, error, "CreateRawMonitor[mutex init]");

#if defined(VT_METR)
/*    if (vt_metric_num() > 0)
      vt_metric_thread_init((long (*)(void))(pthread_self));*/
#endif /* VT_METR */

    /* get name of current thread */
    vt_java_get_thread_name(NULL, NULL, tname, sizeof(tname));

    /* create thread object for master thread */
    VTThrdv[0] = VTThrd_create(0, 0, tname);
    VTThrd_open(VTThrdv[0], 0);
  }
}
static void hash_put_addr(unsigned long addr, uint32_t rid)
{
  /* -- get hash index */
  unsigned long idx = addr % ADDR_HASH_MAX;

  /* -- allocate/initialize new hash entry -- */
  HN_AddrT* add = (HN_AddrT*)malloc(sizeof(HN_AddrT));
  if ( add == NULL )
    vt_error();

  add->addr = addr;
  add->rid = rid;

  /* -- insert new hash entry at calculated hash index -- */
  add->next = htab_addr[idx];
  htab_addr[idx] = add;
}
Beispiel #28
0
struct vt_metv* vt_metric_create()
{
  struct vt_metv* metv;
  int i;

  if ( nmetrics == 0 )
    return NULL;

  metv = (struct vt_metv*)malloc(sizeof(struct vt_metv));
  if ( metv == NULL )
    vt_error();

  /* create CPC set */
  metv->set = NULL;
  if ( ( metv->set = cpc_set_create(cpc) ) == NULL )
    vt_error_msg("cpc_set_create: %s", strerror(errno));

  metv->indices = (int*)calloc(nmetrics, sizeof(int));
  for ( i = 0; i < nmetrics; i++ )
  {
    /* add request to set and store the corresponding index */
    metv->indices[i] = cpc_set_add_request(cpc, metv->set,
					   metricv[i]->name, 0,
					   CPC_COUNT_USER, 0, NULL);
    if ( metv->indices[i] == -1 )
      vt_error_msg("cpc_set_add_request (%s): %s", metricv[i]->name,
		   strerror(errno));
  }

  /* create CPC buffer */
  if ( ( metv->buffer = cpc_buf_create(cpc, metv->set) ) == NULL )
    vt_error_msg("cpc_buf_create: %s", strerror(errno));

  /* bind set to the calling LWP */
  if ( cpc_bind_curlwp(cpc, metv->set, 0) == -1 )
    vt_error_msg("cpc_bind_curlwp: %s",  strerror(errno));

  return metv;
}
void *
vt_expect_node(xmlNodePtr node, struct vtest *test)
{
    unsigned int i;
    bool result;
    /* TODO */
    void *buf = NULL;

    node = node->xmlChildrenNode;
    while (node) {
       for (i = 0; i < vt_message_modules_num; i++) {
            if (!strncmp(node->name, vt_message_modules[i].vmm_name,
                        strlen(vt_message_modules[i].vmm_name))) {
                result = vt_message_modules[i].vmm_expect(node, test, buf);
                if (!result) {
                    vt_error(EXPECT, test, -EINVAL);
                    break;
                }
            }
       }
    }

    return NULL;
}
struct vt_metv* vt_metric_create()
{
  struct vt_metv* metv;
  int retval, i,j;
  int component;

  if ( nmetrics == 0 )
    return NULL;

  metv = (struct vt_metv*)malloc(sizeof(struct vt_metv));
  if ( metv == NULL )
    vt_error();

  /* create event set */
  for (i=0; i<VT_METRIC_MAXNUM; i++)
    metv->EventSet[i] = NULL;

  for (i=0; i < nmetrics; i++)
  {
    struct eventmap_t *eventset;

#ifdef PAPIC
    component = PAPI_COMPONENT_INDEX(metricv[i]->papi_code);
#else
    component = 0;
#endif
    /* search for the eventset that matches the counter */
    j=0;
    while (metv->EventSet[j]!=NULL && j < VT_METRIC_MAXNUM && metv->EventSet[j]->ComponentId!=component){
      j++;
    }
    if (metv->EventSet[j]==NULL) /* no event of this component yet! */
    {
      metv->EventSet[j] = (struct eventmap_t*)malloc(sizeof(eventmap_t));
      metv->EventSet[j]->EventId=PAPI_NULL;
      metv->EventSet[j]->nEvents = 0;
      retval = PAPI_create_eventset(&(metv->EventSet[j]->EventId));
      if ( retval != PAPI_OK)
        metric_error(retval, "PAPI_create_eventset");
      metv->EventSet[j]->ComponentId=component;
    }
    eventset = metv->EventSet[j];

    /* add event to event set */
    retval = PAPI_add_event(eventset->EventId, metricv[i]->papi_code);
    if ( retval != PAPI_OK )
      metric_error(retval, "PAPI_add_event");
    /* for demux the values from eventset -> returnvector */
    metv->Values[i] = &(eventset->Values[eventset->nEvents]);
    eventset->nEvents++;
  }

  /* foreach used eventset */
  for (i=0; i < VT_METRIC_MAXNUM && metv->EventSet[i]!=NULL; i++)
  {
    retval = PAPI_start(metv->EventSet[i]->EventId);
    if ( retval != PAPI_OK )
      metric_error(retval, "PAPI_start");
  }

  return metv;
}