From patchwork Thu Apr 13 14:02:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 97371 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp733217qgf; Thu, 13 Apr 2017 07:04:40 -0700 (PDT) X-Received: by 10.98.141.153 with SMTP id p25mr3504065pfk.195.1492092280626; Thu, 13 Apr 2017 07:04:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17si24119967plj.72.2017.04.13.07.04.40; Thu, 13 Apr 2017 07:04:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754189AbdDMOE2 (ORCPT + 15 others); Thu, 13 Apr 2017 10:04:28 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35426 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753869AbdDMODe (ORCPT ); Thu, 13 Apr 2017 10:03:34 -0400 Received: by mail-pf0-f172.google.com with SMTP id i5so29137650pfc.2 for ; Thu, 13 Apr 2017 07:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/6Ae5RRMESoMSrbJif3VReUQY+Xp6meE20gJIT7vRjw=; b=CTIH4q5qiKZtNZ30VB3mhPbQd+BrayvYsTuywBjuhBWayDr83ppD3jBigW4u/6Uj4I VkQDHWyWPK6/X2GPtpJtIYJOK7UmSq3Zan+x+FFywKN4dGgtb3wputq+kL0lDqc75Dsh dQ22NfcwRUQQoI8zsxOqz4uZYE9Y9JnXp5tf8= 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=/6Ae5RRMESoMSrbJif3VReUQY+Xp6meE20gJIT7vRjw=; b=E9L1ocblOrlipDWadRPaLtXV3I9zDoAjOoJd5Ib+ePZecj7xLXaAMDIhTKs7cbhTR7 92uTbbGbzgVBI1hYvLOdh7PCZ/+EJUKEzyKZ7Cy7/kmntVeZuNz0HB3bKlHSDuzIMtSg 1gZYQNtzOi7a7biHbbBIcEvRNDPKOo1pM/kiT5MqActzcQsgfIhcDAKIlp/ZJGbd3Saj rsyv9U2BKbemBxIBTFAMdu9+u8uxTuwv2AmhKnkTu7KhW76KUGkLstroKtnvH5MCuBPA LvzzrWzndnDI8eYcbPgVcyUBpbUMbd3AQVK0/ydZuwhQn1IlRHjXh/oJ+PpKhul1jRTK YjAg== X-Gm-Message-State: AN3rC/6G1KnsMCMl7zJ/XwUAyQ5xhOYK/54E9fiF9Lw4s8O2aMeg8qsd Zop0J5KkofFf8AG1 X-Received: by 10.99.132.72 with SMTP id k69mr3657020pgd.97.1492092213960; Thu, 13 Apr 2017 07:03:33 -0700 (PDT) Received: from localhost.localdomain ([104.237.91.83]) by smtp.gmail.com with ESMTPSA id z21sm43043695pgc.53.2017.04.13.07.03.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Apr 2017 07:03:32 -0700 (PDT) From: Alex Shi To: peterz@infradead.org, mingo@redhat.com, corbet@lwn.net, linux-kernel@vger.kernel.org (open list:LOCKING PRIMITIVES) Cc: linux-kernel@vger.kernel.org, Alex Shi , Steven Rostedt , Sebastian Siewior , Thomas Gleixner Subject: [PATCH 2/3] rtmutex: deboost priority conditionally when rt-mutex unlock Date: Thu, 13 Apr 2017 22:02:53 +0800 Message-Id: <1492092174-31734-3-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1492092174-31734-1-git-send-email-alex.shi@linaro.org> References: <1492092174-31734-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The rt_mutex_fastunlock() will deboost 'current' task when it should be. but the rt_mutex_slowunlock() function will set the 'deboost' flag unconditionally. That cause some unnecessary priority adjustment. 'current' release this lock, so 'current' should be a higher prio task than the next top waiter, unless the current prio was gotten from this top waiter, iff so, we need to deboost 'current' after the lock release. Signed-off-by: Alex Shi Cc: Steven Rostedt Cc: Sebastian Siewior To: linux-kernel@vger.kernel.org To: Ingo Molnar To: Peter Zijlstra Cc: Thomas Gleixner --- kernel/locking/rtmutex.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 6edc32e..05ff685 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1037,10 +1037,11 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock, * * Called with lock->wait_lock held and interrupts disabled. */ -static void mark_wakeup_next_waiter(struct wake_q_head *wake_q, +static bool mark_wakeup_next_waiter(struct wake_q_head *wake_q, struct rt_mutex *lock) { struct rt_mutex_waiter *waiter; + bool deboost = false; raw_spin_lock(¤t->pi_lock); @@ -1055,6 +1056,15 @@ static void mark_wakeup_next_waiter(struct wake_q_head *wake_q, rt_mutex_dequeue_pi(current, waiter); /* + * 'current' release this lock, so 'current' should be a higher prio + * task than the next top waiter, unless the current prio was gotten + * from this top waiter, iff so, we need to deboost 'current' after + * the lock release. + */ + if (current->prio == waiter->prio) + deboost = true; + + /* * As we are waking up the top waiter, and the waiter stays * queued on the lock until it gets the lock, this lock * obviously has waiters. Just set the bit here and this has @@ -1067,6 +1077,8 @@ static void mark_wakeup_next_waiter(struct wake_q_head *wake_q, raw_spin_unlock(¤t->pi_lock); wake_q_add(wake_q, waiter->task); + + return deboost; } /* @@ -1336,6 +1348,7 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock, struct wake_q_head *wake_q) { unsigned long flags; + bool deboost = false; /* irqsave required to support early boot calls */ raw_spin_lock_irqsave(&lock->wait_lock, flags); @@ -1389,12 +1402,12 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock, * * Queue the next waiter for wakeup once we release the wait_lock. */ - mark_wakeup_next_waiter(wake_q, lock); + deboost = mark_wakeup_next_waiter(wake_q, lock); raw_spin_unlock_irqrestore(&lock->wait_lock, flags); /* check PI boosting */ - return true; + return deboost; } /*