From 3510c8b5311a986d920eed407f5aebd36722a7a5 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 13 Oct 2009 13:52:25 +0000 Subject: [PATCH] New function: void gras_cpu_burn(double flops) -- a simple CPU burner git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6753 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 3 ++ include/gras/emul.h | 2 ++ src/gras/Virtu/rl_emul.c | 8 +++++ src/gras/Virtu/sg_emul.c | 70 +++++++++++++++------------------------- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c41c61927..391b915d35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -76,6 +76,9 @@ SimGrid (3.3.4) unstable; urgency=low * Add getter on task kind: SD_task_get_kind(task) * Update the start_time and finish_time of tasks on completion/failure * Bugfix: Remove task from state swags when destroyed + + GRAS: + * New function: void gras_cpu_burn(double flops) -- a simple CPU burner XBT: * New function: xbt_dynar_dopar(dynar,fun) to map a function over the diff --git a/include/gras/emul.h b/include/gras/emul.h index 7b3865d5d7..28ba517b57 100644 --- a/include/gras/emul.h +++ b/include/gras/emul.h @@ -163,6 +163,8 @@ XBT_PUBLIC(int) gras_bench_once_end(void); /** \brief Stop benchmarking this part of the code \hideinitializer */ #define GRAS_BENCH_ONCE_RUN_ONCE_END() } gras_bench_once_end() + +XBT_PUBLIC(void) gras_cpu_burn(double flops); /** @} */ SG_END_DECL() diff --git a/src/gras/Virtu/rl_emul.c b/src/gras/Virtu/rl_emul.c index 3a6f4d83cc..643662118d 100644 --- a/src/gras/Virtu/rl_emul.c +++ b/src/gras/Virtu/rl_emul.c @@ -13,6 +13,14 @@ XBT_LOG_NEW_SUBCATEGORY(gras_virtu_emul, gras_virtu, "Emulation support"); +/*** CPU burning */ +void gras_cpu_burn(double flops) { + while (flops>0) { + flops-=2; + } +} + + /*** Timing macros: nothing to do in RL. Actually do the job and shutup ***/ void gras_emul_init(void) diff --git a/src/gras/Virtu/sg_emul.c b/src/gras/Virtu/sg_emul.c index 05445527c9..785cedea9a 100644 --- a/src/gras/Virtu/sg_emul.c +++ b/src/gras/Virtu/sg_emul.c @@ -18,7 +18,29 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_virtu_emul, gras_virtu, "Emulation support"); +/*** CPU burning */ +void gras_cpu_burn(double flops) { + smx_action_t act; + smx_cond_t cond; + smx_mutex_t mutex; + + cond = SIMIX_cond_init(); + mutex = SIMIX_mutex_init(); + + SIMIX_mutex_lock(mutex); + act = + SIMIX_action_execute(SIMIX_host_self(), "task", flops); + + SIMIX_register_action_to_condition(act, cond); + SIMIX_cond_wait(cond, mutex); + SIMIX_unregister_action_to_condition(act, cond); + + SIMIX_action_destroy(act); + SIMIX_mutex_unlock(mutex); + SIMIX_cond_destroy(cond); + SIMIX_mutex_destroy(mutex); +} /*** Timing macros ***/ static xbt_os_timer_t timer; static int benchmarking = 0; @@ -75,33 +97,13 @@ int gras_bench_always_begin(const char *location, int line) return 0; } -int gras_bench_always_end(void) -{ - smx_action_t act; - smx_cond_t cond; - smx_mutex_t mutex; - +int gras_bench_always_end(void) { xbt_assert0(benchmarking, "Not benchmarking yet"); benchmarking = 0; xbt_os_timer_stop(timer); duration = xbt_os_timer_elapsed(timer); - cond = SIMIX_cond_init(); - mutex = SIMIX_mutex_init(); - - SIMIX_mutex_lock(mutex); - act = - SIMIX_action_execute(SIMIX_host_self(), "task", (duration) / reference); - - SIMIX_register_action_to_condition(act, cond); - SIMIX_cond_wait(cond, mutex); - SIMIX_unregister_action_to_condition(act, cond); - - SIMIX_action_destroy(act); - SIMIX_mutex_unlock(mutex); - - SIMIX_cond_destroy(cond); - SIMIX_mutex_destroy(mutex); + gras_cpu_burn(duration/reference); return 0; } @@ -130,12 +132,7 @@ int gras_bench_once_begin(const char *location, int line) } } -int gras_bench_once_end(void) -{ - smx_action_t act; - smx_cond_t cond; - smx_mutex_t mutex; - +int gras_bench_once_end(void) { xbt_assert0(benchmarking, "Not benchmarking yet"); benchmarking = 0; if (duration > 0) { @@ -146,22 +143,7 @@ int gras_bench_once_end(void) duration = get_from_dict(benchmark_set, locbuf); } DEBUG2("Simulate the run of a task of %f sec for %s", duration, locbuf); - cond = SIMIX_cond_init(); - mutex = SIMIX_mutex_init(); - - SIMIX_mutex_lock(mutex); - act = - SIMIX_action_execute(SIMIX_host_self(), "task", (duration) / reference); - - SIMIX_register_action_to_condition(act, cond); - SIMIX_cond_wait(cond, mutex); - SIMIX_unregister_action_to_condition(act, cond); - - SIMIX_action_destroy(act); - SIMIX_mutex_unlock(mutex); - - SIMIX_cond_destroy(cond); - SIMIX_mutex_destroy(mutex); + gras_cpu_burn(duration/reference); return 0; } -- 2.20.1