From patchwork Sat Mar 18 08:56:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 3000 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp609825vsy; Sat, 18 Mar 2017 01:57:15 -0700 (PDT) X-Received: by 10.28.87.6 with SMTP id l6mr1755678wmb.109.1489827435111; Sat, 18 Mar 2017 01:57:15 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h82si6463562wmh.163.2017.03.18.01.57.14; Sat, 18 Mar 2017 01:57:15 -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=@googlemail.com; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 412E5688394; Sat, 18 Mar 2017 10:56:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8B15F68836F for ; Sat, 18 Mar 2017 10:56:07 +0200 (EET) Received: by mail-wr0-f196.google.com with SMTP id u48so12003445wrc.1 for ; Sat, 18 Mar 2017 01:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zKTo7u52VhRgx60sfI+CDsvWf/lwXKSzYPNw4aiLu40=; b=t7aO2zgZlyy19teh1/Y1j1sXJJUFmADXuQOwYUM1GriWPu9ZIDy80BXUzMStAJwwIX HCbvDbscFUrws66KrYscAXSIor2qGgrsNx1w0Zbr0Mem967d0vas7kQzJAUM3U+55HmD npjrDt3nt5tyQgIFN7Nk6r7S7kiUjBzutslYBuBgutP8G4zluSBUu2dRKTjeNkwFjSZu vJwLrTzjYAphevi6+yrWP/myyso8FRUSdisT4a8yLhc/0/N6wxhUHREL+2foZsUeR85O Ok/0yAjiXC7apQYV1Iwdb+B/yR/73q9Ivw30RkpLkrS8mMsoBg1/AB+ztOqEQ3lMcVfd RoQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zKTo7u52VhRgx60sfI+CDsvWf/lwXKSzYPNw4aiLu40=; b=FUfKAFwDzXg7FVP9/mGovOlFkqOCO0F98H4YTWIGiqGV4chMXfXnqZVV/jLiV+3n/v zZ5CQE4El3D1xBl0nB7IYgAs+ziDEa4ieLY5lVHnWS77UIeG8eRJy/T0iZa85Yu0sMHg xG+FmOKUxl1PFf+0jd+xOtyOVLTiqqcTHhRkWAuq1BqJVuYt/l3an289QvOjtw1S2oyf w/KJXKFi6eqQJWmfByu3Jg7UGtRrliiiqVFdkpgF6lTGUxvpl10Vzwk8bmHq36DpBqnr DFV5A3+a/Kd8hL1BwHRqaUwVnmZXrJOv7EbbLJbzCGzMtE96xAGhrefSqMThkSN5OKQg CrPA== X-Gm-Message-State: AFeK/H2SwCl9Pl1oEwPwV0gBhan+713IV8PNopSBfffOX3/JdGSID1rYrMaSqykuH+uZ3w== X-Received: by 10.223.176.87 with SMTP id g23mr16025511wra.12.1489827384735; Sat, 18 Mar 2017 01:56:24 -0700 (PDT) Received: from localhost.localdomain (p4FF02CC6.dip0.t-ipconnect.de. [79.240.44.198]) by smtp.googlemail.com with ESMTPSA id p12sm12879637wrb.46.2017.03.18.01.56.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Mar 2017 01:56:23 -0700 (PDT) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 Mar 2017 09:56:02 +0100 Message-Id: <20170318085606.26011-6-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170318085606.26011-1-nfxjfg@googlemail.com> References: <20170318085606.26011-1-nfxjfg@googlemail.com> Subject: [FFmpeg-devel] [PATCH 5/9] pthread_frame: use better memory orders for frame progress X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: wm4 , Wan-Teh Chang , Anton Khirnov MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Wan-Teh Chang This improves commit 59c70227405c214b29971e6272f3a3ff6fcce3d0. In ff_thread_report_progress(), the fast code path can load progress[field] with the relaxed memory order, and the slow code path can store progress[field] with the release memory order. These changes are mainly intended to avoid confusion when one inspects the source code. They are unlikely to have measurable performance improvement. ff_thread_report_progress() and ff_thread_await_progress() form a pair. ff_thread_await_progress() reads progress[field] with the acquire memory order (in the fast code path). Therefore, one expects to see ff_thread_report_progress() write progress[field] with the matching release memory order. In the fast code path in ff_thread_report_progress(), the atomic load of progress[field] doesn't need the acquire memory order because the calling thread is trying to make the data it just decoded visible to the other threads, rather than trying to read the data decoded by other threads. In ff_thread_get_buffer(), initialize progress[0] and progress[1] using atomic_init(). Signed-off-by: Wan-Teh Chang Signed-off-by: Anton Khirnov Merges Libav commit 343e2833. Signed-off-by: wm4 --- libavcodec/pthread_frame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index b16c1b9928..2919e9546b 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -500,7 +500,7 @@ void ff_thread_report_progress(ThreadFrame *f, int n, int field) atomic_int *progress = f->progress ? (atomic_int*)f->progress->data : NULL; if (!progress || - atomic_load_explicit(&progress[field], memory_order_acquire) >= n) + atomic_load_explicit(&progress[field], memory_order_relaxed) >= n) return; p = f->owner->internal->thread_ctx; @@ -510,7 +510,7 @@ void ff_thread_report_progress(ThreadFrame *f, int n, int field) pthread_mutex_lock(&p->progress_mutex); - atomic_store(&progress[field], n); + atomic_store_explicit(&progress[field], n, memory_order_release); pthread_cond_broadcast(&p->progress_cond); pthread_mutex_unlock(&p->progress_mutex); @@ -816,8 +816,8 @@ static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int } progress = (atomic_int*)f->progress->data; - atomic_store(&progress[0], -1); - atomic_store(&progress[1], -1); + atomic_init(&progress[0], -1); + atomic_init(&progress[1], -1); } pthread_mutex_lock(&p->parent->buffer_mutex);