From patchwork Tue Nov 28 05:54:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 119792 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1293961qgn; Mon, 27 Nov 2017 21:58:00 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ/wU7oVuBMea+QRsBbuWCP871S2+Dm4Q61yHYRz10L0yhd/QR6P4sh8kglTDC04uEIdP3G X-Received: by 10.84.133.164 with SMTP id f33mr14638626plf.241.1511848679952; Mon, 27 Nov 2017 21:57:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511848679; cv=none; d=google.com; s=arc-20160816; b=qn+e4+CdOR47MLmZH/HH44FhYizcaoO0i+PgqGNW8ihNi332NwgLm4SFF9dLHz7RZC YTuBxJDWb3oYipch3hx3Klg6DYX5u2vGxN5yJGZn4LP4KsPAW6oWGaDF3tL2MQXYeGZC jpgGOPVr+dkeAkZqs899tAgzPMXbzDnJfzy7E36O9Gi4vV70D9FpErjhN8soVmDii3IR EHtAnh6xSFJDyzuDplq9PE0fkvIW2Vbub3KUN71MyYIjQ2vmO5C0IZ7FTJlzMazuG95J Ki8aPAi689B016dA8w3MwKdBWdAQc2N772BacwGOTJ7BaD+/IHW3OSdQ/AuthesiwNTw 1foA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=GcWVw4rVf8g6k5wtQ5DZlgfrPUUYEf4uCQzqavX+DOk=; b=MrFDV8pAOxXaCvhqCMXT+zrO5S/oqpixReO//wpwIFcwtR9xjnIKUnBc6cqMogRNom 9h6finp4mKXrwpioNV8cvilmQF6tKmhDfcJOdahPQLRIeF7apFGPRTvt1rrxH6ie3DEc 5/OMDkUWjF+ZXGvxuAdTjPM77uXNXLYx8mB+JXi+cA9qaFHwWcTqKGvOomf07eZiiAo1 ojWUYbIndo7bmstbnXE2gPVq5RD4cX/QWSYEYJ4P83eMZS3KbbXflg2OJmUjV0Y7yPXK hkkUd5Wqeh/pij5wAaDkEihyW+BLcM53d2YgfVURfby+r1YR+4lb62LERIAL8Y23WxKM YaDA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m18si17042532pge.473.2017.11.27.21.57.59; Mon, 27 Nov 2017 21:57:59 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751036AbdK1F55 (ORCPT + 28 others); Tue, 28 Nov 2017 00:57:57 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:50978 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750711AbdK1F54 (ORCPT ); Tue, 28 Nov 2017 00:57:56 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A81FF851D6C21; Tue, 28 Nov 2017 13:57:42 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Tue, 28 Nov 2017 13:57:37 +0800 From: Zhen Lei To: Ingo Molnar , Peter Zijlstra , linux-kernel CC: Hanjun Guo , Libin , "Kefeng Wang" , Zhen Lei Subject: [PATCH 1/1] sched: simplify find_lock_later_rq and find_lock_lowest_rq code Date: Tue, 28 Nov 2017 13:54:37 +0800 Message-ID: <1511848477-1120-1-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For each function, it's exactly only one place need to return the found rq, all other cases are NULL. So there is no need to explicitly set the local variable later_rq/lowest_rq to NULL. Signed-off-by: Zhen Lei --- kernel/sched/deadline.c | 12 ++++-------- kernel/sched/rt.c | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) -- 1.8.3 diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 2473736..a2ace81 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1876,7 +1876,7 @@ static int find_later_rq(struct task_struct *task) /* Locks the rq it finds */ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) { - struct rq *later_rq = NULL; + struct rq *later_rq; int tries; int cpu; @@ -1890,15 +1890,13 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) if (later_rq->dl.dl_nr_running && !dl_time_before(task->dl.deadline, - later_rq->dl.earliest_dl.curr)) { + later_rq->dl.earliest_dl.curr)) /* * Target rq has tasks of equal or earlier deadline, * retrying does not release any lock and is unlikely * to yield a different result. */ - later_rq = NULL; break; - } /* Retry if something changed. */ if (double_lock_balance(rq, later_rq)) { @@ -1908,7 +1906,6 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) !dl_task(task) || !task_on_rq_queued(task))) { double_unlock_balance(rq, later_rq); - later_rq = NULL; break; } } @@ -1921,14 +1918,13 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) if (!later_rq->dl.dl_nr_running || dl_time_before(task->dl.deadline, later_rq->dl.earliest_dl.curr)) - break; + return later_rq; /* Otherwise we try again. */ double_unlock_balance(rq, later_rq); - later_rq = NULL; } - return later_rq; + return NULL; } static struct task_struct *pick_next_pushable_dl_task(struct rq *rq) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 4056c19..cf78bbb 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1696,7 +1696,7 @@ static int find_lowest_rq(struct task_struct *task) /* Will lock the rq it finds */ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) { - struct rq *lowest_rq = NULL; + struct rq *lowest_rq; int tries; int cpu; @@ -1708,15 +1708,13 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) lowest_rq = cpu_rq(cpu); - if (lowest_rq->rt.highest_prio.curr <= task->prio) { + if (lowest_rq->rt.highest_prio.curr <= task->prio) /* * Target rq has tasks of equal or higher priority, * retrying does not release any lock and is unlikely * to yield a different result. */ - lowest_rq = NULL; break; - } /* if the prio of this runqueue changed, try again */ if (double_lock_balance(rq, lowest_rq)) { @@ -1733,21 +1731,19 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) !task_on_rq_queued(task))) { double_unlock_balance(rq, lowest_rq); - lowest_rq = NULL; break; } } /* If this rq is still suitable use it. */ if (lowest_rq->rt.highest_prio.curr > task->prio) - break; + return lowest_rq; /* try again */ double_unlock_balance(rq, lowest_rq); - lowest_rq = NULL; } - return lowest_rq; + return NULL; } static struct task_struct *pick_next_pushable_task(struct rq *rq)