From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AC3B6A0C4C; Mon, 25 Oct 2021 15:36:50 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 973F5410DA; Mon, 25 Oct 2021 15:36:50 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 9D1CD4003E for ; Mon, 25 Oct 2021 15:36:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635169009; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ES5o9uCJPeBu9WZAavGOVU/hn4iMtMhvMkBYYz2/G1A=; b=SrcGyZvhTTAy9GWh6Fs+2rOfeydltdNI++Ag/UpvXMTBFVGBUN3PODTI72HiWu82mmgJ2C LTzh4/CkzfQqliXiaQGLXZUIHoIEY9rQBS4sp3lWEnX0k7aqHIKvqd5gYHpYiWmTlgSszd 3zYsdE/TNYp45HxqHz5yWkAQRwBtPLM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-447-YW0-Nq3EODWgmL_8y8pa7A-1; Mon, 25 Oct 2021 09:36:45 -0400 X-MC-Unique: YW0-Nq3EODWgmL_8y8pa7A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E62F1017968; Mon, 25 Oct 2021 13:36:44 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD3531816A; Mon, 25 Oct 2021 13:36:40 +0000 (UTC) From: David Marchand To: hkalra@marvell.com, dev@dpdk.org Cc: dmitry.kozliuk@gmail.com, rasland@nvidia.com, thomas@monjalon.net, Nicolas Chautru , Ferruh Yigit , Andrew Rybchenko Date: Mon, 25 Oct 2021 15:34:51 +0200 Message-Id: <20211025133456.26850-6-david.marchand@redhat.com> In-Reply-To: <20211025133456.26850-1-david.marchand@redhat.com> References: <20211022204934.132186-1-hkalra@marvell.com> <20211025133456.26850-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v7 5/9] lib: remove direct access to interrupt handle 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" From: Harman Kalra Removing direct access to interrupt handle structure fields, rather use respective get set APIs for the same. Making changes to all the libraries access the interrupt handle fields. Signed-off-by: Harman Kalra Signed-off-by: David Marchand --- Changes since v5: - split from patch4, --- lib/bbdev/rte_bbdev.c | 4 +-- lib/eal/linux/eal_dev.c | 57 ++++++++++++++++++++++++----------------- lib/ethdev/rte_ethdev.c | 14 +++++----- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/lib/bbdev/rte_bbdev.c b/lib/bbdev/rte_bbdev.c index defddcfc28..b86c5fdcc0 100644 --- a/lib/bbdev/rte_bbdev.c +++ b/lib/bbdev/rte_bbdev.c @@ -1094,7 +1094,7 @@ rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op, VALID_QUEUE_OR_RET_ERR(queue_id, dev); intr_handle = dev->intr_handle; - if (!intr_handle || !intr_handle->intr_vec) { + if (intr_handle == NULL) { rte_bbdev_log(ERR, "Device %u intr handle unset\n", dev_id); return -ENOTSUP; } @@ -1105,7 +1105,7 @@ rte_bbdev_queue_intr_ctl(uint16_t dev_id, uint16_t queue_id, int epfd, int op, return -ENOTSUP; } - vec = intr_handle->intr_vec[queue_id]; + vec = rte_intr_vec_list_index_get(intr_handle, queue_id); ret = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data); if (ret && (ret != -EEXIST)) { rte_bbdev_log(ERR, diff --git a/lib/eal/linux/eal_dev.c b/lib/eal/linux/eal_dev.c index 3b905e18f5..06820a3666 100644 --- a/lib/eal/linux/eal_dev.c +++ b/lib/eal/linux/eal_dev.c @@ -23,10 +23,7 @@ #include "eal_private.h" -static struct rte_intr_handle intr_handle = { - .type = RTE_INTR_HANDLE_DEV_EVENT, - .fd = -1, -}; +static struct rte_intr_handle *intr_handle; static rte_rwlock_t monitor_lock = RTE_RWLOCK_INITIALIZER; static uint32_t monitor_refcount; static bool hotplug_handle; @@ -109,12 +106,11 @@ static int dev_uev_socket_fd_create(void) { struct sockaddr_nl addr; - int ret; + int ret, fd; - intr_handle.fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | - SOCK_NONBLOCK, - NETLINK_KOBJECT_UEVENT); - if (intr_handle.fd < 0) { + fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, + NETLINK_KOBJECT_UEVENT); + if (fd < 0) { RTE_LOG(ERR, EAL, "create uevent fd failed.\n"); return -1; } @@ -124,16 +120,19 @@ dev_uev_socket_fd_create(void) addr.nl_pid = 0; addr.nl_groups = 0xffffffff; - ret = bind(intr_handle.fd, (struct sockaddr *) &addr, sizeof(addr)); + ret = bind(fd, (struct sockaddr *) &addr, sizeof(addr)); if (ret < 0) { RTE_LOG(ERR, EAL, "Failed to bind uevent socket.\n"); goto err; } + if (rte_intr_fd_set(intr_handle, fd)) + goto err; + return 0; err: - close(intr_handle.fd); - intr_handle.fd = -1; + close(fd); + fd = -1; return ret; } @@ -217,9 +216,9 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length) static void dev_delayed_unregister(void *param) { - rte_intr_callback_unregister(&intr_handle, dev_uev_handler, param); - close(intr_handle.fd); - intr_handle.fd = -1; + rte_intr_callback_unregister(intr_handle, dev_uev_handler, param); + close(rte_intr_fd_get(intr_handle)); + rte_intr_fd_set(intr_handle, -1); } static void @@ -235,7 +234,8 @@ dev_uev_handler(__rte_unused void *param) memset(&uevent, 0, sizeof(struct rte_dev_event)); memset(buf, 0, EAL_UEV_MSG_LEN); - ret = recv(intr_handle.fd, buf, EAL_UEV_MSG_LEN, MSG_DONTWAIT); + ret = recv(rte_intr_fd_get(intr_handle), buf, EAL_UEV_MSG_LEN, + MSG_DONTWAIT); if (ret < 0 && errno == EAGAIN) return; else if (ret <= 0) { @@ -311,24 +311,35 @@ rte_dev_event_monitor_start(void) goto exit; } + intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE); + if (intr_handle == NULL) { + RTE_LOG(ERR, EAL, "Fail to allocate intr_handle\n"); + goto exit; + } + + if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_DEV_EVENT)) + goto exit; + + if (rte_intr_fd_set(intr_handle, -1)) + goto exit; + ret = dev_uev_socket_fd_create(); if (ret) { RTE_LOG(ERR, EAL, "error create device event fd.\n"); goto exit; } - ret = rte_intr_callback_register(&intr_handle, dev_uev_handler, NULL); + ret = rte_intr_callback_register(intr_handle, dev_uev_handler, NULL); if (ret) { - RTE_LOG(ERR, EAL, "fail to register uevent callback.\n"); - close(intr_handle.fd); - intr_handle.fd = -1; + close(rte_intr_fd_get(intr_handle)); goto exit; } monitor_refcount++; exit: + rte_intr_instance_free(intr_handle); rte_rwlock_write_unlock(&monitor_lock); return ret; } @@ -350,15 +361,15 @@ rte_dev_event_monitor_stop(void) goto exit; } - ret = rte_intr_callback_unregister(&intr_handle, dev_uev_handler, + ret = rte_intr_callback_unregister(intr_handle, dev_uev_handler, (void *)-1); if (ret < 0) { RTE_LOG(ERR, EAL, "fail to unregister uevent callback.\n"); goto exit; } - close(intr_handle.fd); - intr_handle.fd = -1; + close(rte_intr_fd_get(intr_handle)); + rte_intr_instance_free(intr_handle); monitor_refcount--; diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 74de29c2e0..7db84b12d0 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -4819,13 +4819,13 @@ rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data) } intr_handle = dev->intr_handle; - if (!intr_handle->intr_vec) { + if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) { RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n"); return -EPERM; } for (qid = 0; qid < dev->data->nb_rx_queues; qid++) { - vec = intr_handle->intr_vec[qid]; + vec = rte_intr_vec_list_index_get(intr_handle, qid); rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data); if (rc && rc != -EEXIST) { RTE_ETHDEV_LOG(ERR, @@ -4860,15 +4860,15 @@ rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id) } intr_handle = dev->intr_handle; - if (!intr_handle->intr_vec) { + if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) { RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n"); return -1; } - vec = intr_handle->intr_vec[queue_id]; + vec = rte_intr_vec_list_index_get(intr_handle, queue_id); efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ? (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec; - fd = intr_handle->efds[efd_idx]; + fd = rte_intr_efds_index_get(intr_handle, efd_idx); return fd; } @@ -5046,12 +5046,12 @@ rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id, } intr_handle = dev->intr_handle; - if (!intr_handle->intr_vec) { + if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) { RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n"); return -EPERM; } - vec = intr_handle->intr_vec[queue_id]; + vec = rte_intr_vec_list_index_get(intr_handle, queue_id); rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data); if (rc && rc != -EEXIST) { RTE_ETHDEV_LOG(ERR, -- 2.23.0