瀏覽代碼

Add a reference to each handle used by each submitted task

In order to make starpu_data_unregister_lazy work properly, we need to
increment the reference counter of every data used by a task as soon as the
latter is submitted, that is when starpu_task_submit is called. Counters are
decremented when tasks are terminated.
Sylvain Henry 13 年之前
父節點
當前提交
2e15c35f4b
共有 2 個文件被更改,包括 26 次插入0 次删除
  1. 12 0
      src/core/jobs.c
  2. 14 0
      src/core/task.c

+ 12 - 0
src/core/jobs.c

@@ -162,6 +162,18 @@ void _starpu_handle_job_termination(struct _starpu_job *j)
 
 	_STARPU_PTHREAD_MUTEX_UNLOCK(&j->sync_mutex);
 
+	/* We release handle reference count */
+	if (task->cl) {
+		unsigned i;
+		for (i=0; i<task->cl->nbuffers; i++) {
+			starpu_data_handle_t handle = task->handles[i];
+			_starpu_spin_lock(&handle->header_lock);
+			handle->busy_count--;
+			if (!_starpu_data_check_not_busy(handle))
+				_starpu_spin_unlock(&handle->header_lock);
+		}
+	}
+
 	/* Tell other tasks that we don't exist any more, thus no need for
 	 * implicit dependencies any more.  */
 	_starpu_release_task_enforce_sequential_consistency(j);

+ 14 - 0
src/core/task.c

@@ -206,12 +206,26 @@ struct _starpu_job *_starpu_get_job_associated_to_task(struct starpu_task *task)
  * already counted. */
 int _starpu_submit_job(struct _starpu_job *j)
 {
+
+	struct starpu_task *task = j->task;
+
         _STARPU_LOG_IN();
 	/* notify bound computation of a new task */
 	_starpu_bound_record(j);
 
 	_starpu_increment_nsubmitted_tasks();
 
+	/* We retain handle reference count */
+	if (task->cl) {
+		unsigned i;
+		for (i=0; i<task->cl->nbuffers; i++) {
+			starpu_data_handle_t handle = task->handles[i];
+			_starpu_spin_lock(&handle->header_lock);
+			handle->busy_count++;
+			_starpu_spin_unlock(&handle->header_lock);
+		}
+	}
+
 	_STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 
 	/* Need to atomically set submitted to 1 and check dependencies, since