Use rseq for cpu_id in libringbuffer
[lttng-ust.git] / liblttng-ust / lttng-ring-buffer-client.h
index 5e95244f724b36dbcf23bedc6435c2407d401156..b397a5e06b176b9e3027ab8095d2ddec54a09f63 100644 (file)
@@ -695,12 +695,27 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx,
                      uint32_t event_id)
 {
        struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
+       struct lttng_rseq_state rseq_state;
        int ret, cpu;
 
-       //TODO register (lazy)
-       cpu = lib_ring_buffer_get_cpu(&client_config);
-       if (cpu < 0)
+       if (lib_ring_buffer_begin(&client_config))
                return -EPERM;
+retry:
+       rseq_state = rseq_start();
+       if (caa_unlikely(rseq_cpu_at_start(rseq_state) < 0)) {
+               if (caa_unlikely(rseq_cpu_at_start(rseq_state) == -1)) {
+                       if (!rseq_register_current_thread())
+                               goto retry;
+               }
+               /* rseq is unavailable. */
+               cpu = lib_ring_buffer_get_cpu(&client_config);
+               if (caa_unlikely(cpu < 0)) {
+                       ret = -EPERM;
+                       goto end;
+               }
+       } else {
+               cpu = rseq_cpu_at_start(rseq_state);
+       }
        ctx->cpu = cpu;
 
        switch (lttng_chan->header_type) {
@@ -724,13 +739,13 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx,
                if (lib_ring_buffer_backend_get_pages(&client_config, ctx,
                                &ctx->backend_pages)) {
                        ret = -EPERM;
-                       goto put;
+                       goto end;
                }
        }
        lttng_write_event_header(&client_config, ctx, event_id);
        return 0;
-put:
-       lib_ring_buffer_put_cpu(&client_config);
+end:
+       lib_ring_buffer_end(&client_config);
        return ret;
 }
 
@@ -738,7 +753,7 @@ static
 void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx *ctx)
 {
        lib_ring_buffer_commit(&client_config, ctx);
-       lib_ring_buffer_put_cpu(&client_config);
+       lib_ring_buffer_end(&client_config);
 }
 
 static
This page took 0.029558 seconds and 5 git commands to generate.