* Re: Possible deadlock errors in tools/perf/builtin-sched.c [not found] <CAAo+4rXNLdgvAiT2-B8cWtLNPnWoGo9RWMW=8SPchzRgxJ4BhA@mail.gmail.com> @ 2021-08-28 8:06 ` 叶澄锋 2021-08-31 18:46 ` Jiri Olsa 1 sibling, 0 replies; 3+ messages in thread From: 叶澄锋 @ 2021-08-28 8:06 UTC (permalink / raw) To: peterz, mingo, acme Cc: mark.rutland, alexander.shishkin, jolsa, namhyung, linux-perf-users, linux-kernel, CAI Yuandao Dear developers: Thank you for your checking. It seems there are two deadlock errors on the locksched->work_done_wait_mutexandsched->start_work_mutex. They are triggered due to one thread(A) runs function run_one_test locating in a loop and unreleasing the two locks in thewait_for_tasksfunction, and another thread(B) runs function thread_func acquiring the two locks. Because the two locks are not properly released in thread A, there will be a deadlock problem if thread B acquires the two locks. The related codes are below: Thread A: static void create_tasks(struct perf_sched *sched) { ...; err = pthread_mutex_lock(&sched->start_work_mutex); ...; err = pthread_mutex_lock(&sched->work_done_wait_mutex); ...; } static int perf_sched__replay(struct perf_sched *sched) { ...; create_tasks(sched); printf("------------------------------------------------------------\n"); for (i = 0; i < sched->replay_repeat; i++) run_one_test(sched); // multiple reacquisition on the lock sched->work_done_wait_mutex and sched->start_work_mutex return 0; } static void run_one_test(struct perf_sched *sched) { ...; wait_for_tasks(sched); ...; } static void wait_for_tasks(struct perf_sched *sched) { ...; pthread_mutex_unlock(&sched->work_done_wait_mutex); ...; ret = pthread_mutex_lock(&sched->work_done_wait_mutex); ...; pthread_mutex_unlock(&sched->start_work_mutex); ...; ret = pthread_mutex_lock(&sched->start_work_mutex); ....; } Thread B: static void *thread_func(void *ctx) { ...; ret = pthread_mutex_lock(&sched->start_work_mutex); ...; ret = pthread_mutex_unlock(&sched->start_work_mutex); ...; ret = pthread_mutex_lock(&sched->work_done_wait_mutex); ...; ret = pthread_mutex_unlock(&sched->work_done_wait_mutex); ..; } PS: The previous email fails to reach the maillist, so I send it again. Thanks, 叶澄锋 <dg573847474@gmail.com> 于2021年8月28日周六 下午3:57写道: > > Dear developers: > > Thank you for your checking. > > It seems there are two deadlock errors on the locksched->work_done_wait_mutexandsched->start_work_mutex. > > They are triggered due to one thread(A) runs function run_one_test locating in a loop and unreleasing the two locks in thewait_for_tasksfunction, and another thread(B) runs function thread_func acquiring the two locks. > > Because the two locks are not properly released in thread A, there will be a deadlock problem if thread B acquires the two locks. > > The related codes are below: > > Thread A: > > static void create_tasks(struct perf_sched *sched) > { > ...; > err = pthread_mutex_lock(&sched->start_work_mutex); > ...; > err = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > } > static int perf_sched__replay(struct perf_sched *sched) > { > ...; > > create_tasks(sched); > printf("------------------------------------------------------------\n"); > for (i = 0; i < sched->replay_repeat; i++) > run_one_test(sched); // multiple reacquisition on the lock sched->work_done_wait_mutex and sched->start_work_mutex > > return 0; > } > > static void run_one_test(struct perf_sched *sched) > { > ...; > wait_for_tasks(sched); > ...; > } > static void wait_for_tasks(struct perf_sched *sched) > { > ...; > pthread_mutex_unlock(&sched->work_done_wait_mutex); > > ...; > ret = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > pthread_mutex_unlock(&sched->start_work_mutex); > > ...; > > ret = pthread_mutex_lock(&sched->start_work_mutex); > ....; > } > > Thread B: > > static void *thread_func(void *ctx) > { > > ...; > ret = pthread_mutex_lock(&sched->start_work_mutex); > ...; > ret = pthread_mutex_unlock(&sched->start_work_mutex); > > ...; > > ret = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > ret = pthread_mutex_unlock(&sched->work_done_wait_mutex); > ..; > > } > > > Thanks, ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Possible deadlock errors in tools/perf/builtin-sched.c [not found] <CAAo+4rXNLdgvAiT2-B8cWtLNPnWoGo9RWMW=8SPchzRgxJ4BhA@mail.gmail.com> 2021-08-28 8:06 ` Possible deadlock errors in tools/perf/builtin-sched.c 叶澄锋 @ 2021-08-31 18:46 ` Jiri Olsa 2021-09-01 5:19 ` CAI Yuandao 1 sibling, 1 reply; 3+ messages in thread From: Jiri Olsa @ 2021-08-31 18:46 UTC (permalink / raw) To: 叶澄锋 Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, namhyung, linux-perf-users, linux-kernel, CAI Yuandao On Sat, Aug 28, 2021 at 03:57:17PM +0800, 叶澄锋 wrote: > Dear developers: > > Thank you for your checking. > > It seems there are two deadlock errors on the lock > *sched->work_done_wait_mutex*and*sched->start_work_mutex.* > > They are triggered due to one thread(A) runs function *run_one_test* locating > in a loop and unreleasing the two locks in the*wait_for_tasks*function, and > another thread(B) runs function *thread_func *acquiring the two locks. > > Because the two locks are not properly released in thread A, there will be > a deadlock problem if thread B acquires the two locks. hi, do you have a way to reproduce this? thanks, jirka > > The related codes are below: > > Thread A: > > static void create_tasks(struct perf_sched *sched) > { > ...; > err = pthread_mutex_lock(&sched->start_work_mutex); > ...; > err = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > } > static int perf_sched__replay(struct perf_sched *sched) > { > ...; > > create_tasks(sched); > printf("------------------------------------------------------------\n"); > for (i = 0; i < sched->replay_repeat; i++) > run_one_test(sched); // multiple reacquisition on the lock > sched->work_done_wait_mutex and sched->start_work_mutex > > return 0; > } > > static void run_one_test(struct perf_sched *sched) > { > ...; > wait_for_tasks(sched); > ...; > } > static void wait_for_tasks(struct perf_sched *sched) > { > ...; > pthread_mutex_unlock(&sched->work_done_wait_mutex); > > ...; > ret = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > pthread_mutex_unlock(&sched->start_work_mutex); > > ...; > > ret = pthread_mutex_lock(&sched->start_work_mutex); > ....; > } > > Thread B: > > static void *thread_func(void *ctx) > { > > ...; > ret = pthread_mutex_lock(&sched->start_work_mutex); > ...; > ret = pthread_mutex_unlock(&sched->start_work_mutex); > > ...; > > ret = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > ret = pthread_mutex_unlock(&sched->work_done_wait_mutex); > ..; > > } > > > Thanks, ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Possible deadlock errors in tools/perf/builtin-sched.c 2021-08-31 18:46 ` Jiri Olsa @ 2021-09-01 5:19 ` CAI Yuandao 0 siblings, 0 replies; 3+ messages in thread From: CAI Yuandao @ 2021-09-01 5:19 UTC (permalink / raw) To: Jiri Olsa Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, namhyung, linux-perf-users, linux-kernel, 叶澄锋 Hi Jirka, They were found by our static code analyzer and manually checked as true positives by us. Are they real bugs? Best, Ryan On 1/9/2021, 2:46 AM, "Jiri Olsa" <jolsa@redhat.com> wrote: On Sat, Aug 28, 2021 at 03:57:17PM +0800, 叶澄锋 wrote: > Dear developers: > > Thank you for your checking. > > It seems there are two deadlock errors on the lock > *sched->work_done_wait_mutex*and*sched->start_work_mutex.* > > They are triggered due to one thread(A) runs function *run_one_test* locating > in a loop and unreleasing the two locks in the*wait_for_tasks*function, and > another thread(B) runs function *thread_func *acquiring the two locks. > > Because the two locks are not properly released in thread A, there will be > a deadlock problem if thread B acquires the two locks. hi, do you have a way to reproduce this? thanks, jirka > > The related codes are below: > > Thread A: > > static void create_tasks(struct perf_sched *sched) > { > ...; > err = pthread_mutex_lock(&sched->start_work_mutex); > ...; > err = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > } > static int perf_sched__replay(struct perf_sched *sched) > { > ...; > > create_tasks(sched); > printf("------------------------------------------------------------\n"); > for (i = 0; i < sched->replay_repeat; i++) > run_one_test(sched); // multiple reacquisition on the lock > sched->work_done_wait_mutex and sched->start_work_mutex > > return 0; > } > > static void run_one_test(struct perf_sched *sched) > { > ...; > wait_for_tasks(sched); > ...; > } > static void wait_for_tasks(struct perf_sched *sched) > { > ...; > pthread_mutex_unlock(&sched->work_done_wait_mutex); > > ...; > ret = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > pthread_mutex_unlock(&sched->start_work_mutex); > > ...; > > ret = pthread_mutex_lock(&sched->start_work_mutex); > ....; > } > > Thread B: > > static void *thread_func(void *ctx) > { > > ...; > ret = pthread_mutex_lock(&sched->start_work_mutex); > ...; > ret = pthread_mutex_unlock(&sched->start_work_mutex); > > ...; > > ret = pthread_mutex_lock(&sched->work_done_wait_mutex); > ...; > ret = pthread_mutex_unlock(&sched->work_done_wait_mutex); > ..; > > } > > > Thanks, ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-01 5:28 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CAAo+4rXNLdgvAiT2-B8cWtLNPnWoGo9RWMW=8SPchzRgxJ4BhA@mail.gmail.com> 2021-08-28 8:06 ` Possible deadlock errors in tools/perf/builtin-sched.c 叶澄锋 2021-08-31 18:46 ` Jiri Olsa 2021-09-01 5:19 ` CAI Yuandao
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).