4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <cmdline_rdline.h>
40 #include <cmdline_parse.h>
41 #include <cmdline_parse_num.h>
42 #include <cmdline_parse_string.h>
48 #include "../include/conf.h"
55 struct cmd_help_tokens {
56 cmdline_fixed_string_t verb;
59 cmdline_parse_token_string_t cmd_help_verb =
60 TOKEN_STRING_INITIALIZER(struct cmd_help_tokens, verb, "help");
63 cmd_help_handler(__attribute__((unused)) void *parsed_result,
65 __attribute__((unused)) void *data)
67 cmdline_printf(cl, "Available commands:\n"
69 "- set [ring_name|variable] <value>\n"
70 "- show [ring_name|variable]\n"
72 "Available variables:\n"
75 "- ring names follow the core%%u_port%%u format\n");
78 cmdline_parse_inst_t cmd_help = {
79 .f = cmd_help_handler,
81 .help_str = "show help",
83 (void *) &cmd_help_verb,
93 struct cmd_set_tokens {
94 cmdline_fixed_string_t verb;
95 cmdline_fixed_string_t variable;
99 cmdline_parse_token_string_t cmd_set_verb =
100 TOKEN_STRING_INITIALIZER(struct cmd_set_tokens, verb, "set");
102 cmdline_parse_token_string_t cmd_set_variable =
103 TOKEN_STRING_INITIALIZER(struct cmd_set_tokens, variable, NULL);
105 cmdline_parse_token_num_t cmd_set_value =
106 TOKEN_NUM_INITIALIZER(struct cmd_set_tokens, value, UINT32);
109 cmd_set_handler(__attribute__((unused)) void *parsed_result,
111 __attribute__((unused)) void *data)
113 struct cmd_set_tokens *tokens = parsed_result;
114 struct rte_ring *ring;
116 if (!strcmp(tokens->variable, "quota")) {
118 if (tokens->value > 0 && tokens->value <= MAX_PKT_QUOTA)
119 *quota = tokens->value;
121 cmdline_printf(cl, "quota must be between 1 and %u\n", MAX_PKT_QUOTA);
124 else if (!strcmp(tokens->variable, "low_watermark")) {
126 if (tokens->value <= 100)
127 *low_watermark = tokens->value * RING_SIZE / 100;
129 cmdline_printf(cl, "low_watermark must be between 0%% and 100%%\n");
134 ring = rte_ring_lookup(tokens->variable);
136 cmdline_printf(cl, "Cannot find ring \"%s\"\n", tokens->variable);
138 if (tokens->value >= *low_watermark * 100 / RING_SIZE
139 && tokens->value <= 100)
140 rte_ring_set_water_mark(ring, tokens->value * RING_SIZE / 100);
142 cmdline_printf(cl, "ring high watermark must be between %u%% "
143 "and 100%%\n", *low_watermark * 100 / RING_SIZE);
147 cmdline_parse_inst_t cmd_set = {
148 .f = cmd_set_handler,
150 .help_str = "Set a variable value",
152 (void *) &cmd_set_verb,
153 (void *) &cmd_set_variable,
154 (void *) &cmd_set_value,
164 struct cmd_show_tokens {
165 cmdline_fixed_string_t verb;
166 cmdline_fixed_string_t variable;
169 cmdline_parse_token_string_t cmd_show_verb =
170 TOKEN_STRING_INITIALIZER(struct cmd_show_tokens, verb, "show");
172 cmdline_parse_token_string_t cmd_show_variable =
173 TOKEN_STRING_INITIALIZER(struct cmd_show_tokens, variable, NULL);
177 cmd_show_handler(__attribute__((unused)) void *parsed_result,
179 __attribute__((unused)) void *data)
181 struct cmd_show_tokens *tokens = parsed_result;
182 struct rte_ring *ring;
184 if (!strcmp(tokens->variable, "quota"))
185 cmdline_printf(cl, "Global quota: %d\n", *quota);
187 else if (!strcmp(tokens->variable, "low_watermark"))
188 cmdline_printf(cl, "Global low_watermark: %u\n", *low_watermark);
192 ring = rte_ring_lookup(tokens->variable);
194 cmdline_printf(cl, "Cannot find ring \"%s\"\n", tokens->variable);
196 rte_ring_dump(stdout, ring);
200 cmdline_parse_inst_t cmd_show = {
201 .f = cmd_show_handler,
203 .help_str = "Show a variable value",
205 (void *) &cmd_show_verb,
206 (void *) &cmd_show_variable,
212 cmdline_parse_ctx_t qwctl_ctx[] = {
213 (cmdline_parse_inst_t *)&cmd_help,
214 (cmdline_parse_inst_t *)&cmd_set,
215 (cmdline_parse_inst_t *)&cmd_show,