From patchwork Thu Apr 26 10:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 134464 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2075093lji; Thu, 26 Apr 2018 03:31:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/0siTdabOjXfXSuQ95z9JM9W7TueTZh8q1D2J16uhVkIPfRcQP5/WXDL/1F/9R2IHBLnqL X-Received: by 10.98.12.202 with SMTP id 71mr31566931pfm.61.1524738673629; Thu, 26 Apr 2018 03:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524738673; cv=none; d=google.com; s=arc-20160816; b=vy95X+l4H5dNEOAp54VhmOuDmnhipefEIEvg+ojZ33HGp4Yd5EsoyzM3tiVxOo0R8X 9tikkjVuo/dNV0vZN13o6PToB2qvRgsPln13u/FRV/SI5NvmcLCX7+uSqBPnIZAq6gxU Iw8MlJvg+480gVo33Kk3DmgGB1Q2qU1BoReuLIWVInkSvU62pGSSAftroEtbi8nRh4tE n7enrCHGGe1kpuK+Klx+hlR4G5vEOzoC2iSgqW6oDzCCAXsOzaS9fqRTWc50BwA/8wch sEQx79OQSROqN32ip/rEoq+7qmhxTsGCp/mzFJR/Rr/1NOje7oo11bKfxZ24vVz5IwNf mYhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=lpfosxyDddJXn7jrg2jVCbacgU4loajLBn+6hTy39WA=; b=nYoBjK6vaMirq3VhC8xd0rR24H3nZFuUuf2Z2b6ryJ6dVQ/9wArYJCpBgYtEXBxEHM sHmauS7lScStgni99dVXZ6nn2OrxCp3gNkXsmsKbBfhxaf10bVk/0wyE8JElHAUHh3N0 mj12713havj6ebYYieY/ZrqGidpESuYhzLFrevy+i3Aw3QIQqMfm/WXAjvSswPGLWFYa ipGUVWiIAcbJdC9y9E2Fr+yKgEnkoR+qVRA9l39mIzSoRnmNwnlzuo3Vlc/VM4Xkhr2S MIwWdYHUzHCmeQ3VzJNVtj+Y067qXAFdYnUUMGuxmtFPC5FLqKKTcE0wONIyJp2JKDXy 3IOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YdB3Zzws; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j70si14510907pfj.267.2018.04.26.03.31.13; Thu, 26 Apr 2018 03:31:13 -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 header.s=google header.b=YdB3Zzws; 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 S1755312AbeDZKbI (ORCPT + 29 others); Thu, 26 Apr 2018 06:31:08 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:39685 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754081AbeDZKbE (ORCPT ); Thu, 26 Apr 2018 06:31:04 -0400 Received: by mail-pg0-f66.google.com with SMTP id b9so15597688pgf.6 for ; Thu, 26 Apr 2018 03:31:04 -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; bh=lpfosxyDddJXn7jrg2jVCbacgU4loajLBn+6hTy39WA=; b=YdB3Zzws8QxlNqSNa6Y6xyhXNsrssKgE89ZHVX/4M1mLXkqxZh4G8Q/LEPlp/3fUtB NNzY9y0bTb7+zlxWF+B/VVcL2/oLT3D+7fz86owxpcPdHL0x8fzLROsBrEYZ60MqgifA NdvLV3k7YQtI8sUPqInnUUhB6kswDtI368NPE= 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; bh=lpfosxyDddJXn7jrg2jVCbacgU4loajLBn+6hTy39WA=; b=IsyHvMTT/+iVGUeyeFws/o5xGAKRSoSkjUa3psHTT+6CajiX3jSM32MbaSVnaiP6uE fbWO9snN3D3w2sUAXx293UUxWyo9k9T8RIwzq4ZavAuDVpGdx13P+RbVEzgPLBnu/PWV L2hjxmO2AB/3rxk5rIcxZHU9SmQJYGn5t75GQ0PkXUSb311FqjufqOSJBI9vR5GQor+4 xkXXgKLvcZUgUfn4FSJoFE1kc3X76WSrKwsjS2YSnAs6lSE+xemXpqL+oxn8FH/E9LWk a3giB06uXqIhfAZgoW2rL3QdfN4ii5AA1QaL/KdewWEhq11fO8zFgqRqXjkk0g7l4ogX RguQ== X-Gm-Message-State: ALQs6tCobZRL7wD6FOrH6lkaUGmAukJAOljkYlTj2l+ixblEz2mxYccH fPP9NF8vjU/Ecbefx05dUAedQA== X-Received: by 2002:a17:902:848e:: with SMTP id c14-v6mr32673965plo.95.1524738664020; Thu, 26 Apr 2018 03:31:04 -0700 (PDT) Received: from localhost ([122.172.61.40]) by smtp.gmail.com with ESMTPSA id u27sm37259012pfk.100.2018.04.26.03.31.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Apr 2018 03:31:03 -0700 (PDT) From: Viresh Kumar To: Ingo Molnar , Peter Zijlstra Cc: Viresh Kumar , Vincent Guittot , Rohit Jain , linux-kernel@vger.kernel.org Subject: [PATCH V2 1/2] sched/fair: Rearrange select_task_rq_fair() to optimize it Date: Thu, 26 Apr 2018 16:00:50 +0530 Message-Id: <20831b8d237bf3a20e4e328286f678b425ff04c9.1524738578.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rearrange select_task_rq_fair() a bit to avoid executing some conditional statements in few specific code-paths. That gets rid of the goto as well. This shouldn't result in any functional changes. Signed-off-by: Viresh Kumar Tested-by: Rohit Jain --- V1->V2: - Optimize a bit more and get rid of affine_sd variable (Valentin) - Add unlikely while checking for non-NULL sd and add fast/slow path comments (Joel) - Add tested-by from Rohit. kernel/sched/fair.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 54dc31e7ab9b..84fc74ddbd4b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6613,7 +6613,7 @@ static int wake_cap(struct task_struct *p, int cpu, int prev_cpu) static int select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_flags) { - struct sched_domain *tmp, *affine_sd = NULL, *sd = NULL; + struct sched_domain *tmp, *sd = NULL; int cpu = smp_processor_id(); int new_cpu = prev_cpu; int want_affine = 0; @@ -6636,7 +6636,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f */ if (want_affine && (tmp->flags & SD_WAKE_AFFINE) && cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) { - affine_sd = tmp; + if (cpu != prev_cpu) + new_cpu = wake_affine(tmp, p, cpu, prev_cpu, sync); + + sd = NULL; /* Prefer wake_affine over balance flags */ break; } @@ -6646,33 +6649,25 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f break; } - if (affine_sd) { - sd = NULL; /* Prefer wake_affine over balance flags */ - if (cpu == prev_cpu) - goto pick_cpu; - - new_cpu = wake_affine(affine_sd, p, cpu, prev_cpu, sync); - } + if (unlikely(sd)) { + /* Slow path */ - if (sd && !(sd_flag & SD_BALANCE_FORK)) { /* * We're going to need the task's util for capacity_spare_wake * in find_idlest_group. Sync it up to prev_cpu's * last_update_time. */ - sync_entity_load_avg(&p->se); - } - - if (!sd) { -pick_cpu: - if (sd_flag & SD_BALANCE_WAKE) { /* XXX always ? */ - new_cpu = select_idle_sibling(p, prev_cpu, new_cpu); + if (!(sd_flag & SD_BALANCE_FORK)) + sync_entity_load_avg(&p->se); - if (want_affine) - current->recent_used_cpu = cpu; - } - } else { new_cpu = find_idlest_cpu(sd, p, cpu, prev_cpu, sd_flag); + } else if (sd_flag & SD_BALANCE_WAKE) { /* XXX always ? */ + /* Fast path */ + + new_cpu = select_idle_sibling(p, prev_cpu, new_cpu); + + if (want_affine) + current->recent_used_cpu = cpu; } rcu_read_unlock();