Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2284002rwr; Fri, 28 Apr 2023 08:22:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SfPit3FL/i7s5u6aH45AbQ4T817UEL4vNuzpkBLvR8eXfE9EjFcNZTj3NZ1HzKcr2DVsm X-Received: by 2002:a17:903:2287:b0:1a2:8940:6dbd with SMTP id b7-20020a170903228700b001a289406dbdmr6840535plh.45.1682695363767; Fri, 28 Apr 2023 08:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682695363; cv=none; d=google.com; s=arc-20160816; b=MZerYWKf1hqPJWb4yanKmr3t/r/sbgvBuB5SsoOsw56H1GOblxCNlbpvlV/amAYAfb cSNQBo56q/H5OyyTST/SQn5jSQge3RqL083xadYbJDpqbRLndCp5nfiYOtdBc5YJb2hq dwKlwsxheQW8fESYN+3lmLauAnvbRdCBS7sGnpqICJFeBbRsS5sdp76q1ugD+Ut49ImW Gg24VfI85pjFl0YAv/Mi8bk0/oOHdekXCmZLgoGCDc+rJ3Il3eBpSjpiTU5MUnDGoOqc 1vu466UeCknz8h6QiiPXkozshHMm3q8l49fAKutKs3gk5tPNXZW3Nh6iCEJJtuhsKZqt gEiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=I9awZVrQ/g6iwhSYIH2zAUUpQ7e2bMID/Z2xMbDlULI=; b=c+yQMdmX8Tjs53KTL4IMMhnMi8j8dyF4yZso3fBNwFoUI5Y49v/1BmPpQWd3Fg8ISd YPOjSKnR/C88veXfbUS9VamPNNAh68w7Zpk+viGvBXQLZpIZ4nSCRnxVbzrtmQzIvfIA tnVgnCSx2UNG7TnMRmtBg5WeDuTwW43gQWOVbU5Jc21zA2hLJyWSIziPXqsuxqbql9En juXAU0muaXNhhkK1TzBlJBErLfU5Q7aLLPnQCYv00X7ja+pGLz+B4bD6Gn+lO+n6B6V0 QmsIlmXpIP4NRm0kFaq3LkhusovWdMvdxCMkq/M6jm2Ft7OlHeP9A75QqNJ9EJH3C/XS kgqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aNJP0dyA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a170902684f00b001a24efa45bfsi20390394pln.81.2023.04.28.08.22.29; Fri, 28 Apr 2023 08:22:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aNJP0dyA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346085AbjD1PUp (ORCPT + 99 others); Fri, 28 Apr 2023 11:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbjD1PUo (ORCPT ); Fri, 28 Apr 2023 11:20:44 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B9B72109 for ; Fri, 28 Apr 2023 08:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682695243; x=1714231243; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=geOWADtIr/X6yJyStUIGmxf2Rf+0LYbb/uDeFXpP+oU=; b=aNJP0dyAqJvHE+zAVhsOZgNb5Fz63FV/mZvYSpCnn5AwDELZU9bW3zGa vPe3IpRPAodOLX2mN9h+afFVzMn2oA0Fg57dFo29cE2fAb9XvN8RfN/Sz PvV2EcX2rZ4nzJSAVmZYfmnqAqj6Fc3+HMVpxQH+guLkcIn++yLq9gZvq qidedtOxgY3mBaCff6mc0mCclBIIzm0nxIKsRuuEL8axjX3wJ6zjk4UAh cQ4l5RhWXqDeDbNLo6fINnGZUoLTeKbW4FZx6cz1TEvbAy5KcNncRLuB/ Pzy4fu3iRATQ3kvbrOVBo013dKugHZJICXGtSnQyY1lcjeneluLCWdHD9 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10694"; a="375768796" X-IronPort-AV: E=Sophos;i="5.99,234,1677571200"; d="scan'208";a="375768796" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2023 08:20:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10694"; a="672224122" X-IronPort-AV: E=Sophos;i="5.99,234,1677571200"; d="scan'208";a="672224122" Received: from chenyu-dev.sh.intel.com ([10.239.62.164]) by orsmga006.jf.intel.com with ESMTP; 28 Apr 2023 08:20:36 -0700 From: Chen Yu To: Peter Zijlstra , Vincent Guittot , Ingo Molnar , Juri Lelli Cc: Mel Gorman , Tim Chen , Dietmar Eggemann , Steven Rostedt , Ben Segall , K Prateek Nayak , Abel Wu , Yicong Yang , "Gautham R . Shenoy" , Honglei Wang , Len Brown , Chen Yu , Tianchen Ding , Joel Fernandes , Josh Don , kernel test robot , Arjan Van De Ven , Aaron Lu , linux-kernel@vger.kernel.org, Chen Yu Subject: [PATCH v8 0/2] sched/fair: Introduce SIS_CURRENT to wake up short task on current CPU Date: Sat, 29 Apr 2023 07:15:59 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The main purpose is to avoid too many cross CPU wake up when it is unnecessary. The frequent cross CPU wakeup brings significant damage to some workloads, especially on high core count systems: 1. The cross CPU wakeup triggers race condition that, some wakers are stacked on 1 CPU which delays the wakeup of their wakees. 2. The cross CPU wakeup brings c2c overhead if the waker and wakee share cache resource. Inhibits the cross CPU wake-up by placing the wakee on waking CPU, if both the waker and wakee are short-duration tasks, and when the waker and wakee wake up each other. The first patch introduces the definition of a short-duration task. The second patch leverages the first patch to choose a local CPU for wakee. Overall there is performance improvement when the benchmark has close 1:1 waker/wakee relationship, such as will-it-scale, netperf, tbench. And for netperf, it has a universal performance improvement under many different utilization. And there is no noticeable impact on schbench, hackbench, or a OLTP workload with a commercial RDBMS, according to the test on Intel Sapphire Rapids, which has 2 x 56C/112T = 224 CPUs. Per the test on Zen3 from Prateek on v7, tbench/netperf shows good improvement at 128 clients, SPECjbb2015 shows improvement in max-jOPS. And the result of v8 should not be quite different from v7 because the threshold in v7 and v8 are comparable. Changes since v7: 1. Replace sysctl_sched_min_granularity with sysctl_sched_migration_cost to determine if a task is a short duration one, according to Peter's suggestion. Changes since v6: 1. Rename SIS_SHORT to SIS_CURRENT, which better describes this feature. 2. Remove the 50% utilization threshold. Removes the has_idle_cores check. After this change, SIS_CURRENT is applicable to all system utilization. 3. Add a condition that only waker and wakee wake up each other would enable the SIS_CURRENT. That is, A->last_wakee = B and B->last_wakee = A. Changes since v5: 1. Check the wakee_flips of the waker/wakee. If the wakee_flips of waker/wakee are both 0, it indicates that the waker and the wakee are waking up each other. In this case, put them together on the same CPU. This is to avoid that too many wakees are stacked on one CPU, which might cause regression on redis. Changes since v4: 1. Dietmar has commented on the task duration calculation. So refined the commit log to reduce confusion. 2. Change [PATCH 1/2] to only record the average duration of a task. So this change could benefit UTIL_EST_FASTER[1]. 3. As v4 reported regression on Zen3 and Kunpeng Arm64, add back the system average utilization restriction that, if the system is not busy, do not enable the short wake up. Above logic has shown improvment on Zen3[2]. 4. Restrict the wakeup target to be current CPU, rather than both current CPU and task's previous CPU. This could also benefit wakeup optimization from interrupt in the future, which is suggested by Yicong. Changes since v3: 1. Honglei and Josh have concern that the threshold of short task duration could be too long. Decreased the threshold from sysctl_sched_min_granularity to (sysctl_sched_min_granularity / 8), and the '8' comes from get_update_sysctl_factor(). 2. Export p->se.dur_avg to /proc/{pid}/sched per Yicong's suggestion. 3. Move the calculation of average duration from put_prev_task_fair() to dequeue_task_fair(). Because there is an issue in v3 that, put_prev_task_fair() will not be invoked by pick_next_task_fair() in fast path, thus the dur_avg could not be updated timely. 4. Fix the comment in PATCH 2/2, that "WRITE_ONCE(CPU1->ttwu_pending, 1);" on CPU0 is earlier than CPU1 getting "ttwu_list->p0", per Tianchen. 5. Move the scan for CPU with short duration task from select_idle_cpu() to select_idle_siblings(), because there is no CPU scan involved, per Yicong. Changes since v2: 1. Peter suggested comparing the duration of waker and the cost to scan for an idle CPU: If the cost is higher than the task duration, do not waste time finding an idle CPU, choose the local or previous CPU directly. A prototype was created based on this suggestion. However, according to the test result, this prototype does not inhibit the cross CPU wakeup and did not bring improvement. Because the cost to find an idle CPU is small in the problematic scenario. The root cause of the problem is a race condition between scanning for an idle CPU and task enqueue(please refer to the commit log in PATCH 2/2). So v3 does not change the core logic of v2, with some refinement based on Peter's suggestion. 2. Simplify the logic to record the task duration per Peter and Abel's suggestion. [1] https://lore.kernel.org/lkml/c56855a7-14fd-4737-fc8b-8ea21487c5f6@arm.com/ [2] https://lore.kernel.org/all/cover.1666531576.git.yu.c.chen@intel.com/ v6: https://lore.kernel.org/lkml/cover.1677069490.git.yu.c.chen@intel.com/ v5: https://lore.kernel.org/lkml/cover.1675361144.git.yu.c.chen@intel.com/ v4: https://lore.kernel.org/lkml/cover.1671158588.git.yu.c.chen@intel.com/ v3: https://lore.kernel.org/lkml/cover.1669862147.git.yu.c.chen@intel.com/ v2: https://lore.kernel.org/all/cover.1666531576.git.yu.c.chen@intel.com/ v1: https://lore.kernel.org/lkml/20220915165407.1776363-1-yu.c.chen@intel.com/ Chen Yu (2): sched/fair: Record the average duration of a task sched/fair: Introduce SIS_CURRENT to wake up short task on current CPU include/linux/sched.h | 3 +++ kernel/sched/core.c | 2 ++ kernel/sched/debug.c | 1 + kernel/sched/fair.c | 59 +++++++++++++++++++++++++++++++++++++++++ kernel/sched/features.h | 1 + 5 files changed, 66 insertions(+) -- 2.25.1