From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 20CC2A050B;
	Fri,  8 Apr 2022 16:09:31 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 95C5E42802;
	Fri,  8 Apr 2022 16:09:21 +0200 (CEST)
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by mails.dpdk.org (Postfix) with ESMTP id 74C9F427F0
 for <dev@dpdk.org>; Fri,  8 Apr 2022 16:09:19 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1649426959; x=1680962959;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=SZIegY4jMalbwMHw3L565OoxJNqT7cn1Olr793tKWO8=;
 b=lqf2IzqPqJGa4ZIHZL7f9vsRKdoqM1M+V/Tgz9TvQ4A9y01lz9qhOXP0
 BhIjCqPIuPitL9u+zPFx8qCdpgSqEzQSv3sZEuWwNQ8SiVmvx5vfS1FUj
 YwwJSe/3hqGhOs68wH92JrTQLjqvjyZ+bTZ4MV5YTQ7ihNLrPoJmmrEy9
 dz1/FpN3FtphpJSPEP7tceW5/fxvyeMCrSwGqi517e0zN4HN7uT7U2zgv
 2eqOvskwJMv694UH5/0PAXGUjlLFNarrJo0yJcw/4BEyIJvuGY9jQxsxW
 ETVMjyG3gVXIjolhxFq33Pkz6wStW0w5DHQEVdCHkHankBRO91QJvc628 w==;
X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="261290254"
X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="261290254"
Received: from fmsmga001.fm.intel.com ([10.253.24.23])
 by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 08 Apr 2022 07:09:19 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="698192908"
Received: from silpixa00401122.ir.intel.com ([10.55.128.10])
 by fmsmga001.fm.intel.com with ESMTP; 08 Apr 2022 07:09:18 -0700
From: Kevin Laatz <kevin.laatz@intel.com>
To: dev@dpdk.org
Cc: Kevin Laatz <kevin.laatz@intel.com>,
	David Hunt <david.hunt@intel.com>
Subject: [PATCH 4/4] examples/l3fwd_power: add cli for configurable options
Date: Fri,  8 Apr 2022 15:08:47 +0100
Message-Id: <20220408140847.1319312-5-kevin.laatz@intel.com>
X-Mailer: git-send-email 2.31.1
In-Reply-To: <20220408140847.1319312-1-kevin.laatz@intel.com>
References: <20220408140847.1319312-1-kevin.laatz@intel.com>
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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Add CLI options to l3fwd_power to utilize the new power APIs introduced in
this patchset. These CLI options allow the user to configure the
heuritstics made available through the new API via the l3fwd_power
application options.

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
---
 examples/l3fwd-power/main.c | 75 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 20e5b59af9..f480de2420 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -265,6 +265,10 @@ static struct rte_eth_conf port_conf = {
 };
 
 static uint32_t max_pkt_len;
+static uint32_t max_empty_polls;
+static uint32_t pause_duration;
+static uint32_t scale_freq_min;
+static uint32_t scale_freq_max;
 
 static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
 
@@ -1626,10 +1630,32 @@ print_usage(const char *prgname)
 		" empty polls, full polls, and core busyness to telemetry\n"
 		" --interrupt-only: enable interrupt-only mode\n"
 		" --pmd-mgmt MODE: enable PMD power management mode. "
-		"Currently supported modes: baseline, monitor, pause, scale\n",
+		"Currently supported modes: baseline, monitor, pause, scale\n"
+		"  --max-empty-polls MAX_EMPTY_POLLS: number of empty polls to"
+		" wait before entering sleep state\n"
+		"  --pause-duration DURATION: set the duration, in microseconds,"
+		" of the pause callback\n"
+		"  --scale-freq-min FREQ_MIN: set minimum frequency for scaling"
+		" mode for all application lcores\n"
+		"  --scale-freq-max FREQ_MAX: set maximum frequency for scaling"
+		" mode for all application lcores\n",
 		prgname);
 }
 
+static int
+parse_int(const char *opt)
+{
+	char *end = NULL;
+	unsigned long val;
+
+	/* parse integer string */
+	val = strtoul(opt, &end, 10);
+	if ((opt[0] == '\0') || (end == NULL) || (*end != '\0'))
+		return -1;
+
+	return val;
+}
+
 static int parse_max_pkt_len(const char *pktlen)
 {
 	char *end = NULL;
@@ -1803,6 +1829,10 @@ parse_ep_config(const char *q_arg)
 #define CMD_LINE_OPT_TELEMETRY "telemetry"
 #define CMD_LINE_OPT_PMD_MGMT "pmd-mgmt"
 #define CMD_LINE_OPT_MAX_PKT_LEN "max-pkt-len"
+#define CMD_LINE_OPT_MAX_EMPTY_POLLS "max-empty-polls"
+#define CMD_LINE_OPT_PAUSE_DURATION "pause-duration"
+#define CMD_LINE_OPT_SCALE_FREQ_MIN "scale-freq-min"
+#define CMD_LINE_OPT_SCALE_FREQ_MAX "scale-freq-max"
 
 /* Parse the argument given in the command line of the application */
 static int
@@ -1812,6 +1842,7 @@ parse_args(int argc, char **argv)
 	char **argvopt;
 	int option_index;
 	uint32_t limit;
+	int i;
 	char *prgname = argv[0];
 	static struct option lgopts[] = {
 		{"config", 1, 0, 0},
@@ -1825,6 +1856,10 @@ parse_args(int argc, char **argv)
 		{CMD_LINE_OPT_TELEMETRY, 0, 0, 0},
 		{CMD_LINE_OPT_INTERRUPT_ONLY, 0, 0, 0},
 		{CMD_LINE_OPT_PMD_MGMT, 1, 0, 0},
+		{CMD_LINE_OPT_MAX_EMPTY_POLLS, 1, 0, 0},
+		{CMD_LINE_OPT_PAUSE_DURATION, 1, 0, 0},
+		{CMD_LINE_OPT_SCALE_FREQ_MIN, 1, 0, 0},
+		{CMD_LINE_OPT_SCALE_FREQ_MAX, 1, 0, 0},
 		{NULL, 0, 0, 0}
 	};
 
@@ -1975,6 +2010,44 @@ parse_args(int argc, char **argv)
 				parse_ptype = 1;
 			}
 
+			if (!strncmp(lgopts[option_index].name,
+					CMD_LINE_OPT_MAX_EMPTY_POLLS,
+					sizeof(CMD_LINE_OPT_MAX_EMPTY_POLLS))) {
+				printf("Maximum empty polls configured\n");
+				max_empty_polls = parse_int(optarg);
+				rte_power_pmd_mgmt_set_emptypoll_max(max_empty_polls);
+			}
+
+			if (!strncmp(lgopts[option_index].name,
+					CMD_LINE_OPT_PAUSE_DURATION,
+					sizeof(CMD_LINE_OPT_PAUSE_DURATION))) {
+				printf("Pause duration configured\n");
+				pause_duration = parse_int(optarg);
+				rte_power_pmd_mgmt_set_pause_duration(pause_duration);
+			}
+
+			if (!strncmp(lgopts[option_index].name,
+					CMD_LINE_OPT_SCALE_FREQ_MIN,
+					sizeof(CMD_LINE_OPT_SCALE_FREQ_MIN))) {
+				printf("Scaling frequency minimum configured\n");
+				scale_freq_min = parse_int(optarg);
+				for (i = 0; i < RTE_MAX_LCORE; i++)
+					if (rte_lcore_is_enabled(i))
+						rte_power_pmd_mgmt_set_scaling_freq_min(i,
+								scale_freq_min);
+			}
+
+			if (!strncmp(lgopts[option_index].name,
+					CMD_LINE_OPT_SCALE_FREQ_MAX,
+					sizeof(CMD_LINE_OPT_SCALE_FREQ_MAX))) {
+				printf("Scaling frequency maximum configured\n");
+				scale_freq_max = parse_int(optarg);
+				for (i = 0; i < RTE_MAX_LCORE; i++)
+					if (rte_lcore_is_enabled(i))
+						rte_power_pmd_mgmt_set_scaling_freq_max(i,
+								scale_freq_max);
+			}
+
 			break;
 
 		default:
-- 
2.31.1