From patchwork Wed Oct 2 01:43:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 51981 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cb8a:0:b0:48e:c0f8:d0de with SMTP id d10csp665941vqv; Tue, 1 Oct 2024 18:44:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUqr7Y1cIV6UnlASxvzfwHxUspyLWD7/46jCfkDGktHKvue/fG9DpNyL9HoyGG0yIdNQXmYErmVUjmgwxO4Fqap@gmail.com X-Google-Smtp-Source: AGHT+IF3h87iZfLsQ/mx6EY0pVdiwd12Etw3GZjt9cboLnOuUW8c0+YT5g3NaFa3bds0qKhPCggS X-Received: by 2002:a17:906:dc92:b0:a8d:2623:dd18 with SMTP id a640c23a62f3a-a98f8386df2mr60497266b.13.1727833466644; Tue, 01 Oct 2024 18:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727833466; cv=none; d=google.com; s=arc-20240605; b=OtT5KfVB4AWO2gVDlSpm1hEUXLV2h5VGaelZyiCDNpjrAIsS376SKGLNpZu0pXD0Rr +SPne8gKXEdeKdSNV8Fg7fZP8obWcWwzyHmXepTdTztheBRu3BncBSZeHo+zRbmFmrqI 3W0fLeAFZjHZXNMNGgG5kTCXqJraWr7PlYy8+UMFb4JRc0aVpmg/5CSsOpU3CTmZYjpZ o875pHJO6GIcyQ5JiMNIN6EOEyzSCJxLXm83l2PtWXB2TElNfFZTUWzV9Zkf4r+byQDu eNhEQxnlQvhIiqGEDiJXStMiVw6fVfsBqLh2hP8t2wyf77+AAF8FbKKA4XBNOr/Ahzfo gqfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=ZXfJYAy7r7dlHf62vJeKMeqKamZM43dPmP0OXALmXbs=; fh=mZk9AfRmPBMGW9h158yccPeJgZmEjzU2tMQtLZcF184=; b=DJDrwrlUlFmG8DFBRtUpaDZYzhv4TAVn13+bE2ul7b30IxakJE174J+bptzvU/qMIO FFWfycu2gANd8Qwq7RxwVMUQ4LxRR6FXYtNj062K8y3USKCG5StsnYSzsz/0wNh5uwsv 6SY8BBB2xdW1MCzL0NH3Ie+XTzkluPbwu8r707vR+iCzvLho+00fpko6cdFFyzfTrI0g C2CsiwfHKUdnVzMD2Y1HxA3KIhRb8z0a1F9yTmb1dgwj7OTplmsnqNe32yaVC6dfTyxO 0SMdcM7s0XzyEUmpa2EMcxAQbOnpg81RBdlTwY7vbRIiF8XrHs+QmoAmv+/6OGd64jJg QkTw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=E2UDj4D5; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a93c27f2219si814837866b.159.2024.10.01.18.44.25; Tue, 01 Oct 2024 18:44:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=E2UDj4D5; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F209068D68B; Wed, 2 Oct 2024 04:44:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 387BB68D653 for ; Wed, 2 Oct 2024 04:44:11 +0300 (EEST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20bc2970df5so6577865ad.3 for ; Tue, 01 Oct 2024 18:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727833449; x=1728438249; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jyGEArRnTGZ0KuxOe03Cdqxm2weUt3wO9IuddLnW8/4=; b=E2UDj4D5q4zWxmmPzpJvq11xrIWFcXt2T+UEdtOD1LzutxAiMJYlMkV0XHlHgffG5M pHvHlQPzqY05h/lA1Y53qokopeh8Ki0CDAbY/3FKSB8cM1GKFWfOPZoQxGRcIU8VWzXN yfhNbfSv3jH991Xjt1vQl92a8lLb5wyrac0wHfj4nAHvsSqO2dZlX4UK5/kTNZRVSbCV tR53x6NflMXXb6+gak8ZIFFuwbGgv30E42iBfYoaJp+Vbs84pIQvWQ3eTKywJdUmCh1P DvWr55tMNUUlVxtrtHvQ5dkk0InwcaxJMUqGHRYd66xj7xcuPvzh6lR7QNSbBGg8tie/ U5Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727833449; x=1728438249; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jyGEArRnTGZ0KuxOe03Cdqxm2weUt3wO9IuddLnW8/4=; b=Hq6vnMD6QLwpNLcOOKPcCuwpLrDJ1e4iaq6Tgjgwtao2zvpD0UmEe8C4zS7Q/y6ik+ 3GsY5S6zsjZ1GPlM7e5v7PGrzeHloLZBykn+kpajxS4Oa7UrCYMZ+T9IxvvJciT/i1wY GUeuTpkauha7zMkMqaQYlGA4k3VJoyesEAAqL0aLOF9B94i1G+90SjOrOlhsrEKnKnjV Z9LxNmzUd0J0ydtZ4QPCEyy5HlJWP/8vC6XnF+BXMN1ajwXvwLjwZ/rwM7Z4YdVv0r8n JxeD7mzoyOGLiMuPRMJzToIoyVjgkfmvFcPdG8SIewfWmFCwQ/Gbec6JkfVxDkfabl8X y/Gw== X-Gm-Message-State: AOJu0YxZNK4EQ+QmABcPQDLjgBGsl9zwDMTZGl60GLhfJCgM+ds2QMpy xx09l5eFxpcm/hINRa6wElLLPKgTpkc42njWTa9rTv1ZRogVN2B3FkLEjSb+ X-Received: by 2002:a17:902:d48d:b0:20b:81bb:4a8a with SMTP id d9443c01a7336-20bc59992f4mr19236675ad.6.1727833448705; Tue, 01 Oct 2024 18:44:08 -0700 (PDT) Received: from localhost ([112.64.8.17]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37d5edc6sm75483605ad.28.2024.10.01.18.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 18:44:08 -0700 (PDT) From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Oct 2024 09:43:57 +0800 Message-Id: <20241002014358.296769-2-nuomi2021@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241002014358.296769-1-nuomi2021@gmail.com> References: <20241002014358.296769-1-nuomi2021@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 2/3] avcodec/executor: remove unused ready callback X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nuo Mi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QBQ2D9fb3wtp Due to the nature of multithreading, using a "ready check" mechanism may introduce a deadlock. For example: Suppose all tasks have been submitted to the executor, and the last thread checks the entire list and finds no ready tasks. It then goes to sleep, waiting for a new task. However, for some multithreading-related reason, a task becomes ready after the check. Since no other thread is aware of this and no new tasks are being added to the executor, a deadlock occurs. In VVC, this function is unnecessary because we use a scoreboard. All tasks submitted to the executor are ready tasks. --- libavcodec/executor.c | 6 ++---- libavcodec/executor.h | 3 --- libavcodec/vvc/thread.c | 8 -------- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/libavcodec/executor.c b/libavcodec/executor.c index 574c5c7be7..21ebad3def 100644 --- a/libavcodec/executor.c +++ b/libavcodec/executor.c @@ -79,10 +79,8 @@ static void add_task(FFTask **prev, FFTask *t) static int run_one_task(FFExecutor *e, void *lc) { FFTaskCallbacks *cb = &e->cb; - FFTask **prev; + FFTask **prev = &e->tasks; - for (prev = &e->tasks; *prev && !cb->ready(*prev, cb->user_data); prev = &(*prev)->next) - /* nothing */; if (*prev) { FFTask *t = remove_task(prev, *prev); if (e->thread_count > 0) @@ -143,7 +141,7 @@ FFExecutor* ff_executor_alloc(const FFTaskCallbacks *cb, int thread_count) { FFExecutor *e; int has_lock = 0, has_cond = 0; - if (!cb || !cb->user_data || !cb->ready || !cb->run || !cb->priority_higher) + if (!cb || !cb->user_data || !cb->run || !cb->priority_higher) return NULL; e = av_mallocz(sizeof(*e)); diff --git a/libavcodec/executor.h b/libavcodec/executor.h index 2d02734ad6..51763ec25e 100644 --- a/libavcodec/executor.h +++ b/libavcodec/executor.h @@ -42,9 +42,6 @@ typedef struct FFTaskCallbacks { // return 1 if a's priority > b's priority int (*priority_higher)(const FFTask *a, const FFTask *b); - // task is ready for run - int (*ready)(const FFTask *t, void *user_data); - // run the task int (*run)(FFTask *t, void *local_context, void *user_data); } FFTaskCallbacks; diff --git a/libavcodec/vvc/thread.c b/libavcodec/vvc/thread.c index e6907fd764..a8c19b17cf 100644 --- a/libavcodec/vvc/thread.c +++ b/libavcodec/vvc/thread.c @@ -372,13 +372,6 @@ static int task_is_stage_ready(VVCTask *t, int add) return task_has_target_score(t, stage, score); } -static int task_ready(const FFTask *_t, void *user_data) -{ - VVCTask *t = (VVCTask*)_t; - - return task_is_stage_ready(t, 0); -} - #define CHECK(a, b) \ do { \ if ((a) != (b)) \ @@ -689,7 +682,6 @@ FFExecutor* ff_vvc_executor_alloc(VVCContext *s, const int thread_count) s, sizeof(VVCLocalContext), task_priority_higher, - task_ready, task_run, }; return ff_executor_alloc(&callbacks, thread_count);