2016-07-08 08:13:45 -04:00
|
|
|
/*
|
2015-12-08 15:45:58 -07:00
|
|
|
*------------------------------------------------------------------
|
|
|
|
* cj.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Cisco and/or its affiliates.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2016-09-12 08:55:13 -04:00
|
|
|
/**
|
|
|
|
* @file
|
2019-03-27 11:25:48 -07:00
|
|
|
* Circular journal diagnostic mechanism.
|
2016-09-12 08:55:13 -04:00
|
|
|
*
|
|
|
|
* The @c cj thread-safe circular log buffer scheme is occasionally useful
|
|
|
|
* when chasing bugs. Calls to it should not be checked in.
|
|
|
|
*/
|
|
|
|
/*? %%clicmd:group_label Circular Journal %% ?*/
|
|
|
|
/*? %%syscfg:group_label Circular Journal %% ?*/
|
|
|
|
|
2015-12-08 15:45:58 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <vlib/vlib.h>
|
|
|
|
|
|
|
|
#include <vlib/unix/cj.h>
|
|
|
|
|
|
|
|
cj_main_t cj_main;
|
|
|
|
|
|
|
|
void
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_log (u32 type, void *data0, void *data1)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
u64 new_tail;
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_main_t *cjm = &cj_main;
|
|
|
|
cj_record_t *r;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
if (cjm->enable == 0)
|
|
|
|
return;
|
|
|
|
|
2018-10-03 22:53:51 +00:00
|
|
|
new_tail = clib_atomic_add_fetch (&cjm->tail, 1);
|
2015-12-08 15:45:58 -07:00
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
r = (cj_record_t *) & (cjm->records[new_tail & (cjm->num_records - 1)]);
|
2015-12-08 15:45:58 -07:00
|
|
|
r->time = vlib_time_now (cjm->vlib_main);
|
2017-04-05 19:18:20 +02:00
|
|
|
r->thread_index = vlib_get_thread_index ();
|
2015-12-08 15:45:58 -07:00
|
|
|
r->type = type;
|
2016-07-08 08:13:45 -04:00
|
|
|
r->data[0] = pointer_to_uword (data0);
|
|
|
|
r->data[1] = pointer_to_uword (data1);
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
void
|
|
|
|
cj_stop (void)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_main_t *cjm = &cj_main;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
cjm->enable = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
clib_error_t *
|
|
|
|
cj_init (vlib_main_t * vm)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_main_t *cjm = &cj_main;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
cjm->vlib_main = vm;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-08 08:13:45 -04:00
|
|
|
|
2015-12-08 15:45:58 -07:00
|
|
|
VLIB_INIT_FUNCTION (cj_init);
|
|
|
|
|
|
|
|
static clib_error_t *
|
|
|
|
cj_config (vlib_main_t * vm, unformat_input_t * input)
|
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_main_t *cjm = &cj_main;
|
2015-12-08 15:45:58 -07:00
|
|
|
int matched = 0;
|
|
|
|
int enable = 0;
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
if (unformat (input, "records %d", &cjm->num_records))
|
2016-07-08 08:13:45 -04:00
|
|
|
matched = 1;
|
2015-12-08 15:45:58 -07:00
|
|
|
else if (unformat (input, "on"))
|
2016-07-08 08:13:45 -04:00
|
|
|
enable = 1;
|
2015-12-08 15:45:58 -07:00
|
|
|
else
|
2016-07-08 08:13:45 -04:00
|
|
|
return clib_error_return (0, "cj_config: unknown input '%U'",
|
|
|
|
format_unformat_error, input);
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (matched == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cjm->num_records = max_pow2 (cjm->num_records);
|
2016-07-08 08:13:45 -04:00
|
|
|
vec_validate (cjm->records, cjm->num_records - 1);
|
2018-10-17 10:38:51 -04:00
|
|
|
clib_memset (cjm->records, 0xff, cjm->num_records * sizeof (cj_record_t));
|
2015-12-08 15:45:58 -07:00
|
|
|
cjm->tail = ~0;
|
|
|
|
cjm->enable = enable;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:55:13 -04:00
|
|
|
/*?
|
|
|
|
* Configure the circular journal diagnostic mechanism. This is only useful
|
2019-03-27 11:25:48 -07:00
|
|
|
* if you, the developer, have written code to make use of the circular
|
2016-09-12 08:55:13 -04:00
|
|
|
* journal.
|
|
|
|
*
|
|
|
|
* @cfgcmd{records, <number>}
|
|
|
|
* Configure the number of records to allocate for the circular journal.
|
|
|
|
*
|
|
|
|
* @cfgcmd{on}
|
|
|
|
* Enable the collection of records in the circular journal at the
|
|
|
|
* earliest opportunity.
|
|
|
|
?*/
|
2015-12-08 15:45:58 -07:00
|
|
|
VLIB_CONFIG_FUNCTION (cj_config, "cj");
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
void
|
|
|
|
cj_enable_disable (int is_enable)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_main_t *cjm = &cj_main;
|
|
|
|
|
2015-12-08 15:45:58 -07:00
|
|
|
if (cjm->num_records)
|
|
|
|
cjm->enable = is_enable;
|
|
|
|
else
|
|
|
|
vlib_cli_output (cjm->vlib_main, "CJ not configured...");
|
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
static inline void
|
|
|
|
cj_dump_one_record (cj_record_t * r)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
fprintf (stderr, "[%d]: %10.6f T%02d %llx %llx\n",
|
2017-04-05 19:18:20 +02:00
|
|
|
r->thread_index, r->time, r->type,
|
|
|
|
(long long unsigned int) r->data[0],
|
2016-07-08 08:13:45 -04:00
|
|
|
(long long unsigned int) r->data[1]);
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
static void
|
|
|
|
cj_dump_internal (u8 filter0_enable, u64 filter0,
|
|
|
|
u8 filter1_enable, u64 filter1)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_main_t *cjm = &cj_main;
|
|
|
|
cj_record_t *r;
|
2015-12-08 15:45:58 -07:00
|
|
|
u32 i, index;
|
2016-07-08 08:13:45 -04:00
|
|
|
|
2015-12-08 15:45:58 -07:00
|
|
|
if (cjm->num_records == 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "CJ not configured...\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
if (cjm->tail == (u64) ~ 0)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
fprintf (stderr, "No data collected...\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Has the trace wrapped? */
|
2016-07-08 08:13:45 -04:00
|
|
|
index = (cjm->tail + 1) & (cjm->num_records - 1);
|
2015-12-08 15:45:58 -07:00
|
|
|
r = &(cjm->records[index]);
|
|
|
|
|
2017-04-05 19:18:20 +02:00
|
|
|
if (r->thread_index != (u32) ~ 0)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
/* Yes, dump from tail + 1 to the end */
|
2015-12-08 15:45:58 -07:00
|
|
|
for (i = index; i < cjm->num_records; i++)
|
2016-07-08 08:13:45 -04:00
|
|
|
{
|
|
|
|
if (filter0_enable && (r->data[0] != filter0))
|
|
|
|
goto skip;
|
|
|
|
if (filter1_enable && (r->data[1] != filter1))
|
|
|
|
goto skip;
|
|
|
|
cj_dump_one_record (r);
|
|
|
|
skip:
|
|
|
|
r++;
|
|
|
|
}
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
/* dump from the beginning through the final tail */
|
|
|
|
r = cjm->records;
|
cj: cj dump crash
Thread 1 "vpp_main" received signal SIGSEGV, Segmentation fault.
0x00007ffff670da53 in cj_dump_one_record (r=0x7ffff50f0fec)
at /home/sluong/vpp3/vpp/src/vlib/unix/cj.c:138
138 (long long unsigned int) r->data[1]);
(gdb) p *cjm
$1 = {tail = 58645908, records = 0x7fffb64646ec, num_records = 512,
enable = 1, vlib_main = 0x7ffff6953240 <vlib_global_main>}
(gdb) p /x cjm
$2 = 0x7ffff6953880
(gdb) p /x *cjm
$3 = {tail = 0x37edd94, records = 0x7fffb64646ec, num_records = 0x200,
enable = 0x1, vlib_main = 0x7ffff6953240}
(gdb)
cjm->tail is a 64 bit counter, not the total number of records. Dumping from
0 to cjm->tail can be a very large number of records which go beyond the
limit. I believe we meant to dump from 0 to index. index has been set by
this statement
index = (cjm->tail + 1) & (cjm->num_records - 1);
Change-Id: Ie1a8ba757598de9757accc1488577c15aa49726b
Signed-off-by: Steven <sluong@cisco.com>
2018-10-10 14:48:32 -07:00
|
|
|
for (i = 0; i < index; i++)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
if (filter0_enable && (r->data[0] != filter0))
|
2016-07-08 08:13:45 -04:00
|
|
|
goto skip2;
|
2015-12-08 15:45:58 -07:00
|
|
|
if (filter1_enable && (r->data[1] != filter1))
|
2016-07-08 08:13:45 -04:00
|
|
|
goto skip2;
|
2015-12-08 15:45:58 -07:00
|
|
|
cj_dump_one_record (r);
|
|
|
|
skip2:
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
void
|
|
|
|
cj_dump (void)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
cj_dump_internal (0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
void
|
|
|
|
cj_dump_filter_data0 (u64 filter0)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_dump_internal (1 /* enable f0 */ , filter0, 0, 0);
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
void
|
|
|
|
cj_dump_filter_data1 (u64 filter1)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
2016-07-08 08:13:45 -04:00
|
|
|
cj_dump_internal (0, 0, 1 /* enable f1 */ , filter1);
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
void
|
|
|
|
cj_dump_filter_data12 (u64 filter0, u64 filter1)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
cj_dump_internal (1, filter0, 1, filter1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static clib_error_t *
|
|
|
|
cj_command_fn (vlib_main_t * vm,
|
2016-07-08 08:13:45 -04:00
|
|
|
unformat_input_t * input, vlib_cli_command_t * cmd)
|
2015-12-08 15:45:58 -07:00
|
|
|
{
|
|
|
|
int is_enable = -1;
|
|
|
|
int is_dump = -1;
|
2017-12-04 11:54:43 +05:30
|
|
|
unformat_input_t _line_input, *line_input = &_line_input;
|
|
|
|
clib_error_t *error = NULL;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
2017-12-04 11:54:43 +05:30
|
|
|
/* Get a line of input. */
|
|
|
|
if (!unformat_user (input, unformat_line_input, line_input))
|
|
|
|
return clib_error_return (0, "expected enable | disable | dump");
|
|
|
|
|
|
|
|
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
|
2016-07-08 08:13:45 -04:00
|
|
|
{
|
2017-12-04 11:54:43 +05:30
|
|
|
if (unformat (line_input, "enable") || unformat (line_input, "on"))
|
2016-07-08 08:13:45 -04:00
|
|
|
is_enable = 1;
|
2017-12-04 11:54:43 +05:30
|
|
|
else if (unformat (line_input, "disable")
|
|
|
|
|| unformat (line_input, "off"))
|
2016-07-08 08:13:45 -04:00
|
|
|
is_enable = 0;
|
2017-12-04 11:54:43 +05:30
|
|
|
else if (unformat (line_input, "dump"))
|
2016-07-08 08:13:45 -04:00
|
|
|
is_dump = 1;
|
|
|
|
else
|
2017-12-04 11:54:43 +05:30
|
|
|
{
|
|
|
|
error = clib_error_return (0, "unknown input `%U'",
|
|
|
|
format_unformat_error, line_input);
|
|
|
|
goto done;
|
|
|
|
}
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_enable >= 0)
|
|
|
|
cj_enable_disable (is_enable);
|
|
|
|
|
|
|
|
if (is_dump > 0)
|
|
|
|
cj_dump ();
|
|
|
|
|
2017-12-04 11:54:43 +05:30
|
|
|
done:
|
|
|
|
unformat_free (line_input);
|
|
|
|
return error;
|
2015-12-08 15:45:58 -07:00
|
|
|
}
|
|
|
|
|
2016-09-12 08:55:13 -04:00
|
|
|
/*?
|
|
|
|
* Enable, disable the collection of diagnostic data into a
|
|
|
|
* circular journal or dump the circular journal diagnostic data.
|
2019-03-27 11:25:48 -07:00
|
|
|
* This is only useful if you, the developer, have written code to make
|
2016-09-12 08:55:13 -04:00
|
|
|
* use of the circular journal.
|
|
|
|
*
|
|
|
|
* When dumping the data it is formatted and sent to @c stderr of the
|
|
|
|
* VPP process; when running VPP in <code>unix interactive</code> mode
|
|
|
|
* this is typically the same place as the Debug CLI.
|
|
|
|
?*/
|
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
/* *INDENT-OFF* */
|
2015-12-08 15:45:58 -07:00
|
|
|
VLIB_CLI_COMMAND (cj_command,static) = {
|
|
|
|
.path = "cj",
|
2016-09-12 08:55:13 -04:00
|
|
|
.short_help = "cj <enable | disable | dump>",
|
2015-12-08 15:45:58 -07:00
|
|
|
.function = cj_command_fn,
|
|
|
|
};
|
2016-07-08 08:13:45 -04:00
|
|
|
/* *INDENT-ON* */
|
2015-12-08 15:45:58 -07:00
|
|
|
|
2016-07-08 08:13:45 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fd.io coding-style-patch-verification: ON
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* eval: (c-set-style "gnu")
|
|
|
|
* End:
|
|
|
|
*/
|