Explorar o código

explain profiling safety to helgrind through annotation rather than suppression

Samuel Thibault %!s(int64=12) %!d(string=hai) anos
pai
achega
8162e8cfed
Modificáronse 3 ficheiros con 34 adicións e 31 borrados
  1. 9 2
      include/starpu_profiling.h
  2. 25 15
      src/profiling/profiling.c
  3. 0 14
      tools/valgrind/starpu.suppr

+ 9 - 2
include/starpu_profiling.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2013  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -101,8 +101,15 @@ int starpu_profiling_status_set(int status);
  * error. */
 int starpu_profiling_status_get(void);
 #ifdef BUILDING_STARPU
+#include <common/utils.h>
 extern int _starpu_profiling;
-#define starpu_profiling_status_get() _starpu_profiling
+#define starpu_profiling_status_get() ({ \
+	int __ret; \
+	ANNOTATE_HAPPENS_AFTER(&_starpu_profiling); \
+	__ret = _starpu_profiling; \
+	ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling); \
+	__ret; \
+})
 #endif
 
 /* Get the profiling info associated to a worker, and reset the profiling

+ 25 - 15
src/profiling/profiling.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2013  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -68,8 +68,10 @@ int _starpu_profiling =
 
 int starpu_profiling_status_set(int status)
 {
+	ANNOTATE_HAPPENS_AFTER(&_starpu_profiling);
 	int prev_value = _starpu_profiling;
 	_starpu_profiling = status;
+	ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling);
 
 	_STARPU_TRACE_SET_PROFILING(status);
 
@@ -94,12 +96,6 @@ int starpu_profiling_status_set(int status)
 	return prev_value;
 }
 
-#undef starpu_profiling_status_get
-int starpu_profiling_status_get(void)
-{
-	return _starpu_profiling;
-}
-
 void _starpu_profiling_init(void)
 {
 	int worker;
@@ -110,7 +106,11 @@ void _starpu_profiling_init(void)
 		_starpu_worker_reset_profiling_info(worker);
 	}
 	if ((env = getenv("STARPU_PROFILING")) && atoi(env))
+	{
+		ANNOTATE_HAPPENS_AFTER(&_starpu_profiling);
 		_starpu_profiling = STARPU_PROFILING_ENABLE;
+		ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling);
+	}
 }
 
 void _starpu_profiling_terminate(void)
@@ -127,7 +127,7 @@ struct starpu_task_profiling_info *_starpu_allocate_profiling_info_if_needed(str
 	struct starpu_task_profiling_info *info = NULL;
 
 	/* If we are benchmarking, we need room for the power consumption */
-	if (_starpu_profiling || (task->cl && task->cl->power_model && (task->cl->power_model->benchmarking || _starpu_get_calibrate_flag())))
+	if (starpu_profiling_status_get() || (task->cl && task->cl->power_model && (task->cl->power_model->benchmarking || _starpu_get_calibrate_flag())))
 	{
 		info = (struct starpu_task_profiling_info *) calloc(1, sizeof(struct starpu_task_profiling_info));
 		STARPU_ASSERT(info);
@@ -191,7 +191,7 @@ void _starpu_worker_reset_profiling_info(int workerid)
 
 void _starpu_worker_restart_sleeping(int workerid)
 {
-	if (_starpu_profiling)
+	if (starpu_profiling_status_get())
 	{
 		struct timespec sleep_start_time;
 		_starpu_clock_gettime(&sleep_start_time);
@@ -205,7 +205,7 @@ void _starpu_worker_restart_sleeping(int workerid)
 
 void _starpu_worker_stop_sleeping(int workerid)
 {
-	if (_starpu_profiling)
+	if (starpu_profiling_status_get())
 	{
 		struct timespec *sleeping_start, sleep_end_time;
 
@@ -240,7 +240,7 @@ void _starpu_worker_stop_sleeping(int workerid)
 
 void _starpu_worker_register_executing_start_date(int workerid, struct timespec *executing_start)
 {
-	if (_starpu_profiling)
+	if (starpu_profiling_status_get())
 	{
 		_STARPU_PTHREAD_MUTEX_LOCK(&worker_info_mutex[workerid]);
 		worker_registered_executing_start[workerid] = 1;
@@ -252,7 +252,7 @@ void _starpu_worker_register_executing_start_date(int workerid, struct timespec
 
 void _starpu_worker_update_profiling_info_executing(int workerid, struct timespec *executing_time, int executed_tasks, uint64_t used_cycles, uint64_t stall_cycles, double power_consumed)
 {
-	if (_starpu_profiling)
+	if (starpu_profiling_status_get())
 	{
 		_STARPU_PTHREAD_MUTEX_LOCK(&worker_info_mutex[workerid]);
 
@@ -272,7 +272,7 @@ void _starpu_worker_update_profiling_info_executing(int workerid, struct timespe
 
 int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *info)
 {
-	if (!_starpu_profiling)
+	if (!starpu_profiling_status_get())
 	{
 		/* Not thread safe, shouldn't be too much a problem */
 		info->executed_tasks = worker_info[workerid].executed_tasks;
@@ -319,7 +319,7 @@ int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profilin
 /* When did the task reach the scheduler  ? */
 void _starpu_profiling_set_task_push_start_time(struct starpu_task *task)
 {
-	if (!_starpu_profiling)
+	if (!starpu_profiling_status_get())
 		return;
 
 	struct starpu_task_profiling_info *profiling_info;
@@ -331,7 +331,7 @@ void _starpu_profiling_set_task_push_start_time(struct starpu_task *task)
 
 void _starpu_profiling_set_task_push_end_time(struct starpu_task *task)
 {
-	if (!_starpu_profiling)
+	if (!starpu_profiling_status_get())
 		return;
 
 	struct starpu_task_profiling_info *profiling_info;
@@ -429,3 +429,13 @@ void _starpu_bus_update_profiling_info(int src_node, int dst_node, size_t size)
 	bus_profiling_info[src_node][dst_node].transfer_count++;
 //	fprintf(stderr, "PROFILE %d -> %d : %d (cnt %d)\n", src_node, dst_node, size, bus_profiling_info[src_node][dst_node].transfer_count);
 }
+
+#undef starpu_profiling_status_get
+int starpu_profiling_status_get(void)
+{
+	int ret;
+	ANNOTATE_HAPPENS_AFTER(&_starpu_profiling);
+	ret = _starpu_profiling;
+	ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling);
+	return ret;
+}

+ 0 - 14
tools/valgrind/starpu.suppr

@@ -36,20 +36,6 @@
 {
    We do not care about races on profiling statistics
    Helgrind:Race
-   fun:starpu_profiling_status_get
-   ...
-}
-
-{
-   This is the counterpart of the suppression above.
-   Helgrind:Race
-   fun:starpu_profiling_status_set
-   ...
-}
-
-{
-   We do not care about races on profiling statistics
-   Helgrind:Race
    fun:_starpu_worker_get_status
    fun:_starpu_worker_reset_profiling_info_with_lock
    ...