lib: reduce global variable usage
authorFerruh Yigit <ferruh.yigit@intel.com>
Sun, 28 Oct 2018 23:57:41 +0000 (23:57 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 29 Oct 2018 01:34:27 +0000 (02:34 +0100)
Some global variables can be eliminated, since they are not part of
public interface, it is free to remove them.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
lib/librte_compressdev/rte_compressdev.c
lib/librte_compressdev/rte_compressdev_pmd.h
lib/librte_cryptodev/rte_cryptodev.c
lib/librte_cryptodev/rte_cryptodev_pmd.h
lib/librte_eventdev/rte_eventdev.c
lib/librte_eventdev/rte_eventdev_pmd.h
lib/librte_rawdev/rte_rawdev.c
lib/librte_rawdev/rte_rawdev_pmd.h

index 9091dd6..10101eb 100644 (file)
 #define RTE_COMPRESSDEV_DETACHED  (0)
 #define RTE_COMPRESSDEV_ATTACHED  (1)
 
-struct rte_compressdev rte_comp_devices[RTE_COMPRESS_MAX_DEVS];
-
-struct rte_compressdev *rte_compressdevs = &rte_comp_devices[0];
+static struct rte_compressdev rte_comp_devices[RTE_COMPRESS_MAX_DEVS];
 
 static struct rte_compressdev_global compressdev_globals = {
-               .devs                   = &rte_comp_devices[0],
+               .devs                   = rte_comp_devices,
                .data                   = { NULL },
                .nb_devs                = 0,
                .max_devs               = RTE_COMPRESS_MAX_DEVS
 };
 
-struct rte_compressdev_global *rte_compressdev_globals = &compressdev_globals;
-
 const struct rte_compressdev_capabilities * __rte_experimental
 rte_compressdev_capability_get(uint8_t dev_id,
                        enum rte_comp_algorithm algo)
@@ -78,7 +74,7 @@ rte_compressdev_get_feature_name(uint64_t flag)
 static struct rte_compressdev *
 rte_compressdev_get_dev(uint8_t dev_id)
 {
-       return &rte_compressdev_globals->devs[dev_id];
+       return &compressdev_globals.devs[dev_id];
 }
 
 struct rte_compressdev * __rte_experimental
@@ -90,8 +86,8 @@ rte_compressdev_pmd_get_named_dev(const char *name)
        if (name == NULL)
                return NULL;
 
-       for (i = 0; i < rte_compressdev_globals->max_devs; i++) {
-               dev = &rte_compressdev_globals->devs[i];
+       for (i = 0; i < compressdev_globals.max_devs; i++) {
+               dev = &compressdev_globals.devs[i];
 
                if ((dev->attached == RTE_COMPRESSDEV_ATTACHED) &&
                                (strcmp(dev->data->name, name) == 0))
@@ -106,7 +102,7 @@ rte_compressdev_is_valid_dev(uint8_t dev_id)
 {
        struct rte_compressdev *dev = NULL;
 
-       if (dev_id >= rte_compressdev_globals->nb_devs)
+       if (dev_id >= compressdev_globals.nb_devs)
                return 0;
 
        dev = rte_compressdev_get_dev(dev_id);
@@ -125,10 +121,10 @@ rte_compressdev_get_dev_id(const char *name)
        if (name == NULL)
                return -1;
 
-       for (i = 0; i < rte_compressdev_globals->nb_devs; i++)
-               if ((strcmp(rte_compressdev_globals->devs[i].data->name, name)
+       for (i = 0; i < compressdev_globals.nb_devs; i++)
+               if ((strcmp(compressdev_globals.devs[i].data->name, name)
                                == 0) &&
-                               (rte_compressdev_globals->devs[i].attached ==
+                               (compressdev_globals.devs[i].attached ==
                                                RTE_COMPRESSDEV_ATTACHED))
                        return i;
 
@@ -138,7 +134,7 @@ rte_compressdev_get_dev_id(const char *name)
 uint8_t __rte_experimental
 rte_compressdev_count(void)
 {
-       return rte_compressdev_globals->nb_devs;
+       return compressdev_globals.nb_devs;
 }
 
 uint8_t __rte_experimental
@@ -146,8 +142,8 @@ rte_compressdev_devices_get(const char *driver_name, uint8_t *devices,
        uint8_t nb_devices)
 {
        uint8_t i, count = 0;
-       struct rte_compressdev *devs = rte_compressdev_globals->devs;
-       uint8_t max_devs = rte_compressdev_globals->max_devs;
+       struct rte_compressdev *devs = compressdev_globals.devs;
+       uint8_t max_devs = compressdev_globals.max_devs;
 
        for (i = 0; i < max_devs && count < nb_devices; i++) {
 
@@ -578,7 +574,7 @@ uint16_t __rte_experimental
 rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
                struct rte_comp_op **ops, uint16_t nb_ops)
 {
-       struct rte_compressdev *dev = &rte_compressdevs[dev_id];
+       struct rte_compressdev *dev = &rte_comp_devices[dev_id];
 
        nb_ops = (*dev->dequeue_burst)
                        (dev->data->queue_pairs[qp_id], ops, nb_ops);
@@ -590,7 +586,7 @@ uint16_t __rte_experimental
 rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
                struct rte_comp_op **ops, uint16_t nb_ops)
 {
-       struct rte_compressdev *dev = &rte_compressdevs[dev_id];
+       struct rte_compressdev *dev = &rte_comp_devices[dev_id];
 
        return (*dev->enqueue_burst)(
                        dev->data->queue_pairs[qp_id], ops, nb_ops);
index 38e9ea0..043353c 100644 (file)
@@ -51,11 +51,6 @@ struct rte_compressdev_global {
        uint8_t max_devs;               /**< Max number of devices */
 };
 
-/** Pointer to global array of comp devices */
-extern struct rte_compressdev *rte_compressdevs;
-/** Pointer to global comp devices data structure */
-extern struct rte_compressdev_global *rte_compressdev_globals;
-
 /**
  * Get the rte_compressdev structure device pointer for the named device.
  *
index 608323f..a52eaaa 100644 (file)
 
 static uint8_t nb_drivers;
 
-struct rte_cryptodev rte_crypto_devices[RTE_CRYPTO_MAX_DEVS];
+static struct rte_cryptodev rte_crypto_devices[RTE_CRYPTO_MAX_DEVS];
 
-struct rte_cryptodev *rte_cryptodevs = &rte_crypto_devices[0];
+struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
 
 static struct rte_cryptodev_global cryptodev_globals = {
-               .devs                   = &rte_crypto_devices[0],
+               .devs                   = rte_crypto_devices,
                .data                   = { NULL },
                .nb_devs                = 0,
                .max_devs               = RTE_CRYPTO_MAX_DEVS
 };
 
-struct rte_cryptodev_global *rte_cryptodev_globals = &cryptodev_globals;
-
 /* spinlock for crypto device callbacks */
 static rte_spinlock_t rte_cryptodev_cb_lock = RTE_SPINLOCK_INITIALIZER;
 
@@ -486,7 +484,7 @@ rte_cryptodev_get_feature_name(uint64_t flag)
 struct rte_cryptodev *
 rte_cryptodev_pmd_get_dev(uint8_t dev_id)
 {
-       return &rte_cryptodev_globals->devs[dev_id];
+       return &cryptodev_globals.devs[dev_id];
 }
 
 struct rte_cryptodev *
@@ -498,8 +496,8 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
        if (name == NULL)
                return NULL;
 
-       for (i = 0; i < rte_cryptodev_globals->max_devs; i++) {
-               dev = &rte_cryptodev_globals->devs[i];
+       for (i = 0; i < cryptodev_globals.max_devs; i++) {
+               dev = &cryptodev_globals.devs[i];
 
                if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
                                (strcmp(dev->data->name, name) == 0))
@@ -514,7 +512,7 @@ rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id)
 {
        struct rte_cryptodev *dev = NULL;
 
-       if (dev_id >= rte_cryptodev_globals->nb_devs)
+       if (dev_id >= cryptodev_globals.nb_devs)
                return 0;
 
        dev = rte_cryptodev_pmd_get_dev(dev_id);
@@ -533,10 +531,10 @@ rte_cryptodev_get_dev_id(const char *name)
        if (name == NULL)
                return -1;
 
-       for (i = 0; i < rte_cryptodev_globals->nb_devs; i++)
-               if ((strcmp(rte_cryptodev_globals->devs[i].data->name, name)
+       for (i = 0; i < cryptodev_globals.nb_devs; i++)
+               if ((strcmp(cryptodev_globals.devs[i].data->name, name)
                                == 0) &&
-                               (rte_cryptodev_globals->devs[i].attached ==
+                               (cryptodev_globals.devs[i].attached ==
                                                RTE_CRYPTODEV_ATTACHED))
                        return i;
 
@@ -546,7 +544,7 @@ rte_cryptodev_get_dev_id(const char *name)
 uint8_t
 rte_cryptodev_count(void)
 {
-       return rte_cryptodev_globals->nb_devs;
+       return cryptodev_globals.nb_devs;
 }
 
 uint8_t
@@ -554,9 +552,9 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id)
 {
        uint8_t i, dev_count = 0;
 
-       for (i = 0; i < rte_cryptodev_globals->max_devs; i++)
-               if (rte_cryptodev_globals->devs[i].driver_id == driver_id &&
-                       rte_cryptodev_globals->devs[i].attached ==
+       for (i = 0; i < cryptodev_globals.max_devs; i++)
+               if (cryptodev_globals.devs[i].driver_id == driver_id &&
+                       cryptodev_globals.devs[i].attached ==
                                        RTE_CRYPTODEV_ATTACHED)
                        dev_count++;
 
@@ -568,8 +566,8 @@ rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
        uint8_t nb_devices)
 {
        uint8_t i, count = 0;
-       struct rte_cryptodev *devs = rte_cryptodev_globals->devs;
-       uint8_t max_devs = rte_cryptodev_globals->max_devs;
+       struct rte_cryptodev *devs = cryptodev_globals.devs;
+       uint8_t max_devs = cryptodev_globals.max_devs;
 
        for (i = 0; i < max_devs && count < nb_devices; i++) {
 
index 6ff49d6..1b6cafd 100644 (file)
@@ -71,9 +71,6 @@ struct cryptodev_driver {
        uint8_t id;
 };
 
-/** pointer to global crypto devices data structure. */
-extern struct rte_cryptodev_global *rte_cryptodev_globals;
-
 /**
  * Get the rte_cryptodev structure device pointer for the device. Assumes a
  * valid device index.
index e70315e..ebaf308 100644 (file)
 
 static struct rte_eventdev rte_event_devices[RTE_EVENT_MAX_DEVS];
 
-struct rte_eventdev *rte_eventdevs = &rte_event_devices[0];
+struct rte_eventdev *rte_eventdevs = rte_event_devices;
 
 static struct rte_eventdev_global eventdev_globals = {
        .nb_devs                = 0
 };
 
-struct rte_eventdev_global *rte_eventdev_globals = &eventdev_globals;
-
 /* Event dev north bound API implementation */
 
 uint8_t
 rte_event_dev_count(void)
 {
-       return rte_eventdev_globals->nb_devs;
+       return eventdev_globals.nb_devs;
 }
 
 int
@@ -62,7 +60,7 @@ rte_event_dev_get_dev_id(const char *name)
        if (!name)
                return -EINVAL;
 
-       for (i = 0; i < rte_eventdev_globals->nb_devs; i++) {
+       for (i = 0; i < eventdev_globals.nb_devs; i++) {
                cmp = (strncmp(rte_event_devices[i].data->name, name,
                                RTE_EVENTDEV_NAME_MAX_LEN) == 0) ||
                        (rte_event_devices[i].dev ? (strncmp(
index aa6e52c..1a01326 100644 (file)
@@ -87,8 +87,6 @@ struct rte_eventdev_global {
        uint8_t nb_devs;        /**< Number of devices found */
 };
 
-extern struct rte_eventdev_global *rte_eventdev_globals;
-/** Pointer to global event devices data structure. */
 extern struct rte_eventdev *rte_eventdevs;
 /** The pool of rte_eventdev structures. */
 
index 62b6b97..9f1e359 100644 (file)
 /* dynamic log identifier */
 int librawdev_logtype;
 
-struct rte_rawdev rte_rawdevices[RTE_RAWDEV_MAX_DEVS];
+static struct rte_rawdev rte_rawdevices[RTE_RAWDEV_MAX_DEVS];
 
-struct rte_rawdev *rte_rawdevs = &rte_rawdevices[0];
+struct rte_rawdev *rte_rawdevs = rte_rawdevices;
 
 static struct rte_rawdev_global rawdev_globals = {
        .nb_devs                = 0
 };
 
-struct rte_rawdev_global *rte_rawdev_globals = &rawdev_globals;
-
 /* Raw device, northbound API implementation */
 uint8_t
 rte_rawdev_count(void)
 {
-       return rte_rawdev_globals->nb_devs;
+       return rawdev_globals.nb_devs;
 }
 
 uint16_t
@@ -60,7 +58,7 @@ rte_rawdev_get_dev_id(const char *name)
        if (!name)
                return -EINVAL;
 
-       for (i = 0; i < rte_rawdev_globals->nb_devs; i++)
+       for (i = 0; i < rawdev_globals.nb_devs; i++)
                if ((strcmp(rte_rawdevices[i].name, name)
                                == 0) &&
                                (rte_rawdevices[i].attached ==
index bb9bbc3..811e51d 100644 (file)
@@ -73,8 +73,6 @@ struct rte_rawdev_global {
        uint16_t nb_devs;
 };
 
-extern struct rte_rawdev_global *rte_rawdev_globals;
-/** Pointer to global raw devices data structure. */
 extern struct rte_rawdev *rte_rawdevs;
 /** The pool of rte_rawdev structures. */