counters_offset = shm_length;
shm_length += counter_size * nr_elem;
overflow_offset = shm_length;
- shm_length += ALIGN(nr_elem, 8) / 8;
+ shm_length += LTTNG_UST_ALIGN(nr_elem, 8) / 8;
underflow_offset = shm_length;
- shm_length += ALIGN(nr_elem, 8) / 8;
+ shm_length += LTTNG_UST_ALIGN(nr_elem, 8) / 8;
layout->shm_len = shm_length;
if (counter->is_daemon) {
/* Allocate and clear shared memory. */
{
struct lib_counter_config *config = &counter->config;
struct lib_counter_layout *layout;
+ int ret;
if (!(config->alloc & COUNTER_ALLOC_GLOBAL))
return -EINVAL;
layout = &counter->global_counters;
if (layout->shm_fd >= 0)
return -EBUSY;
- return lttng_counter_layout_init(counter, -1, fd);
+ ret = lttng_counter_layout_init(counter, -1, fd);
+ if (!ret)
+ counter->received_shm++;
+ return ret;
}
int lttng_counter_set_cpu_shm(struct lib_counter *counter, int cpu, int fd)
{
struct lib_counter_config *config = &counter->config;
struct lib_counter_layout *layout;
+ int ret;
if (cpu < 0 || cpu >= lttng_counter_num_possible_cpus())
return -EINVAL;
layout = &counter->percpu_counters[cpu];
if (layout->shm_fd >= 0)
return -EBUSY;
- return lttng_counter_layout_init(counter, cpu, fd);
+ ret = lttng_counter_layout_init(counter, cpu, fd);
+ if (!ret)
+ counter->received_shm++;
+ return ret;
}
static
return -1;
if (!(config->alloc & COUNTER_ALLOC_PER_CPU) && counter_cpu_fds)
return -1;
- if (!(config->alloc & COUNTER_ALLOC_PER_CPU) && counter_cpu_fds >= 0)
+ if (!(config->alloc & COUNTER_ALLOC_PER_CPU) && nr_counter_cpu_fds >= 0)
return -1;
if (counter_cpu_fds && nr_cpus != nr_counter_cpu_fds)
return -1;
nr_handles++;
if (config->alloc & COUNTER_ALLOC_PER_CPU)
nr_handles += nr_cpus;
+ counter->expected_shm = nr_handles;
+
/* Allocate table for global and per-cpu counters. */
counter->object_table = lttng_counter_shm_object_table_create(nr_handles);
if (!counter->object_table)
return 0;
}
+bool lttng_counter_ready(struct lib_counter *counter)
+{
+ if (counter->received_shm == counter->expected_shm)
+ return true;
+ return false;
+}
+
int lttng_counter_read(const struct lib_counter_config *config,
struct lib_counter *counter,
const size_t *dimension_indexes,