dnxWLM.c File Reference

Implements the Work Load Manager functionality. More...

#include "dnxWLM.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxLogging.h"
#include "dnxTransport.h"
#include "dnxSleep.h"
#include "dnxClntProt.h"
#include "dnxPlugin.h"
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <ifaddrs.h>

Go to the source code of this file.

Data Structures

struct  DnxWorkerStatus
 A structure that describes the attribues of a pool thread. More...
struct  iDnxWlm
 The implementation of a work load manager object. More...

Defines

#define elemcount(x)   (sizeof(x)/sizeof(*(x)))
#define MAX_RESULT_DATA   1024
#define MAX_IP_ADDRSZ   64

Enumerations

enum  DnxThreadState { DNX_THREAD_DEAD = 0, DNX_THREAD_RUNNING, DNX_THREAD_ZOMBIE }
 A value that indicates that current state of a pool thread. More...

Functions

static void * dnxWorker (void *data)
 The main thread routine for a worker thread.
static void logConfigChanges (DnxWlmCfgData *ocp, DnxWlmCfgData *ncp)
 Log changes between old and new configuration data sets.
static int initWorkerComm (DnxWorkerStatus *ws)
 Initialize worker thread communication resources.
static void releaseWorkerComm (DnxWorkerStatus *ws)
 Clean up worker thread communications resources.
static int workerCreate (iDnxWlm *iwlm, DnxWorkerStatus **pws)
 Create a new worker thread.
static void cleanThreadPool (iDnxWlm *iwlm)
 Clean up zombie threads and compact the thread pool.
static int growThreadPool (iDnxWlm *iwlm)
 Grow the thread pool to the configured number of threads.
static void dnxWorkerCleanup (void *data)
 Dispatch thread clean-up routine.
void dnxWlmResetStats (DnxWlm *wlm)
 Reset all WLM statistics counters.
void dnxWlmGetStats (DnxWlm *wlm, DnxWlmStats *wsp)
 Return a snapshot of WLM statistics.
int dnxWlmReconfigure (DnxWlm *wlm, DnxWlmCfgData *cfg)
 Reconfigure an existing Work Load Manager object.
int dnxWlmCreate (DnxWlmCfgData *cfg, DnxWlm **pwlm)
 Creates a new Work Load Manager object.
void dnxWlmDestroy (DnxWlm *wlm)
 The main thread routine for the work load manager.


Detailed Description

Implements the Work Load Manager functionality.

Functions:

1. Started by the DNX Client main 2. Creates the initial thread pool 3. Monitors the thread pool for the need to increase worker thread count 4. Cleans-up worker threads upon shutdown

Author:
Robert W. Ingraham (dnx-devel@lists.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxWLM.c.


Define Documentation

#define elemcount (  )     (sizeof(x)/sizeof(*(x)))

Definition at line 61 of file dnxWLM.c.

#define MAX_IP_ADDRSZ   64

Definition at line 66 of file dnxWLM.c.

#define MAX_RESULT_DATA   1024

Todo:
Dynamically allocate based on config file maxResultBuffer setting.

Definition at line 64 of file dnxWLM.c.

Referenced by dnxWorker().


Enumeration Type Documentation

A value that indicates that current state of a pool thread.

Enumerator:
DNX_THREAD_DEAD 
DNX_THREAD_RUNNING 
DNX_THREAD_ZOMBIE 

Definition at line 71 of file dnxWLM.c.


Function Documentation

static void cleanThreadPool ( iDnxWlm iwlm  )  [static]

Clean up zombie threads and compact the thread pool.

Parameters:
[in] iwlm - a pointer to the work load manager data structure.

Definition at line 308 of file dnxWLM.c.

References DNX_THREAD_ZOMBIE, dnxDebug(), iDnxWlm::pool, releaseWorkerComm(), DnxWorkerStatus::state, iDnxWlm::tdestroyed, iDnxWlm::threads, iDnxWlm::threadtm, DnxWorkerStatus::tid, DnxWorkerStatus::tstart, and xfree.

Referenced by dnxWlmDestroy(), and dnxWorker().

int dnxWlmCreate ( DnxWlmCfgData cfg,
DnxWlm **  pwlm 
)

Creates a new Work Load Manager object.

Parameters:
[in] cfg - a reference to the WLM configuration data structure.
[out] pwlm - the address of storage for the returned WLM object.
Returns:
Zero on success, or a non-zero error value.

Definition at line 676 of file dnxWLM.c.

References iDnxWlm::cfg, DnxWlmCfgData::collectorUrl, DnxWlmCfgData::dispatcherUrl, DNX_ERR_MEMORY, DNX_OK, DNX_PT_MUTEX_DESTROY, DNX_PT_MUTEX_INIT, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, dnxErrorString(), dnxLog(), growThreadPool(), iDnxWlm::minexectm, iDnxWlm::mutex, iDnxWlm::myipaddr, iDnxWlm::myipaddrstr, iDnxWlm::pool, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, iDnxWlm::poolsz, iDnxWlm::threads, xfree, xmalloc, and xstrdup.

Referenced by main().

void dnxWlmDestroy ( DnxWlm wlm  ) 

void dnxWlmGetStats ( DnxWlm wlm,
DnxWlmStats wsp 
)

int dnxWlmReconfigure ( DnxWlm wlm,
DnxWlmCfgData cfg 
)

Reconfigure an existing Work Load Manager object.

Parameters:
[in] wlm - the work load manager object to be reconfigured.
[in] cfg - the new configuration parameters.
Returns:
Zero on success, or a non-zero error value.

Definition at line 620 of file dnxWLM.c.

References iDnxWlm::cfg, DNX_ERR_MEMORY, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, dnxCancelableSleep(), logConfigChanges(), DnxWlmCfgData::maxResults, DnxWlmCfgData::maxRetries, iDnxWlm::mutex, DnxWlmCfgData::pollInterval, iDnxWlm::pool, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, iDnxWlm::poolsz, DnxWlmCfgData::reqTimeout, DnxWlmCfgData::showNodeAddr, DnxWlmCfgData::shutdownGrace, iDnxWlm::threads, DnxWlmCfgData::ttlBackoff, and xrealloc.

void dnxWlmResetStats ( DnxWlm wlm  ) 

static void * dnxWorker ( void *  data  )  [static]

The main thread routine for a worker thread.

Parameters:
[in] data - an opaque pointer to a DnxWorkerStatus structure for this thread.
Returns:
Always returns 0.

Todo:
Allocate result data buffer based on configured buffer size.

Definition at line 403 of file dnxWLM.c.

References iDnxWlm::active, iDnxWlm::avgexectm, iDnxWlm::cfg, cleanThreadPool(), DnxJob::cmd, DnxWorkerStatus::collect, DnxResult::delta, DnxWorkerStatus::dispatch, DNX_ERR_ADDRESS, DNX_ERR_TIMEOUT, DNX_JOB_COMPLETE, DNX_OBJ_WORKER, DNX_OK, DNX_PLUGIN_RESULT_OK, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, DNX_REQ_REGISTER, dnxCancelableSleep(), dnxDebug(), dnxErrorString(), dnxLog(), dnxMakeXID(), dnxPluginExecute(), dnxSendNodeRequest(), dnxSendResult(), dnxWaitForJob(), dnxWorkerCleanup(), growThreadPool(), DnxWorkerStatus::iwlm, DnxNodeRequest::jobCap, iDnxWlm::jobsfail, iDnxWlm::jobsok, iDnxWlm::jobsrcvd, iDnxWlm::jobtm, MAX_RESULT_DATA, iDnxWlm::maxexectm, DnxWlmCfgData::maxRetries, iDnxWlm::minexectm, iDnxWlm::mutex, iDnxWlm::myipaddr, iDnxWlm::myipaddrstr, DnxXID::objSerial, DnxXID::objSlot, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, iDnxWlm::reqsent, DnxWlmCfgData::reqTimeout, DnxNodeRequest::reqType, DnxResult::resCode, DnxResult::resData, DnxWorkerStatus::serial, DnxWlmCfgData::showNodeAddr, DnxResult::state, iDnxWlm::terminate, iDnxWlm::threads, DnxJob::timeout, DnxWorkerStatus::tstart, DnxNodeRequest::ttl, DnxWlmCfgData::ttlBackoff, xfree, DnxResult::xid, DnxJob::xid, DnxNodeRequest::xid, and xstrdup.

Referenced by workerCreate().

static void dnxWorkerCleanup ( void *  data  )  [static]

Dispatch thread clean-up routine.

Parameters:
[in] data - an opaque pointer to a worker's status data structure.

Definition at line 386 of file dnxWLM.c.

References DNX_THREAD_ZOMBIE, dnxDebug(), and DnxWorkerStatus::state.

Referenced by dnxWorker().

static int growThreadPool ( iDnxWlm iwlm  )  [static]

Grow the thread pool to the configured number of threads.

This routine calculates an appropriate growth factor. If the current number of threads is less than the requested initial pool size, then the pool is grown to the initial pool size. If the current number of threads is near the maximum pool size, then only grow to the maximum. Otherwise it is grown by the configured pool growth value.

Parameters:
[in] iwlm - a reference to the work load manager whose thread pool size is to be increased.
Returns:
Zero on success, or a non-zero error value.

Definition at line 355 of file dnxWLM.c.

References iDnxWlm::cfg, dnxLog(), iDnxWlm::pool, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, iDnxWlm::tcreated, iDnxWlm::threads, and workerCreate().

Referenced by dnxWlmCreate(), and dnxWorker().

static int initWorkerComm ( DnxWorkerStatus ws  )  [static]

Initialize worker thread communication resources.

Parameters:
[in] ws - a pointer to a worker thread's status data structure.
Returns:
Zero on success, or a non-zero error value.

Definition at line 200 of file dnxWLM.c.

References iDnxWlm::cfg, DnxWorkerStatus::collect, DnxWlmCfgData::collectorUrl, DnxWorkerStatus::dispatch, DnxWlmCfgData::dispatcherUrl, DNX_MODE_ACTIVE, DNX_OK, dnxChanMapAdd(), dnxChanMapDelete(), dnxConnect(), dnxDisconnect(), dnxErrorString(), dnxLog(), elemcount, and DnxWorkerStatus::iwlm.

Referenced by workerCreate().

static void logConfigChanges ( DnxWlmCfgData ocp,
DnxWlmCfgData ncp 
) [static]

Log changes between old and new configuration data sets.

Dynamic reconfiguration of dispatcher and collector URL's is not allowed so we don't need to check differences in those string values.

Parameters:
[in] ocp - a reference to the old configuration data set.
[in] ncp - a reference to the new configuration data set.

Definition at line 134 of file dnxWLM.c.

References DnxWlmCfgData::collectorUrl, DnxWlmCfgData::dispatcherUrl, dnxLog(), DnxWlmCfgData::maxResults, DnxWlmCfgData::maxRetries, DnxWlmCfgData::pollInterval, DnxWlmCfgData::poolGrow, DnxWlmCfgData::poolInitial, DnxWlmCfgData::poolMax, DnxWlmCfgData::poolMin, DnxWlmCfgData::reqTimeout, DnxWlmCfgData::showNodeAddr, DnxWlmCfgData::shutdownGrace, and DnxWlmCfgData::ttlBackoff.

Referenced by dnxWlmReconfigure().

static void releaseWorkerComm ( DnxWorkerStatus ws  )  [static]

Clean up worker thread communications resources.

Parameters:
[in] ws - a pointer to a worker thread's status data structure.

Definition at line 246 of file dnxWLM.c.

References DnxWorkerStatus::collect, DnxWorkerStatus::dispatch, dnxChanMapDelete(), and dnxDisconnect().

Referenced by cleanThreadPool(), and workerCreate().

static int workerCreate ( iDnxWlm iwlm,
DnxWorkerStatus **  pws 
) [static]

Create a new worker thread.

Parameters:
[in] iwlm - the WLM object whose thread pool is being updated.
[in] pws - the address of storage for the address of the newly allocated and configured worker status structure.
Returns:
Zero on success, or a non-zero error value.

Definition at line 271 of file dnxWLM.c.

References DNX_ERR_MEMORY, DNX_ERR_THREAD, DNX_THREAD_RUNNING, dnxErrorString(), dnxLog(), dnxWorker(), initWorkerComm(), DnxWorkerStatus::iwlm, releaseWorkerComm(), DnxWorkerStatus::state, DnxWorkerStatus::tid, xfree, and xmalloc.

Referenced by growThreadPool().


Generated on Tue Apr 13 15:48:07 2010 for DNX by  doxygen 1.5.6