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 2639E44121; Sat, 1 Jun 2024 01:35:04 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EB2CE402A7; Sat, 1 Jun 2024 01:35:03 +0200 (CEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 3681B40299 for ; Sat, 1 Jun 2024 01:35:02 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1f62fae8c3cso15318585ad.3 for ; Fri, 31 May 2024 16:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717198501; x=1717803301; 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=Ribm8b3CzlGhEwO/7Stdv0gci84mlf5L+IWrxk9U3Jw=; b=b7vsEwQw9evlNRo73ONe/0oJbTa5L3GN/TtrD5rpJbbVMpJd4DUdUBqBMgQYdrJb1P byMR2WSP425VB5JKH1MgZE8nLnXo0B+hAkCLfDsnGOHAuM2s2L/EF+aZ08zW048XC352 GBxTs+9eIOViwdIvO7UfL1Oq4xiscPGWGluJ6w+26JJ2ZDOaekb17TE/Y29eG5L85hGL kDGQul1vhHKFsDoFq+WKOegpuLpPXOxVsRafTWrEXGlSqSwbY5Yz4MDIou5PCWE7p8N9 SyvDK5/KL9//t3D9mN3p0TTyxDOR4G9Pq4gYo59KME5kZZKOmq34INAtcUVnUtW7JaPU 4/gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717198501; x=1717803301; 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=Ribm8b3CzlGhEwO/7Stdv0gci84mlf5L+IWrxk9U3Jw=; b=SqKCo0NNTgaGXAeOy283CUG4yXZRcXKJK+YljSPrGu9ZvVNSRMGqu7f6ndkLD6uPfv J6XZVv3jchtZjmCMyaa13b1Q/hZPP6BBnZmNxC6PERQWGG7lz5wHSBjgTqwrbYE/Qyfm 6bzBjLtC6cT0qUViy+fiADUqiZxBGJlOz4etMaIzAF04WMaJcRh7CtHFXXJYS6p38aAT 7xi/bddvWOdiZ64llrpxHr3b7FQ4h2tnhhsb/1Vp613t2nGDcHYHZSpACEsWPK8CGLm6 Fqx1dT/pQfZ5hZ7YAqv/qXgElcZ+cwjlPy3UXeCxA0u4QlqgDq5ylbsrRLXMRoJTc9LR 6ybA== X-Gm-Message-State: AOJu0Ywhh/bnNwbywjggQeDJw1Vtz7EyQ5bm/yTDVJe++jyHYQzH8bZy rx04l9agBDPDDdyVzN4KIsL9g2MXYXHfVScbxvUVLucp6RAbL7GmmHcSKWTiLABi/byieaOjm94 R X-Google-Smtp-Source: AGHT+IGsuCMKmzyauocLaTW0WYFId+Ej/2/+A8qeFL97r0aJhg86mX23zBmQ6njBDoJ16cgcZaNKvQ== X-Received: by 2002:a17:902:e152:b0:1f4:9138:8178 with SMTP id d9443c01a7336-1f63709e30amr25994185ad.49.1717198500983; Fri, 31 May 2024 16:35:00 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323e9aa7sm21804685ad.192.2024.05.31.16.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 16:35:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v2] dumpcap: add lcores option Date: Fri, 31 May 2024 16:33:55 -0700 Message-ID: <20240531233450.6979-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531164027.4062-1-stephen@networkplumber.org> References: <20240531164027.4062-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 --- v2 - fix typos - name it "--lcore" since dumpcap only uses single lcore - use rte_thread instead of pthread 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