Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf sched: Factor out destroy_tasks()

Add destroy_tasks() as a counterpart of create_tasks() and put the
thread safety notations there. After join, it destroys semaphores too.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220908225448.4105056-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
165da802 c7202d20

+22 -2
+22 -2
tools/perf/builtin-sched.c
··· 690 690 } 691 691 } 692 692 693 + static void destroy_tasks(struct perf_sched *sched) 694 + UNLOCK_FUNCTION(sched->start_work_mutex) 695 + UNLOCK_FUNCTION(sched->work_done_wait_mutex) 696 + { 697 + struct task_desc *task; 698 + unsigned long i; 699 + int err; 700 + 701 + mutex_unlock(&sched->start_work_mutex); 702 + mutex_unlock(&sched->work_done_wait_mutex); 703 + /* Get rid of threads so they won't be upset by mutex destrunction */ 704 + for (i = 0; i < sched->nr_tasks; i++) { 705 + task = sched->tasks[i]; 706 + err = pthread_join(task->thread, NULL); 707 + BUG_ON(err); 708 + sem_destroy(&task->sleep_sem); 709 + sem_destroy(&task->ready_for_work); 710 + sem_destroy(&task->work_done_sem); 711 + } 712 + } 713 + 693 714 static void wait_for_tasks(struct perf_sched *sched) 694 715 EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex) 695 716 EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex) ··· 3345 3324 run_one_test(sched); 3346 3325 3347 3326 sched->thread_funcs_exit = true; 3348 - mutex_unlock(&sched->start_work_mutex); 3349 - mutex_unlock(&sched->work_done_wait_mutex); 3327 + destroy_tasks(sched); 3350 3328 return 0; 3351 3329 } 3352 3330