fix: cpu/hotplug: Remove deprecated CPU-hotplug functions. (v5.15)
[lttng-modules.git] / lib / ringbuffer / ring_buffer_iterator.c
index 61eaa5b775ece93034391c6e169ecbafd7cc78da..671249ae7ade1d5d15eef62493f2889fdff524ae 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/* SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
+ *
  * ring_buffer_iterator.c
  *
  * Ring buffer and channel iterators. Get each event of a channel in order. Uses
@@ -6,27 +7,12 @@
  * complexity for the "get next event" operation.
  *
  * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; only
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author:
- *     Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  */
 
 #include <wrapper/ringbuffer/iterator.h>
+#include <wrapper/cpu.h>
 #include <wrapper/file.h>
+#include <wrapper/uaccess.h>
 #include <linux/jiffies.h>
 #include <linux/delay.h>
 #include <linux/module.h>
@@ -61,7 +47,7 @@ restart:
        switch (iter->state) {
        case ITER_GET_SUBBUF:
                ret = lib_ring_buffer_get_next_subbuf(buf);
-               if (ret && !READ_ONCE(buf->finalized)
+               if (ret && !LTTNG_READ_ONCE(buf->finalized)
                    && config->alloc == RING_BUFFER_ALLOC_GLOBAL) {
                        /*
                         * Use "pull" scheme for global buffers. The reader
@@ -350,7 +336,7 @@ void lib_ring_buffer_iterator_init(struct channel *chan, struct lib_ring_buffer
                list_add(&buf->iter.empty_node, &chan->iter.empty_head);
 }
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
 
 int lttng_cpuhp_rb_iter_online(unsigned int cpu,
                struct lttng_cpuhp_node *node)
@@ -367,7 +353,7 @@ int lttng_cpuhp_rb_iter_online(unsigned int cpu,
 }
 EXPORT_SYMBOL_GPL(lttng_cpuhp_rb_iter_online);
 
-#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
 
 #ifdef CONFIG_HOTPLUG_CPU
 static
@@ -399,7 +385,7 @@ int channel_iterator_cpu_hotplug(struct notifier_block *nb,
 }
 #endif
 
-#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
 
 int channel_iterator_init(struct channel *chan)
 {
@@ -416,13 +402,13 @@ int channel_iterator_init(struct channel *chan)
                if (ret)
                        return ret;
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
                chan->cpuhp_iter_online.component = LTTNG_RING_BUFFER_ITER;
                ret = cpuhp_state_add_instance(lttng_rb_hp_online,
                        &chan->cpuhp_iter_online.node);
                if (ret)
                        return ret;
-#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
                {
                        int cpu;
 
@@ -437,13 +423,13 @@ int channel_iterator_init(struct channel *chan)
                        chan->hp_iter_notifier.priority = 10;
                        register_cpu_notifier(&chan->hp_iter_notifier);
 
-                       get_online_cpus();
+                       lttng_cpus_read_lock();
                        for_each_online_cpu(cpu) {
                                buf = per_cpu_ptr(chan->backend.buf, cpu);
                                lib_ring_buffer_iterator_init(chan, buf);
                        }
                        chan->hp_iter_enable = 1;
-                       put_online_cpus();
+                       lttng_cpus_read_unlock();
 #else
                        for_each_possible_cpu(cpu) {
                                buf = per_cpu_ptr(chan->backend.buf, cpu);
@@ -451,7 +437,7 @@ int channel_iterator_init(struct channel *chan)
                        }
 #endif
                }
-#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
        } else {
                buf = channel_get_ring_buffer(config, chan, 0);
                lib_ring_buffer_iterator_init(chan, buf);
@@ -464,7 +450,7 @@ void channel_iterator_unregister_notifiers(struct channel *chan)
        const struct lib_ring_buffer_config *config = &chan->backend.config;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
                {
                        int ret;
 
@@ -472,10 +458,10 @@ void channel_iterator_unregister_notifiers(struct channel *chan)
                                &chan->cpuhp_iter_online.node);
                        WARN_ON(ret);
                }
-#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
                chan->hp_iter_enable = 0;
                unregister_cpu_notifier(&chan->hp_iter_notifier);
-#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
+#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
        }
 }
 
@@ -516,7 +502,7 @@ int channel_iterator_open(struct channel *chan)
        CHAN_WARN_ON(chan, config->output != RING_BUFFER_ITERATOR);
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
-               get_online_cpus();
+               lttng_cpus_read_lock();
                /* Allow CPU hotplug to keep track of opened reader */
                chan->iter.read_open = 1;
                for_each_channel_cpu(cpu, chan) {
@@ -526,7 +512,7 @@ int channel_iterator_open(struct channel *chan)
                                goto error;
                        buf->iter.read_open = 1;
                }
-               put_online_cpus();
+               lttng_cpus_read_unlock();
        } else {
                buf = channel_get_ring_buffer(config, chan, 0);
                ret = lib_ring_buffer_iterator_open(buf);
@@ -535,7 +521,7 @@ int channel_iterator_open(struct channel *chan)
 error:
        /* Error should always happen on CPU 0, hence no close is required. */
        CHAN_WARN_ON(chan, cpu != 0);
-       put_online_cpus();
+       lttng_cpus_read_unlock();
        return ret;
 }
 EXPORT_SYMBOL_GPL(channel_iterator_open);
@@ -547,7 +533,7 @@ void channel_iterator_release(struct channel *chan)
        int cpu;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
-               get_online_cpus();
+               lttng_cpus_read_lock();
                for_each_channel_cpu(cpu, chan) {
                        buf = channel_get_ring_buffer(config, chan, cpu);
                        if (buf->iter.read_open) {
@@ -556,7 +542,7 @@ void channel_iterator_release(struct channel *chan)
                        }
                }
                chan->iter.read_open = 0;
-               put_online_cpus();
+               lttng_cpus_read_unlock();
        } else {
                buf = channel_get_ring_buffer(config, chan, 0);
                lib_ring_buffer_iterator_release(buf);
@@ -621,7 +607,7 @@ ssize_t channel_ring_buffer_file_read(struct file *filp,
        ssize_t len;
 
        might_sleep();
-       if (!access_ok(VERIFY_WRITE, user_buf, count))
+       if (!lttng_access_ok(VERIFY_WRITE, user_buf, count))
                return -EFAULT;
 
        /* Finish copy of previous record */
This page took 0.027173 seconds and 4 git commands to generate.