From patchwork Thu Aug 8 19:46:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 143028 X-Patchwork-Delegate: thomas@monjalon.net 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 241044576E; Thu, 8 Aug 2024 21:48:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 976C742D8C; Thu, 8 Aug 2024 21:48:10 +0200 (CEST) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTP id 8F61542D92 for ; Thu, 8 Aug 2024 21:48:08 +0200 (CEST) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7a23fbb372dso1028501a12.0 for ; Thu, 08 Aug 2024 12:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723146488; x=1723751288; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jXPhvXK1VIpf6boz2Rwgf9kQO+JhMST6iysb/fpeHlk=; b=ywF0UbS84ksxVkwOH61U16edwFvAWywzTyA5veoNvtsvRRORQyq85uWz9SYe2mW13b q7HrNWwlOwtzLkJwkk3WtLVG6Qm8Lcve7kF27vYvBWGsHLaV5Jjr8UgK90JAo3yajMu5 R08lm2zU+ZBTgQEGV3FmNx00GnvJW+l+LsQrnuO+CAhvKaBhF1B22PArl/j1EfJiCYd3 iM0A7LfJemrrLq39xrxxvTDMQiwC9SvpZ6qrjPB8BBmzCY3Ylgw9USZ9TU/ZQqkoj840 dXhAjxr2VAULvPjKETtqF7vCitInH2WSBXx2dPojaGwT/ySNFIa2VvyQI+iw8+CLpzAI yBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723146488; x=1723751288; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jXPhvXK1VIpf6boz2Rwgf9kQO+JhMST6iysb/fpeHlk=; b=OdmIxeBiNhjar6seHwcBbdxl8OEsuBUR5DZEpts1R7jBJ7aMEVJoS5YuYi79XJlnx4 qTb+wLiztXLxwwRN/cU1Ohvzp6lLQpiRwHCdo7CREUucmrDxl988RTiKA1FsHiQNu3l5 ElrTmV9GQZdJu42plrW+mthd4dpavZhGqihkiUIjogfvDFvv4mkZEi1awNQZvGUeYOa8 ToHv9e4+XHYI6th59ElgzbUuPW2O8KtiugFGsBYZnOFKWDk3msr01vPG/VfaQ7/B0Tx1 S79G7njX6tCWAEpJWmYyWVY4ZStoaUT6I16l6ommmGXa2gBoKeL6ZY/cekJalDjzrydz t7YQ== X-Gm-Message-State: AOJu0YxfCAcgqrdc5wHTEsDDaT+V+XlWyUfxkWqMXOc/GupkJr9qEEbb dkAg80oBqL6AnqlI9tp6SHrILI5NrPzVIhT7LFLmyE36QVtQWxTFbCMXrA531SR4uI3uklATp/u a X-Google-Smtp-Source: AGHT+IFqBGofPK9sXmzTQMSp1kWyELiWsPFiXq8hKBX+GjExBbqqNazyM8hpQxhIdGC+oDqvrBUvgQ== X-Received: by 2002:a05:6a20:7347:b0:1c6:fc9f:eb68 with SMTP id adf61e73a8af0-1c6fcfd8be1mr3496863637.50.1723146487685; Thu, 08 Aug 2024 12:48:07 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2d376csm1469804b3a.111.2024.08.08.12.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 12:48:07 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Dmitry Kozlyuk , Tyler Retzlaff , Pallavi Kadam Subject: [PATCH 1/5] eal: add missing parameter check to rte_eal_alarm_set on Windows Date: Thu, 8 Aug 2024 12:46:57 -0700 Message-ID: <20240808194756.167664-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808194756.167664-1-stephen@networkplumber.org> References: <20240808194756.167664-1-stephen@networkplumber.org> MIME-Version: 1.0 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 Both Linux and FreeBSD, check parameters to rte_eal_alarm_set, but Windows missed this. And the test was "fixed" instead. Signed-off-by: Stephen Hemminger --- lib/eal/windows/eal_alarm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c index 052af4b21b..09a02a1cbf 100644 --- a/lib/eal/windows/eal_alarm.c +++ b/lib/eal/windows/eal_alarm.c @@ -92,6 +92,13 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg) LARGE_INTEGER deadline; int ret; + /* Check parameters, including that us won't cause a uint64_t overflow */ + if (us < 1 || us > (UINT64_MAX - US_PER_S)) { + EAL_LOG(ERR, "Invalid alarm interval"); + ret = -EINVAL; + goto exit; + } + if (cb_fn == NULL) { EAL_LOG(ERR, "NULL callback"); ret = -EINVAL; From patchwork Thu Aug 8 19:46:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 143029 X-Patchwork-Delegate: thomas@monjalon.net 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 0C9B74576E; Thu, 8 Aug 2024 21:48:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6F3BA42DD3; Thu, 8 Aug 2024 21:48:12 +0200 (CEST) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 8B12442D9D for ; Thu, 8 Aug 2024 21:48:09 +0200 (CEST) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70d25b5b6b0so1089736b3a.2 for ; Thu, 08 Aug 2024 12:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723146488; x=1723751288; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0GMGD7ep2Et0TYc0CKuoFMKUX6MNI7T0gRKKJ5S0AO4=; b=yakRpBgxq68Tdv7seS4oYLIFMt7dEVtokHScu6uYYX26GsgR24ZunbrEezZlURGRC8 YvgddwDPEd9nR4TIVu8xbmeDfswjw29OxsBeC/24t29fztrpvW7oaq2zLY12uhXzu3O9 yUhqXGzHyG8Q9ATF5sdAx+iXaVPghT5vxI/CRPG99zWLwO8pdKkHAWmKEBcUFbTE9NRq 79P+8wwVhzTBk57ZwBoQypK8RgzLwzHjq3XzK8RAsY+fDKbGOPkNfJyAfvfuwuouJuxv 6bJYeD/Yl8mzDvZw+imEW8/HjAMCSKWAuKU2y6X3KIXGWZAjw+5ABNjZOi+laLwtYmI/ uw8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723146488; x=1723751288; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0GMGD7ep2Et0TYc0CKuoFMKUX6MNI7T0gRKKJ5S0AO4=; b=nPYPYaYmXa1iucv6XDyqASvIcQLLmp5O/yUUqyVFWf8sbBiXSKRtMUvd5BF/lXpeNu lUHWD/hpa/2gEHytWs+TTkEaJhfUC3RtWXWYTXH9Dln/U8H12gAEXewgjFacSGC6lfUF x8BaCPWwFDjA+iaHUXXCzXzKKdbACukv0xfhO2SSJV0ZhE8t99L9fycMg1T+RFLu6dOf awM6mW+Yb3qfcz3pAl45BFQabVZmsFNIqVAIKumUQRwCo7vr7BGLEkCW7Y/dsXmah+A0 EqHhSdzs5lqTRmlJcYaqKYzune2munjsMH4aIW+089cDE9JmBXjSksx+mu6152xd7GqN GZRQ== X-Gm-Message-State: AOJu0YzZmetpYbbRPaIYSvN52h+KsXQdUdtGK4ij48F6UttTHQSxiJ0Y X3bI7+jL3iRhnUVaYcrJM1VqWJPpmiDfqV6sNkQ+XYO2143hQR6y6YW/poXTtWN3RBi0rAbWEue B X-Google-Smtp-Source: AGHT+IFiGsfBmAjOAz8Pjc/Z+3dAwKmvSM9a+tYjPiD/fknsRWytBxCD5NvRPvGqYs7J1ulZ9p9pEA== X-Received: by 2002:a05:6a00:460e:b0:70d:181f:c082 with SMTP id d2e1a72fcca58-710cad8e299mr4209013b3a.11.1723146488500; Thu, 08 Aug 2024 12:48:08 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2d376csm1469804b3a.111.2024.08.08.12.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 12:48:08 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH 2/5] Revert "test/alarm: disable bad time cases on Windows" Date: Thu, 8 Aug 2024 12:46:58 -0700 Message-ID: <20240808194756.167664-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808194756.167664-1-stephen@networkplumber.org> References: <20240808194756.167664-1-stephen@networkplumber.org> MIME-Version: 1.0 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 This reverts commit a089d320338d708f5b7126dab5fd6861c82e6347. Windows EAL should have been fixed rather than papering over the bug. Signed-off-by: Stephen Hemminger --- app/test/test_alarm.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/test/test_alarm.c b/app/test/test_alarm.c index 70e97a3109..b4034339b8 100644 --- a/app/test/test_alarm.c +++ b/app/test/test_alarm.c @@ -10,7 +10,6 @@ #include "test.h" -#ifndef RTE_EXEC_ENV_WINDOWS static volatile int flag; static void @@ -19,7 +18,6 @@ test_alarm_callback(void *cb_arg) flag = 1; printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg); } -#endif static int test_alarm(void) @@ -29,7 +27,6 @@ test_alarm(void) return 0; #endif -#ifndef RTE_EXEC_ENV_WINDOWS /* check if it will fail to set alarm with wrong us value */ printf("check if it will fail to set alarm with wrong ms values\n"); if (rte_eal_alarm_set(0, test_alarm_callback, @@ -42,7 +39,6 @@ test_alarm(void) printf("should not be successful with (UINT64_MAX-1) us value\n"); return -1; } -#endif /* check if it will fail to set alarm with null callback parameter */ printf("check if it will fail to set alarm with null callback parameter\n"); From patchwork Thu Aug 8 19:46:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 143030 X-Patchwork-Delegate: thomas@monjalon.net 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 D52EB4576E; Thu, 8 Aug 2024 21:48:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A660A42DDA; Thu, 8 Aug 2024 21:48:13 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id 267D642D9F for ; Thu, 8 Aug 2024 21:48:10 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70d1a74a43bso1162252b3a.1 for ; Thu, 08 Aug 2024 12:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723146489; x=1723751289; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KI75ES28RmRSZwX5pwgOkPVl4wZrL3lPSfKfOonm2PY=; b=WIcrFXqjQpmFavue2bW8thAjCIEKNUKGA1KSSd6nGYLUhQLWb7L0fKveRl42tdDt5h ZS1qRB28tmpdRz1uIMv5MDWwmUGVSv1npFzBw3yycSVsPMww63Bq8Wuku/g1Zlh/iVOA pVIq7HXoXCxuSbV4FKbpgIkBw6C65W4eR2vdYOTYt6GqQkkS74ux8h9PmQFlhOA0J+FA FGfI6bAYQp86VSgkKYJAw+Fr1NCFMlCB8KTc20p53YDOYwRqnBGMSRnDhXkOrTpZNyrf xG4Ddi6NwrMelwZoMm6YisAuBPLCFmb3A8lX7W15zQgWAVGff2kKLHt6sJAnZy90hJ6B EaAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723146489; x=1723751289; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KI75ES28RmRSZwX5pwgOkPVl4wZrL3lPSfKfOonm2PY=; b=gFY2fUgr5xIsWhrZzBu74isTPnC+wpNbm/KgAYW9kisY5fF/9SrnmeGX207985cC+f jMIkTLQlXK55aK2UZWM+AWjk4/4Rdf5Zp5N+zoYkduOJbS+HBYadWC3HM/1VOxj5uVXR i6MPvXyX6+4Eb/A/l+m57CEBP/Qv8W/DCv6odfk4CHz3tWKkJORDDHLaHH9MXOkZfODZ KhwB6YBLTgIz25iqDekNfByRoR8WPkyARgR2TU0GJYd1pAdV1gMN0oLa9IlqHIQNbigc HMPaY1MiP8tjv3EXID1O4S7nggi9FosgvukImtDiA+7OQn124IxCcpNoHc9zmuf9TveZ 5OJQ== X-Gm-Message-State: AOJu0YxEI9KE5NaqPotN+E3wXV57A00tzfV/lPdRjwmTw6z2uIbOQ6RS KHMFNWSqd/a1O9SfJ3lrKTCAXj7QdLvETYoUeuOYaqQOl2oV3C4R42cN7rblbKBM3J07aVuKX7y m X-Google-Smtp-Source: AGHT+IF7GJTjr+wqg1h/S1qwF7qj9zegaPy62eISizfLrbLRqwRplbF0VQjxvdujB3yrZxykYumrtA== X-Received: by 2002:a05:6a00:915a:b0:70d:1a82:f9a4 with SMTP id d2e1a72fcca58-710cae89caemr2753217b3a.30.1723146489264; Thu, 08 Aug 2024 12:48:09 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2d376csm1469804b3a.111.2024.08.08.12.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 12:48:08 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH 3/5] test: support alarm test on FreeBSD Date: Thu, 8 Aug 2024 12:46:59 -0700 Message-ID: <20240808194756.167664-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808194756.167664-1-stephen@networkplumber.org> References: <20240808194756.167664-1-stephen@networkplumber.org> MIME-Version: 1.0 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 Yes the alarm API is supported on FreeBSD. Signed-off-by: Stephen Hemminger --- app/test/test_alarm.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/test/test_alarm.c b/app/test/test_alarm.c index b4034339b8..0cdfad1374 100644 --- a/app/test/test_alarm.c +++ b/app/test/test_alarm.c @@ -22,11 +22,6 @@ test_alarm_callback(void *cb_arg) static int test_alarm(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - printf("The alarm API is not supported on FreeBSD\n"); - return 0; -#endif - /* check if it will fail to set alarm with wrong us value */ printf("check if it will fail to set alarm with wrong ms values\n"); if (rte_eal_alarm_set(0, test_alarm_callback, From patchwork Thu Aug 8 19:47:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 143031 X-Patchwork-Delegate: thomas@monjalon.net 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 982C74576E; Thu, 8 Aug 2024 21:48:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C60B442DE3; Thu, 8 Aug 2024 21:48:14 +0200 (CEST) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 1205D42DB1 for ; Thu, 8 Aug 2024 21:48:11 +0200 (CEST) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7b594936e9bso934486a12.1 for ; Thu, 08 Aug 2024 12:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723146490; x=1723751290; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2rwZlBG8abKJfoIMjqbIA+3btUaxKinEosLlyHzAiec=; b=gKT9OIDgMYjdZ9B4MrGu6BaY4jRaXCOBGBfXCtSkhqsSysLE9IlPm27Wz+NQrU298B clNGm+MD2bIfVt6CJH2yxY4JvN94mUmv4FpRO/58S6v3ulMCYPEobYf249XEcNGsxQwN gnLTxhTtIYa1LGU+7fHhk4chhrEg25p2F17zD0zZhBAJd9Dtn85AMQg+qLDKbTVlGfIL 3p/TduhR0dYomUAWGS1aph8nahCIKVblkr9SFizSZhaoMQQegvINwITgpjRkSSCXx5ww tsM/Ckl+mQ+kjASH/Lc/a2eBBG1tT2sJoXt64GmI3A/5ORFXlxRE6d+2IabZEdLhi4Mh 99WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723146490; x=1723751290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2rwZlBG8abKJfoIMjqbIA+3btUaxKinEosLlyHzAiec=; b=rhKOqcZMMnVgqsLC+C5Eb2TTjQcY79gamiWcMwjvC2vuil0j3qia6U8SEFk0/948MX Su8vG9S5hQq+VPeZUp+U4eDceIbqKi91umbEKRpV4eyBLQ7nZOR0EotwhUIemZd4LWg6 nv4c10uMn+vFcBcvFWgZFq0gF1S9oQ4HZK5FJ8+o/+Co0+w+RsRhbWSBBcT/DUINEmlt 7BCoExLHlJQVM/GK/HPeJnMswfxRBkpTbaq3YNt3V3hEN7zWdpsW7F81j/euDkUVBKsQ vvqlZ6nJBUgntEUjimAvfDAq6Fu/ePpugUErSN+7XGyaOX/iZLG7YR0tIiE7WZ1c+lo+ oz1g== X-Gm-Message-State: AOJu0YyPnOPeozUcKJdPq4Z89Nmqg7EtnRQR9kxxPqasGnFpBYIHOE6b J2a9WdBO2sElbcORSsAlcx24DTT8GqcSIRdkMfaNGlCAk8fQawuKCQlCAvPFXTqlIVVY/zX1Fok 9 X-Google-Smtp-Source: AGHT+IHa8h3HXQq5XdkMEoQ2jTCv67NCxXjeZUhTwX3g2iZUlhZAjvnT8zkLIj3fTT6wso577oFOpw== X-Received: by 2002:a05:6a20:9184:b0:1c0:f315:ec7e with SMTP id adf61e73a8af0-1c6fcf1947fmr3507376637.28.1723146490051; Thu, 08 Aug 2024 12:48:10 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2d376csm1469804b3a.111.2024.08.08.12.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 12:48:09 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH 4/5] test/alarm: rewrite the alarm test Date: Thu, 8 Aug 2024 12:47:00 -0700 Message-ID: <20240808194756.167664-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808194756.167664-1-stephen@networkplumber.org> References: <20240808194756.167664-1-stephen@networkplumber.org> MIME-Version: 1.0 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 The alarm test had several issues: - only negative tests were done, no positive test to make sure API worked - the set/cancel test had too short an interval and the alarm might expire - the test should have used the standard TEST macros. Signed-off-by: Stephen Hemminger --- app/test/test_alarm.c | 77 ++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/app/test/test_alarm.c b/app/test/test_alarm.c index 0cdfad1374..67ca30b1fe 100644 --- a/app/test/test_alarm.c +++ b/app/test/test_alarm.c @@ -3,53 +3,76 @@ */ #include +#include #include -#include #include +#include +#include +#include +#include #include "test.h" -static volatile int flag; +#ifndef US_PER_SEC +#define US_PER_SEC 1000000u +#endif static void test_alarm_callback(void *cb_arg) { - flag = 1; - printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg); + bool *triggered = cb_arg; + + rte_atomic_store_explicit(triggered, 1, rte_memory_order_release); } + static int test_alarm(void) { - /* check if it will fail to set alarm with wrong us value */ - printf("check if it will fail to set alarm with wrong ms values\n"); - if (rte_eal_alarm_set(0, test_alarm_callback, - NULL) >= 0) { - printf("should not be successful with 0 us value\n"); - return -1; - } - if (rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback, - NULL) >= 0) { - printf("should not be successful with (UINT64_MAX-1) us value\n"); - return -1; - } + bool triggered = false; + bool later = false; + int ret; + + /* check if it will fail to set alarm with wrong us values */ + TEST_ASSERT_FAIL(rte_eal_alarm_set(0, test_alarm_callback, NULL), + "Expected rte_eal_alarm_set to fail with 0 us value"); + + /* check it if will fail with a very large timeout value */ + TEST_ASSERT_FAIL(rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback, NULL), + "Expected rte_eal_alarm_set to fail with (UINT64_MAX-1) us value"); /* check if it will fail to set alarm with null callback parameter */ - printf("check if it will fail to set alarm with null callback parameter\n"); - if (rte_eal_alarm_set(10 /* ms */, NULL, NULL) >= 0) { - printf("should not be successful to set alarm with null callback parameter\n"); - return -1; - } + TEST_ASSERT_FAIL(rte_eal_alarm_set(US_PER_SEC, NULL, NULL), + "Expected rte_eal_alarm_set to fail with null callback parameter"); /* check if it will fail to remove alarm with null callback parameter */ - printf("check if it will fail to remove alarm with null callback parameter\n"); - if (rte_eal_alarm_cancel(NULL, NULL) == 0) { - printf("should not be successful to remove alarm with null callback parameter"); - return -1; - } + TEST_ASSERT_FAIL(rte_eal_alarm_cancel(NULL, NULL), + "Expected rte_eal_alarm_cancel to fail with null callback parameter"); + + /* check if can set a alarm for one second */ + TEST_ASSERT_SUCCESS(rte_eal_alarm_set(US_PER_SEC, test_alarm_callback, &triggered), + "Setting one second alarm failed"); + + /* set a longer alarm that will be canceled. */ + TEST_ASSERT_SUCCESS(rte_eal_alarm_set(10 * US_PER_SEC, test_alarm_callback, &later), + "Setting ten second alarm failed"); + + /* wait for alarm to happen */ + while (rte_atomic_load_explicit(&triggered, rte_memory_order_acquire) == false) + rte_delay_us_sleep(US_PER_SEC / 10); + + TEST_ASSERT(!rte_atomic_load_explicit(&later, rte_memory_order_acquire), + "Only one alarm should have fired."); + + ret = rte_eal_alarm_cancel(test_alarm_callback, &triggered); + TEST_ASSERT(ret == 0 && rte_errno == ENOENT, + "Canceling alarm after run ret %d: %s", ret, rte_strerror(rte_errno)); + + ret = rte_eal_alarm_cancel(test_alarm_callback, &later); + TEST_ASSERT(ret == 1, "Canceling ten second alarm failed %d: %s", ret, rte_strerror(rte_errno)); return 0; } -REGISTER_TEST_COMMAND(alarm_autotest, test_alarm); +REGISTER_FAST_TEST(alarm_autotest, true, true, test_alarm); From patchwork Thu Aug 8 19:47:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 143032 X-Patchwork-Delegate: thomas@monjalon.net 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 453614576E; Thu, 8 Aug 2024 21:48:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 193F042E0C; Thu, 8 Aug 2024 21:48:16 +0200 (CEST) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id C0D8242DB1 for ; Thu, 8 Aug 2024 21:48:11 +0200 (CEST) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70d2ae44790so1063859b3a.2 for ; Thu, 08 Aug 2024 12:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723146491; x=1723751291; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rFBnp8Lh6Mk4fP2ithFemfGBD9iluovj29NuWtDI1fw=; b=sj6D+LsYr2HNIZqkPeNlh0fkjPDJoK40wEjBRnOJi1s3I9WHzRdTXtuWFxT7xpEr7z OP8uvJr2jdbp5+G6jZh/jxy2H+HsFdAleMsiqCNWbZm6R0bsS7S8GNxReVOx1qOgQUrv rF6hYn9TWYHq6lcB6iZH34cKFwod9FuZWe3KUhlkaYr9UAFVShmcCCPi946eQpdd4dgB 8tH4daTuljp8WEEUVBhg7DHzPbVKCmZ8wtmLMCJlASa9rOhQGCAe45Lf+ahGGl9LD97i /BVypP2L8HJD0vxA3O4fWzmaMw8M4py3qYjY4eZTd0oIQJVa+PdHYB/bpSYIVyYrpmLe JQrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723146491; x=1723751291; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rFBnp8Lh6Mk4fP2ithFemfGBD9iluovj29NuWtDI1fw=; b=d2SIqTe7wlXoJN3BvPMBSjJbA+GCh/pcA66UEGL54Kz9eAtIc9g+lrCZkCHK6nZA6C peikICBuRrYatOYpKFvlOvDrGW0Xpj1aVn3/5kWzc9B1GnDdgRC7+WeRek+pEPSk3WiW sJ14he9Xh8b4LbTb76fwBQgnJAnrtLnXZ0piHVeXA2qtqS7nrR/q3SUiI8H2vFPYwrQD X7er3I8p3FzTM8NLk6l/KgKCSi3f+CUgx/07/R2lWeJSUtBN5p+yknsEq/30mhvYI0me 0zsfstUPmV83Eex4UtAm7Wk/Aq/V8TIQwK6WJ4p+mieojFr5OfXsV0uz22ouJiQmpNy+ NAVA== X-Gm-Message-State: AOJu0YwCemQI1u4TKYP4I/1TnxRFkSB7BIOM/YPkcI9VvFJZUzTAud4e 2LPiYxwwOwrWP1i7t7nV+CKMBF/3+PtWtlZvhDeXTy63FUvmWOd/w3sK6dSEX3QSS2kEjYu/zJ6 n X-Google-Smtp-Source: AGHT+IGK4TC12jTVP2MBjt5PLm95iYAo6huf+1RpLK48sZKiVvFkMQRz6uuD/JROCb0oqEMDHZi3mg== X-Received: by 2002:a05:6a00:3e02:b0:70d:2b23:a720 with SMTP id d2e1a72fcca58-710cad45100mr3289522b3a.5.1723146490823; Thu, 08 Aug 2024 12:48:10 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2d376csm1469804b3a.111.2024.08.08.12.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 12:48:10 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH 5/5] eal: simplify eal alarm cancel by using LIST_FOREACH_SAFE Date: Thu, 8 Aug 2024 12:47:01 -0700 Message-ID: <20240808194756.167664-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808194756.167664-1-stephen@networkplumber.org> References: <20240808194756.167664-1-stephen@networkplumber.org> MIME-Version: 1.0 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 The code for rte_eal_alarm_cancel was using two loops and duplicate code to handle cancel at the start of the list. Introduce the LIST_FOREACH_SAFE() macro from FreeBsd which makes writing the loop cleaner and simpler. Signed-off-by: Stephen Hemminger --- lib/eal/linux/eal_alarm.c | 51 +++++++++++++++------------------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/lib/eal/linux/eal_alarm.c b/lib/eal/linux/eal_alarm.c index eeb096213b..3f3b722421 100644 --- a/lib/eal/linux/eal_alarm.c +++ b/lib/eal/linux/eal_alarm.c @@ -53,6 +53,13 @@ static struct rte_intr_handle *intr_handle; static int handler_registered = 0; static void eal_alarm_callback(void *arg); +#ifndef LIST_FOREACH_SAFE +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif + void rte_eal_alarm_cleanup(void) { @@ -194,7 +201,7 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg) int rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) { - struct alarm_entry *ap, *ap_prev; + struct alarm_entry *ap, *tmp; int count = 0; int err = 0; int executing; @@ -207,46 +214,26 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) do { executing = 0; rte_spinlock_lock(&alarm_list_lk); - /* remove any matches at the start of the list */ - while ((ap = LIST_FIRST(&alarm_list)) != NULL && - cb_fn == ap->cb_fn && - (cb_arg == (void *)-1 || cb_arg == ap->cb_arg)) { - - if (ap->executing == 0) { - LIST_REMOVE(ap, next); - free(ap); - count++; - } else { - /* If calling from other context, mark that alarm is executing - * so loop can spin till it finish. Otherwise we are trying to - * cancel our self - mark it by EINPROGRESS */ - if (pthread_equal(ap->executing_id, pthread_self()) == 0) - executing++; - else - err = EINPROGRESS; - - break; - } - } - ap_prev = ap; - /* now go through list, removing entries not at start */ - LIST_FOREACH(ap, &alarm_list, next) { + LIST_FOREACH_SAFE(ap, &alarm_list, next, tmp) { /* this won't be true first time through */ if (cb_fn == ap->cb_fn && (cb_arg == (void *)-1 || cb_arg == ap->cb_arg)) { - if (ap->executing == 0) { LIST_REMOVE(ap, next); free(ap); count++; - ap = ap_prev; - } else if (pthread_equal(ap->executing_id, pthread_self()) == 0) - executing++; - else - err = EINPROGRESS; + } else { + /* If calling from other context, mark that alarm is executing + * so loop can spin till it finish. Otherwise we are trying to + * cancel our self - mark it by EINPROGRESS + */ + if (pthread_equal(ap->executing_id, pthread_self()) == 0) + executing++; + else + err = EINPROGRESS; + } } - ap_prev = ap; } rte_spinlock_unlock(&alarm_list_lk); } while (executing != 0);