Commit Graph

261 Commits

Author SHA1 Message Date
David Lamparter
89cb86aeb0 build, vtysh: extract vtysh commands from .xref
Rather than running selected source files through the preprocessor and a
bunch of perl regex'ing to get the list of all DEFUNs, use the data
collected in frr.xref.

This not only eliminates issues we've been having with preprocessor
failures due to nonexistent header files, but is also much faster.
Where extract.pl would take 5s, this now finishes in 0.2s.  And since
this is a non-parallelizable build step towards the end of the build
(dependent on a lot of other things being done already), the speedup is
actually noticeable.

Also files containing CLI no longer need to be listed in `vtysh_scan`
since the .xref data covers everything.  `#ifndef VTYSH_EXTRACT_PL`
checks are equally obsolete.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-26 17:12:34 +01:00
Mark Stapp
7e93a54c6c lib: ensure locals are inited to NULL
A couple of pointers in do_thread_cancel() we only inited at
the start of the function; make sure they're inited during
each iteration of the loop.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2022-08-31 11:47:39 -04:00
Donald Sharp
cb1991af8c *: frr_with_mutex change to follow our standard
convert:
	frr_with_mutex(..)

to:
	frr_with_mutex (..)

To make all our code agree with what clang-format is going to produce

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-20 15:50:32 -04:00
Donatas Abraitis
13bcc010e3 lib: Return 0 as remaining msec if the thread is not scheduled
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-07-18 16:43:44 +03:00
Donald Sharp
cfb9e0ee59 lib: Make thread_is_scheduled a static inline
For performance, yo.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-05-20 09:53:44 -04:00
Donald Sharp
94202742fb lib, yang: Fix spellinig of miliseconds
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-02 07:48:18 -04:00
Donald Sharp
4e2839de64 lib: Fix FreeBSD clock_gettime(CLOCK_THREAD_CPUTIME_ID,..) going backwards
On FreeBSD I have noticed that subsuquent calls to clock_gettime(..)
can return an after time that is before first calls value.
This in turn is generating CPU_HOG's because the subtraction
is wrapping into very very large numbers:

2022/02/28 20:12:58 SHARP: [PTDQA-70FG5]     start: 35.741981000  now: 35.740581000
2022/02/28 20:12:58 SHARP: [XK9YH-ZD8FA][EC 100663313] CPU HOG: task zclient_read (800744240) ran for 0ms (cpu time 18446744073709550ms)

(Please note I added the first line of debug to figure this issue out).

I have been asked to open a FreeBSD bug report and have done so.
In the mean time I think that it is important that FRR does
not generate bogus CPU HOG's on FreeBSD ( especially since
this may or may not be easily fixed and FRR has no control
over what version of the operating system, operators are
going to be running with FRR.

So, add a bit of specialized code that checks to see if
the after time in FreeBSD is before the now time in
thread_consumed_time and do some quick manipulations
to not have this issue.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-03-01 09:08:32 -05:00
Donald Sharp
22f31b8c52 lib, vtysh: Add show thread timers command
Add the ability to inspect the timers and when they will pop
per daemon:

sharpd@eva ~/frr (thread_return_null)> vtysh -c "show thread timers"
Thread timers for zebra:

Showing timers for default
--------------------------
  rtadv_timer                                       00:00:00.520
  if_zebra_speed_update                             00:00:02.745
  if_zebra_speed_update                             00:00:02.745
  if_zebra_speed_update                             00:00:02.745
  if_zebra_speed_update                             00:00:02.745
  if_zebra_speed_update                             00:00:02.745
  if_zebra_speed_update                             00:00:02.745
  if_zebra_speed_update                             00:00:02.746
  if_zebra_speed_update                             00:00:02.744
  if_zebra_speed_update                             00:00:02.745

Showing timers for Zebra dplane thread
--------------------------------------

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-28 06:39:07 -05:00
Donald Sharp
e2eff5c3b1 lib: Add a Dev catch for when a timer is set for > 1 year
Since there are timers that are created based upon doing some
math and we know that unsigned values when doing math and we accidently
subtract a larger number from a smaller number causes the unsigned
number to wrap to very large numbers, let's put in a small catch
in place to see if there are any places in the system that
mistakes are made and FRR is accidently creating a problem
for itself.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-25 08:19:07 -05:00
Donald Sharp
cc9f21da22 *: Change thread->func to return void instead of int
The int return value is never used.  Modify the code
base to just return a void instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23 19:56:04 -05:00
Donald Sharp
1dd08c2243 lib: Save number of times a thread is starved
Add a counter to the number of times a thread is starved from
a timer event and add the output to `show thread cpu`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-10 14:10:26 -05:00
Donald Sharp
e8b3a2f74b lib, zebra: Add ability to tell thread system to ignore late timers
Add a thread_ignore_late_timer(struct thread *thread) function
that allows thread.c to ignore when timers are late to the party.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-20 11:58:48 -05:00
Donald Sharp
ab01a00176 lib: Figure out if we are being starved for cpu
If a thread timer should have popped CPU_CONSUMED_CHECK
seconds in the past, and we are only handling it now.  Consider
the thread starved and notice it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-20 11:56:27 -05:00
David Lamparter
54929fd38a *: use semicolon after printfrr_ext_autoreg_{p,d}
Mostly to make clang-format not format these to peak ugly.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 13:33:57 +01:00
David Lamparter
f59e688226 lib: add %pTH / %pTHD for printing thread info
Refer to docs in doc/developer for details.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 13:33:57 +01:00
Donald Sharp
7cc91e67a3 *: Convert quagga_signal_X to frr_signal_X
Naming functions/data structures more appropriately for
the project we are actually in.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
Igor Ryzhov
ee1455dd98 lib: change thread_add_* API
Do not return pointer to the newly created thread from various thread_add
functions. This should prevent developers from storing a thread pointer
into some variable without letting the lib know that the pointer is
stored. When the lib doesn't know that the pointer is stored, it doesn't
prevent rescheduling and it can lead to hard to find bugs. If someone
wants to store the pointer, they should pass a double pointer as the last
argument.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-20 20:07:15 +03:00
Donald Sharp
a505383d6a lib: Add a thread_is_scheduled function
The function thread_is_scheduled allows us to know if
the particular thread is scheduled for execution or not.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-20 08:28:52 -04:00
David Lamparter
6418e2d342 lib: try CLOCK_THREAD_CPUTIME_ID
This might be faster if at some point in the future the Linux vDSO
supports CLOCK_THREAD_CPUTIME_ID without making a syscall.  (Same
applies for other OSes.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-24 16:42:59 +02:00
David Lamparter
45f0118832 lib: make cputime checks runtime options (v2)
...really no reason to force this into a compile time decision.  The
only point is avoiding the getrusage() syscall, which can easily be a
runtime decision.

[v2: also split cputime & walltime limits]

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-24 16:42:59 +02:00
Mark Stapp
f71e1ff6a9
Merge pull request #8545 from opensourcerouting/assert-our-own
*: make our own assert() actually work
2021-05-03 11:17:36 -04:00
Donald Sharp
188acbb9a3 lib: Provide some better error handling for operator
When an operator encounters a situation where the number
of FD's open is greater than what we have been configured
to legitimately handle via uname or the `--limit-fds` command
line, abort with a message that they should be able to
debug and figure out what is going on.

Fixes: #8596
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-05-02 07:41:11 -04:00
David Lamparter
642ac49da4 *: remaining zassert => assert
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-23 12:25:51 +02:00
Mark Stapp
861ea6f268
Merge pull request #8465 from opensourcerouting/vtysh-scan-snafu
fix vtysh_scan SNAFUs
2021-04-16 08:23:20 -04:00
David Lamparter
ee4dcee834 vtysh: add lib/thread.c to vtysh_scan
Signed-off-by: David Lamparter <equinox@diac24.net>
2021-04-15 23:12:45 +02:00
Donald Sharp
9b8e01cae4 lib: Incorporate Wall and Cpu warning into show thread cpu
Incorporate into the `show thread cpu` the number of times
we have issued warnings about a particular thread being
too slow.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-03-26 13:27:45 -04:00
Donald Sharp
039d547f6f lib: Differentiate between real and cpu bound processes
When generating SLOW_THREAD warnings let's differentiate between
a cpu bound process and a wall bound process.  Effectively
a slow thread can now be a process in FRR doing lots of work( cpu bound )
or wall bound ( the cpu is heavy load and a FRR process may be pre-empted
and never scheduled ).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-03-26 11:41:57 -04:00
David Lamparter
960b9a5383 *: require semicolon after DEFINE_<typesafe...>
Again, see previous commits.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:39 +01:00
David Lamparter
bf8d3d6aca *: require semicolon after DEFINE_MTYPE & co
Back when I put this together in 2015, ISO C11 was still reasonably new
and we couldn't require it just yet.  Without ISO C11, there is no
"good" way (only bad hacks) to require a semicolon after a macro that
ends with a function definition.  And if you added one anyway, you'd get
"spurious semicolon" warnings on some compilers...

With C11, `_Static_assert()` at the end of a macro will make it so that
the semicolon is properly required, consumed, and not warned about.

Consistently requiring semicolons after "file-level" macros matches
Linux kernel coding style and helps some editors against mis-syntax'ing
these macros.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:17 +01:00
Donald Sharp
fe914c4b60
Merge pull request #7951 from mjstapp/fix_cancel_event
libs, bgpd: improve task cancellation by argument value
2021-03-02 07:21:47 -05:00
Donald Sharp
5e8229578a lib: Reduce getrusage/monotime for event handling
When handling a large number of events at one time
FRR will call monotime and getrusage 2 times for each
event.  With this change modify the code to change
this to (X events / 2) + 1 calls of getrusage and monotime

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-02-22 09:20:33 -05:00
Mark Stapp
e7d9e44b02 lib: pass the thread_master to process_timers()
Pass the thread_master pointer to process_timers() as we
do for other list-processing apis.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-02-18 09:42:03 -05:00
Mark Stapp
96fe578a64 lib: don't awaken from poll for every timer
Only ask the event-loop poll() to awaken if a newly-added timer
actually might have changed the required timeout. Also compute
timer deadline outside of mutex locks.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-02-18 09:42:03 -05:00
Mark Stapp
4322dea7e0 lib: remove unneeded arg from timer api
Timers are always type TIMER - remove 'type' arg from some
timer apis.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-02-18 09:42:03 -05:00
Mark Stapp
a582429008 lib: small code cleanup in thread.c
Fix an indentation in thread.c.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-02-18 09:41:38 -05:00
David Lamparter
1d5453d607 *: remove tabs & newlines from log messages
Neither tabs nor newlines are acceptable in syslog messages.  They also
break line-based parsing of file logs.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-14 15:36:51 +01:00
Mark Stapp
a9318a3287 libs, bgpd: improve task cancellation by argument value
Extend the thread_cancel_event api so that it's more complete:
look in all the lists of events, including io and timers, for
matching tasks. Add a limited version of the api that only
examines tasks in the event and ready queues.

BGP appears to require the old behavior, so change its macro
to use the more limited cancel api.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-02-09 12:10:51 -05:00
Mark Stapp
aea25d1ec8 libs: make the task cancellation struct private
No reason for the thread/task cancellation struct to be public:
move it out of the header file. Also add a flags field.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-02-09 12:10:51 -05:00
David Lamparter
6c3aa850ea lib/xref: fix frrtrace() calls in thread code
This didn't exist yet when the xref code came around, and since
frrtrace() gets collapsed to nothing by the preprocessor when
tracepoints are disabled, it didn't cause any compiler errors...

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-03 00:55:07 +01:00
Russ White
8f57f7413c
Merge pull request #6766 from opensourcerouting/xref
lib: xrefs - general cross-references & unique IDs
2021-02-02 07:44:21 -05:00
David Lamparter
60a3efec24 lib/xref: use to transport thread_* file/line/func
Just a better way of doing what was previously the "debugargdef" macro.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-01 17:20:41 +01:00
Donald Sharp
84d951d0cb lib: Line up show thread cpu output appropriately
The output from `show thread cpu` was not lined up appropriately
for the header line.  As well as the function name we were
calling in the output.  Fix it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-02-01 08:59:18 -05:00
Mark Stapp
1a9f340b6b lib: add startup option to limit fds
Add a startup-time option to limit the number of fds used
by the thread/event infrastructure. If nothing is configured,
the system ulimit is used.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-11-18 15:34:35 -05:00
Mark Stapp
72327cf3e7 * : clean up format specifiers for gcc-10
gcc 10 complains about some of our format specs, fix them. Use
atomic size_t in thread stats, to work around platform
differences.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-11-04 16:56:17 -05:00
Quentin Young
b4d6e8559f lib: fix missed pointer update
Function argument changed from thread * to thread ** without updating
the corresponding tracepoint.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-11-02 16:22:54 -05:00
Mark Stapp
d81ca9a3fa lib: avoid signal-handling race with event loop poll call
Manage the main pthread's signal mask to avoid a signal-handling
race. Before entering poll, check for pending signals that the
application needs to handle. Use ppoll() to re-enable those
signals during the poll call.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-10-28 16:31:54 -04:00
Mark Stapp
1543c387be lib: add debug output for signal mask
Add an api that debugs the signals in a sigset.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-10-28 16:31:54 -04:00
Mark Stapp
cbd492990d
Merge pull request #7194 from qlyoung/tracing
Tracing
2020-10-24 16:50:35 -04:00
Quentin Young
c7bb4f006b lib, bgpd: convert lttng tracepoints to frrtrace()
- tracepoint() -> frrtrace()
- tracelog() -> frrtracelog()
- tracepoint_enabled() -> frrtrace_enabled()

Also removes copypasta'd #ifdefs for those LTTng macros, those are
handled in lib/trace.h

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-10-23 15:13:51 -04:00
Quentin Young
912d45a161 lib: move trace.h -> libfrr_trace.h
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-10-23 15:13:51 -04:00