Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4728922pxb; Tue, 31 Aug 2021 11:49:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQQ2X2R4ZJRMWKq00NhTz0mS1UZHkoSE9UAXqdxML92qhYw/m9V1DMfU/5dbenDo+n5eHc X-Received: by 2002:a05:6e02:1bab:: with SMTP id n11mr22073214ili.85.1630435765359; Tue, 31 Aug 2021 11:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630435765; cv=none; d=google.com; s=arc-20160816; b=p5AkW19mgm5AH3NLF1Qa1CS5jPOHaQmZ2MA8mZYuOtGZglgUoaLyRjbMdSyOWNVZd/ aUSWSdI3/ccpxV163kd8F7U8lAqyA4NKVTKyWdZzHlOQJ2Eb1TokzBUmxanXWRkib3GX EfUNgYc1/ykYptJRIm3V5iw7uWRbojBR2jwGB3OCnyytvYRaj53r1hCVKyxKKJ/7Ysim 7X8gCKYQpXEywNSMwozXXWH/l46crkouNUGD7XwFKxGRtOBrqvQ4xpSQhrdYEnHw1BHd FazDpgAgMhO0VcA90eBqALzV2Jm/FTshSobRI5kDiaqB0opIPpkAqaP3cTD0iUghR+3A 1d0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=w/RxQVYmK+yNYBTCuOat/QUyeOlO0WxA8hvVfGxmPpM=; b=eF/d98vXr2sp2sLgMxZbcU06CkjForscG5vZIhdW1J4wPeuQbjxsrL9jR/eerzhNZy hhz3IjiaWH+ri8o33gsaS6p+JqlL/sUmWqWFd2x5+oFNhXI2PYR1d8maoGnSrNVdgJhl aQRN8VOZ1p3YAPYLekW5r28H7R68I7KXUBjiBT5n/lzr55gIbcdcNj132CXcfdrVod0Y /RTe0PqWyYaK1KtphN3EaiLo4nO0RjhZsyOJOyr+/MHjQpQhDAq3VxX0BDQWzFsCj8Ap wjAMC/jY57EhumLn8e7djFucx+PduzL33DzoFw5rDtRZqdc/f/Pu9PGFnzG+B7CNuWKV QNug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e8Xkqc5M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m6si19815405iol.83.2021.08.31.11.49.14; Tue, 31 Aug 2021 11:49:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e8Xkqc5M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239484AbhHaSrj (ORCPT + 99 others); Tue, 31 Aug 2021 14:47:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38139 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239498AbhHaSri (ORCPT ); Tue, 31 Aug 2021 14:47:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630435602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w/RxQVYmK+yNYBTCuOat/QUyeOlO0WxA8hvVfGxmPpM=; b=e8Xkqc5MJDUQ9715df7vDrq4IVOnjA5tyVighsXDvJ7FcFwplEZw9ujAFVAuMaDGShUHbT 2PPZTpvwcL0plYnq8wz4jKJqj0CsSCX/DWqUzMUEriftsqUQjlz0PNmo0QYiQ+LhE3Vf3J CrWmsVDMbF/1PaTkHAofRPYEkuYlOc0= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-NZltg8OSOR2xJE6Qp2ljEw-1; Tue, 31 Aug 2021 14:46:41 -0400 X-MC-Unique: NZltg8OSOR2xJE6Qp2ljEw-1 Received: by mail-ej1-f70.google.com with SMTP id x21-20020a170906135500b005d8d4900c5eso191150ejb.4 for ; Tue, 31 Aug 2021 11:46:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=w/RxQVYmK+yNYBTCuOat/QUyeOlO0WxA8hvVfGxmPpM=; b=Wjk0B3gA280KkMnvcnpiHPxWnOa76vpdFA4krQGfSfqT4cYnfZqMtwwrkQFiB0QNy8 OWeGoA8EGXpUQrccc48iO5NljgaxJxXqz+TDFrKLL8cxaHRxN91bYtLOwHzA7cuRjiMV KfiuN9FVE4pVojlUz9LvhIcLec8gKkP6sRmQDC6BOocYuy4W4y/hD7atvLooZvtAYhhp lBmYExgf7mCy4DITAkLEDwjFq+EMhx45fjDBw6n31fWHGTKed783Y7TShFuj9hNT7rpV i646dqTbNFNoVZAl+Z+dcrfPIKKZZCcOO8Qd+9u2L5ye8HTXJ3K9S5F8XOMo+lwzaqfy vJXw== X-Gm-Message-State: AOAM532+M68ph4ls1HfHgW777Xnjj7iI/erB05THbrgfxyeJGTHOH2Rb orD7E3iMW7FwEuhHUyFVX5WsrOFCRrYjC5Ib4b5rDMcbcc3H8yr8KHwGR6qoOV5gkbk9jqZOxeE qEUXR1qElITHVTLZvaxOCVZu/ X-Received: by 2002:a50:fd02:: with SMTP id i2mr27374860eds.22.1630435600256; Tue, 31 Aug 2021 11:46:40 -0700 (PDT) X-Received: by 2002:a50:fd02:: with SMTP id i2mr27374846eds.22.1630435600051; Tue, 31 Aug 2021 11:46:40 -0700 (PDT) Received: from krava ([2a00:102a:4005:bb4:e4bf:9f13:dbe6:2d14]) by smtp.gmail.com with ESMTPSA id i6sm8600992ejr.68.2021.08.31.11.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 11:46:39 -0700 (PDT) Date: Tue, 31 Aug 2021 20:46:36 +0200 From: Jiri Olsa To: =?utf-8?B?5Y+25r6E6ZSL?= Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, CAI Yuandao Subject: Re: Possible deadlock errors in tools/perf/builtin-sched.c Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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,