Commit graph

234 commits

Author SHA1 Message Date
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
Quentin Young abf96a87f3 lib: add tracepoints for hash ops, thread events
Define some initial tracepoints for hash table operations, thread
schedules, and thread cancels

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-10-23 15:13:51 -04:00
Mark Stapp 5047884528 *: unify thread/event cancel macros
Replace all lib/thread cancel macros, use thread_cancel()
everywhere. Only the THREAD_OFF macro and thread_cancel() api are
supported. Also adjust thread_cancel_async() to NULL caller's pointer (if
present).

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-10-23 12:16:52 -04:00
Mark Stapp b3d6bc6ef0 * : update signature of thread_cancel api
Change thread_cancel to take a ** to an event, NULL-check
before dereferencing, and NULL the caller's pointer. Update
many callers to use the new signature.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-10-23 08:59:34 -04:00
Quentin Young 7ffcd8bd2d lib: set threadmaster name to 'default' if none
And also include the name of the threadmaster in its event hash name.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-09-15 20:16:56 -04:00
Donald Sharp d142453d6b lib: Properly handle POLLERR from poll()
There are situations where POLLERR will be returned.  But
since we were not handling it.  Thread processing effectively
is turned into an infinite loop, which is bad.

Modify the code so that if we receive a POLLERR we turn it
into a read event to be handled as an error from the handler
function.

This was discovered in pim:

Thread statistics for pimd:
Showing poll FD's for main
--------------------------
Count: 14/1024
	     0 fd:     9 events: 1 revents: 0		mroute_read
	     1 fd:    12 events: 1 revents: 0		vty_accept
	     2 fd:    13 events: 1 revents: 0		vtysh_accept
	     3 fd:    11 events: 1 revents: 0		zclient_read
	     4 fd:    15 events: 1 revents: 0		mroute_read
	     5 fd:    16 events: 1 revents: 0		mroute_read
	     6 fd:    17 events: 1 revents: 0		pim_sock_read
	     7 fd:    19 events: 1 revents: 0		pim_sock_read
	     8 fd:    21 events: 1 revents: 0		pim_igmp_read
	     9 fd:    22 events: 1 revents: 0		pim_sock_read
	    10 fd:    23 events: 1 revents: 0		pim_sock_read
	    11 fd:    20 events: 1 revents: 0		vtysh_read
	    12 fd:    18 events: 1 revents: 0		pim_sock_read
	    13 fd:    24 events: 0 revents: 0

strace was showing this line over and over and over:

poll([{fd=9, events=POLLIN}, {fd=12, events=POLLIN}, {fd=13, events=POLLIN}, {fd=11, events=POLLIN}, {fd=15, events=POLLIN}, {fd=16, events=POLLIN}, {fd=17, events=POLLIN}, {fd=19, events=POLLIN}, {fd=21, events=POLLIN}, {fd=22, events=POLLIN}, {fd=23, events=POLLIN}, {fd=20, events=POLLIN}, {fd=18, events=POLLIN}, {fd=6, events=POLLIN}], 14, 20) = 1 ([{fd=21, revents=POLLERR}])

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-08-12 09:49:20 -04:00
Donald Sharp d279ef571e lib: Fixup comment indentations in thread.c
Somewhere along the way the indentation for comments got
all messed up.  Let's make it follow our standards and
also look right too.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-08-12 09:46:44 -04:00
Anuradha Karuppiah 0447957e62 lib: timer: move the timer string api to lib
This api was earlier present in the daemon code but as multiple daemons
need it moving it to lib will avoid unnecessary copy-paste.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2020-08-05 06:46:12 -07:00
David Lamparter 3efd0893d0 *: un-split strings across lines
Remove mid-string line breaks, cf. workflow doc:

  .. [#tool_style_conflicts] For example, lines over 80 characters are allowed
     for text strings to make it possible to search the code for them: please
     see `Linux kernel style (breaking long lines and strings)
     <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_
     and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --unwrap `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:37:25 +02:00
Mark Stapp 41b21bfa60 *: have daemons call frr_fini() at termination
Fix a number of library and daemon issues so that daemons can
call frr_fini() during normal termination. Without this,
temporary logging files are left behind in /var/tmp/frr/.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-06-11 15:31:54 -04:00
David Lamparter 0bdeb5e58d lib: rewrite zlog lock-free & TLS-buffered
This is a full rewrite of the "back end" logging code.  It now uses a
lock-free list to iterate over logging targets, and the targets
themselves are as lock-free as possible.  (syslog() may have a hidden
internal mutex in the C library;  the file/fd targets use a single
write() call which should ensure atomicity kernel-side.)

Note that some functionality is lost in this patch:
- Solaris printstack() backtraces are ditched (unlikely to come back)
- the `log-filter` machinery is gone (re-added in followup commit)
- `terminal monitor` is temporarily stubbed out.  The old code had a
  race condition with VTYs going away.  It'll likely come back rewritten
  and with vtysh support.
- The `zebra_ext_log` hook is gone.  Instead, it's now much easier to
  add a "proper" logging target.

v2: TLS buffer to get some actual performance

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-01 06:53:26 +02:00
David Lamparter 566bdaf68c *: fix format string warnings
Signed-off-by: David Lamparter <equinox@diac24.net>
2020-03-29 10:45:46 +02:00
Donatas Abraitis 0d6f7fd6fd *: Replace sizeof something to sizeof(something)
Satisfy checkpatch.pl requirements (check for sizeof without parenthesis)

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-08 21:44:53 +02:00
David Lamparter 2b64873d24 *: generously apply const
const const const your boat, merrily down the stream...

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-02 15:01:29 +01:00
Donald Sharp f75e802d8a *: Allow disabling of getrusage calls
getrusage, in a heavily stressed system, can account for
signficant running time due to process switching to the kernel.
Allow the end-operator to specify `--disable-cpu-time` to
avoid this call.  Additionally we cause `show thread cpu` to
not show up if this is selected.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-10-16 13:34:59 -04:00
Spantik e985cda017 lib: Clean up the index that is being used for storing FD and events.
When POLLNVAL is received for a FD then that FD is removed from the
pfd array and also array is rearranged using memmove. When memmove
is used then unused index are not cleanedup. When a new FD takes
up that index then it ends up using stale events without any handler
set for the same.

Signed-off-by: Santosh P K <sapk@vmware.com>
2019-10-15 01:47:30 -07:00
David Lamparter 00dffa8cde lib: add frr_with_mutex() block-wrapper
frr_with_mutex(...) { ... } locks and automatically unlocks the listed
mutex(es) when the block is exited.  This adds a bit of safety against
forgetting the unlock in error paths & co. and makes the code a slight
bit more readable.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-09-03 17:15:17 +02:00
Donald Sharp f79f7a7bb2 *: Fix spelling errors pointed out by debian packaging
Debian packaging when run finds a bunch of spelling errors:

I: frr: spelling-error-in-binary usr/bin/vtysh occurences occurrences
I: frr: spelling-error-in-binary usr/lib/frr/bfdd Amount of times Number of times
I: frr: spelling-error-in-binary usr/lib/frr/bgpd occurences occurrences
I: frr: spelling-error-in-binary usr/lib/frr/bgpd recieved received
I: frr: spelling-error-in-binary usr/lib/frr/isisd betweeen between
I: frr: spelling-error-in-binary usr/lib/frr/ospf6d Infomation Information
I: frr: spelling-error-in-binary usr/lib/frr/ospfd missmatch mismatch
I: frr: spelling-error-in-binary usr/lib/frr/pimd bootsrap bootstrap
I: frr: spelling-error-in-binary usr/lib/frr/pimd Unknwon Unknown
I: frr: spelling-error-in-binary usr/lib/frr/zebra Requsted Requested
I: frr: spelling-error-in-binary usr/lib/frr/zebra uknown unknown
I: frr: spelling-error-in-binary usr/lib/x86_64-linux-gnu/frr/libfrr.so.0.0.0 overriden overridden

This commit fixes all of them except the bgp `recieved` issue due to
it being part of json output.  That one will need to go through
a deprecation cycle.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-08-19 10:36:53 -04:00
Donald Sharp 76eb017923
Merge pull request #4497 from opensourcerouting/rcu
RCU support
2019-08-08 08:41:07 -04:00
David Lamparter 27d29ced68 lib: use DECLARE_HEAP for timers instead of pqueue
Replaces the use of pqueue_* for the thread_master's timer list with an
instance of DECLARE_HEAP_*.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-08-01 16:59:29 +02:00
David Lamparter 3e41733f1b lib: RCU
Please refer to doc/developer/rcu.rst for documentation.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-07-31 03:34:09 +02:00
Donald Sharp a0b36ae673 lib: Add function name to show thread poll
When displaying `show thread poll` data add the
function we are supposed to call when the poll
event happens.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-13 15:14:04 -04:00
Donald Sharp 1ef14bee7a lib: Add check for non-preexisting thread
When adding a read/write poll event and we are using a developmental
build add a bit of code to ensure that we do not already have an read
or write event scheduled.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-13 15:14:04 -04:00
Donald Sharp 45f3d59084 lib: Prevent infinite loop in fd handling
If we have a case where have created a fd for i/o and we have
removed the handling thread but still have the fd in the poll
data structure, there existed a case where we would get
the handle this fd return from poll but we would immediately
do nothing with it because we didn't have a thread to hand
the event to.

This leads to an infinite loop.  Prevent the infinite loop
from happening and log the problem.

We still need to find the cause of this happening.  But
let's prevent the system from melting down in the mean time.

Fixes: #2796
Signed-off-by: David Lamparter <equinox@diac24.net>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-13 15:14:04 -04:00
David Lamparter 051a0be4b2 *: fix some dumb printf format warnings
Some types like `time_t` vary across platforms and always need to be
cast when printed.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-11 13:34:57 +02:00
Donald Sharp 9a8a7b0ed1 lib, pimd, sharpd: Various output string cleanups
Various compilers in our CI system were complaining about various
auto-conversions.  Let's get these cleaned up a bit more.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-07 09:29:45 -04:00
Donald Sharp 6c19478a3b lib: Display to end user the MAX_FDS allowed
Upon startup FRR reads in the MAX_FDS variable from
it's control files via the getrlimit call.  We then
setup code to limit the poll data structure size to
that value.  The OS also limits our FD's to that value
because that is what is set.  Provide a methodology
that a interested end user can figure this data out.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-24 08:24:18 -04:00
Donald Sharp 61fa0b976a lib: 'show thread cpu' help strings referenced a weird option
The 'show thread cpu' command referenced a 'b' option.  Which
is not parsed at all in the parse_filter function.  As such
I do not know what this was referencing as that it has been
removed.  Update the help strings to reflect this reality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-24 08:24:18 -04:00