Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New function: void gras_cpu_burn(double flops) -- a simple CPU burner
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 13 Oct 2009 13:52:25 +0000 (13:52 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 13 Oct 2009 13:52:25 +0000 (13:52 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6753 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
include/gras/emul.h
src/gras/Virtu/rl_emul.c
src/gras/Virtu/sg_emul.c

index 8c41c61..391b915 100644 (file)
--- 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
index 7b3865d..28ba517 100644 (file)
@@ -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()
index 3a6f4d8..6436621 100644 (file)
 
 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)
index 0544552..785cede 100644 (file)
 
 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;
 }