From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 7EC96A0096 for ; Mon, 3 Jun 2019 19:36:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3FE8A1BAA7; Mon, 3 Jun 2019 19:35:02 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 49D091BAA0 for ; Mon, 3 Jun 2019 19:35:00 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x53HKOnN027527; Mon, 3 Jun 2019 10:34:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=4HRHyjMzsx1+DFMZG0tWMj3qY+wvn1teMSYnK+IrPig=; b=YVgZYfHKFKPZ3y47gNIcA2QJzE0G7GH3t3egVPLwoitTi6eSBnX+2XmfNmdZYLq62qnA TbslvbrVUnkiIA8dGFMcfOei7/5PwG0DXNJnwZUkGbDoIWGl9VImiGDfAdo7bQUJI5qg p2WtsvjPrbkRXeiKZBMCPfrGhOkVp/QSHory4BfW+H82rsjQa/17w0JM2w9ajJxsupdz EAgy9yX8UQAUB0rC6mCdicmpPnwJf5yvrIi1XXaxJn3gK31HM7N1nd+rf35GG6LCR6qX RHR1ezFdHslrJkeuu+JyGM6zuPEm00GHkwUkxMcEzVgu2SoDPREaeh9DciIsEGrs9fbS Gg== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2sw79pr6ux-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 03 Jun 2019 10:34:59 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 3 Jun 2019 10:34:55 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 3 Jun 2019 10:34:55 -0700 Received: from ajoseph83.caveonetworks.com.com (unknown [10.29.45.56]) by maili.marvell.com (Postfix) with ESMTP id 3B2053F703F; Mon, 3 Jun 2019 10:34:50 -0700 (PDT) From: Anoob Joseph To: Jerin Jacob , Nikhil Rao , "Erik Gabriel Carrillo" , Abhinandan Gujjar , Bruce Richardson , Pablo de Lara CC: Anoob Joseph , Narayana Prasad , , Lukasz Bartosik , Pavan Nikhilesh , Hemant Agrawal , "Nipun Gupta" , Harry van Haaren , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Liang Ma Date: Mon, 3 Jun 2019 23:02:16 +0530 Message-ID: <1559583160-13944-17-git-send-email-anoobj@marvell.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559583160-13944-1-git-send-email-anoobj@marvell.com> References: <1559583160-13944-1-git-send-email-anoobj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-03_13:, , signatures=0 Subject: [dpdk-dev] [PATCH 16/39] eventdev: add eventmode CL options framework 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" Adding usage prints and CL parsing routines for eventmode. Option to select packet transfer mode is also added. Signed-off-by: Anoob Joseph Signed-off-by: Lukasz Bartosik --- lib/librte_eventdev/rte_eventdev_version.map | 2 + lib/librte_eventdev/rte_eventmode_helper.c | 128 +++++++++++++++++++++++++++ lib/librte_eventdev/rte_eventmode_helper.h | 51 +++++++++++ 3 files changed, 181 insertions(+) diff --git a/lib/librte_eventdev/rte_eventdev_version.map b/lib/librte_eventdev/rte_eventdev_version.map index 95fd089..1199064 100644 --- a/lib/librte_eventdev/rte_eventdev_version.map +++ b/lib/librte_eventdev/rte_eventdev_version.map @@ -128,4 +128,6 @@ EXPERIMENTAL { rte_event_eth_rx_adapter_cb_register; rte_event_eth_rx_adapter_stats_get; + rte_eventmode_helper_print_options_list; + rte_eventmode_helper_print_options_description; }; diff --git a/lib/librte_eventdev/rte_eventmode_helper.c b/lib/librte_eventdev/rte_eventmode_helper.c index f47970e..8119306 100644 --- a/lib/librte_eventdev/rte_eventmode_helper.c +++ b/lib/librte_eventdev/rte_eventmode_helper.c @@ -1,7 +1,135 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright (C) 2019 Marvell International Ltd. */ +#include #include +#include #include "rte_eventmode_helper_internal.h" + +#define CMD_LINE_OPT_TRANSFER_MODE "transfer-mode" + +static const char short_options[] = + "" + ; + +enum { + /* long options mapped to a short option */ + + /* first long only option value must be >= 256, so that we won't + * conflict with short options + */ + CMD_LINE_OPT_MIN_NUM = 256, + CMD_LINE_OPT_TRANSFER_MODE_NUM, +}; + +static const struct option lgopts[] = { + {CMD_LINE_OPT_TRANSFER_MODE, 1, 0, CMD_LINE_OPT_TRANSFER_MODE_NUM}, + {NULL, 0, 0, 0} +}; + +/* Internal functions */ + +static int32_t +internal_parse_decimal(const char *str) +{ + char *end = NULL; + unsigned long num; + + num = strtoul(str, &end, 10); + if ((str[0] == '\0') || (end == NULL) || (*end != '\0')) + return -1; + + return num; +} + +/* Global functions */ + +void __rte_experimental +rte_eventmode_helper_print_options_list(void) +{ + fprintf(stderr, " --" + " [--transfer-mode MODE]" + ); +} + +void __rte_experimental +rte_eventmode_helper_print_options_description(void) +{ + fprintf(stderr, + " --transfer-mode MODE\n" + " 0: Packet transfer via polling (default)\n" + " 1: Packet transfer via eventdev\n" + "\n"); +} + +static int +em_parse_transfer_mode(struct rte_eventmode_helper_conf *conf, + const char *optarg) +{ + int32_t parsed_dec; + + parsed_dec = internal_parse_decimal(optarg); + if (parsed_dec != RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_POLL && + parsed_dec != RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_EVENT) { + RTE_EM_HLPR_LOG_ERR("Unsupported packet transfer mode"); + return -1; + } + conf->mode = parsed_dec; + return 0; +} + +static void +em_initialize_helper_conf(struct rte_eventmode_helper_conf *conf) +{ + /* Set default conf */ + + /* Packet transfer mode: poll */ + conf->mode = RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_POLL; +} + +struct rte_eventmode_helper_conf * +rte_eventmode_helper_parse_args(int argc, char **argv) +{ + int32_t opt, ret; + struct rte_eventmode_helper_conf *conf = NULL; + + /* Allocate memory for conf */ + conf = rte_zmalloc("eventmode-helper-conf", + sizeof(struct rte_eventmode_helper_conf), + RTE_CACHE_LINE_SIZE); + if (conf == NULL) { + RTE_EM_HLPR_LOG_ERR( + "Failed allocating memory for eventmode helper conf"); + goto err; + } + + /* Initialize conf with default values */ + em_initialize_helper_conf(conf); + + while ((opt = getopt_long(argc, argv, short_options, + lgopts, NULL)) != EOF) { + switch (opt) { + + /* Packet transfer mode */ + case CMD_LINE_OPT_TRANSFER_MODE_NUM: + ret = em_parse_transfer_mode(conf, optarg); + if (ret < 0) { + RTE_EM_HLPR_LOG_ERR( + "Invalid packet transfer mode"); + goto err; + } + break; + default: + goto err; + } + } + return conf; + +err: + if (conf != NULL) + rte_free(conf); + + return NULL; +} diff --git a/lib/librte_eventdev/rte_eventmode_helper.h b/lib/librte_eventdev/rte_eventmode_helper.h index d32cd00..2a0cb30 100644 --- a/lib/librte_eventdev/rte_eventmode_helper.h +++ b/lib/librte_eventdev/rte_eventmode_helper.h @@ -8,6 +8,57 @@ extern "C" { #endif +#include + +/* Packet transfer mode of the application */ +enum rte_eventmode_helper_pkt_transfer_mode { + RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_POLL = 0, + RTE_EVENTMODE_HELPER_PKT_TRANSFER_MODE_EVENT, +}; + +struct rte_eventmode_helper_conf { + enum rte_eventmode_helper_pkt_transfer_mode mode; + /**< Packet transfer mode of the application */ + void *mode_params; + /**< Mode specific parameters */ +}; + +/* Common helper functions for command line parsing */ + +/** + * Print event mode options list + * + */ +void __rte_experimental +rte_eventmode_helper_print_options_list(void); + +/** + * Print event mode options description + * + */ +void __rte_experimental +rte_eventmode_helper_print_options_description(void); + +/** + * Parse event mode arguments + * + * The application can call this function in it's argument parsing routine to + * parse the event mode specific args and create the conf accordingly. This + * function is to be executed on the MASTER lcore only. + * + * @param argc + * A non-negative value. If it is greater than 0, the array members + * for argv[0] through argv[argc] (non-inclusive) shall contain pointers + * to strings. + * @param argv + * An array of strings. The contents of the array, as well as the strings + * which are pointed to by the array, may be modified by this function. + * @return + * Configuration generated by parsing the event mode args. + */ +struct rte_eventmode_helper_conf * +rte_eventmode_helper_parse_args(int argc, char **argv); + #ifdef __cplusplus } #endif -- 2.7.4