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

Defines the structures and functions used by MSUs on the local machine. More...

#include "local_msu.h"
#include "routing_strategies.h"
#include "logging.h"
#include "rt_stats.h"
#include "msu_message.h"
#include "inter_runtime_messages.h"
#include "thread_message.h"
#include "msu_state.h"
#include "msu_calls.h"
#include <stdlib.h>
#include <sys/resource.h>
#include <sys/time.h>

Go to the source code of this file.

Macros

#define __USE_GNU
 
#define MAX_MSU_ID   1024
 MOVEME: MAX_MSU_ID Defines the maximum ID that can be assigned to an MSU. More...
 
#define NUM_MSU_STAT_IDS   sizeof(MSU_STAT_IDS) / sizeof(enum stat_id)
 
#define RECORD_DIFF(dstat, rstat, id)   increment_stat(dstat, id, after.rstat - before->rstat)
 
#define RECORD_TIMEDIFF(dstat, rstat, id)
 

Functions

static struct local_msumsu_alloc ()
 Allocates the memory associated with an MSU structure. More...
 
static void msu_free (struct local_msu *msu)
 Frees the memory associated with an MSU structure, including any routes, messages in its queue, or states. More...
 
static int rm_from_local_registry (int id)
 Removes an MSU from the local MSU registry. More...
 
static int add_to_local_registry (struct local_msu *msu)
 Adds an MSU to the local registry so it can be referred to elsewhere by ID. More...
 
struct local_msuget_local_msu (unsigned int id)
 Gets the local MSU with the given ID, or NULL if N/A. More...
 
static void init_msu_stats (int msu_id)
 Initializes the stat IDS that are relevant to an MSU. More...
 
static void unregister_msu_stats (int msu_id)
 Unregisters the stat IDS that are relevant to an MSU. More...
 
struct local_msuinit_msu (unsigned int id, struct msu_type *type, struct worker_thread *thread, struct msu_init_data *data)
 Allocates and creates a new MSU of the specified type and ID on the given thread. More...
 
int try_destroy_msu (struct local_msu *msu)
 Destroys the MSU, but only if it has no states currently saved. More...
 
void destroy_msu (struct local_msu *msu)
 Calls type-specific destroy function and frees associated memory. More...
 
static int msu_receive (struct local_msu *msu, struct msu_msg *msg)
 Calls type-specific MSU receive function and records execution time. More...
 
static int gather_metrics_before (struct rusage *before)
 
static void record_metrics (struct rusage *before, int msu_id)
 
int msu_dequeue (struct local_msu *msu)
 Dequeus a message from a local MSU and calls its receive function. More...
 
int msu_error (struct local_msu *msu, struct msu_msg_hdr *hdr, int broadcast)
 

Variables

pthread_rwlock_t msu_registry_lock
 Lock to protect access to local msu registry. More...
 
struct local_msulocal_msu_registry [1024]
 Mapping of MSU ID to the specific instance of the local MSU. More...
 
static enum stat_id MSU_STAT_IDS []
 The stat IDs that are associated with an MSU, to be registered on MSU creation. More...
 

Detailed Description

Defines the structures and functions used by MSUs on the local machine.

Definition in file local_msu.c.

Macro Definition Documentation

#define __USE_GNU

Definition at line 36 of file local_msu.c.

#define MAX_MSU_ID   1024

MOVEME: MAX_MSU_ID Defines the maximum ID that can be assigned to an MSU.

Necessary becaues MSUs are indexed by ID in the local registry.

Definition at line 44 of file local_msu.c.

#define NUM_MSU_STAT_IDS   sizeof(MSU_STAT_IDS) / sizeof(enum stat_id)

Definition at line 171 of file local_msu.c.

#define RECORD_DIFF (   dstat,
  rstat,
  id 
)    increment_stat(dstat, id, after.rstat - before->rstat)

Definition at line 299 of file local_msu.c.

#define RECORD_TIMEDIFF (   dstat,
  rstat,
  id 
)
Value:
increment_stat(dstat, id, ((double)after.rstat.tv_sec + after.rstat.tv_usec * 1e-6) - \
((double)before->rstat.tv_sec + before->rstat.tv_usec * 1e-6))
int increment_stat(enum stat_id stat_id, unsigned int item_id, double value)
Increments the given statistic by the provided value.
Definition: rt_stats.c:389

Definition at line 302 of file local_msu.c.

Function Documentation

static int add_to_local_registry ( struct local_msu msu)
static

Adds an MSU to the local registry so it can be referred to elsewhere by ID.

Parameters
MSUthe local MSU to add to the registry
Returns
0 on success, -1 on error

Definition at line 114 of file local_msu.c.

void destroy_msu ( struct local_msu msu)

Calls type-specific destroy function and frees associated memory.

Definition at line 257 of file local_msu.c.

static int gather_metrics_before ( struct rusage *  before)
inlinestatic

Definition at line 291 of file local_msu.c.

struct local_msu* get_local_msu ( unsigned int  id)

Gets the local MSU with the given ID, or NULL if N/A.

Parameters
idID of the MSU to retrieve
Returns
local msu instance, or NULL on error

Definition at line 134 of file local_msu.c.

struct local_msu* init_msu ( unsigned int  id,
struct msu_type type,
struct worker_thread thread,
struct msu_init_data data 
)

Allocates and creates a new MSU of the specified type and ID on the given thread.

Parameters
idID of the MSU to be created
typeMSU type of the MSU to be created
threadThe thread on which this MSU is to be created
dataAny initial data that is passed to the MSU's specific init function
Returns
The created local MSU, or NULL on error

Definition at line 198 of file local_msu.c.

static void init_msu_stats ( int  msu_id)
static

Initializes the stat IDS that are relevant to an MSU.

Parameters
msu_idID of the msu to register

Definition at line 177 of file local_msu.c.

static struct local_msu* msu_alloc ( )
static

Allocates the memory associated with an MSU structure.

Returns
Pointer to allocated MSU

Definition at line 58 of file local_msu.c.

int msu_dequeue ( struct local_msu msu)

Dequeus a message from a local MSU and calls its receive function.

Parameters
msuMSU to dequeue the message from
Returns
0 on success, -1 on error, 1 if no message existed to be dequeued

Definition at line 323 of file local_msu.c.

int msu_error ( struct local_msu msu,
struct msu_msg_hdr hdr,
int  broadcast 
)

Definition at line 353 of file local_msu.c.

static void msu_free ( struct local_msu msu)
static

Frees the memory associated with an MSU structure, including any routes, messages in its queue, or states.

Definition at line 71 of file local_msu.c.

static int msu_receive ( struct local_msu msu,
struct msu_msg msg 
)
static

Calls type-specific MSU receive function and records execution time.

Parameters
msuMSU to receive data
dataData to be sent to MSU
Returns
0 on success, -1 on error

Definition at line 275 of file local_msu.c.

static void record_metrics ( struct rusage *  before,
int  msu_id 
)
inlinestatic

Definition at line 306 of file local_msu.c.

static int rm_from_local_registry ( int  id)
static

Removes an MSU from the local MSU registry.

Parameters
idID of the MSU to remove
Returns
0 on success, -1 on error

Definition at line 90 of file local_msu.c.

int try_destroy_msu ( struct local_msu msu)

Destroys the MSU, but only if it has no states currently saved.

Returns
0 on success, 1 if MSU cannot be destroyed

Definition at line 249 of file local_msu.c.

static void unregister_msu_stats ( int  msu_id)
static

Unregisters the stat IDS that are relevant to an MSU.

Parameters
msu_idID of the MSU to register

Definition at line 189 of file local_msu.c.

Variable Documentation

struct local_msu* local_msu_registry[1024]

Mapping of MSU ID to the specific instance of the local MSU.

Definition at line 52 of file local_msu.c.

pthread_rwlock_t msu_registry_lock

Lock to protect access to local msu registry.

Definition at line 50 of file local_msu.c.

enum stat_id MSU_STAT_IDS[]
static