My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Macros | Functions | Variables
dedos_threads.c File Reference

Control spawned threads with message queue within DeDOS. More...

#include "dedos_threads.h"
#include "thread_message.h"
#include "output_thread.h"
#include "logging.h"
#include "rt_stats.h"
#include <stdbool.h>
#include <stdlib.h>
#include <sched.h>
#include <sys/resource.h>

Go to the source code of this file.

Classes

struct  thread_init
 Structure which holds the initialization info for a dedos_thread. More...
 

Macros

#define _GNU_SOURCE
 Needed for CPU_SET etc. More...
 
#define MAX_DEDOS_THREAD_ID   32
 The maximum identifier that can be used for a dedos_thread. More...
 
#define MAX_CORES   16
 The maximum number of cores that can be present on a node. More...
 
#define OUTPUT_THREAD_INDEX   MAX_DEDOS_THREAD_ID + 1
 The index at which to store the dedos_thread handling sending messages. More...
 
#define N_THREAD_STAT_ITEMS   sizeof(thread_stat_items) / sizeof(*thread_stat_items)
 
#define DEFAULT_WAIT_TIMEOUT_S   1
 The amount of time that thread_wait should wait for if no timeout is provided. More...
 
#define MAX_METRIC_INTERVAL_MS   500
 

Functions

static void init_thread_stat_items (int id)
 Initilizes the stat items associated with a thread. More...
 
struct dedos_threadget_dedos_thread (int id)
 Returns the dedos_thread with the given ID. More...
 
static int init_dedos_thread (struct dedos_thread *thread, enum thread_mode mode, int id)
 Initializes a dedos_thread structure to contain the appropriate fields. More...
 
static int pin_thread (pthread_t ptid)
 Pins the thread with the pthread id ptid to the first unused core. More...
 
void dedos_thread_stop (struct dedos_thread *thread)
 Sets the exit signal for a thread, causing the main loop to quit. More...
 
void dedos_thread_join (struct dedos_thread *thread)
 Joins and destroys the dedos_thread. More...
 
int dedos_thread_should_exit (struct dedos_thread *thread)
 Returns 1 if the exit signal has been triggered, otherwise 0. More...
 
static void * dedos_thread_starter (void *thread_init_v)
 The actual function passed to pthread_create() that starts a new thread. More...
 
static void gather_thread_metrics (struct dedos_thread *thread)
 
int thread_wait (struct dedos_thread *thread, struct timespec *abs_timeout)
 To be called from the thread, causes it to wait until a message has been received or the timeout has been reached. More...
 
int start_dedos_thread (dedos_thread_fn thread_fn, dedos_thread_init_fn init_fn, dedos_thread_destroy_fn destroy_fn, enum blocking_mode mode, int id, struct dedos_thread *thread)
 Initilizes and starts execution of a dedos_thread. More...
 

Variables

static struct dedos_threaddedos_threads [32+2]
 Static structure to hold created dedos_thread's. More...
 
static int pinned_cores [16]
 Keep track of which cores have been assigned to threads. More...
 
enum stat_id thread_stat_items []
 

Detailed Description

Control spawned threads with message queue within DeDOS.

Definition in file dedos_threads.c.

Macro Definition Documentation

#define _GNU_SOURCE

Needed for CPU_SET etc.

Definition at line 27 of file dedos_threads.c.

#define DEFAULT_WAIT_TIMEOUT_S   1

The amount of time that thread_wait should wait for if no timeout is provided.

Definition at line 230 of file dedos_threads.c.

#define MAX_CORES   16

The maximum number of cores that can be present on a node.

Definition at line 43 of file dedos_threads.c.

#define MAX_DEDOS_THREAD_ID   32

The maximum identifier that can be used for a dedos_thread.

Definition at line 41 of file dedos_threads.c.

#define MAX_METRIC_INTERVAL_MS   500

Definition at line 232 of file dedos_threads.c.

#define N_THREAD_STAT_ITEMS   sizeof(thread_stat_items) / sizeof(*thread_stat_items)

Definition at line 63 of file dedos_threads.c.

#define OUTPUT_THREAD_INDEX   MAX_DEDOS_THREAD_ID + 1

The index at which to store the dedos_thread handling sending messages.

Definition at line 46 of file dedos_threads.c.

Function Documentation

void dedos_thread_join ( struct dedos_thread thread)

Joins and destroys the dedos_thread.

Definition at line 158 of file dedos_threads.c.

int dedos_thread_should_exit ( struct dedos_thread thread)

Returns 1 if the exit signal has been triggered, otherwise 0.

Definition at line 163 of file dedos_threads.c.

static void* dedos_thread_starter ( void *  thread_init_v)
static

The actual function passed to pthread_create() that starts a new thread.

Initilizes the appropriate structures, posts to the start semaphore, then calls the appropriate function.

Parameters
thread_init_vPointer to the thread_init structure

Definition at line 176 of file dedos_threads.c.

void dedos_thread_stop ( struct dedos_thread thread)

Sets the exit signal for a thread, causing the main loop to quit.

Definition at line 149 of file dedos_threads.c.

static void gather_thread_metrics ( struct dedos_thread thread)
inlinestatic

Definition at line 210 of file dedos_threads.c.

struct dedos_thread* get_dedos_thread ( int  id)

Returns the dedos_thread with the given ID.

Definition at line 72 of file dedos_threads.c.

static int init_dedos_thread ( struct dedos_thread thread,
enum thread_mode  mode,
int  id 
)
static

Initializes a dedos_thread structure to contain the appropriate fields.

Definition at line 92 of file dedos_threads.c.

static void init_thread_stat_items ( int  id)
inlinestatic

Initilizes the stat items associated with a thread.

Definition at line 66 of file dedos_threads.c.

static int pin_thread ( pthread_t  ptid)
static

Pins the thread with the pthread id ptid to the first unused core.

Definition at line 127 of file dedos_threads.c.

int start_dedos_thread ( dedos_thread_fn  thread_fn,
dedos_thread_init_fn  init_fn,
dedos_thread_destroy_fn  destroy_fn,
enum blocking_mode  mode,
int  id,
struct dedos_thread thread 
)

Initilizes and starts execution of a dedos_thread.

Note: Blocks until the thread is started! thread_fn The function to execute once the thread starts.

Parameters
init_fnThe function to execute once, at the start of the thread
destroy_fnThe function to execute when the thread exits
mode[un]pinned
idUnique identifier for the thread
threadThe object into which to store the thread

Definition at line 269 of file dedos_threads.c.

int thread_wait ( struct dedos_thread thread,
struct timespec *  abs_timeout 
)

To be called from the thread, causes it to wait until a message has been received or the timeout has been reached.

Parameters
threadThe thread to block from
abs_timeoutTime since epoch at which thread should block until

Definition at line 234 of file dedos_threads.c.

Variable Documentation

struct dedos_thread* dedos_threads[32+2]
static

Static structure to hold created dedos_thread's.

Definition at line 49 of file dedos_threads.c.

int pinned_cores[16]
static

Keep track of which cores have been assigned to threads.

Definition at line 51 of file dedos_threads.c.

enum stat_id thread_stat_items[]