From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7688BA04B5; Fri, 11 Sep 2020 02:22:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9532D1C0CC; Fri, 11 Sep 2020 02:22:18 +0200 (CEST) Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by dpdk.org (Postfix) with ESMTP id B4E801C0B9 for ; Fri, 11 Sep 2020 02:22:16 +0200 (CEST) Received: by mail-lf1-f66.google.com with SMTP id u8so4582904lff.1 for ; Thu, 10 Sep 2020 17:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y3qzjPoTey9ORwsAvnu8hpzcDKG6NLF1k3dCQgWhyjQ=; b=Xt5EJYmOfI3ZdPvNi6zLmVMTte9Qt0ZWAwkzLfl6UEHYnUjb/ZFhx53I2f4AlAqUJH kPQjnBOcrAUiNqRh5zoLZVCNPE3oNjKJkLQap4taCavPVxBOLc9Mt3swv2JxW+iAtecN Y9Zmkiw7jGcWMgwOySoCv4Dwq56eWurPeOcEeJ43ril3lDLc8jz+HuH6BwH8Ev3MU4U7 73urf/XQkCNL+t4Qy/9O74wScV/Y5ZyOpGy8lZvhpyqGvZQ9rMJVejBnIa6q6JH5+fpn ZdFKGAilBJJjyxRyb4VBszGwdYIv+dpgatYNncgE7AsujLe5mPOkj+zx+9cg+cDPQlE2 l2kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y3qzjPoTey9ORwsAvnu8hpzcDKG6NLF1k3dCQgWhyjQ=; b=pC+BOAOKTH6piSCbCw8Rl7LYOKHD7bHcDKNwfGSvqfs9U3nkeR9x4sc7MCc8w9715N aF3BHy+LCRVG/n27XbYPPkpFTs3+OApYzEvfvaFI7bRVdyC8NPzY/3bBY60K7OErB+db yje/hEbv54sP9D4ja6XY7Vp0+3Gba8ESa+nItoAuietMooAwlzmgZeIKEXa8oI9xZW/t imFREB4l+CRjGAVm4LleUOn4xoMYZm/0tcBL1m1Q+yq+EbWlWkzqhUr4GMRiosuDX9z/ fUlhPD6bBJmTA8i3qqHe4HRqMvnUuflHCRNYosaZ3Ux/ZEhcFWfWrUb/X4B9H2kW6fjo 3xlg== X-Gm-Message-State: AOAM532UjcJUogsV9T6NPsFMk3wGdgf2UEPM8MgWAYvG1Us3/aTToxrD +2r0P+IyZsdXGR8p3OhFLls8PC0ZwvRxsg== X-Google-Smtp-Source: ABdhPJxXF/mq9Hfuas/Jwo/JGyuOS9ORGADu3UoXZ9cuGFO8gbKxcjAmTHPwHExw3cmnd1CKIjH1BA== X-Received: by 2002:a05:6512:32a8:: with SMTP id q8mr5563681lfe.209.1599783735723; Thu, 10 Sep 2020 17:22:15 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id b16sm132765ljh.34.2020.09.10.17.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 17:22:15 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Harman Kalra , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Fri, 11 Sep 2020 03:22:06 +0300 Message-Id: <20200911002207.31813-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200911002207.31813-1-dmitry.kozliuk@gmail.com> References: <20200911002207.31813-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 1/2] eal/windows: add interrupt thread skeleton 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Windows interrupt support is based on IO completion ports (IOCP). Interrupt thread would send the devices requests to notify about interrupts and then wait for any request completion. Add skeleton code of this model without any hardware support. Another way to wake up the interrupt thread is APC (asynchronous procedure call), scheduled by any other thread via eal_intr_thread_schedule(). This internal API is intended for alarm implementation. Signed-off-by: Dmitry Kozlyuk --- lib/librte_eal/include/rte_eal_interrupts.h | 14 ++- lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_eal/windows/eal.c | 5 ++ lib/librte_eal/windows/eal_interrupts.c | 99 +++++++++++++++++++++ lib/librte_eal/windows/eal_windows.h | 12 +++ lib/librte_eal/windows/include/pthread.h | 7 ++ lib/librte_eal/windows/meson.build | 1 + 7 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 lib/librte_eal/windows/eal_interrupts.c diff --git a/lib/librte_eal/include/rte_eal_interrupts.h b/lib/librte_eal/include/rte_eal_interrupts.h index b1e8a2934..b80edfc65 100644 --- a/lib/librte_eal/include/rte_eal_interrupts.h +++ b/lib/librte_eal/include/rte_eal_interrupts.h @@ -69,10 +69,18 @@ struct rte_epoll_event { struct rte_intr_handle { RTE_STD_C11 union { - int vfio_dev_fd; /**< VFIO device file descriptor */ - int uio_cfg_fd; /**< UIO cfg file desc for uio_pci_generic */ + struct { + RTE_STD_C11 + union { + /** VFIO device file descriptor */ + int vfio_dev_fd; + /** UIO cfg file desc for uio_pci_generic */ + int uio_cfg_fd; + }; + int fd; /**< interrupt event file descriptor */ + }; + void *handle; /**< device driver handle (Windows) */ }; - int fd; /**< interrupt event file descriptor */ enum rte_intr_handle_type type; /**< handle type */ uint32_t max_intr; /**< max interrupt requested */ uint32_t nb_efd; /**< number of available efd(event fd) */ diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index f54ed74a5..9baca0110 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -72,6 +72,7 @@ EXPORTS rte_vlog rte_realloc rte_strscpy + rte_thread_is_intr rte_zmalloc rte_zmalloc_socket diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index bc48f27ab..141f22adb 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -344,6 +344,11 @@ rte_eal_init(int argc, char **argv) return -1; } + if (rte_eal_intr_init() < 0) { + rte_eal_init_alert("Cannot init interrupt-handling thread"); + return -1; + } + if (rte_eal_timer_init() < 0) { rte_eal_init_alert("Cannot init TSC timer"); rte_errno = EFAULT; diff --git a/lib/librte_eal/windows/eal_interrupts.c b/lib/librte_eal/windows/eal_interrupts.c new file mode 100644 index 000000000..d9bc5afc7 --- /dev/null +++ b/lib/librte_eal/windows/eal_interrupts.c @@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2020 Dmitry Kozlyuk + */ + +#include + +#include "eal_private.h" +#include "eal_windows.h" + +static pthread_t intr_thread; + +static HANDLE intr_iocp; + +static void +eal_intr_process(const OVERLAPPED_ENTRY *event) +{ + RTE_SET_USED(event); +} + +static void * +eal_intr_thread_main(LPVOID arg __rte_unused) +{ + while (1) { + OVERLAPPED_ENTRY events[16]; + ULONG event_count, i; + BOOL result; + + result = GetQueuedCompletionStatusEx( + intr_iocp, events, RTE_DIM(events), &event_count, + INFINITE, /* no timeout */ + TRUE); /* alertable wait for alarm APCs */ + + if (!result) { + DWORD error = GetLastError(); + if (error != WAIT_IO_COMPLETION) { + RTE_LOG_WIN32_ERR("GetQueuedCompletionStatusEx()"); + RTE_LOG(ERR, EAL, "Failed waiting for interrupts\n"); + break; + } + + /* No I/O events, all work is done in completed APCs. */ + continue; + } + + for (i = 0; i < event_count; i++) + eal_intr_process(&events[i]); + } + + CloseHandle(intr_iocp); + intr_iocp = NULL; + return NULL; +} + +int +rte_eal_intr_init(void) +{ + int ret = 0; + + intr_iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1); + if (intr_iocp == NULL) { + RTE_LOG_WIN32_ERR("CreateIoCompletionPort()"); + RTE_LOG(ERR, EAL, "Cannot create interrupt IOCP\n"); + return -1; + } + + ret = rte_ctrl_thread_create(&intr_thread, "eal-intr-thread", NULL, + eal_intr_thread_main, NULL); + if (ret != 0) { + rte_errno = -ret; + RTE_LOG(ERR, EAL, "Cannot create interrupt thread\n"); + } + + return ret; +} + +int +rte_thread_is_intr(void) +{ + return pthread_equal(intr_thread, pthread_self()); +} + +int +eal_intr_thread_schedule(void (*func)(void *arg), void *arg) +{ + HANDLE handle; + + handle = OpenThread(THREAD_ALL_ACCESS, FALSE, intr_thread); + if (handle == NULL) { + RTE_LOG_WIN32_ERR("OpenThread(%llu)", intr_thread); + return -ENOENT; + } + + if (!QueueUserAPC((PAPCFUNC)(ULONG_PTR)func, handle, (ULONG_PTR)arg)) { + RTE_LOG_WIN32_ERR("QueueUserAPC()"); + return -EINVAL; + } + + return 0; +} diff --git a/lib/librte_eal/windows/eal_windows.h b/lib/librte_eal/windows/eal_windows.h index d48ee0a12..478accc1b 100644 --- a/lib/librte_eal/windows/eal_windows.h +++ b/lib/librte_eal/windows/eal_windows.h @@ -55,6 +55,18 @@ int eal_thread_create(pthread_t *thread); */ unsigned int eal_socket_numa_node(unsigned int socket_id); +/** + * Schedule code for execution in the interrupt thread. + * + * @param func + * Function to call. + * @param arg + * Argument to the called function. + * @return + * 0 on success, netagive error code on failure. + */ +int eal_intr_thread_schedule(void (*func)(void *arg), void *arg); + /** * Open virt2phys driver interface device. * diff --git a/lib/librte_eal/windows/include/pthread.h b/lib/librte_eal/windows/include/pthread.h index 99013dc94..a4ab4d094 100644 --- a/lib/librte_eal/windows/include/pthread.h +++ b/lib/librte_eal/windows/include/pthread.h @@ -42,6 +42,13 @@ typedef SYNCHRONIZATION_BARRIER pthread_barrier_t; #define pthread_self() \ ((pthread_t)GetCurrentThreadId()) + +static inline int +pthread_equal(pthread_t t1, pthread_t t2) +{ + return t1 == t2; +} + static inline int pthread_setaffinity_np(pthread_t threadid, size_t cpuset_size, rte_cpuset_t *cpuset) diff --git a/lib/librte_eal/windows/meson.build b/lib/librte_eal/windows/meson.build index 08c888e01..b690bc6b0 100644 --- a/lib/librte_eal/windows/meson.build +++ b/lib/librte_eal/windows/meson.build @@ -8,6 +8,7 @@ sources += files( 'eal_debug.c', 'eal_file.c', 'eal_hugepages.c', + 'eal_interrupts.c', 'eal_lcore.c', 'eal_log.c', 'eal_memalloc.c', -- 2.25.4