2 * mapfile_tool.c - skeleton vpp engine plug-in
4 * Copyright (c) 2018 Cisco Systems and/or affiliates
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vppinfra/format.h>
19 #include <vppinfra/error.h>
20 #include <vppinfra/unix.h>
29 } mapfile_tool_main_t;
31 mapfile_tool_main_t mapfile_tool_main;
33 static char *top_boilerplate =
39 "} file_by_model_and_stepping_t;\n\n"
40 "static const file_by_model_and_stepping_t fms_table [] =\n"
41 "{\n" " /* model, stepping, stepping valid, file */\n";
43 static char *bottom_boilerplate = "};\n";
46 print_chunk (mapfile_tool_main_t * mtm, char *chunk)
48 fformat (mtm->ofp, "%s", chunk);
52 parse_mapfile (mapfile_tool_main_t * mtm)
54 u8 *cp = mtm->mapfile;
61 /* Skip header line */
62 while (*cp && *cp != '\n')
67 fformat (stderr, "mapfile broken or empty\n");
73 /* GenuineIntel-6-55-[01234],V1.12,/SKX/skylakex_uncore_v1.12.json,uncore */
76 /* Across payload lines... */
82 for (i = 0; i < 15; i++)
87 fformat (stderr, "mapfile broken\n");
92 /* should point at model */
96 vec_reset_length (stepping);
97 /* Stepping significant? */
103 vec_add1 (stepping, *cp);
115 vec_reset_length (filename);
118 vec_add1 (filename, *cp);
123 /* We only want ",core" entries */
124 if (memcmp (cp, "core", 4))
126 while (*cp && *cp != '\n')
133 /* Skip to start of next line */
134 while (*cp && *cp != '\n')
141 if (vec_len (stepping) == 0)
143 vec_add1 (stepping, '0');
147 for (i = 0; i < vec_len (stepping); i++)
150 format (mtm->table, " { 0x%s, 0x%c, %d, \"%v\" },\n",
151 model, stepping[i], has_stepping, filename);
160 mapfile_main (unformat_input_t * input, mapfile_tool_main_t * mtm)
166 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
168 if (unformat (input, "in %s", &mtm->ifile))
170 else if (unformat (input, "out %s", &mtm->ofile))
174 fformat (stderr, "unknown input '%U'\n", format_unformat_error,
177 fformat (stderr, "usage: mapfile_tool in <ifile> out <ofile>\n");
184 fformat (stderr, "input file not specified\n");
189 mtm->ofile = format (0, "perfmon_version.c%c", 0);
191 mtm->ofp = fopen ((char *) mtm->ofile, "w");
192 if (mtm->ofp == NULL)
194 fformat (stderr, "Couldn't create '%s'\n", mtm->ofile);
198 error = unix_proc_file_contents ((char *) mtm->ifile, &mapfile);
202 clib_error_free (error);
203 fformat (stderr, "Failed to read mapfile from %s", mtm->ifile);
207 mtm->mapfile = mapfile;
209 rv = parse_mapfile (mtm);
213 print_chunk (mtm, top_boilerplate);
214 print_chunk (mtm, (char *) mtm->table);
215 print_chunk (mtm, bottom_boilerplate);
220 main (int argc, char *argv[])
222 unformat_input_t input;
223 mapfile_tool_main_t *mtm = &mapfile_tool_main;
226 clib_mem_init (0, 128 << 20);
228 unformat_init_command_line (&input, argv);
229 r = mapfile_main (&input, mtm);
230 unformat_free (&input);
236 * fd.io coding-style-patch-verification: ON
239 * eval: (c-set-style "gnu")