The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
schedule.c File Reference

Network / worker thread scheduling. More...

#include <freeradius-devel/autoconf.h>
#include <freeradius-devel/io/schedule.h>
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/rb.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/server/trigger.h>
#include <pthread.h>
+ Include dependency graph for schedule.c:

Go to the source code of this file.

Data Structures

struct  fr_schedule_network_t
 Scheduler specific information for network threads. More...
 
struct  fr_schedule_s
 The scheduler. More...
 
struct  fr_schedule_worker_t
 Scheduler specific information for worker threads. More...
 

Macros

#define LOG_DST   sc->log
 
#define SEM_WAIT_INTR(_x)   do {if (sem_wait(_x) == 0) break;} while (errno == EINTR)
 
#define SEMAPHORE_LOCKED   (0)
 

Typedefs

typedef enum fr_schedule_child_status_t fr_schedule_child_status_t
 Track the child thread status. More...
 

Enumerations

enum  fr_schedule_child_status_t {
  FR_CHILD_FREE = 0 ,
  FR_CHILD_INITIALIZING ,
  FR_CHILD_RUNNING ,
  FR_CHILD_EXITED ,
  FR_CHILD_FAIL
}
 Track the child thread status. More...
 

Functions

fr_schedule_tfr_schedule_create (TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t *logger, fr_log_lvl_t lvl, fr_schedule_thread_instantiate_t worker_thread_instantiate, fr_schedule_thread_detach_t worker_thread_detach, fr_schedule_config_t *config)
 Create a scheduler and spawn the child threads. More...
 
int fr_schedule_destroy (fr_schedule_t **sc_to_free)
 Destroy a scheduler, and tell its child threads to exit. More...
 
fr_network_tfr_schedule_directory_add (fr_schedule_t *sc, fr_listen_t *li)
 Add a directory NOTE_EXTEND to a scheduler. More...
 
fr_network_tfr_schedule_listen_add (fr_schedule_t *sc, fr_listen_t *li)
 Add a fr_listen_t to a scheduler. More...
 
static void * fr_schedule_network_thread (void *arg)
 Initialize and run the network thread. More...
 
int fr_schedule_pthread_create (pthread_t *thread, void *(*func)(void *), void *arg)
 Creates a new thread using our standard set of options. More...
 
int fr_schedule_worker_id (void)
 Return the worker id for the current thread. More...
 
static void * fr_schedule_worker_thread (void *arg)
 Entry point for worker threads. More...
 
static void stats_timer (fr_event_list_t *el, fr_time_t now, void *uctx)
 

Variables

static _Thread_local int worker_id
 Internal ID of the current worker thread. More...
 

Detailed Description

Network / worker thread scheduling.

Id
eb4ec47bf0228a87b36c1f8c69b6d8e8f919a280

Definition in file schedule.c.


Data Structure Documentation

◆ fr_schedule_network_t

struct fr_schedule_network_t

Scheduler specific information for network threads.

Wraps a fr_network_t, tracking additional information that the scheduler uses.

Definition at line 105 of file schedule.c.

+ Collaboration diagram for fr_schedule_network_t:
Data Fields
TALLOC_CTX * ctx our allocation ctx
fr_dlist_t entry our entry into the linked list of networks
fr_event_timer_t const * ev timer for stats_interval
unsigned int id a unique ID
fr_network_t * nr the receive data structure
pthread_t pthread_id the thread of this network
fr_schedule_t * sc the scheduler we are running under
fr_schedule_child_status_t status status of the worker

◆ fr_schedule_s

struct fr_schedule_s

The scheduler.

Definition at line 125 of file schedule.c.

+ Collaboration diagram for fr_schedule_s:
Data Fields
fr_schedule_config_t * config configuration
CONF_SECTION * cs thread pool configuration section
fr_event_list_t * el event list for single-threaded mode.
fr_log_t * log log destination
fr_log_lvl_t lvl log level
sem_t network_sem for inter-thread signaling
fr_dlist_head_t networks list of networks
unsigned int num_workers_exited number of exited workers
bool running is the scheduler running?
fr_network_t * single_network for single-threaded mode
fr_worker_t * single_worker for single-threaded mode
sem_t worker_sem for inter-thread signaling
fr_schedule_thread_detach_t worker_thread_detach
fr_schedule_thread_instantiate_t worker_thread_instantiate thread instantiation callback
fr_dlist_head_t workers list of workers

◆ fr_schedule_worker_t

struct fr_schedule_worker_t

Scheduler specific information for worker threads.

Wraps a fr_worker_t, tracking additional information that the scheduler uses.

Definition at line 83 of file schedule.c.

+ Collaboration diagram for fr_schedule_worker_t:
Data Fields
fr_channel_t * ch channel for communicating with the worker
fr_time_t cpu_time how much CPU time this worker has used
TALLOC_CTX * ctx our allocation ctx
fr_event_list_t * el our event list
fr_dlist_t entry our entry into the linked list of workers
unsigned int id a unique ID

ID of the worker 0..N.

int id ID of the worker 0..N.
pthread_t pthread_id the thread of this worker

pthread ID of the worker

fr_schedule_t * sc the scheduler we are running under
fr_schedule_child_status_t status status of the worker
int uses how many network threads are using it
fr_worker_t * worker the worker data structure

pointer to the worker

Macro Definition Documentation

◆ LOG_DST

#define LOG_DST   sc->log

Definition at line 27 of file schedule.c.

◆ SEM_WAIT_INTR

#define SEM_WAIT_INTR (   _x)    do {if (sem_wait(_x) == 0) break;} while (errno == EINTR)

Definition at line 65 of file schedule.c.

◆ SEMAPHORE_LOCKED

#define SEMAPHORE_LOCKED   (0)

Definition at line 46 of file schedule.c.

Typedef Documentation

◆ fr_schedule_child_status_t

Track the child thread status.

Enumeration Type Documentation

◆ fr_schedule_child_status_t

Track the child thread status.

Enumerator
FR_CHILD_FREE 

child is free

FR_CHILD_INITIALIZING 

initialized, but not running

FR_CHILD_RUNNING 

running, and in the running queue

FR_CHILD_EXITED 

exited, and in the exited queue

FR_CHILD_FAIL 

failed, and in the exited queue

Definition at line 70 of file schedule.c.

Function Documentation

◆ fr_schedule_create()

fr_schedule_t* fr_schedule_create ( TALLOC_CTX *  ctx,
fr_event_list_t el,
fr_log_t logger,
fr_log_lvl_t  lvl,
fr_schedule_thread_instantiate_t  worker_thread_instantiate,
fr_schedule_thread_detach_t  worker_thread_detach,
fr_schedule_config_t config 
)

Create a scheduler and spawn the child threads.

Parameters
[in]ctxtalloc context.
[in]elevent list, only for single-threaded mode.
[in]loggerdestination for all logging messages.
[in]lvllog level.
[in]worker_thread_instantiatecallback for new worker threads.
[in]worker_thread_detachcallback to destroy resources allocated by worker_thread_instantiate.
[in]configconfiguration for the scheduler
Returns
  • NULL on error
  • fr_schedule_t new scheduler

Definition at line 409 of file schedule.c.

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

◆ fr_schedule_destroy()

int fr_schedule_destroy ( fr_schedule_t **  sc_to_free)

Destroy a scheduler, and tell its child threads to exit.

Note
This may be called with no worker or network threads in the case of a instantiation error. This function should deal with that condition gracefully.
Parameters
[in]sc_to_freethe scheduler
Returns
  • <0 on error
  • 0 on success

Definition at line 703 of file schedule.c.

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

◆ fr_schedule_directory_add()

fr_network_t* fr_schedule_directory_add ( fr_schedule_t sc,
fr_listen_t li 
)

Add a directory NOTE_EXTEND to a scheduler.

Parameters
[in]scthe scheduler
[in]lithe ctx and callbacks for the transport.
Returns
  • NULL on error
  • the fr_network_t that the socket was added to.

Definition at line 855 of file schedule.c.

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

◆ fr_schedule_listen_add()

fr_network_t* fr_schedule_listen_add ( fr_schedule_t sc,
fr_listen_t li 
)

Add a fr_listen_t to a scheduler.

Parameters
[in]scthe scheduler
[in]lithe ctx and callbacks for the transport.
Returns
  • NULL on error
  • the fr_network_t that the socket was added to.

Definition at line 823 of file schedule.c.

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

◆ fr_schedule_network_thread()

static void* fr_schedule_network_thread ( void *  arg)
static

Initialize and run the network thread.

Parameters
[in]argthe fr_schedule_network_t
Returns
NULL

Definition at line 288 of file schedule.c.

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

◆ fr_schedule_pthread_create()

int fr_schedule_pthread_create ( pthread_t *  thread,
void *(*)(void *)  func,
void *  arg 
)

Creates a new thread using our standard set of options.

New threads are:

  • Joinable, i.e. you can call pthread_join on them to confirm they've exited
  • Immune to catchable signals.
Parameters
[out]threadhandled that was created by pthread_create.
[in]funcentry point for the thread.
[in]argArgument to pass to func.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 371 of file schedule.c.

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

◆ fr_schedule_worker_id()

int fr_schedule_worker_id ( void  )

Return the worker id for the current thread.

Returns
worker ID

Definition at line 157 of file schedule.c.

◆ fr_schedule_worker_thread()

static void* fr_schedule_worker_thread ( void *  arg)
static

Entry point for worker threads.

Parameters
[in]argthe fr_schedule_worker_t
Returns
NULL

Definition at line 167 of file schedule.c.

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

◆ stats_timer()

static void stats_timer ( fr_event_list_t el,
fr_time_t  now,
void *  uctx 
)
static

Definition at line 274 of file schedule.c.

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

Variable Documentation

◆ worker_id

_Thread_local int worker_id
static

Internal ID of the current worker thread.

Definition at line 151 of file schedule.c.