The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
coord.c File Reference

Coordination thread management. More...

#include <freeradius-devel/io/listen.h>
#include <freeradius-devel/io/schedule.h>
#include <freeradius-devel/io/thread.h>
#include <freeradius-devel/io/coord_priv.h>
#include <freeradius-devel/unlang/base.h>
#include <freeradius-devel/util/syserror.h>
#include <stdalign.h>
+ Include dependency graph for coord.c:

Go to the source code of this file.

Data Structures

struct  fr_coord_reg_s
 A coordinator registration. More...
 
struct  fr_coord_s
 A coordinator which receives messages from workers. More...
 
struct  fr_coord_worker_attach_msg_t
 Control plane message used for workers attaching / detaching to coordinators. More...
 
struct  fr_coord_worker_detach_msg_t
 
struct  fr_coord_worker_s
 The worker end of worker <-> coordinator communication. More...
 
struct  fr_schedule_coord_t
 Scheduler specific information for coordinator threads. More...
 

Macros

#define FR_CONTROL_ID_COORD_DATA   (4)
 Worker <-> coordinator message to pass data to a callback.
 
#define FR_CONTROL_ID_COORD_WORKER_ACK   (3)
 Message sent to worker to acknowledge attach / detach.
 
#define FR_CONTROL_ID_COORD_WORKER_ATTACH   (1)
 Message sent from worker to attach to a coordinator.
 
#define FR_CONTROL_ID_COORD_WORKER_DETACH   (2)
 Message sent from worker to detach from a coordinator.
 
#define MIN_WORKER_ID   -1
 The minimum value we expect as worker id. -1 is the main thread.
 

Functions

static fr_cmp_ret_t coord_cmp (void const *one, void const *two)
 Compare coordinators by registration.
 
static void coord_data_recv (void const *data, size_t data_size, fr_time_t now, void *uctx)
 Callback for a coordinator receiving data from a worker.
 
static void coord_worker_attach (void const *data, NDEBUG_UNUSED size_t data_size, UNUSED fr_time_t now, void *uctx)
 Callback run by a coordinator when a worker attaches.
 
static void coord_worker_data_recv (void const *data, size_t data_size, fr_time_t now, void *uctx)
 Callback for a worker receiving data from a coordinator.
 
static void coord_worker_detach (void const *data, NDEBUG_UNUSED size_t data_size, UNUSED fr_time_t now, void *uctx)
 Callback run by a coordinator when a worker detaches.
 
static void coordinate_worker_ack (NDEBUG_UNUSED void const *data, NDEBUG_UNUSED size_t data_size, UNUSED fr_time_t now, UNUSED void *uctx)
 A worker got an ack from a coordinator in response to attach / detach.
 
fr_coord_worker_t * fr_coord_attach (TALLOC_CTX *ctx, fr_event_list_t *el, fr_coord_reg_t *coord_reg)
 Attach a worker to a coordinator.
 
int fr_coord_close_event_insert (fr_event_list_t *el)
 
static void fr_coord_close_post_event (fr_event_list_t *el, UNUSED fr_time_t now, UNUSED void *uctx)
 Event loop callback to exit the loop when all workers have detached from all coordinators.
 
static fr_coord_t * fr_coord_create (TALLOC_CTX *ctx, fr_event_list_t *el, fr_coord_reg_t *coord_reg, bool single_thread, uint32_t max_workers)
 Create a coordinator from its registration.
 
void fr_coord_deregister (fr_coord_reg_t *coord_reg)
 De-register a coordinator.
 
static void fr_coord_destroy (fr_coord_t *coord)
 
int fr_coord_detach (fr_coord_worker_t *cw, bool exiting)
 Signal a coordinator that a worker wants to detach.
 
char const * fr_coord_name (fr_coord_t const *coord)
 Return the coordinator name.
 
int fr_coord_post_event_insert (fr_event_list_t *el)
 Insert instance specific post-event callbacks.
 
int fr_coord_pre_event_insert (fr_event_list_t *el)
 Insert instance specific pre-event callbacks.
 
fr_coord_reg_t * fr_coord_register (fr_coord_reg_ctx_t *reg_ctx)
 Register a coordinator.
 
int fr_coord_start (uint32_t num_workers, fr_sem_t *sem)
 Start all registered coordinator threads in multi-threaded mode.
 
void fr_coord_thread_join (void)
 Wait for all the coordinator threads to exit.
 
int fr_coord_to_worker_broadcast (fr_coord_t *coord, uint32_t cb_id, fr_dbuff_t *dbuff)
 Broadcast data from a coordinator to all workers.
 
int fr_coord_to_worker_send (fr_coord_t *coord, int32_t worker_id, uint32_t cb_id, fr_dbuff_t *dbuff)
 Send generic data from a coordinator to a worker.
 
static void fr_coordinate (fr_coord_t *coord)
 Run the event loop for a coordinator thread when in multi-threaded mode.
 
static void * fr_coordinate_thread (void *arg)
 Entry point for a coordinator thread.
 
int fr_coords_create (TALLOC_CTX *ctx, fr_event_list_t *el)
 Start coordinators in single threaded mode.
 
void fr_coords_destroy (void)
 Clean up coordinators in single threaded mode.
 
int fr_worker_to_coord_send (fr_coord_worker_t *cw, uint32_t cb_id, fr_dbuff_t *dbuff)
 Send data from a worker to a coordinator.
 

Variables

static fr_dlist_head_t * coord_regs = NULL
 
static fr_dlist_head_t * coord_threads = NULL
 
static fr_rb_tree_t coords = (fr_rb_tree_t){ .num_elements = 0 }
 

Detailed Description

Coordination thread management.

Id
836b13654accd2a0cfb926e1e81523b26bed6b75

Definition in file coord.c.


Data Structure Documentation

◆ fr_coord_reg_s

struct fr_coord_reg_s

A coordinator registration.

Definition at line 85 of file coord.c.

+ Collaboration diagram for fr_coord_reg_s:
Data Fields
fr_coord_cb_reg_t * coord_cb Callbacks for worker -> coordinator messages.
size_t coord_send_size Initial size for coordinator -> worker ring buffer.
fr_dlist_t entry Entry in list of registrations.
module_instance_t const * mi Module instance which registered this coordinator.
char const * name Name for debugging.
fr_coord_worker_cb_reg_t * worker_cb Callbacks for coordinator -> worker messages.
size_t worker_send_size Initial size for worker -> coordinator ring buffer.

◆ fr_coord_s

struct fr_coord_s

A coordinator which receives messages from workers.

Definition at line 49 of file coord.c.

+ Collaboration diagram for fr_coord_s:
Data Fields
fr_coord_cb_reg_t * callbacks Array of callbacks for worker -> coordinator messages.
fr_coord_cb_inst_t ** cb_inst Array of callback instance specific data.
fr_atomic_queue_t * coord_recv_aq Atomic queue for worker -> coordinator.
fr_control_t * coord_recv_control Control plane for worker -> coordinator messages.
fr_coord_reg_t * coord_reg Coordinator registration details.
fr_atomic_queue_t ** coord_send_aq Atomic queues for coordinator -> worker data.
fr_control_t ** coord_send_control Control planes for coordinator -> worker messages.
fr_message_set_t ** coord_send_ms Message sets for coordinator -> worker data.
fr_ring_buffer_t ** coord_send_rb Ring buffers for coordinator -> worker control messages.
fr_event_list_t * el Coordinator event list.
bool exiting Is this coordinator shutting down.
uint32_t max_workers Maximum number of workers we expect.
fr_rb_node_t node Entry in the tree of coordinators.
uint32_t num_callbacks Number of callbacks defined.
uint32_t num_workers How many workers are attached.
bool single_thread Are we in single thread mode.

◆ fr_coord_worker_attach_msg_t

struct fr_coord_worker_attach_msg_t

Control plane message used for workers attaching / detaching to coordinators.

Definition at line 108 of file coord.c.

+ Collaboration diagram for fr_coord_worker_attach_msg_t:
Data Fields
int32_t worker Worker ID.
fr_atomic_queue_t * worker_recv_aq Atomic queue to send data to this worker.
fr_control_t * worker_recv_control Control plane to send messages to this worker.

◆ fr_coord_worker_detach_msg_t

struct fr_coord_worker_detach_msg_t

Definition at line 114 of file coord.c.

Data Fields
bool exiting Is the server exiting.
int32_t worker Worker ID.

◆ fr_coord_worker_s

struct fr_coord_worker_s

The worker end of worker <-> coordinator communication.

Definition at line 73 of file coord.c.

+ Collaboration diagram for fr_coord_worker_s:
Data Fields
fr_coord_worker_cb_reg_t * callbacks Callbacks for coordinator -> worker messages.
fr_coord_t * coord Coordinator this worker is related to.
uint32_t num_callbacks Number of callbacks registered.
fr_atomic_queue_t * worker_recv_aq Atomic queue for coordinator -> worker messages.
fr_control_t * worker_recv_control Coordinator -> worker control plane.
fr_message_set_t * worker_send_ms Message set for worker -> coordinator messages.
fr_ring_buffer_t * worker_send_rb Ring buffer for worker -> coordinator control plane.

◆ fr_schedule_coord_t

struct fr_schedule_coord_t

Scheduler specific information for coordinator threads.

Definition at line 97 of file coord.c.

+ Collaboration diagram for fr_schedule_coord_t:
Data Fields
fr_coord_t * coord The coordinator data structure.
fr_coord_reg_t * coord_reg Coordinator registration details.
uint32_t max_workers Maximum number of workers which will connect to this coordinator.
fr_sem_t * sem For inter-thread signaling.
fr_thread_t thread common thread information - must be first!

Macro Definition Documentation

◆ FR_CONTROL_ID_COORD_DATA

#define FR_CONTROL_ID_COORD_DATA   (4)

Worker <-> coordinator message to pass data to a callback.

Definition at line 39 of file coord.c.

◆ FR_CONTROL_ID_COORD_WORKER_ACK

#define FR_CONTROL_ID_COORD_WORKER_ACK   (3)

Message sent to worker to acknowledge attach / detach.

Definition at line 38 of file coord.c.

◆ FR_CONTROL_ID_COORD_WORKER_ATTACH

#define FR_CONTROL_ID_COORD_WORKER_ATTACH   (1)

Message sent from worker to attach to a coordinator.

Definition at line 36 of file coord.c.

◆ FR_CONTROL_ID_COORD_WORKER_DETACH

#define FR_CONTROL_ID_COORD_WORKER_DETACH   (2)

Message sent from worker to detach from a coordinator.

Definition at line 37 of file coord.c.

◆ MIN_WORKER_ID

#define MIN_WORKER_ID   -1

The minimum value we expect as worker id. -1 is the main thread.

Definition at line 41 of file coord.c.

Function Documentation

◆ coord_cmp()

static fr_cmp_ret_t coord_cmp ( void const *  one,
void const *  two 
)
static

Compare coordinators by registration.

Definition at line 121 of file coord.c.

+ Here is the caller graph for this function:

◆ coord_data_recv()

static void coord_data_recv ( void const *  data,
size_t  data_size,
fr_time_t  now,
void *  uctx 
)
static

Callback for a coordinator receiving data from a worker.

Definition at line 205 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coord_worker_attach()

static void coord_worker_attach ( void const *  data,
NDEBUG_UNUSED size_t  data_size,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Callback run by a coordinator when a worker attaches.

Definition at line 269 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coord_worker_data_recv()

static void coord_worker_data_recv ( void const *  data,
size_t  data_size,
fr_time_t  now,
void *  uctx 
)
static

Callback for a worker receiving data from a coordinator.

Definition at line 239 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coord_worker_detach()

static void coord_worker_detach ( void const *  data,
NDEBUG_UNUSED size_t  data_size,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Callback run by a coordinator when a worker detaches.

Definition at line 292 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coordinate_worker_ack()

static void coordinate_worker_ack ( NDEBUG_UNUSED void const *  data,
NDEBUG_UNUSED size_t  data_size,
UNUSED fr_time_t  now,
UNUSED void *  uctx 
)
static

A worker got an ack from a coordinator in response to attach / detach.

Definition at line 671 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_attach()

fr_coord_worker_t * fr_coord_attach ( TALLOC_CTX *  ctx,
fr_event_list_t *  el,
fr_coord_reg_t *  coord_reg 
)

Attach a worker to a coordinator.

Parameters
ctxTo allocate worker structure in
elEvent list for control messages
coord_regCoordinator registration to attach to.
Returns
  • Worker structure for coordinator use on success
  • NULL on failure

Definition at line 691 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_close_event_insert()

int fr_coord_close_event_insert ( fr_event_list_t *  el)

Definition at line 905 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_close_post_event()

static void fr_coord_close_post_event ( fr_event_list_t *  el,
UNUSED fr_time_t  now,
UNUSED void *  uctx 
)
static

Event loop callback to exit the loop when all workers have detached from all coordinators.

Used during single threaded shut down to allow the event loop to run any tidy up needed by coordinators.

Definition at line 889 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_create()

static fr_coord_t * fr_coord_create ( TALLOC_CTX *  ctx,
fr_event_list_t *  el,
fr_coord_reg_t *  coord_reg,
bool  single_thread,
uint32_t  max_workers 
)
static

Create a coordinator from its registration.

Parameters
ctxto allocate the coordinator in
elEvent list to run this coordinator
coord_regRegistration to configure this coordinator
single_threadIs the server in single thread mode
max_workersThe maximum number of workers which will attach
Returns
  • the coordinator on success
  • NULL on failure

Definition at line 338 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_deregister()

void fr_coord_deregister ( fr_coord_reg_t *  coord_reg)

De-register a coordinator.

To be called from mod_detach of a module which uses a coordinator

Parameters
coord_regto de-register

Definition at line 172 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_destroy()

static void fr_coord_destroy ( fr_coord_t *  coord)
static

Definition at line 426 of file coord.c.

+ Here is the caller graph for this function:

◆ fr_coord_detach()

int fr_coord_detach ( fr_coord_worker_t *  cw,
bool  exiting 
)

Signal a coordinator that a worker wants to detach.

Parameters
cwWorker which is detaching.
exitingIs the server exiting.

Definition at line 652 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_name()

char const * fr_coord_name ( fr_coord_t const *  coord)

Return the coordinator name.

Definition at line 912 of file coord.c.

+ Here is the caller graph for this function:

◆ fr_coord_post_event_insert()

int fr_coord_post_event_insert ( fr_event_list_t *  el)

Insert instance specific post-event callbacks.

Definition at line 861 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_pre_event_insert()

int fr_coord_pre_event_insert ( fr_event_list_t *  el)

Insert instance specific pre-event callbacks.

Definition at line 836 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_register()

fr_coord_reg_t * fr_coord_register ( fr_coord_reg_ctx_t *  reg_ctx)

Register a coordinator.

To be called from mod_instantiate of a module which uses a coordinator

Parameters
reg_ctxRegistration data
Returns
  • coordination registration on success
  • NULL on failure

Definition at line 137 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_start()

int fr_coord_start ( uint32_t  num_workers,
fr_sem_t *  sem 
)

Start all registered coordinator threads in multi-threaded mode.

Parameters
num_workersThe number of workers which will be attaching
semSemaphore to use signalling the threads are ready
Returns
  • 0 on success
  • -1 on failure

Definition at line 553 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_thread_join()

void fr_coord_thread_join ( void  )

Wait for all the coordinator threads to exit.

To be called during the scheduler shutdown in multi-threaded mode.

Definition at line 185 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_to_worker_broadcast()

int fr_coord_to_worker_broadcast ( fr_coord_t *  coord,
uint32_t  cb_id,
fr_dbuff_t *  dbuff 
)

Broadcast data from a coordinator to all workers.

Parameters
coordCoordinator which is sending the data.
cb_idCallback ID for the workers to run.
dbuffBuffer containing data to send.
Returns
  • 0 on success
  • <0 on failure - indicating the number of sends which failed.

Definition at line 789 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coord_to_worker_send()

int fr_coord_to_worker_send ( fr_coord_t *  coord,
int32_t  worker_id,
uint32_t  cb_id,
fr_dbuff_t *  dbuff 
)

Send generic data from a coordinator to a worker.

Parameters
coordCoordinator which is sending the data.
worker_idWorker to send data to.
cb_idCallback ID for the worker to run.
dbuffBuffer containing data to send.
Returns
  • 0 on success
  • <0 on failure

Definition at line 754 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coordinate()

static void fr_coordinate ( fr_coord_t *  coord)
static

Run the event loop for a coordinator thread when in multi-threaded mode.

Definition at line 438 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coordinate_thread()

static void * fr_coordinate_thread ( void *  arg)
static

Entry point for a coordinator thread.

Definition at line 506 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coords_create()

int fr_coords_create ( TALLOC_CTX *  ctx,
fr_event_list_t *  el 
)

Start coordinators in single threaded mode.

Definition at line 621 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_coords_destroy()

void fr_coords_destroy ( void  )

Clean up coordinators in single threaded mode.

Definition at line 603 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_worker_to_coord_send()

int fr_worker_to_coord_send ( fr_coord_worker_t *  cw,
uint32_t  cb_id,
fr_dbuff_t *  dbuff 
)

Send data from a worker to a coordinator.

Parameters
cwWorker side of coordinator sending the data.
cb_idCallback ID for the coordinator to run.
dbuffBuffer containing data to send.
Returns
  • 0 on success
  • < 0 on failure

Definition at line 811 of file coord.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ coord_regs

fr_dlist_head_t* coord_regs = NULL
static

Definition at line 43 of file coord.c.

◆ coord_threads

fr_dlist_head_t* coord_threads = NULL
static

Definition at line 44 of file coord.c.

◆ coords

fr_rb_tree_t coords = (fr_rb_tree_t){ .num_elements = 0 }
static

Definition at line 45 of file coord.c.