The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | 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 MIN_WORKER_ID   -1
 The minimum value we expect as worker id. -1 is the main thread.
 

Typedefs

typedef enum fr_coord_control_event_t fr_coord_control_event_t
 Events on a coordinator's control plane, sent by workers, in the FR_CONTROL_EVENTSET_COORD event set.
 
typedef enum fr_coord_worker_control_event_t fr_coord_worker_control_event_t
 Events on a coordinator worker's control plane, sent by the coordinator, in the FR_CONTROL_EVENTSET_COORD event set.
 

Enumerations

enum  fr_coord_control_event_t : uint16_t {
  FR_COORD_CONTROL_WORKER_ATTACH = 0 ,
  FR_COORD_CONTROL_WORKER_DETACH ,
  FR_COORD_CONTROL_DATA
}
 Events on a coordinator's control plane, sent by workers, in the FR_CONTROL_EVENTSET_COORD event set. More...
 
enum  fr_coord_worker_control_event_t : uint16_t {
  FR_COORD_WORKER_CONTROL_ACK = 0 ,
  FR_COORD_WORKER_CONTROL_DATA
}
 Events on a coordinator worker's control plane, sent by the coordinator, in the FR_CONTROL_EVENTSET_COORD event set. More...
 

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
2892e3b717ae3f9f1ea2cf36dcf2c3a7a4f50fd6

Definition in file coord.c.


Data Structure Documentation

◆ fr_coord_reg_s

struct fr_coord_reg_s

A coordinator registration.

Definition at line 93 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 59 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_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 116 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 122 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 82 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_schedule_coord_t

struct fr_schedule_coord_t

Scheduler specific information for coordinator threads.

Definition at line 105 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

◆ MIN_WORKER_ID

#define MIN_WORKER_ID   -1

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

Definition at line 51 of file coord.c.

Typedef Documentation

◆ fr_coord_control_event_t

Events on a coordinator's control plane, sent by workers, in the FR_CONTROL_EVENTSET_COORD event set.

◆ fr_coord_worker_control_event_t

Events on a coordinator worker's control plane, sent by the coordinator, in the FR_CONTROL_EVENTSET_COORD event set.

Enumeration Type Documentation

◆ fr_coord_control_event_t

Events on a coordinator's control plane, sent by workers, in the FR_CONTROL_EVENTSET_COORD event set.

Enumerator
FR_COORD_CONTROL_WORKER_ATTACH 

Message sent from worker to attach to a coordinator.

FR_COORD_CONTROL_WORKER_DETACH 

Message sent from worker to detach from a coordinator.

FR_COORD_CONTROL_DATA 

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

Definition at line 38 of file coord.c.

◆ fr_coord_worker_control_event_t

Events on a coordinator worker's control plane, sent by the coordinator, in the FR_CONTROL_EVENTSET_COORD event set.

Enumerator
FR_COORD_WORKER_CONTROL_ACK 

Message sent to worker to acknowledge attach / detach.

FR_COORD_WORKER_CONTROL_DATA 

Coordinator -> worker message to pass data to a callback.

Definition at line 46 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 129 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 213 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 277 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 247 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 300 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 669 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 689 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 900 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 884 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 346 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 180 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 424 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 650 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 907 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 856 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 831 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 145 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 551 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 193 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 784 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 749 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 436 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 504 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 619 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 601 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 806 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 53 of file coord.c.

◆ coord_threads

fr_dlist_head_t* coord_threads = NULL
static

Definition at line 54 of file coord.c.

◆ coords

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

Definition at line 55 of file coord.c.