X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=libcounter%2Fcounter.c;h=780f8de84eab3f4f8b2c3ae755fdac604bc25029;hb=refs%2Fheads%2Fsow-2020-0002-rev2;hp=4010d5dd7f152b8c29d300d4e15ac751a6c04cc5;hpb=ebabbf580131acd1fe246c4d31fc5c044d36a038;p=deliverable%2Flttng-ust.git diff --git a/libcounter/counter.c b/libcounter/counter.c index 4010d5dd..780f8de8 100644 --- a/libcounter/counter.c +++ b/libcounter/counter.c @@ -75,9 +75,9 @@ static int lttng_counter_layout_init(struct lib_counter *counter, int cpu, int s 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. */ @@ -102,19 +102,24 @@ int lttng_counter_set_global_shm(struct lib_counter *counter, int fd) { 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; @@ -124,7 +129,10 @@ int lttng_counter_set_cpu_shm(struct lib_counter *counter, int cpu, int fd) 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 @@ -188,7 +196,7 @@ int validate_args(const struct lib_counter_config *config, 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; @@ -247,6 +255,8 @@ struct lib_counter *lttng_counter_create(const struct lib_counter_config *config 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) @@ -318,6 +328,13 @@ int lttng_counter_get_cpu_shm(struct lib_counter *counter, int cpu, int *fd, siz 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,