浏览代码

Add starpu_sleep

Samuel Thibault 9 年之前
父节点
当前提交
444635d429
共有 7 个文件被更改,包括 19 次插入16 次删除
  1. 1 1
      ChangeLog
  2. 6 0
      doc/doxygen/chapters/api/threads.doxy
  3. 1 0
      include/starpu_stdlib.h
  4. 2 3
      src/common/timing.c
  5. 5 4
      src/common/utils.c
  6. 0 2
      src/common/utils.h
  7. 4 6
      src/core/task.c

+ 1 - 1
ChangeLog

@@ -179,7 +179,7 @@ Small features:
     which allocates the pointers located_file_name, located_dir_name
     and opencl_program_source.
   * Add submit_hook and do_schedule scheduler methods.
-
+  * Add starpu_sleep.
 
 Changes:
   * Data interfaces (variable, vector, matrix and block) now define

+ 6 - 0
doc/doxygen/chapters/api/threads.doxy

@@ -365,5 +365,11 @@ todo
 \ingroup API_Threads
 todo
 
+\fn void starpu_sleep(float nb_sec)
+\ingroup API_Threads
+This is the same as calling Unix' sleep function, except that it takes a float
+to allow sub-second sleeping, and when StarPU is compiled in simgrid mode it
+does not really sleep but just makes simgrid record that the thread has taken
+some time to sleep.
 
 */

+ 1 - 0
include/starpu_stdlib.h

@@ -66,6 +66,7 @@ int starpu_memory_allocate(unsigned node, size_t size, int flags);
  */
 void starpu_memory_deallocate(unsigned node, size_t size);
 
+void starpu_sleep(float nb_sec);
 
 #ifdef __cplusplus
 }

+ 2 - 3
src/common/timing.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2012, 2014-2015  Université de Bordeaux
+ * Copyright (C) 2009-2012, 2014-2016  Université de Bordeaux
  * Copyright (C) 2010, 2011, 2012  CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -171,11 +171,10 @@ void _starpu_timing_init(void)
 
 	{
 		struct timeval tv1,tv2;
-		struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000000UL };
 
 		STARPU_GET_TICK(t1);
 		mygettimeofday(&tv1,0);
-		_starpu_sleep(ts);
+		starpu_sleep(0.5);
 		STARPU_GET_TICK(t2);
 		mygettimeofday(&tv2,0);
 		_starpu_scale = ((tv2.tv_sec*1e6 + tv2.tv_usec) -

+ 5 - 4
src/common/utils.c

@@ -379,16 +379,17 @@ void _starpu_gethostname(char *hostname, size_t size)
 	}
 }
 
-void _starpu_sleep(struct timespec ts)
+void starpu_sleep(float nb_sec)
 {
 #ifdef STARPU_SIMGRID
-	MSG_process_sleep(ts.tv_sec + ts.tv_nsec / 1000000000.);
+	MSG_process_sleep(nb_sec);
 #elif defined(STARPU_HAVE_WINDOWS)
-	Sleep((ts.tv_sec * 1000) + (ts.tv_nsec / 1000000));
+	Sleep(nb_sec * 1000);
 #else
 	struct timespec req, rem;
 
-	req = ts;
+	req.tv_sec = nb_sec;
+	req.tv_nsec = (nb_sec - (float) req.tv_sec) * 1000000000;
 	while (nanosleep(&req, &rem))
 		req = rem;
 #endif

+ 0 - 2
src/common/utils.h

@@ -153,8 +153,6 @@ const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
 
 int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex);
 
-void _starpu_sleep(struct timespec ts);
-
 void _starpu_util_init(void);
 
 #endif // __COMMON_UTILS_H__

+ 4 - 6
src/core/task.c

@@ -1176,15 +1176,13 @@ static void *watchdog_func(void *arg)
 {
 	struct timespec ts;
 	char *timeout_env = arg;
-	unsigned long long timeout;
+	float timeout;
 
 #ifdef _MSC_VER
-	timeout = (unsigned long long) _atoi64(timeout_env);
+	timeout = ((float) _atoi64(timeout_env)) / 1000000;
 #else
-	timeout = atoll(timeout_env);
+	timeout = ((float) atoll(timeout_env)) / 1000000;
 #endif
-	ts.tv_sec = timeout / 1000000;
-	ts.tv_nsec = (timeout % 1000000) * 1000;
 	struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
 	
 	STARPU_PTHREAD_MUTEX_LOCK(&config->submitted_mutex);
@@ -1194,7 +1192,7 @@ static void *watchdog_func(void *arg)
 		config->watchdog_ok = 0;
 		STARPU_PTHREAD_MUTEX_UNLOCK(&config->submitted_mutex);
 
-		_starpu_sleep(ts);
+		starpu_sleep(timeout);
 
 		STARPU_PTHREAD_MUTEX_LOCK(&config->submitted_mutex);
 		if (!config->watchdog_ok && last_nsubmitted