pmm  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions | Variables
pmm_executor.c File Reference

Functions for executing a benchmark. More...

#include <stdlib.h>
#include <signal.h>
#include <sys/signal.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <paths.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <libgen.h>
#include "pmm_model.h"
#include "pmm_selector.h"
#include "pmm_cfgparser.h"
#include "pmm_log.h"
#include "pmm_util.h"

Go to the source code of this file.

Functions

int my_popen (char *cmd, char **args, int n, pid_t *pid)
int set_non_blocking (int fd)
struct pmm_benchmarkparse_bench_output (char *output, int n_p, int *rargs)
int read_benchmark_output (int fd, char **output_p, pid_t bench_pid)
void sig_childexit (int sig)
double calculate_flops (struct timeval tv, long long int complexity)
double timeval_to_seconds (struct timeval tv)
void set_executing_benchmark (int i)
char * pmm_bench_exit_status_to_string (int bench_status)
int spawn_benchmark_process (struct pmm_routine *r, int *params, pid_t *bench_pid)
void cleanup_benchmark_process (FILE *fp, pid_t bench_pid)
void * benchmark (void *scheduled_r)

Variables

int executing_benchmark
 daemon executing variable or not
pthread_mutex_t executing_benchmark_mutex
 mutex for accessing executing_benchmark variable
int signal_quit
 signal to indicate benchmark should be terminated
pthread_mutex_t signal_quit_mutex
 mutex for accessing singal_quit

Detailed Description

Functions for executing a benchmark.

This file contains code for calling a benchmark executable from the pmm daemon, dealing with the system level requirements of spawning the benchmark process and parsing the output of said benchmark.

Definition in file pmm_executor.c.

Function Documentation

void* benchmark ( void *  scheduled_r)

Given a routine to benchmark, select a point, execute the benchmark and insert the new point into the model. Set the global 'executing_benchark' to false/0 when the operation is complete (or has failed).

Parameters
scheduled_rvoid pointer to a routine structure that has been scheduled for a benchmark execution
Returns
void pointer to an integer with value of: 0 on success, 1 on quit from signal, -1 on failure

Definition at line 685 of file pmm_executor.c.

double calculate_flops ( struct timeval  tv,
long long int  complexity 
)

calculate (FL)OPS (floating point operations per second or any other type of operations per second)

Parameters
tvtimeval structure representing duration of computation
complexitycomplexity of computation (volume of operations)
Returns
flops as a double

Definition at line 304 of file pmm_executor.c.

void cleanup_benchmark_process ( FILE *  fp,
pid_t  bench_pid 
)

clean up a benchmark process

closes file handles and kills the process

Parameters
fpfile pointer to the benchmarks standard output
bench_pidbenchmark process id

Definition at line 465 of file pmm_executor.c.

int my_popen ( char *  cmd,
char **  args,
int  n,
pid_t *  pid 
)

Forks a process that executes and external program with a an argument string and returns a file distriptor and sets the child processes pid

Parameters
cmdstring with the full path of the program
argsarray of strings with all arguments of the program
nnumber of arguments in arg vector
pidpointer to the pid which will be set to the pid of the external program
Returns
file descriptor of the pipe opened to the command cmd.

TODO test for file not found

Definition at line 134 of file pmm_executor.c.

struct pmm_benchmark * parse_bench_output ( char *  output,
int  n_p,
int *  rargs 
)
read

Given the output of a benchmark execution parse and create a new benchmark structure storing all the information gained

Parameters
outputpointer to benchmark output string
n_pnumber of parameters of benchmark
rargsarguments passed to the benchmarked routine
Returns
pointer to newly allocated benchmark reflecting the parsed output

Definition at line 233 of file pmm_executor.c.

char * pmm_bench_exit_status_to_string ( int  bench_status)

convert benchmark exit status to a string

Parameters
bench_statusbenchmark status represented by an int
Returns
pointer to a character string

Definition at line 970 of file pmm_executor.c.

int read_benchmark_output ( int  fd,
char **  output_p,
pid_t  bench_pid 
)

Read the output of a benchmark process

Parameters
fdbenchmark process output file descriptor
output_ppointer to a character array where output will be stored
bench_pidprocess id of the benchmark process
Returns
0 on success, -1 if there was an error reading (output_p also set to NULL) 1 if a quit signal was received while waiting for output

Definition at line 490 of file pmm_executor.c.

void set_executing_benchmark ( int  i)

set the executing_benchmark variable via mutex

Parameters
ivalue to set variable with

Definition at line 952 of file pmm_executor.c.

int set_non_blocking ( int  fd)

a roughly portable way of setting a file descriptor for non-blocking I/O.

Parameters
fdfile descriptor to modify
Returns
-1 on error, 0 on success

Definition at line 94 of file pmm_executor.c.

void sig_childexit ( int  sig)

SIGCHLD signal handler

Parameters
sigthe signal
Warning
Do not use *PRINTF logging facility in this thread, it is not 'async-signal-safe' (though it is threadsafe).

Definition at line 212 of file pmm_executor.c.

int spawn_benchmark_process ( struct pmm_routine r,
int *  params,
pid_t *  bench_pid 
)

Convert params to an array of strings and call my_popen

Parameters
rpointer to routine that will be executed
paramspointer to array of parameters
bench_pidpointer to pid_t to store spawned process pid
Returns
int index of file descriptor that points to the stdout of the spawned process, or -1 if there is an error

Definition at line 332 of file pmm_executor.c.

double timeval_to_seconds ( struct timeval  tv)

convert a timeval to second in double

Parameters
tvtimeval structure
Returns
timeval as seconds

Definition at line 316 of file pmm_executor.c.

Variable Documentation

int executing_benchmark

daemon executing variable or not

Definition at line 54 of file pmm_main.c.

pthread_mutex_t executing_benchmark_mutex

mutex for accessing executing_benchmark variable

Definition at line 55 of file pmm_main.c.

int signal_quit

signal to indicate benchmark should be terminated

Definition at line 57 of file pmm_main.c.

pthread_mutex_t signal_quit_mutex

mutex for accessing singal_quit

Definition at line 58 of file pmm_main.c.