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_thread * | get_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_thread * | dedos_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 [] |
Control spawned threads with message queue within DeDOS.
Definition in file dedos_threads.c.
| #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.
| 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 |
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.
| thread_init_v | Pointer 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.
|
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 |
Initializes a dedos_thread structure to contain the appropriate fields.
Definition at line 92 of file dedos_threads.c.
|
inlinestatic |
Initilizes the stat items associated with a thread.
Definition at line 66 of file dedos_threads.c.
|
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.
| init_fn | The function to execute once, at the start of the thread |
| destroy_fn | The function to execute when the thread exits |
| mode | [un]pinned |
| id | Unique identifier for the thread |
| thread | The 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.
| thread | The thread to block from |
| abs_timeout | Time since epoch at which thread should block until |
Definition at line 234 of file dedos_threads.c.
|
static |
Static structure to hold created dedos_thread's.
Definition at line 49 of file dedos_threads.c.
|
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[] |
Definition at line 53 of file dedos_threads.c.
1.8.6