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 8D6A4440B7; Fri, 31 May 2024 18:40:47 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 797C942D95; Fri, 31 May 2024 18:40:47 +0200 (CEST) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mails.dpdk.org (Postfix) with ESMTP id 8B37A4027D for ; Fri, 31 May 2024 18:40:39 +0200 (CEST) Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7024003a515so1239659b3a.3 for ; Fri, 31 May 2024 09:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717173639; x=1717778439; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mxc4biCSKXVBZHOqtelZnRVGzzoyqLggZkk9d8M2QpU=; b=cHSC1VvpV6GuQb+QtZ3g+dtCbZonWsAyKL5B81wqNbbTQB1WqiTBcEmGVrKfBFmJyo tUJSbY7C+SqUULO4xgBw1BgyvAFppew0TL5xJQvNwcnCSbv9oilvNG4ll2bmsbEHKT9g 5lvtkQpRwnLcX3fTwb1895jvwNP41TQQPCvzziKxUyIVQ6mFgrcVpjGisCy7loozDP88 0WEwOOiZSFeFlmJINJ8OQK969gm6dimw0lVXWbP7TVgeNfLTUW++OkLuzKd/ZzGmL4N1 3g3uFAV6gpEouO1K2D5UfIEVhzc5WXp0bKsB3XPMbes1wLAI7GNFGhPI7JnpPkpy+/Q9 t37A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717173639; x=1717778439; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mxc4biCSKXVBZHOqtelZnRVGzzoyqLggZkk9d8M2QpU=; b=ON0vjJ9GVKZcLYzRTOcQQHLRYCz5DpjqN9/ucjsqmCuWJTXSx0+HVUGmTBAi6W/z2B OjhmaLoVrMg+slizSh7h1sZIk2ICLOLaV2BaWAGJBnua1ubyzBvieccGzDBo8ax8vqe6 EWK4Lj1RIT+4Jo/JpED6q3P1Z5OeJ37QP+9NwaPk4s1Ns8Hsudc+HJ2a1HiSFxfW6QTz /vRM8hNAqWbC9JbLWwAwD/vOprLjV23NwVeBe4vwBouYLT/C+cTr4Fdx98ihrQQGrOel 8kcmAUQD+C7Ph5gzi0ZiO3cQHzN5q7Ti/A9EubvjXtfZf5YES6RrFh81QqKCf0Yd/mVi sjCg== X-Gm-Message-State: AOJu0Yy9AxL16L5HmB8kR0rik40elndV7A5XOWi/ZvQHFV88KvGiilZr mtzdPmveCby+RFAhjg32EFqn/iBF6LAWfbEKqlYvsq3vmSAJd1PM0L1e039ppYAITca1uY7X4Jl A X-Google-Smtp-Source: AGHT+IFj2aIGnzy8rYrPJzNueYnYvaYpDYNphgHg45qEAnHAeeXN7Id7ccEULzE8PFdq+pMrJajOmQ== X-Received: by 2002:a05:6a21:99a0:b0:1a7:9476:6cb9 with SMTP id adf61e73a8af0-1b26f205182mr3048652637.32.1717173638669; Fri, 31 May 2024 09:40:38 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-702425e2c23sm1589387b3a.85.2024.05.31.09.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 09:40:37 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH] dumpcap: add lcores option Date: Fri, 31 May 2024 09:40:27 -0700 Message-ID: <20240531164027.4062-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index ba91ca94d0..879d2b3ea5 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -11,6 +11,7 @@ #include #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 *lcores_arg; static bool dump_bpf; static bool show_interfaces; static bool print_stats; @@ -343,6 +345,7 @@ static void parse_opts(int argc, char **argv) { "ifdescr", required_argument, NULL, 0 }, { "ifname", required_argument, NULL, 0 }, { "interface", required_argument, NULL, 'i' }, + { "lcores", 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 +372,8 @@ static void parse_opts(int argc, char **argv) if (!strcmp(longopt, "capture-comment")) { capture_comment = optarg; + } else if (!strcmp(longopt, "lcores")) { + lcores_arg = optarg; } else if (!strcmp(longopt, "file-prefix")) { file_prefix = optarg; } else if (!strcmp(longopt, "temp-dir")) { @@ -608,12 +613,16 @@ static void dpdk_init(void) "--log-level", "notice" }; int eal_argc = RTE_DIM(args); + cpu_set_t cpuset; char **eal_argv; unsigned int i; if (file_prefix != NULL) eal_argc += 2; + if (lcores_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 +632,11 @@ static void dpdk_init(void) for (i = 1; i < RTE_DIM(args); i++) eal_argv[i] = strdup(args[i]); + if (lcores_arg != NULL) { + eal_argv[i++] = strdup("--lcores"); + eal_argv[i++] = strdup(lcores_arg); + } + if (file_prefix != NULL) { eal_argv[i++] = strdup("--file-prefix"); eal_argv[i++] = strdup(file_prefix); @@ -633,8 +647,24 @@ static void dpdk_init(void) rte_panic("No memory\n"); } + if (pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset) < 0) + rte_panic("pthread_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 lcores argument was speciried, then run this program as a normal process + * which can be scheduled on any non-isolated CPU. + * + * EAL init will cause this thread to be assigned to the first lcore + * which is not what what we want for this secondary process that will + * be interacting with the Linux kernel. + */ + if (lcores_arg == NULL) { + if (pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset) < 0) + perror("pthread_setaffinity"); + } } /* Create packet ring shared between callbacks and process */ -- 2.43.0