pmm  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
pmm_model.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2010 Robert Higgins
3  Author: Robert Higgins <robert.higgins@ucd.ie>
4 
5  This file is part of PMM.
6 
7  PMM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  PMM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with PMM. If not, see <http://www.gnu.org/licenses/>.
19 */
20 /*!
21  * @file pmm_model.h
22  * @brief general PMM data structures
23  *
24  * Data structures representing models, routines and the benchmarking
25  * server configuration are described here, along with functions that
26  * operate on them.
27  *
28  */
29 
30 #ifndef PMM_DATA_H_
31 #define PMM_DATA_H_
32 
33 #if HAVE_CONFIG_H
34 #include "config.h"
35 #endif
36 
37 #include <sys/time.h> // for timeval
38 
39 #include "pmm_interval.h"
40 #include "pmm_param.h"
41 #include "pmm_load.h"
42 
43 /*!
44  * enumeration fo different model construction conditions that must be
45  * satisified to conduct benchmarking
46  */
48  CC_INVALID, /*< invalid status */
49  CC_NOW, /*< build model immidiately */
50  CC_UNTIL, /*< build model as much as up to a certain time */
51  CC_PERIODIC, /*< build model during a specific period of time only */
52  CC_IDLE, /*< build model only when machine is considered idle */
53  CC_NOUSERS /*< build model only when no users are logged in */
55 
56 
57 
58 /*!
59  * structure to hold the configuration of the benchmarking server
60  */
61 typedef struct pmm_config {
62  struct pmm_routine **routines; /**< pointer to array of routines to be
63  benchmarked */
64  int allocated; /**< number of allocated elements in the
65  routines array */
66  int used; /**< number of used elements in the
67  routines array */
68 
69  struct pmm_loadhistory *loadhistory; /**< pointer to load history */
70 
71  int daemon; /**< toggle whether to go to background */
72  int build_only; /**< toggle whether to build, then exit */
73 
74  struct timespec ts_main_sleep_period; /**< sleep period of scheduling
75  loop */
76  int time_spend_threshold; /**< threshold for time spend
77  benchmarking before writing
78  models to disk */
79  int num_execs_threshold; /**< threshold for number of
80  benchmark executions before
81  writing models to disk */
82 
83  char *logfile; /**< log file name */
84  char *configfile; /**< configuartion filename */
85 
86  int pause; /**< toggle pause after a
87  benchmark */
88 
89 } PMM_Config;
90 
91 /*!
92  * enumeration of different model construction methods
93  */
95  CM_NAIVE, /*!< construct by testing every problem size from start
96  to finish */
97  CM_NAIVE_BISECT, /*!< construct by testing every problem size but use
98  bisection of problem size range to get quicker
99  coverage */
100  CM_RAND, /*!< construct using random sampling */
101  CM_GBBP, /*!< construct using optimised Geometric Bisection
102  Building Procedure */
103  CM_GBBP_NAIVE, /*!< construct using GPPB but with a naive initial
104  period */
105  CM_INVALID /*!< invalid construction method */
107 
108 
109 /*!
110  * Benchmark structure, storing information routine tests.
111  *
112  * Details the on the parameters and execution results of a benchmark
113  * execution. Also pointers to next/previous benchmarks should the one in
114  * question is a member of a list.
115  */
116 typedef struct pmm_benchmark {
117  int n_p; //!< number of parameters
118  int *p; //!< array of parameters
119 
120  //TODO calculate complexity from problem size variables with muparser
121  long long int complexity; //!< complexity of benchmark (no. of float ops.)
122  double flops; //!< speed of benchmark execution
123  double seconds; //!< benchmark execution time in seconds
124 
125  struct timeval wall_t; //!< wall clock execution time (timeval)
126 
127  struct timeval used_t; //!< kernel and user mode execution time summed
128 
129  struct pmm_benchmark *previous; //!< pointer to previous bench in list
130  struct pmm_benchmark *next; //!< pointer to next bench in list
131 } PMM_Benchmark;
132 
133 
134 /*!
135  * structure describing a list of benchmarks
136  *
137  * Benchmarks are doubly linked.
138  */
139 typedef struct pmm_bench_list {
140  int size; /*!< number of benchmarks stored in the list */
141  int n_p; /*!< number of parameters the benchmarks have */
142 
143  struct pmm_benchmark *first; /*!< first element of the list */
144  struct pmm_benchmark *last; /*!< last element of the list */
145 
146  struct pmm_model *parent_model; /*!< model to which the benchmarks belong */
148 
149 
150 /*!
151  * functional performance model of a routine
152  */
153 typedef struct pmm_model {
154  char *model_path; /*!< path to model filee */
155  int unwritten_num_execs; /*!< number of executions since last write */
156  double unwritten_time_spend; /*!< benchmarking time spend since last
157  write */
158  time_t mtime; /*!< modified time of the model file */
159 
160  int n_p; /*!< number of parameters of the model */
161 
162  int completion; /*!< completion state of the model */
163  int complete; /*!< is model complete */
164  int unique_benches; /*!< number of unique benchmarks made to
165  build model */
166 
167  struct pmm_bench_list *bench_list; /*! pointer to benchmark list */
168 
169  double peak_flops; /*!< peak speed observed over all
170  benchmarks */
171 
172  struct pmm_interval_list *interval_list; /*!< intervals describing
173  unfinished parts of the model */
174 
175  struct pmm_paramdef_set *pd_set; /*!< set of parameter definition for
176  the routine */
177 
178  struct pmm_routine *parent_routine; /*!< routine to which the model
179  belongs */
180 } PMM_Model;
181 
182 /*!
183  * structure describing a routine to be benchmarked by pmm
184  */
185 typedef struct pmm_routine {
186 
187  char *name; /*!< name of routine */
188  char *exe_path; /*!< path to benchmark executable */
189  char *exe_args; /*!< extra arguments of benchmark */
190 
191  struct pmm_paramdef_set *pd_set; /*!< set of parameter defintions */
192 
193  //struct pmm_policy *policy; TODO implement policies
194  enum pmm_construction_condition condition; /*!< benchmarking condition */
195  int priority; /*!< benchmarking priority */
196  int executable; /*!< toggle for executability */
197 
198  enum pmm_construction_method construction_method; /*!< model construction method */
199  int min_sample_num; /*!< minimum samples for each model point */
200  int min_sample_time; /*!< minimum time to spend benchmarking each model
201  point */
202  int max_completion; /*!< maximum number of model points */
203 
204  struct pmm_model *model; /*!< pointer to model */
205 
206  struct pmm_routine *next_routine; /*!< next routine in routine array/list */
207 
208  struct pmm_config *parent_config; /*!< configuration of host */
209 
210 } PMM_Routine;
211 
212 
213 
214 char*
216 char*
218 char*
220 
221 
222 /*
223 typedef struct pmm_benchmark {
224  long long int size; //TODO support multiple problem size variables
225  long long int complexity; //TODO calculate complexity from problem size variables
226  double flops;
227  double seconds;
228 
229  //wall time for benchmark execution
230  struct timeval wall_t;
231 
232  //user+system time for benchmark execution
233  struct timeval used_t;
234 
235  struct pmm_benchmark *previous;
236  struct pmm_benchmark *next;
237 } PMM_Benchmark;
238 */
239 
240 
241 /*
242  * new_ functions typically allocate memory and set values to failsafes (-1)
243  */
244 struct pmm_config* new_config();
245 struct pmm_routine* new_routine();
246 struct pmm_model* new_model();
247 struct pmm_benchmark* new_benchmark();
248 
249 struct pmm_bench_list*
250 new_bench_list(struct pmm_model *m,
251  int n_p);
252 
253 /*
254  * init_ functions initialize structures with initial condition data values
255  */
256 
257 int
258 init_bench_list(struct pmm_model *m, struct pmm_paramdef_set *pd_set);
259 struct pmm_benchmark*
260 init_zero_benchmark(int *params, int n_p);
261 
262 int isempty_model(struct pmm_model *m);
263 
264 int add_routine(struct pmm_config *c, struct pmm_routine *r);
265 int insert_bench(struct pmm_model *m, struct pmm_benchmark *b);
266 int
267 remove_benchmarks_at_param(struct pmm_model *m, int *p,
268  struct pmm_benchmark ***removed_array);
269 
270 int copy_benchmark(struct pmm_benchmark *dst, struct pmm_benchmark *src);
271 
272 void add_bench(struct pmm_benchmark *a, struct pmm_benchmark *b,
273  struct pmm_benchmark *res);
274 void div_bench(struct pmm_benchmark *b, double d, struct pmm_benchmark *res);
275 
276 int sum_bench_list(struct pmm_benchmark *start, struct pmm_benchmark *end,
277  struct pmm_benchmark *sum);
278 
279 void avg_bench_list(struct pmm_benchmark *start, struct pmm_benchmark *end,
280  struct pmm_benchmark *avg_b);
281 
282 void copy_timeval(struct timeval *src, struct timeval *dst);
283 double timeval_to_double(struct timeval *tv);
284 void double_to_timeval(double d, struct timeval *tv);
285 void double_to_timespec(double d, struct timespec *ts);
286 void timeval_add(struct timeval *tv_a, struct timeval *tv_b,
287  struct timeval *tv_res);
288 void timeval_div(struct timeval *tv, double d);
289 
290 int
292 int
294 
295 int
297 
298 int
299 insert_bench_into_sorted_list(struct pmm_benchmark **list_start,
300  struct pmm_benchmark **list_end,
301  struct pmm_benchmark *b);
302 int
304  struct pmm_benchmark **list_last,
305  struct pmm_benchmark *before,
306  struct pmm_benchmark *b);
307 int
309  struct pmm_benchmark **list_last,
310  struct pmm_benchmark *after,
311  struct pmm_benchmark *b);
312 int
314  struct pmm_benchmark *b);
315 
316 int
317 remove_bench_from_sorted_list(struct pmm_benchmark **list_first,
318  struct pmm_benchmark **list_last,
319  struct pmm_benchmark *b);
320 int
322  struct pmm_benchmark *b);
323 
324 int benchmark_on_axis(struct pmm_model *m, struct pmm_benchmark *b);
325 
326 int is_benchmark_at_origin(int n, struct pmm_paramdef *paramdef_array,
327  struct pmm_benchmark *b);
328 
329 
330 int isequal_benchmarks(struct pmm_benchmark *b1, struct pmm_benchmark *b2);
331 
332 struct pmm_benchmark*
333 get_avg_aligned_bench(struct pmm_model *m, int *param);
334 
335 struct pmm_benchmark*
336 get_avg_bench(struct pmm_model *m, int *param);
337 
338 struct pmm_benchmark*
340  int *param);
341 struct pmm_benchmark*
343  int *param);
344 int
345 search_sorted_bench_list(int direction,
346  struct pmm_benchmark *start,
347  int *param,
348  int n_p,
349  struct pmm_benchmark **first,
350  struct pmm_benchmark **last);
351 
352 struct pmm_benchmark*
354 
355 struct pmm_benchmark*
357 
358 struct pmm_benchmark*
359 get_first_bench(struct pmm_model *m, int *param);
360 
361 struct pmm_benchmark*
363  int *p);
364 
365 void
366 calc_bench_exec_stats(struct pmm_model *m, int *param,
367  double *time_spent, int *num_execs);
368 double
369 calc_model_stats(struct pmm_model *m);
370 
371 struct pmm_benchmark *
372 find_oldapprox(struct pmm_model *m, int *p);
373 struct pmm_benchmark* lookup_model(struct pmm_model *m, int *p);
375  int *p);
376 
377 
378 int bench_cut_contains(struct pmm_loadhistory *h, struct pmm_benchmark *b1,
379  struct pmm_benchmark *b2);
380 int bench_cut_intersects(struct pmm_loadhistory *h, struct pmm_benchmark *b1,
381  struct pmm_benchmark *b2);
382 int bench_cut_greater(struct pmm_loadhistory *h, struct pmm_benchmark *b1,
383  struct pmm_benchmark *b2);
384 int bench_cut_less(struct pmm_loadhistory *h, struct pmm_benchmark *b1,
385  struct pmm_benchmark *b2);
386 
387 void print_routine(const char *output, struct pmm_routine *r);
388 void print_model(const char *output, struct pmm_model *m);
389 void print_bench_list(const char *output, struct pmm_bench_list *bl);
390 void print_benchmark(const char *output, struct pmm_benchmark *b);
391 int set_str(char **dst, char *src);
392 
393 time_t parseISO8601Date(char *date);
394 
395 int check_routine(struct pmm_routine *r);
396 
397 void print_config(const char *output, struct pmm_config *cfg);
398 void free_model(struct pmm_model **m);
399 void free_bench_list(struct pmm_bench_list **bl);
400 void free_benchmark_list_backwards(struct pmm_benchmark **first_b);
401 void free_benchmark_list_forwards(struct pmm_benchmark **last_b);
402 void free_benchmark(struct pmm_benchmark **b);
403 void free_routine(struct pmm_routine **r);
404 void free_config(struct pmm_config **cfg);
405 void free_loadhistory(struct pmm_loadhistory **h);
406 
407 #endif /*PMM_DATA_H_*/
408