Skip to contentSkip to conversation

export numa_init

DISCUSSION Daniel Kozak 2 participants 2 messages Oct 12, 2013 – Oct 13, 2013

lore
Share & tools
lore
#1 lore raw
Quoted 10 lines · Daniel Kozak

Hello,

when I compile latest libnuma.so, the numa_init symbol is not exported. So it is not possible to linked against this lib with code which called numa_init directly from code. One of affected program is HipHop Virtual Machine (HHVM)
https://github.com/facebook/hiphop-php/blob/master/hphp/util/alloc.cpp#L135

So it is possible to add numa_init into global section in versions.ldscript?

Ah makes sense:

// numa_init is called automatically, but is probably called after // JEMallocInitializer(). its idempotent, so call it here.

     numa_init();

When libnuma code is called from a constructor then the function may need to be called explicitely to avoid ordering problems.

So yes exporting this is ok I guess.

This is also interesting. I'm surprised this doesn't work (maybe for an old version?)

/*
* libnuma is only partially aware of taskset. If on entry,
* you have completely disabled a node via taskset, the node
* will not be available, and calling numa_run_on_node will
* not work for that node. But if only some of the cpu's on a
* node were disabled, then calling numa_run_on_node will enable
* them all. To prevent this, compute the actual masks up front */
bitmask* enabled = numa_allocate_cpumask();

  if (numa_sched_getaffinity(0, enabled) < 0) {
    return;
  }
  node_to_cpu_mask = new std::vector<bitmask*>;
  int num_cpus = numa_num_configured_cpus();
  int max_node = numa_max_node();
  for (int i = 0; i <= max_node; i++) {
    bitmask* cpus_for_node = numa_allocate_cpumask();
    numa_node_to_cpus(i, cpus_for_node);
    for (int j = 0; j < num_cpus; j++) {
      if (!numa_bitmask_isbitset(enabled, j)) {
        numa_bitmask_clearbit(cpus_for_node, j);
      }
    }
    assert(node_to_cpu_mask->size() == i);
    node_to_cpu_mask->push_back(cpus_for_node);

}
numa_bitmask_free(enabled);

-andi