From patchwork Fri Feb 12 10:13:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shijith Thotton X-Patchwork-Id: 87882 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 06647A0547; Fri, 12 Feb 2021 11:13:57 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 790CD22A237; Fri, 12 Feb 2021 11:13:57 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id E101C22A233 for ; Fri, 12 Feb 2021 11:13:55 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 11CAAOQL021209; Fri, 12 Feb 2021 02:13:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=a0mAsPl6PT6vqRLmn0Afo5JZUP1KT4GmJq4Iq6oQn0Q=; b=FYQZEgOUEM5a22uS1608+py5SdUdjYDoLpU1tXJqGevEd/Jxdvls+MW/d5Wkdv4HElwm DC9Fr6ld3O5l0PtfwuJLyz6awNH5TifbofMGAZ++TFH4O0yug3B+gUZKPRGonWonOYnt 0xnbuOUANn3fmzzoEIS/yMldpzIJTsgHqZO3ZC8+3+cC1uLw4JsDr6hnHJfsnw/qdQKf VwXicgBy7CkfH4tMIrKGRxoeFfC8QUfUhhiuwxyBESKY406shfYEfQxRyFxxGC+KKu2C 6tjNEPTgTunCv4RD/Kv/JOMVDrYEtqA/6IT67U5L6hDeTWDREZadWdTnKB5DcNdvxyw7 3g== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 36hsbrtaty-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 12 Feb 2021 02:13:54 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 12 Feb 2021 02:13:52 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 12 Feb 2021 02:13:52 -0800 Received: from localhost.localdomain (unknown [10.28.34.29]) by maili.marvell.com (Postfix) with ESMTP id ABDE23F703F; Fri, 12 Feb 2021 02:13:50 -0800 (PST) From: Shijith Thotton To: Erik Gabriel Carrillo CC: Shijith Thotton , Pavan Nikhilesh , Jerin Jacob , Date: Fri, 12 Feb 2021 15:43:43 +0530 Message-ID: <20210212101343.689792-1-sthotton@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.737 definitions=2021-02-12_03:2021-02-12, 2021-02-12 signatures=0 Subject: [dpdk-dev] [RFC PATCH] eventdev: use shared memory to store timer adapter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" It is not possible for secondary process to arm timer as timer adapter is not stored in shared memory. Using shared memory allows the secondary to lookup adapters and arm them. Signed-off-by: Shijith Thotton --- drivers/event/octeontx/timvf_evdev.c | 20 +- drivers/event/octeontx/timvf_worker.c | 12 +- drivers/event/octeontx2/otx2_tim_evdev.c | 28 +-- drivers/event/octeontx2/otx2_tim_worker.c | 4 +- lib/librte_eventdev/rte_event_timer_adapter.c | 193 ++++++++++-------- lib/librte_eventdev/rte_event_timer_adapter.h | 58 ++++-- .../rte_event_timer_adapter_pmd.h | 31 --- 7 files changed, 186 insertions(+), 160 deletions(-) diff --git a/drivers/event/octeontx/timvf_evdev.c b/drivers/event/octeontx/timvf_evdev.c index 8af4d6e37..ee93c87b5 100644 --- a/drivers/event/octeontx/timvf_evdev.c +++ b/drivers/event/octeontx/timvf_evdev.c @@ -39,10 +39,10 @@ static void timvf_ring_info_get(const struct rte_event_timer_adapter *adptr, struct rte_event_timer_adapter_info *adptr_info) { - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; adptr_info->max_tmo_ns = timr->max_tout; adptr_info->min_resolution_ns = timr->tck_nsec; - rte_memcpy(&adptr_info->conf, &adptr->data->conf, + rte_memcpy(&adptr_info->conf, &adptr->data.conf, sizeof(struct rte_event_timer_adapter_conf)); } @@ -123,7 +123,7 @@ timvf_ring_start(const struct rte_event_timer_adapter *adptr) uintptr_t pool; struct timvf_ctrl_reg rctrl; struct timvf_mbox_dev_info dinfo; - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; ret = timvf_mbox_dev_info_get(&dinfo); if (ret < 0 || ret != sizeof(struct timvf_mbox_dev_info)) @@ -210,7 +210,7 @@ timvf_ring_start(const struct rte_event_timer_adapter *adptr) static int timvf_ring_stop(const struct rte_event_timer_adapter *adptr) { - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; struct timvf_ctrl_reg rctrl = {0}; rctrl.rctrl0 = timvf_read64((uint8_t *)timr->vbar0 + TIM_VRING_CTL0); rctrl.rctrl1 = timvf_read64((uint8_t *)timr->vbar0 + TIM_VRING_CTL1); @@ -225,7 +225,7 @@ timvf_ring_stop(const struct rte_event_timer_adapter *adptr) static int timvf_ring_create(struct rte_event_timer_adapter *adptr) { - struct rte_event_timer_adapter_conf *rcfg = &adptr->data->conf; + struct rte_event_timer_adapter_conf *rcfg = &adptr->data.conf; uint16_t free_idx = UINT16_MAX; unsigned int mp_flags = 0; struct ssovf_evdev *edev; @@ -245,7 +245,7 @@ timvf_ring_create(struct rte_event_timer_adapter *adptr) if (timr == NULL) return -ENOMEM; - adptr->data->adapter_priv = timr; + adptr->data.adapter_priv = timr; /* Check config parameters. */ if ((rcfg->clk_src != RTE_EVENT_TIMER_ADAPTER_CPU_CLK) && (!rcfg->timer_tick_ns || @@ -364,7 +364,7 @@ timvf_ring_create(struct rte_event_timer_adapter *adptr) static int timvf_ring_free(struct rte_event_timer_adapter *adptr) { - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; struct ssovf_evdev *edev; int i; @@ -380,7 +380,7 @@ timvf_ring_free(struct rte_event_timer_adapter *adptr) rte_mempool_free(timr->chunk_pool); rte_free(timr->bkt); timvf_release_ring(timr->tim_ring_id); - rte_free(adptr->data->adapter_priv); + rte_free(adptr->data.adapter_priv); return 0; } @@ -388,7 +388,7 @@ static int timvf_stats_get(const struct rte_event_timer_adapter *adapter, struct rte_event_timer_adapter_stats *stats) { - struct timvf_ring *timr = adapter->data->adapter_priv; + struct timvf_ring *timr = adapter->data.adapter_priv; uint64_t bkt_cyc = rte_rdtsc() - timr->ring_start_cyc; stats->evtim_exp_count = timr->tim_arm_cnt; @@ -401,7 +401,7 @@ timvf_stats_get(const struct rte_event_timer_adapter *adapter, static int timvf_stats_reset(const struct rte_event_timer_adapter *adapter) { - struct timvf_ring *timr = adapter->data->adapter_priv; + struct timvf_ring *timr = adapter->data.adapter_priv; timr->tim_arm_cnt = 0; return 0; diff --git a/drivers/event/octeontx/timvf_worker.c b/drivers/event/octeontx/timvf_worker.c index 50790e199..2e33ddd33 100644 --- a/drivers/event/octeontx/timvf_worker.c +++ b/drivers/event/octeontx/timvf_worker.c @@ -70,7 +70,7 @@ timvf_timer_arm_burst_sp(const struct rte_event_timer_adapter *adptr, int ret; uint16_t index; struct tim_mem_entry entry; - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; for (index = 0; index < nb_timers; index++) { if (timvf_timer_reg_checks(timr, tim[index])) break; @@ -92,7 +92,7 @@ timvf_timer_arm_burst_sp_stats(const struct rte_event_timer_adapter *adptr, struct rte_event_timer **tim, const uint16_t nb_timers) { uint16_t ret; - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; ret = timvf_timer_arm_burst_sp(adptr, tim, nb_timers); timr->tim_arm_cnt += ret; @@ -107,7 +107,7 @@ timvf_timer_arm_burst_mp(const struct rte_event_timer_adapter *adptr, int ret; uint16_t index; struct tim_mem_entry entry; - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; for (index = 0; index < nb_timers; index++) { if (timvf_timer_reg_checks(timr, tim[index])) break; @@ -128,7 +128,7 @@ timvf_timer_arm_burst_mp_stats(const struct rte_event_timer_adapter *adptr, struct rte_event_timer **tim, const uint16_t nb_timers) { uint16_t ret; - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; ret = timvf_timer_arm_burst_mp(adptr, tim, nb_timers); timr->tim_arm_cnt += ret; @@ -145,7 +145,7 @@ timvf_timer_arm_tmo_brst(const struct rte_event_timer_adapter *adptr, uint16_t set_timers = 0; uint16_t idx; uint16_t arr_idx = 0; - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; struct tim_mem_entry entry[TIMVF_MAX_BURST] __rte_cache_aligned; if (unlikely(!timeout_tick || timeout_tick >= timr->nb_bkts)) { @@ -180,7 +180,7 @@ timvf_timer_arm_tmo_brst_stats(const struct rte_event_timer_adapter *adptr, const uint16_t nb_timers) { uint16_t set_timers; - struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ring *timr = adptr->data.adapter_priv; set_timers = timvf_timer_arm_tmo_brst(adptr, tim, timeout_tick, nb_timers); diff --git a/drivers/event/octeontx2/otx2_tim_evdev.c b/drivers/event/octeontx2/otx2_tim_evdev.c index 4c24cc8a6..24b8c605b 100644 --- a/drivers/event/octeontx2/otx2_tim_evdev.c +++ b/drivers/event/octeontx2/otx2_tim_evdev.c @@ -62,11 +62,11 @@ static void otx2_tim_ring_info_get(const struct rte_event_timer_adapter *adptr, struct rte_event_timer_adapter_info *adptr_info) { - struct otx2_tim_ring *tim_ring = adptr->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adptr->data.adapter_priv; adptr_info->max_tmo_ns = tim_ring->max_tout; adptr_info->min_resolution_ns = tim_ring->tck_nsec; - rte_memcpy(&adptr_info->conf, &adptr->data->conf, + rte_memcpy(&adptr_info->conf, &adptr->data.conf, sizeof(struct rte_event_timer_adapter_conf)); } @@ -247,7 +247,7 @@ tim_err_desc(int rc) static int otx2_tim_ring_create(struct rte_event_timer_adapter *adptr) { - struct rte_event_timer_adapter_conf *rcfg = &adptr->data->conf; + struct rte_event_timer_adapter_conf *rcfg = &adptr->data.conf; struct otx2_tim_evdev *dev = tim_priv_get(); struct otx2_tim_ring *tim_ring; struct tim_config_req *cfg_req; @@ -259,13 +259,13 @@ otx2_tim_ring_create(struct rte_event_timer_adapter *adptr) if (dev == NULL) return -ENODEV; - if (adptr->data->id >= dev->nb_rings) + if (adptr->data.id >= dev->nb_rings) return -ENODEV; req = otx2_mbox_alloc_msg_tim_lf_alloc(dev->mbox); req->npa_pf_func = otx2_npa_pf_func_get(); req->sso_pf_func = otx2_sso_pf_func_get(); - req->ring = adptr->data->id; + req->ring = adptr->data.id; rc = otx2_mbox_process_msg(dev->mbox, (void **)&rsp); if (rc < 0) { @@ -290,11 +290,11 @@ otx2_tim_ring_create(struct rte_event_timer_adapter *adptr) goto rng_mem_err; } - adptr->data->adapter_priv = tim_ring; + adptr->data.adapter_priv = tim_ring; tim_ring->tenns_clk_freq = rsp->tenns_clk; tim_ring->clk_src = (int)rcfg->clk_src; - tim_ring->ring_id = adptr->data->id; + tim_ring->ring_id = adptr->data.id; tim_ring->tck_nsec = RTE_ALIGN_MUL_CEIL(rcfg->timer_tick_ns, 10); tim_ring->max_tout = rcfg->max_tmo_ns; tim_ring->nb_bkts = (tim_ring->max_tout / tim_ring->tck_nsec); @@ -393,7 +393,7 @@ otx2_tim_ring_create(struct rte_event_timer_adapter *adptr) rte_free(tim_ring); rng_mem_err: free_req = otx2_mbox_alloc_msg_tim_lf_free(dev->mbox); - free_req->ring = adptr->data->id; + free_req->ring = adptr->data.id; otx2_mbox_process(dev->mbox); return rc; } @@ -426,7 +426,7 @@ otx2_tim_calibrate_start_tsc(struct otx2_tim_ring *tim_ring) static int otx2_tim_ring_start(const struct rte_event_timer_adapter *adptr) { - struct otx2_tim_ring *tim_ring = adptr->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adptr->data.adapter_priv; struct otx2_tim_evdev *dev = tim_priv_get(); struct tim_enable_rsp *rsp; struct tim_ring_req *req; @@ -469,7 +469,7 @@ otx2_tim_ring_start(const struct rte_event_timer_adapter *adptr) static int otx2_tim_ring_stop(const struct rte_event_timer_adapter *adptr) { - struct otx2_tim_ring *tim_ring = adptr->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adptr->data.adapter_priv; struct otx2_tim_evdev *dev = tim_priv_get(); struct tim_ring_req *req; int rc; @@ -492,7 +492,7 @@ otx2_tim_ring_stop(const struct rte_event_timer_adapter *adptr) static int otx2_tim_ring_free(struct rte_event_timer_adapter *adptr) { - struct otx2_tim_ring *tim_ring = adptr->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adptr->data.adapter_priv; struct otx2_tim_evdev *dev = tim_priv_get(); struct tim_ring_req *req; int rc; @@ -513,7 +513,7 @@ otx2_tim_ring_free(struct rte_event_timer_adapter *adptr) rte_free(tim_ring->bkt); rte_mempool_free(tim_ring->chunk_pool); - rte_free(adptr->data->adapter_priv); + rte_free(adptr->data.adapter_priv); return 0; } @@ -522,7 +522,7 @@ static int otx2_tim_stats_get(const struct rte_event_timer_adapter *adapter, struct rte_event_timer_adapter_stats *stats) { - struct otx2_tim_ring *tim_ring = adapter->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adapter->data.adapter_priv; uint64_t bkt_cyc = rte_rdtsc() - tim_ring->ring_start_cyc; @@ -537,7 +537,7 @@ otx2_tim_stats_get(const struct rte_event_timer_adapter *adapter, static int otx2_tim_stats_reset(const struct rte_event_timer_adapter *adapter) { - struct otx2_tim_ring *tim_ring = adapter->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adapter->data.adapter_priv; __atomic_store_n(&tim_ring->arm_cnt, 0, __ATOMIC_RELAXED); return 0; diff --git a/drivers/event/octeontx2/otx2_tim_worker.c b/drivers/event/octeontx2/otx2_tim_worker.c index 4b5cfdc72..5614e1643 100644 --- a/drivers/event/octeontx2/otx2_tim_worker.c +++ b/drivers/event/octeontx2/otx2_tim_worker.c @@ -61,7 +61,7 @@ tim_timer_arm_burst(const struct rte_event_timer_adapter *adptr, const uint16_t nb_timers, const uint8_t flags) { - struct otx2_tim_ring *tim_ring = adptr->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adptr->data.adapter_priv; struct otx2_tim_ent entry; uint16_t index; int ret; @@ -100,7 +100,7 @@ tim_timer_arm_tmo_brst(const struct rte_event_timer_adapter *adptr, const uint16_t nb_timers, const uint8_t flags) { struct otx2_tim_ent entry[OTX2_TIM_MAX_BURST] __rte_cache_aligned; - struct otx2_tim_ring *tim_ring = adptr->data->adapter_priv; + struct otx2_tim_ring *tim_ring = adptr->data.adapter_priv; uint16_t set_timers = 0; uint16_t arr_idx = 0; uint16_t idx; diff --git a/lib/librte_eventdev/rte_event_timer_adapter.c b/lib/librte_eventdev/rte_event_timer_adapter.c index dd7b83087..682b1c3c2 100644 --- a/lib/librte_eventdev/rte_event_timer_adapter.c +++ b/lib/librte_eventdev/rte_event_timer_adapter.c @@ -26,14 +26,14 @@ #include "rte_event_timer_adapter.h" #include "rte_event_timer_adapter_pmd.h" -#define DATA_MZ_NAME_MAX_LEN 64 -#define DATA_MZ_NAME_FORMAT "rte_event_timer_adapter_data_%d" +#define EVTIM_MZ_NAME_MAX_LEN 64 +#define EVTIM_MZ_NAME_FORMAT "rte_event_timer_adapter_%d" RTE_LOG_REGISTER(evtim_logtype, lib.eventdev.adapter.timer, NOTICE); RTE_LOG_REGISTER(evtim_buffer_logtype, lib.eventdev.adapter.timer, NOTICE); RTE_LOG_REGISTER(evtim_svc_logtype, lib.eventdev.adapter.timer.svc, NOTICE); -static struct rte_event_timer_adapter adapters[RTE_EVENT_TIMER_ADAPTER_NUM_MAX]; +static struct rte_event_timer_adapter **adapters; static const struct rte_event_timer_adapter_ops swtim_ops; @@ -72,8 +72,8 @@ default_port_conf_cb(uint16_t id, uint8_t event_dev_id, uint8_t *event_port_id, RTE_SET_USED(event_dev_id); - adapter = &adapters[id]; - dev = &rte_eventdevs[adapter->data->event_dev_id]; + adapter = adapters[id]; + dev = &rte_eventdevs[adapter->data.event_dev_id]; dev_id = dev->data->dev_id; dev_conf = dev->data->dev_conf; @@ -118,6 +118,31 @@ default_port_conf_cb(uint16_t id, uint8_t event_dev_id, uint8_t *event_port_id, return ret; } +static int +rte_event_timer_adapter_init(void) +{ + const char *name = "rte_event_timer_adapter_array"; + const struct rte_memzone *mz; + unsigned int sz; + + sz = sizeof(*adapters) * RTE_EVENT_TIMER_ADAPTER_NUM_MAX; + sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE); + + mz = rte_memzone_lookup(name); + if (mz == NULL) { + mz = rte_memzone_reserve_aligned(name, sz, rte_socket_id(), 0, + RTE_CACHE_LINE_SIZE); + if (mz == NULL) { + EVTIM_LOG_ERR("failed to reserve memzone err = %" + PRId32, rte_errno); + return -rte_errno; + } + } + + adapters = mz->addr; + return 0; +} + struct rte_event_timer_adapter * rte_event_timer_adapter_create(const struct rte_event_timer_adapter_conf *conf) { @@ -134,7 +159,7 @@ rte_event_timer_adapter_create_ext( uint16_t adapter_id; struct rte_event_timer_adapter *adapter; const struct rte_memzone *mz; - char mz_name[DATA_MZ_NAME_MAX_LEN]; + char mz_name[EVTIM_MZ_NAME_MAX_LEN]; int n, ret; struct rte_eventdev *dev; @@ -143,6 +168,11 @@ rte_event_timer_adapter_create_ext( return NULL; } + if (adapters == NULL) { + if (rte_event_timer_adapter_init()) + return NULL; + } + /* Check eventdev ID */ if (!rte_event_pmd_is_valid_dev(conf->event_dev_id)) { rte_errno = EINVAL; @@ -159,49 +189,51 @@ rte_event_timer_adapter_create_ext( } /* Check adapter ID not already allocated */ - adapter = &adapters[adapter_id]; - if (adapter->allocated) { + adapter = adapters[adapter_id]; + if (adapter) { + EVTIM_LOG_ERR("Timer adapter id %u already exists", adapter_id); rte_errno = EEXIST; return NULL; } - /* Create shared data area. */ - n = snprintf(mz_name, sizeof(mz_name), DATA_MZ_NAME_FORMAT, adapter_id); + /* Reserve timer adapter memory. */ + n = snprintf(mz_name, sizeof(mz_name), EVTIM_MZ_NAME_FORMAT, + adapter_id); if (n >= (int)sizeof(mz_name)) { rte_errno = EINVAL; return NULL; } mz = rte_memzone_reserve(mz_name, - sizeof(struct rte_event_timer_adapter_data), + sizeof(struct rte_event_timer_adapter), conf->socket_id, 0); if (mz == NULL) /* rte_errno set by rte_memzone_reserve */ return NULL; - adapter->data = mz->addr; - memset(adapter->data, 0, sizeof(struct rte_event_timer_adapter_data)); + adapter = mz->addr; + memset(adapter, 0, sizeof(struct rte_event_timer_adapter)); - adapter->data->mz = mz; - adapter->data->event_dev_id = conf->event_dev_id; - adapter->data->id = adapter_id; - adapter->data->socket_id = conf->socket_id; - adapter->data->conf = *conf; /* copy conf structure */ + adapter->mz = mz; + adapter->data.event_dev_id = conf->event_dev_id; + adapter->data.id = adapter_id; + adapter->data.socket_id = conf->socket_id; + adapter->data.conf = *conf; /* copy conf structure */ /* Query eventdev PMD for timer adapter capabilities and ops */ ret = dev->dev_ops->timer_adapter_caps_get(dev, - adapter->data->conf.flags, - &adapter->data->caps, + adapter->data.conf.flags, + &adapter->data.caps, &adapter->ops); if (ret < 0) { rte_errno = -ret; goto free_memzone; } - if (!(adapter->data->caps & + if (!(adapter->data.caps & RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) { FUNC_PTR_OR_NULL_RET_WITH_ERRNO(conf_cb, EINVAL); - ret = conf_cb(adapter->data->id, adapter->data->event_dev_id, - &adapter->data->event_port_id, conf_arg); + ret = conf_cb(adapter->data.id, adapter->data.event_dev_id, + &adapter->data.event_port_id, conf_arg); if (ret < 0) { rte_errno = -ret; goto free_memzone; @@ -227,14 +259,14 @@ rte_event_timer_adapter_create_ext( adapter->arm_tmo_tick_burst = adapter->ops->arm_tmo_tick_burst; adapter->cancel_burst = adapter->ops->cancel_burst; - adapter->allocated = 1; + adapters[adapter_id] = adapter; rte_eventdev_trace_timer_adapter_create(adapter_id, adapter, conf, conf_cb); return adapter; free_memzone: - rte_memzone_free(adapter->data->mz); + rte_memzone_free(adapter->mz); return NULL; } @@ -249,24 +281,24 @@ rte_event_timer_adapter_get_info(const struct rte_event_timer_adapter *adapter, adapter->ops->get_info(adapter, adapter_info); /* Set common values */ - adapter_info->conf = adapter->data->conf; - adapter_info->event_dev_port_id = adapter->data->event_port_id; - adapter_info->caps = adapter->data->caps; + adapter_info->conf = adapter->data.conf; + adapter_info->event_dev_port_id = adapter->data.event_port_id; + adapter_info->caps = adapter->data.caps; return 0; } int -rte_event_timer_adapter_start(const struct rte_event_timer_adapter *adapter) +rte_event_timer_adapter_start(struct rte_event_timer_adapter *adapter) { int ret; ADAPTER_VALID_OR_ERR_RET(adapter, -EINVAL); FUNC_PTR_OR_ERR_RET(adapter->ops->start, -EINVAL); - if (adapter->data->started) { + if (adapter->data.started) { EVTIM_LOG_ERR("event timer adapter %"PRIu8" already started", - adapter->data->id); + adapter->data.id); return -EALREADY; } @@ -274,22 +306,22 @@ rte_event_timer_adapter_start(const struct rte_event_timer_adapter *adapter) if (ret < 0) return ret; - adapter->data->started = 1; + adapter->data.started = 1; rte_eventdev_trace_timer_adapter_start(adapter); return 0; } int -rte_event_timer_adapter_stop(const struct rte_event_timer_adapter *adapter) +rte_event_timer_adapter_stop(struct rte_event_timer_adapter *adapter) { int ret; ADAPTER_VALID_OR_ERR_RET(adapter, -EINVAL); FUNC_PTR_OR_ERR_RET(adapter->ops->stop, -EINVAL); - if (adapter->data->started == 0) { + if (adapter->data.started == 0) { EVTIM_LOG_ERR("event timer adapter %"PRIu8" already stopped", - adapter->data->id); + adapter->data.id); return 0; } @@ -297,7 +329,7 @@ rte_event_timer_adapter_stop(const struct rte_event_timer_adapter *adapter) if (ret < 0) return ret; - adapter->data->started = 0; + adapter->data.started = 0; rte_eventdev_trace_timer_adapter_stop(adapter); return 0; } @@ -305,34 +337,26 @@ rte_event_timer_adapter_stop(const struct rte_event_timer_adapter *adapter) struct rte_event_timer_adapter * rte_event_timer_adapter_lookup(uint16_t adapter_id) { - char name[DATA_MZ_NAME_MAX_LEN]; - const struct rte_memzone *mz; - struct rte_event_timer_adapter_data *data; struct rte_event_timer_adapter *adapter; - int ret; + char name[EVTIM_MZ_NAME_MAX_LEN]; + const struct rte_memzone *mz; struct rte_eventdev *dev; + int ret; - if (adapters[adapter_id].allocated) - return &adapters[adapter_id]; /* Adapter is already loaded */ - - snprintf(name, DATA_MZ_NAME_MAX_LEN, DATA_MZ_NAME_FORMAT, adapter_id); + snprintf(name, EVTIM_MZ_NAME_MAX_LEN, EVTIM_MZ_NAME_FORMAT, adapter_id); mz = rte_memzone_lookup(name); if (mz == NULL) { rte_errno = ENOENT; return NULL; } - data = mz->addr; - - adapter = &adapters[data->id]; - adapter->data = data; - - dev = &rte_eventdevs[adapter->data->event_dev_id]; + adapter = mz->addr; + dev = &rte_eventdevs[adapter->data.event_dev_id]; /* Query eventdev PMD for timer adapter capabilities and ops */ ret = dev->dev_ops->timer_adapter_caps_get(dev, - adapter->data->conf.flags, - &adapter->data->caps, + adapter->data.conf.flags, + &adapter->data.caps, &adapter->ops); if (ret < 0) { rte_errno = EINVAL; @@ -350,37 +374,36 @@ rte_event_timer_adapter_lookup(uint16_t adapter_id) adapter->arm_tmo_tick_burst = adapter->ops->arm_tmo_tick_burst; adapter->cancel_burst = adapter->ops->cancel_burst; - adapter->allocated = 1; - return adapter; } int rte_event_timer_adapter_free(struct rte_event_timer_adapter *adapter) { + uint8_t adapter_id; int ret; ADAPTER_VALID_OR_ERR_RET(adapter, -EINVAL); FUNC_PTR_OR_ERR_RET(adapter->ops->uninit, -EINVAL); - if (adapter->data->started == 1) { + if (adapter->data.started == 1) { EVTIM_LOG_ERR("event timer adapter %"PRIu8" must be stopped " - "before freeing", adapter->data->id); + "before freeing", adapter->data.id); return -EBUSY; } + adapter_id = adapter->data.id; /* free impl priv data */ ret = adapter->ops->uninit(adapter); if (ret < 0) return ret; - /* free shared data area */ - ret = rte_memzone_free(adapter->data->mz); + /* free shared adapter memory */ + ret = rte_memzone_free(adapter->mz); if (ret < 0) return ret; - adapter->data = NULL; - adapter->allocated = 0; + adapters[adapter_id] = NULL; rte_eventdev_trace_timer_adapter_free(adapter); return 0; @@ -392,10 +415,10 @@ rte_event_timer_adapter_service_id_get(struct rte_event_timer_adapter *adapter, { ADAPTER_VALID_OR_ERR_RET(adapter, -EINVAL); - if (adapter->data->service_inited && service_id != NULL) - *service_id = adapter->data->service_id; + if (adapter->data.service_inited && service_id != NULL) + *service_id = adapter->data.service_id; - return adapter->data->service_inited ? 0 : -ESRCH; + return adapter->data.service_inited ? 0 : -ESRCH; } int @@ -569,7 +592,7 @@ struct swtim { static inline struct swtim * swtim_pmd_priv(const struct rte_event_timer_adapter *adapter) { - return adapter->data->adapter_priv; + return adapter->data.adapter_priv; } static void @@ -635,8 +658,8 @@ swtim_callback(struct rte_timer *tim) if (event_buffer_batch_ready(&sw->buffer)) { event_buffer_flush(&sw->buffer, - adapter->data->event_dev_id, - adapter->data->event_port_id, + adapter->data.event_dev_id, + adapter->data.event_port_id, &nb_evs_flushed, &nb_evs_invalid); @@ -712,7 +735,7 @@ check_destination_event_queue(struct rte_event_timer *evtim, int ret; uint32_t sched_type; - ret = rte_event_queue_attr_get(adapter->data->event_dev_id, + ret = rte_event_queue_attr_get(adapter->data.event_dev_id, evtim->ev.queue_id, RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE, &sched_type); @@ -744,8 +767,8 @@ swtim_service_func(void *arg) sw->n_expired_timers = 0; event_buffer_flush(&sw->buffer, - adapter->data->event_dev_id, - adapter->data->event_port_id, + adapter->data.event_dev_id, + adapter->data.event_port_id, &nb_evs_flushed, &nb_evs_invalid); @@ -799,9 +822,9 @@ swtim_init(struct rte_event_timer_adapter *adapter) #define SWTIM_NAMESIZE 32 char swtim_name[SWTIM_NAMESIZE]; snprintf(swtim_name, SWTIM_NAMESIZE, "swtim_%"PRIu8, - adapter->data->id); + adapter->data.id); sw = rte_zmalloc_socket(swtim_name, sizeof(*sw), RTE_CACHE_LINE_SIZE, - adapter->data->socket_id); + adapter->data.socket_id); if (sw == NULL) { EVTIM_LOG_ERR("failed to allocate space for private data"); rte_errno = ENOMEM; @@ -809,25 +832,25 @@ swtim_init(struct rte_event_timer_adapter *adapter) } /* Connect storage to adapter instance */ - adapter->data->adapter_priv = sw; + adapter->data.adapter_priv = sw; sw->adapter = adapter; - sw->timer_tick_ns = adapter->data->conf.timer_tick_ns; - sw->max_tmo_ns = adapter->data->conf.max_tmo_ns; + sw->timer_tick_ns = adapter->data.conf.timer_tick_ns; + sw->max_tmo_ns = adapter->data.conf.max_tmo_ns; /* Create a timer pool */ char pool_name[SWTIM_NAMESIZE]; snprintf(pool_name, SWTIM_NAMESIZE, "swtim_pool_%"PRIu8, - adapter->data->id); + adapter->data.id); /* Optimal mempool size is a power of 2 minus one */ - uint64_t nb_timers = rte_align64pow2(adapter->data->conf.nb_timers); + uint64_t nb_timers = rte_align64pow2(adapter->data.conf.nb_timers); int pool_size = nb_timers - 1; int cache_size = compute_msg_mempool_cache_size( - adapter->data->conf.nb_timers, nb_timers); + adapter->data.conf.nb_timers, nb_timers); flags = 0; /* pool is multi-producer, multi-consumer */ sw->tim_pool = rte_mempool_create(pool_name, pool_size, sizeof(struct rte_timer), cache_size, 0, NULL, NULL, - NULL, NULL, adapter->data->socket_id, flags); + NULL, NULL, adapter->data.socket_id, flags); if (sw->tim_pool == NULL) { EVTIM_LOG_ERR("failed to create timer object mempool"); rte_errno = ENOMEM; @@ -863,8 +886,8 @@ swtim_init(struct rte_event_timer_adapter *adapter) /* Register a service component to run adapter logic */ memset(&service, 0, sizeof(service)); snprintf(service.name, RTE_SERVICE_NAME_MAX, - "swtim_svc_%"PRIu8, adapter->data->id); - service.socket_id = adapter->data->socket_id; + "swtim_svc_%"PRIu8, adapter->data.id); + service.socket_id = adapter->data.socket_id; service.callback = swtim_service_func; service.callback_userdata = adapter; service.capabilities &= ~(RTE_SERVICE_CAP_MT_SAFE); @@ -881,8 +904,8 @@ swtim_init(struct rte_event_timer_adapter *adapter) EVTIM_LOG_DBG("registered service %s with id %"PRIu32, service.name, sw->service_id); - adapter->data->service_id = sw->service_id; - adapter->data->service_inited = 1; + adapter->data.service_id = sw->service_id; + adapter->data.service_inited = 1; return 0; free_mempool: @@ -924,7 +947,7 @@ swtim_uninit(struct rte_event_timer_adapter *adapter) rte_mempool_free(sw->tim_pool); rte_free(sw); - adapter->data->adapter_priv = NULL; + adapter->data.adapter_priv = NULL; return 0; } @@ -1025,7 +1048,7 @@ __swtim_arm_burst(const struct rte_event_timer_adapter *adapter, #ifdef RTE_LIBRTE_EVENTDEV_DEBUG /* Check that the service is running. */ - if (rte_service_runstate_get(adapter->data->service_id) != 1) { + if (rte_service_runstate_get(adapter->data.service_id) != 1) { rte_errno = EINVAL; return 0; } @@ -1149,7 +1172,7 @@ swtim_cancel_burst(const struct rte_event_timer_adapter *adapter, #ifdef RTE_LIBRTE_EVENTDEV_DEBUG /* Check that the service is running. */ - if (rte_service_runstate_get(adapter->data->service_id) != 1) { + if (rte_service_runstate_get(adapter->data.service_id) != 1) { rte_errno = EINVAL; return 0; } diff --git a/lib/librte_eventdev/rte_event_timer_adapter.h b/lib/librte_eventdev/rte_event_timer_adapter.h index d2ebcb090..af9541736 100644 --- a/lib/librte_eventdev/rte_event_timer_adapter.h +++ b/lib/librte_eventdev/rte_event_timer_adapter.h @@ -320,8 +320,7 @@ rte_event_timer_adapter_get_info( * be started before calling rte_event_timer_adapter_start(). */ int -rte_event_timer_adapter_start( - const struct rte_event_timer_adapter *adapter); +rte_event_timer_adapter_start(struct rte_event_timer_adapter *adapter); /** * Stop an event timer adapter. @@ -338,7 +337,7 @@ rte_event_timer_adapter_start( * - -EINVAL if adapter identifier invalid */ int -rte_event_timer_adapter_stop(const struct rte_event_timer_adapter *adapter); +rte_event_timer_adapter_stop(struct rte_event_timer_adapter *adapter); /** * Lookup an event timer adapter using its identifier. @@ -503,6 +502,34 @@ typedef uint16_t (*rte_event_timer_cancel_burst_t)( uint16_t nb_tims); /**< @internal Prevent event timers from enqueuing timer events */ +/** + * @internal Adapter data. + */ +struct rte_event_timer_adapter_data { + uint8_t id; + /**< Event timer adapter ID */ + uint8_t event_dev_id; + /**< Event device ID */ + uint32_t socket_id; + /**< Socket ID where memory is allocated */ + uint8_t event_port_id; + /**< Optional: event port ID used when the inbuilt port is absent */ + struct rte_event_timer_adapter_conf conf; + /**< Configuration used to configure the adapter. */ + uint32_t caps; + /**< Adapter capabilities */ + void *adapter_priv; + /**< Timer adapter private data*/ + uint8_t service_inited; + /**< Service initialization state */ + uint32_t service_id; + /**< Service ID*/ + + RTE_STD_C11 + uint8_t started : 1; + /**< Flag to indicate adapter started. */ +} __rte_cache_aligned; + /** * @internal Data structure associated with each event timer adapter. */ @@ -513,19 +540,26 @@ struct rte_event_timer_adapter { /**< Pointer to driver arm_tmo_tick_burst function. */ rte_event_timer_cancel_burst_t cancel_burst; /**< Pointer to driver cancel function. */ - struct rte_event_timer_adapter_data *data; - /**< Pointer to shared adapter data */ + struct rte_event_timer_adapter_data data; + /**< Event timer adapter data. */ const struct rte_event_timer_adapter_ops *ops; /**< Functions exported by adapter driver */ - - RTE_STD_C11 - uint8_t allocated : 1; - /**< Flag to indicate that this adapter has been allocated */ + const struct rte_memzone *mz; + /**< Event timer adapter memzone pointer */ } __rte_cache_aligned; -#define ADAPTER_VALID_OR_ERR_RET(adapter, retval) do { \ - if (adapter == NULL || !adapter->allocated) \ - return retval; \ +#define ADAPTER_VALID_OR_ERR_RET(adapter, retval) do { \ + if (adapter == NULL) { \ + return retval; \ + } else { \ + int i; \ + for (i = 0; i < RTE_EVENT_TIMER_ADAPTER_NUM_MAX; i++) { \ + if (adapters[i] == adapter) \ + break; \ + } \ + if (i == RTE_EVENT_TIMER_ADAPTER_NUM_MAX) \ + return retval; \ + } \ } while (0) #define FUNC_PTR_OR_ERR_RET(func, errval) do { \ diff --git a/lib/librte_eventdev/rte_event_timer_adapter_pmd.h b/lib/librte_eventdev/rte_event_timer_adapter_pmd.h index cf3509dc6..0766b336e 100644 --- a/lib/librte_eventdev/rte_event_timer_adapter_pmd.h +++ b/lib/librte_eventdev/rte_event_timer_adapter_pmd.h @@ -76,37 +76,6 @@ struct rte_event_timer_adapter_ops { /**< Cancel one or more event timers */ }; -/** - * @internal Adapter data; structure to be placed in shared memory to be - * accessible by various processes in a multi-process configuration. - */ -struct rte_event_timer_adapter_data { - uint8_t id; - /**< Event timer adapter ID */ - uint8_t event_dev_id; - /**< Event device ID */ - uint32_t socket_id; - /**< Socket ID where memory is allocated */ - uint8_t event_port_id; - /**< Optional: event port ID used when the inbuilt port is absent */ - const struct rte_memzone *mz; - /**< Event timer adapter memzone pointer */ - struct rte_event_timer_adapter_conf conf; - /**< Configuration used to configure the adapter. */ - uint32_t caps; - /**< Adapter capabilities */ - void *adapter_priv; - /**< Timer adapter private data*/ - uint8_t service_inited; - /**< Service initialization state */ - uint32_t service_id; - /**< Service ID*/ - - RTE_STD_C11 - uint8_t started : 1; - /**< Flag to indicate adapter started. */ -} __rte_cache_aligned; - #ifdef __cplusplus } #endif