From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 504305A6A for ; Sun, 28 Oct 2018 23:58:21 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Oct 2018 15:58:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,437,1534834800"; d="scan'208";a="85185657" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.212]) by orsmga008.jf.intel.com with ESMTP; 28 Oct 2018 15:58:18 -0700 From: Ferruh Yigit To: Fiona Trahe , Pablo de Lara , Ashish Gupta , Declan Doherty , Jerin Jacob , Shreyansh Jain , Hemant Agrawal Cc: dev@dpdk.org, Ferruh Yigit Date: Sun, 28 Oct 2018 23:57:41 +0000 Message-Id: <20181028235741.12354-4-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181028235741.12354-1-ferruh.yigit@intel.com> References: <20181005162612.31906-1-ferruh.yigit@intel.com> <20181028235741.12354-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH v3 4/4] lib: reduce global variable usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Oct 2018 22:58:22 -0000 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 Acked-by: Jerin Jacob Acked-by: Shreyansh Jain --- lib/librte_compressdev/rte_compressdev.c | 32 ++++++++---------- lib/librte_compressdev/rte_compressdev_pmd.h | 5 --- lib/librte_cryptodev/rte_cryptodev.c | 34 +++++++++----------- lib/librte_cryptodev/rte_cryptodev_pmd.h | 3 -- lib/librte_eventdev/rte_eventdev.c | 8 ++--- lib/librte_eventdev/rte_eventdev_pmd.h | 2 -- lib/librte_rawdev/rte_rawdev.c | 10 +++--- lib/librte_rawdev/rte_rawdev_pmd.h | 2 -- 8 files changed, 37 insertions(+), 59 deletions(-) diff --git a/lib/librte_compressdev/rte_compressdev.c b/lib/librte_compressdev/rte_compressdev.c index 9091dd6ee..10101ebbe 100644 --- a/lib/librte_compressdev/rte_compressdev.c +++ b/lib/librte_compressdev/rte_compressdev.c @@ -18,19 +18,15 @@ #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); diff --git a/lib/librte_compressdev/rte_compressdev_pmd.h b/lib/librte_compressdev/rte_compressdev_pmd.h index 38e9ea02b..043353c99 100644 --- a/lib/librte_compressdev/rte_compressdev_pmd.h +++ b/lib/librte_compressdev/rte_compressdev_pmd.h @@ -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. * diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 608323fdd..a52eaaa45 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -43,19 +43,17 @@ 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++) { diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h index 6ff49d64d..1b6cafd17 100644 --- a/lib/librte_cryptodev/rte_cryptodev_pmd.h +++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h @@ -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. diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c index e70315e49..ebaf3087d 100644 --- a/lib/librte_eventdev/rte_eventdev.c +++ b/lib/librte_eventdev/rte_eventdev.c @@ -37,20 +37,18 @@ 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( diff --git a/lib/librte_eventdev/rte_eventdev_pmd.h b/lib/librte_eventdev/rte_eventdev_pmd.h index aa6e52c63..1a01326b8 100644 --- a/lib/librte_eventdev/rte_eventdev_pmd.h +++ b/lib/librte_eventdev/rte_eventdev_pmd.h @@ -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. */ diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c index 62b6b97ef..9f1e3592d 100644 --- a/lib/librte_rawdev/rte_rawdev.c +++ b/lib/librte_rawdev/rte_rawdev.c @@ -35,21 +35,19 @@ /* 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 == diff --git a/lib/librte_rawdev/rte_rawdev_pmd.h b/lib/librte_rawdev/rte_rawdev_pmd.h index bb9bbc350..811e51d07 100644 --- a/lib/librte_rawdev/rte_rawdev_pmd.h +++ b/lib/librte_rawdev/rte_rawdev_pmd.h @@ -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. */ -- 2.17.2