The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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.
 

Functions

static int8_t coord_cmp (void const *one, void const *two)
 Compare coordinators by registration.
 
static void coord_data_recv (void *ctx, void const *data, size_t data_size, fr_time_t now)
 Callback for a coordinator receiving data from a worker.
 
static void coord_worker_attach (void *ctx, void const *data, NDEBUG_UNUSED size_t data_size, UNUSED fr_time_t now)
 Callback run by a coordinator when a worker attaches.
 
static void coord_worker_data_recv (void *ctx, void const *data, size_t data_size, fr_time_t now)
 Callback for a worker receiving data from a coordinator.
 
static void coord_worker_detach (void *ctx, void const *data, NDEBUG_UNUSED size_t data_size, UNUSED fr_time_t now)
 Callback run by a coordinator when a worker detaches.
 
static void coordinate_worker_ack (UNUSED void *ctx, NDEBUG_UNUSED void const *data, NDEBUG_UNUSED size_t data_size, UNUSED fr_time_t now)
 A worker got an ack from a coordinator in response to attach / detach.
 
fr_coord_worker_tfr_coord_attach (TALLOC_CTX *ctx, fr_event_list_t *el, fr_coord_reg_t *coord_reg)
 Attach a worker to a coordinator.
 
static fr_coord_tfr_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.
 
int fr_coord_detach (fr_coord_worker_t *cw, bool exiting)
 Signal a coordinator that a worker wants to detach.
 
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_tfr_coord_register (TALLOC_CTX *ctx, 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.
 
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, uint32_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_tcoord_regs = NULL
 
static fr_dlist_head_tcoord_threads = NULL
 
static fr_rb_tree_t coords = (fr_rb_tree_t){ .num_elements = 0 }
 

Detailed Description

Coordination thread management.

Id
7fc62cb27893f4f8957139302e4609b18b2565cf

Definition in file coord.c.


Data Structure Documentation

◆ fr_coord_reg_s

struct fr_coord_reg_s

A coordinator registration.

Definition at line 83 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.
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 47 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 105 of file coord.c.

+ Collaboration diagram for fr_coord_worker_attach_msg_t:
Data Fields
uint32_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 111 of file coord.c.

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

◆ fr_coord_worker_s

struct fr_coord_worker_s

The worker end of worker <-> coordinator communication.

Definition at line 71 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 94 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.

Function Documentation

◆ coord_cmp()

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

Compare coordinators by registration.

Definition at line 118 of file coord.c.

+ Here is the caller graph for this function:

◆ coord_data_recv()

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

Callback for a coordinator receiving data from a worker.

Definition at line 200 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 *  ctx,
void const *  data,
NDEBUG_UNUSED size_t  data_size,
UNUSED fr_time_t  now 
)
static

Callback run by a coordinator when a worker attaches.

Definition at line 258 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 *  ctx,
void const *  data,
size_t  data_size,
fr_time_t  now 
)
static

Callback for a worker receiving data from a coordinator.

Definition at line 231 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 *  ctx,
void const *  data,
NDEBUG_UNUSED size_t  data_size,
UNUSED fr_time_t  now 
)
static

Callback run by a coordinator when a worker detaches.

Definition at line 279 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 ( UNUSED void *  ctx,
NDEBUG_UNUSED void const *  data,
NDEBUG_UNUSED size_t  data_size,
UNUSED fr_time_t  now 
)
static

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

Definition at line 608 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 628 of file coord.c.

+ Here is the call 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 311 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

When running in threaded mode, will wait for the coordinator to exit.

Parameters
coord_regto de-register

Definition at line 167 of file coord.c.

+ Here is the call 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 589 of file coord.c.

+ Here is the call 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 796 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 771 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 ( TALLOC_CTX *  ctx,
fr_coord_reg_ctx_t reg_ctx 
)

Register a coordinator.

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

Parameters
ctxto allocate registration under
reg_ctxRegistration data
Returns
  • coordination registration on success
  • NULL on failure

Definition at line 135 of file coord.c.

+ Here is the call 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 490 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 724 of file coord.c.

+ Here is the call graph for this function:

◆ fr_coord_to_worker_send()

int fr_coord_to_worker_send ( fr_coord_t coord,
uint32_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 691 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 394 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 443 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 558 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 540 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 746 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 41 of file coord.c.

◆ coord_threads

fr_dlist_head_t* coord_threads = NULL
static

Definition at line 42 of file coord.c.

◆ coords

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

Definition at line 43 of file coord.c.