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 3D4B645562; Wed, 3 Jul 2024 17:47:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0979842E76; Wed, 3 Jul 2024 17:47:55 +0200 (CEST) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mails.dpdk.org (Postfix) with ESMTP id CEFD742E15 for ; Wed, 3 Jul 2024 17:47:52 +0200 (CEST) Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-652fd0bb5e6so3799073a12.0 for ; Wed, 03 Jul 2024 08:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1720021672; x=1720626472; 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=xZDHLywVJ28uH0pRrlxCp+zb/kEUptYdBsqa5147arU=; b=XVKvPnctuuxDTtu0TDHq9XV3B7/bjaqEqSHVI1Xo/3uVyKXYQQsobn0Xa9XuqS7YC0 ghUy7NTy7vubmPKhFfJAPyt3NbwvIM87SyMmQw2GxP5iJDKFjdo/6JyNBCN8wtaPiCtK yRhg7Odqhhgt5LGfcgDFPv89cVYvqzsALaFan2zdT+SIzy89IkOov1lx/W/2pAskFUl1 K9hNHg2yD7xcCVP28e5tjZ+cCYZhNUcnyNU8c6GWAkgbeK+ANvLl5lXgYjD4pPc9Rdcf MgDDldF+Y0lsuaVi3PK9rZyvcIay+sQzq8HoD4HX77i6Qk/1zQu+5kkAXPnYvy/ohPLt F3xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720021672; x=1720626472; 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=xZDHLywVJ28uH0pRrlxCp+zb/kEUptYdBsqa5147arU=; b=wFh4mdzH06I4bmoQsNdq11LjPUnecdEztkD2J+TOUVPUDkeLlRhFQRZfAi2izyhHxZ nBYRHNUKM9HNcTKoKUfs2HRcclQiim2fgBr0i/UzxcG3YI8ikQE5oj32+cGnAeAvrZfN aNEBIdsurFspLYmIe/wjRfG7HH/ssnSbBtmqV5mnd+dXjGlLp9uZbUr8nnaM5HA79WQx 57PxEWbdyJEK7m+CprReN7nOgEBevMqfeSbK5ZnWU7wBORtNna6JFDWg8e1nJ+RjQMDH DEe/YpIEZ8kISp+iY2eiCR34FkCvg8KTWeRenzZAtzZ4j3foWuig0+lZoIyxd+WdKqAC pmTg== X-Gm-Message-State: AOJu0YyPbo49jV+2C6T3vvjuiU1101j+ISjecQio9DU7ToRMG5tnIvwQ n2QJVbWlcbLlPGKFXlqd3r89azZBOdw/Xix3z2joebmB5ug5a76IPgIBfgGElC76LIUHH+H96E9 gEe0= X-Google-Smtp-Source: AGHT+IE1MvEprtjVbWaGvRhQx7UjYD6KlFVAOrYjsFyWONwalnunkZ6EHk1biy4TdTIZZbpKLuhBCg== X-Received: by 2002:a05:6a20:9f99:b0:1be:c1c0:b8de with SMTP id adf61e73a8af0-1bef6217106mr14330527637.42.1720021671930; Wed, 03 Jul 2024 08:47:51 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb0bd80588sm24653345ad.7.2024.07.03.08.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 08:47:51 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v3 3/3] dumpcap: add lcores option Date: Wed, 3 Jul 2024 08:45:45 -0700 Message-ID: <20240703154705.19192-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240703154705.19192-1-stephen@networkplumber.org> References: <20240529160933.282846-1-stephen@networkplumber.org> <20240703154705.19192-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 dumpcap application is reading from ring and writing to the kernel. By default the EAL init will cause the main thread to bound to the first lcore (cpu 0). Add a command line option to select the lcore to use; or if no lcores are specified then just be a normal process and let the CPU scheduler handle it. Letting scheduler is likely to work well for process doint I/O with kernel. Signed-off-by: Stephen Hemminger --- app/dumpcap/main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index ba91ca94d0..cb2a439f79 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,7 @@ static const char *tmp_dir = "/tmp"; static unsigned int ring_size = 2048; static const char *capture_comment; static const char *file_prefix; +static const char *lcore_arg; static bool dump_bpf; static bool show_interfaces; static bool print_stats; @@ -143,6 +145,7 @@ static void usage(void) " (default: /tmp)\n" "\n" "Miscellaneous:\n" + " --lcore= cpu core to run on (default: any)\n" " --file-prefix= prefix to use for multi-process\n" " -q don't report packet capture counts\n" " -v, --version print version information and exit\n" @@ -343,6 +346,7 @@ static void parse_opts(int argc, char **argv) { "ifdescr", required_argument, NULL, 0 }, { "ifname", required_argument, NULL, 0 }, { "interface", required_argument, NULL, 'i' }, + { "lcore", required_argument, NULL, 0 }, { "list-interfaces", no_argument, NULL, 'D' }, { "no-promiscuous-mode", no_argument, NULL, 'p' }, { "output-file", required_argument, NULL, 'w' }, @@ -369,6 +373,8 @@ static void parse_opts(int argc, char **argv) if (!strcmp(longopt, "capture-comment")) { capture_comment = optarg; + } else if (!strcmp(longopt, "lcore")) { + lcore_arg = optarg; } else if (!strcmp(longopt, "file-prefix")) { file_prefix = optarg; } else if (!strcmp(longopt, "temp-dir")) { @@ -608,12 +614,16 @@ static void dpdk_init(void) "--log-level", "notice" }; int eal_argc = RTE_DIM(args); + rte_cpuset_t cpuset = { }; char **eal_argv; unsigned int i; if (file_prefix != NULL) eal_argc += 2; + if (lcore_arg != NULL) + eal_argc += 2; + /* DPDK API requires mutable versions of command line arguments. */ eal_argv = calloc(eal_argc + 1, sizeof(char *)); if (eal_argv == NULL) @@ -623,6 +633,11 @@ static void dpdk_init(void) for (i = 1; i < RTE_DIM(args); i++) eal_argv[i] = strdup(args[i]); + if (lcore_arg != NULL) { + eal_argv[i++] = strdup("--lcores"); + eal_argv[i++] = strdup(lcore_arg); + } + if (file_prefix != NULL) { eal_argv[i++] = strdup("--file-prefix"); eal_argv[i++] = strdup(file_prefix); @@ -633,8 +648,24 @@ static void dpdk_init(void) rte_panic("No memory\n"); } + /* + * Need to get the original cpuset, before EAL init changes + * the affinity of this thread (main lcore). + */ + if (lcore_arg == NULL && + rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset) != 0) + rte_panic("rte_thread_getaffinity failed\n"); + if (rte_eal_init(eal_argc, eal_argv) < 0) rte_exit(EXIT_FAILURE, "EAL init failed: is primary process running?\n"); + + /* + * If no lcore argument was specified, then run this program as a normal process + * which can be scheduled on any non-isolated CPU. + */ + if (lcore_arg == NULL && + rte_thread_set_affinity_by_id(rte_thread_self(), &cpuset) != 0) + rte_exit(EXIT_FAILURE, "Can not restore original cpu affinity\n"); } /* Create packet ring shared between callbacks and process */ -- 2.43.0