Пример #1
0
/*
* Get the memory policy of a process 
*/
void hw_get_mempol(int *node, int *mem_pol)
{
  hwloc_nodeset_t nset;
  hwloc_membind_policy_t mempol=-1;

 if (local_topo->nnodes != 0 ){

  nset = hwloc_bitmap_alloc();
  hwloc_get_membind_nodeset(topology,nset,&mempol,0);  
  (*node) = hwloc_bitmap_first(nset);
  switch(mempol)
  {
   case HWLOC_MEMBIND_FIRSTTOUCH:
     (*mem_pol) = OS; 
   break;
   case HWLOC_MEMBIND_BIND:
     (*mem_pol) = LOCAL; 
   break;
   case HWLOC_MEMBIND_INTERLEAVE: 
     (*mem_pol) = INTERLEAVE;
     (*node)   = -1;
   break;
   default:
     (*mem_pol) = -1;
     (*node) = -1;
   break;
  }
 }
 else
  (*mem_pol) = -1;
}
Пример #2
0
/*******************  FUNCTION  *********************/
int TopoHwloc::getCurrentIdFromNUMABinding(void) const
{
	hwloc_nodeset_t nodeset = hwloc_bitmap_alloc();
	hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
	hwloc_membind_policy_t policy;
	int res = -1;
	int weight;
	int status;
	#if defined(SCTK_ALLOC_DEBUG) && defined(hwloc_bitmap_list_snprintf)
	char buffer[4096];
	#endif

	//if no numa node, return immediately
	if (getNbNumaEntities() == 1)
		return -1;

	//nodes
	// flags = 0 fallback on PROCESS if THREAD is not supported (as for windows).
	status =  hwloc_get_membind_nodeset(topology,nodeset,&policy,0);
	assert(status == 0);
	if (status == 0)
		return -1;

	#if defined(SCTK_ALLOC_DEBUG) && defined(hwloc_bitmap_list_snprintf)
	status = hwloc_bitmap_list_snprintf(buffer,4096,nodeset);
	sprintf(stderr,"Current nodes : %s\n",buffer);
	#endif

	//cores
	// flags = 0 fallback on PROCESS if THREAD is not supported (as for windows).
	status =  hwloc_get_membind(topology,cpuset,&policy,0);
	assert(status == 0);
	if (status == 0)
		return -1;

	#if defined(SCTK_ALLOC_DEBUG) && defined(hwloc_bitmap_list_snprintf)
	status = hwloc_bitmap_list_snprintf(buffer,4096,cpuset);
	sprintf(stderr,"Current cores : %s\n",buffer);
	#endif

	//nodes from cores
	hwloc_cpuset_to_nodeset(topology,cpuset,nodeset);

	#if defined(SCTK_ALLOC_DEBUG) && defined(hwloc_bitmap_list_snprintf)
	status = hwloc_bitmap_list_snprintf(buffer,4096,nodeset);
	sprintf(stderr,"Current nodes from cores : %s\n",buffer);
	#endif

	//calc res
	weight = hwloc_bitmap_weight(nodeset);
	assert(weight != 0);
	if (weight == 1)
		res = getFirstBitInBitmap(nodeset);

	hwloc_bitmap_free(cpuset);
	hwloc_bitmap_free(nodeset);

	return res;
}
Пример #3
0
int
hwloc_get_membind(hwloc_topology_t topology, hwloc_cpuset_t set, hwloc_membind_policy_t * policy, int flags)
{
  hwloc_nodeset_t nodeset;
  int ret;

  nodeset = hwloc_bitmap_alloc();
  ret = hwloc_get_membind_nodeset(topology, nodeset, policy, flags);

  if (!ret)
    hwloc_cpuset_from_nodeset(topology, set, nodeset);

  hwloc_bitmap_free(nodeset);
  return ret;
}
Пример #4
0
int main(void)
{
    hwloc_topology_t topology;
    hwloc_bitmap_t set;
    hwloc_const_bitmap_t cset;
    hwloc_membind_policy_t policy;
    const struct hwloc_topology_support *support;
    int nbnodes;
    hwloc_obj_t obj;
    char *buffer, *s;
    unsigned i;
    int err;

    /* create a topology */
    err = hwloc_topology_init(&topology);
    if (err < 0) {
        fprintf(stderr, "failed to initialize the topology\n");
        return EXIT_FAILURE;
    }
    err = hwloc_topology_load(topology);
    if (err < 0) {
        fprintf(stderr, "failed to load the topology\n");
        hwloc_topology_destroy(topology);
        return EXIT_FAILURE;
    }

    /* retrieve the entire set of NUMA nodes and count them */
    cset = hwloc_topology_get_topology_nodeset(topology);
    nbnodes = hwloc_bitmap_weight(cset);
    if (nbnodes <= 0) {
        /* nbnodes may be -1 when there's no NUMA information,
         * or 0 when the machine is known to be non-NUMA */
        printf("this machine is not NUMA, nothing to do\n");
        hwloc_topology_destroy(topology);
        return EXIT_SUCCESS;
    }
    printf("there are %d nodes in the machine\n", nbnodes);

    /* get the process memory binding as a nodeset */
    set = hwloc_bitmap_alloc();
    if (!set) {
        fprintf(stderr, "failed to allocate a bitmap\n");
        hwloc_topology_destroy(topology);
        return EXIT_FAILURE;
    }
    err = hwloc_get_membind_nodeset(topology, set, &policy, 0);
    if (err < 0) {
        fprintf(stderr, "failed to retrieve my memory binding and policy\n");
        hwloc_topology_destroy(topology);
        hwloc_bitmap_free(set);
        return EXIT_FAILURE;
    }

    /* print the corresponding NUMA nodes */
    hwloc_bitmap_asprintf(&s, set);
    printf("bound to nodeset %s with contains:\n", s);
    free(s);
    hwloc_bitmap_foreach_begin(i, set) {
        obj = hwloc_get_numanode_obj_by_os_index(topology, i);
        printf("  node #%u (OS index %u) with %lld bytes of memory\n",
               obj->logical_index, i, (unsigned long long) obj->memory.local_memory);
    }