ssa.c: Implement multithreaded PR computation

1. Current implementation is based on Glib's thread pool
2. Each PRDB calculation is a separate thread
3. Multithreaded calculation is used only during SMDB update
4. Number of AL workers is number of available cores - 3
   (upstream, downstream, access). This doesn't mean that
   that there is no context switch during PR computation.
   Also, probably, upstream, downstream, and access are waiting
   for IO and don't actually spend CPU. The formula can
   be changed in the future.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Store number of al workers in access context

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Push a access task to thread pool only if number of workers > 1

Otherwise, use the access thread for the computation.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Log an error in case of g_thread_pool_push failure

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Block access thread until all pushed tasks have been processed

Glib implementation is not clear what exactly
g_thread_pool_unprocessed returns: number of waiting tasks
or number of waiting + processing tasks.
Instead of g_thread_pool_unprocessed, access will use an
atomic variable: num_tasks.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
[ssa.c common.h]: Move some private SSA structs from common.h to ssa.c

Now, tests will build without include path for glib

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: A couple of cosmetic formatting changes

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Clean events and revents for closing upstream connection

In response to IBV_EVENT_CLIENT_REREGISTER event, upstream
closes the upstream connection, but doesn't clean event and
revent. After SM handover, it could crash an application.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Cosmetic formatting change

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Factor enable keepalive code into ssa_rsock_enable_keepalive routine

and invoke in ssa_downstream_svc_server when it formerly was "in line" code

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_upstream_initiate_conn, enable keepalives for non consumer nodes

So keepalives now enabled on downstream node side of upstream
connections for SMDB transfers. This is needed for initial
resiliency.

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
plugin/core.c: Update find_best_parent description comments

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
plugin/core.c: Cosmetic formatting changes

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Decouple access and downstream threads during PRDB update

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Removed some unneeded checks for not NULL before calling ssa_db_destroy

ssa_db_destroy checks for NULL and if so, immediately returns

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_calculate_prdb, change prdb_epoch increment code style

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_calculate_prdb, move creation of prdb_copy into existing success case

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_calculate_prdb, log warning message when creating PRDB copy fails

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Cosmetic formatting change

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Removed some unneeded sets of g_Error to NULL

Signed-off-by: Hal Rosenstock <hal@mellanox.com>