aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@linaro.org>2018-11-09 15:05:56 +0200
committerMaxim Uvarov <maxim.uvarov@linaro.org>2018-11-22 18:23:09 +0300
commit3529f3b8713021e45c7dbdd81f839d8b9049efcc (patch)
tree936bfb3f09443fd770d55d5607abff58e13b137c
parentaf055783f975e2b8b9e443565b3abdc9f7946ade (diff)
linux-gen: cls: simplify shm usage
Combine three shm reservations into one reservation. This simplifies shm usage and results less ODP internally allocated SHM blocks. Also one combined block is more memory efficient than multiple (saves memory and page mappings). Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r--platform/linux-generic/odp_classification.c97
1 files changed, 25 insertions, 72 deletions
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index fd20e3e0b..e6d75cb6c 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -35,6 +35,16 @@ static cos_tbl_t *cos_tbl;
static pmr_tbl_t *pmr_tbl;
static _cls_queue_grp_tbl_t *queue_grp_tbl;
+typedef struct cls_global_t {
+ cos_tbl_t cos_tbl;
+ pmr_tbl_t pmr_tbl;
+ _cls_queue_grp_tbl_t queue_grp_tbl;
+ odp_shm_t shm;
+
+} cls_global_t;
+
+static cls_global_t *cls_global;
+
static const rss_key default_rss = {
.u8 = {
0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
@@ -79,102 +89,45 @@ pmr_t *get_pmr_entry_internal(odp_pmr_t pmr)
int odp_classification_init_global(void)
{
- odp_shm_t cos_shm;
- odp_shm_t pmr_shm;
- odp_shm_t queue_grp_shm;
+ odp_shm_t shm;
int i;
- cos_shm = odp_shm_reserve("_odp_shm_odp_cos_tbl",
- sizeof(cos_tbl_t),
- sizeof(cos_t),
- 0);
+ shm = odp_shm_reserve("_odp_cls_global", sizeof(cls_global_t),
+ ODP_CACHE_LINE_SIZE, 0);
+ if (shm == ODP_SHM_INVALID)
+ return -1;
- if (cos_shm == ODP_SHM_INVALID) {
- ODP_ERR("shm allocation failed for shm_odp_cos_tbl");
- goto error;
- }
+ cls_global = odp_shm_addr(shm);
+ memset(cls_global, 0, sizeof(cls_global_t));
- cos_tbl = odp_shm_addr(cos_shm);
- if (cos_tbl == NULL)
- goto error_cos;
+ cls_global->shm = shm;
+ cos_tbl = &cls_global->cos_tbl;
+ pmr_tbl = &cls_global->pmr_tbl;
+ queue_grp_tbl = &cls_global->queue_grp_tbl;
- memset(cos_tbl, 0, sizeof(cos_tbl_t));
for (i = 0; i < CLS_COS_MAX_ENTRY; i++) {
/* init locks */
cos_t *cos = get_cos_entry_internal(_odp_cos_from_ndx(i));
LOCK_INIT(&cos->s.lock);
}
- pmr_shm = odp_shm_reserve("_odp_shm_odp_pmr_tbl",
- sizeof(pmr_tbl_t),
- sizeof(pmr_t),
- 0);
-
- if (pmr_shm == ODP_SHM_INVALID) {
- ODP_ERR("shm allocation failed for shm_odp_pmr_tbl");
- goto error_cos;
- }
-
- pmr_tbl = odp_shm_addr(pmr_shm);
- if (pmr_tbl == NULL)
- goto error_pmr;
-
- memset(pmr_tbl, 0, sizeof(pmr_tbl_t));
for (i = 0; i < CLS_PMR_MAX_ENTRY; i++) {
/* init locks */
pmr_t *pmr = get_pmr_entry_internal(_odp_pmr_from_ndx(i));
LOCK_INIT(&pmr->s.lock);
}
- queue_grp_shm = odp_shm_reserve("_odp_shm_cls_queue_grp_tbl",
- sizeof(_cls_queue_grp_tbl_t),
- sizeof(queue_entry_t *),
- 0);
-
- if (queue_grp_shm == ODP_SHM_INVALID) {
- ODP_ERR("shm allocation failed for queue_grp_tbl");
- goto error_queue_grp;
- }
-
- queue_grp_tbl = odp_shm_addr(queue_grp_shm);
- memset(queue_grp_tbl, 0, sizeof(_cls_queue_grp_tbl_t));
-
return 0;
-
-error_queue_grp:
- odp_shm_free(queue_grp_shm);
-error_pmr:
- odp_shm_free(pmr_shm);
-error_cos:
- odp_shm_free(cos_shm);
-error:
- return -1;
}
int odp_classification_term_global(void)
{
- int ret = 0;
- int rc = 0;
-
- ret = odp_shm_free(odp_shm_lookup("_odp_shm_odp_cos_tbl"));
- if (ret < 0) {
- ODP_ERR("shm free failed for shm_odp_cos_tbl");
- rc = -1;
- }
-
- ret = odp_shm_free(odp_shm_lookup("_odp_shm_odp_pmr_tbl"));
- if (ret < 0) {
- ODP_ERR("shm free failed for shm_odp_pmr_tbl");
- rc = -1;
- }
-
- ret = odp_shm_free(odp_shm_lookup("_odp_shm_cls_queue_grp_tbl"));
- if (ret < 0) {
- ODP_ERR("shm free failed for shm_odp_cls_queue_grp_tbl");
- rc = -1;
+ if (cls_global && odp_shm_free(cls_global->shm)) {
+ ODP_ERR("shm free failed");
+ return -1;
}
- return rc;
+ return 0;
}
void odp_cls_cos_param_init(odp_cls_cos_param_t *param)