From patchwork Tue Oct 12 23:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Oskolkov X-Patchwork-Id: 12553921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A02F5C4332F for ; Tue, 12 Oct 2021 23:25:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3451360F3A for ; Tue, 12 Oct 2021 23:25:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3451360F3A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=posk.io Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D282A6B0071; Tue, 12 Oct 2021 19:25:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD545940007; Tue, 12 Oct 2021 19:25:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9CDF900002; Tue, 12 Oct 2021 19:25:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id ACDAB6B0071 for ; Tue, 12 Oct 2021 19:25:33 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3608F182152DA for ; Tue, 12 Oct 2021 23:25:33 +0000 (UTC) X-FDA: 78689369346.25.833D07B Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf29.hostedemail.com (Postfix) with ESMTP id E5671900013E for ; Tue, 12 Oct 2021 23:25:32 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id t11so542534plq.11 for ; Tue, 12 Oct 2021 16:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posk.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g+AAlSGdfykU1tO7w/flE6eblBoqjmus4rn0qbCYx5Y=; b=AOOMDKLEjpTIzLN/vIxj+Sop5AXNOpIZViYdWXnt644rrwdnl8WZQLZU34oi5ObIW8 LKfVKIZa+YTZ5GS6Zg7Ai/8ED7pCYe69eOp/AQCE6Acslk9WrjTEUjR8jfsTHx5DchuE sE/z/EmcB6hAKEaIfUwxF6SpTORvci8CD2JC4InwTBqLp6NgAqhx9cSEr3sBV1pwURXW OZ9yvzZNRilMWGVvXQBYwdOzLB1b/lXcDFi973ZAh+CNuP1p2osjYmCw0b7sntKP5FRO rBU0Yi66VVe7eweJ5YRvAeznEZLuzqrvw8RpC24/SCavF6BtN4QtcmmYMVb3eIkJmLkv r1bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g+AAlSGdfykU1tO7w/flE6eblBoqjmus4rn0qbCYx5Y=; b=UvEHsT/T/WTB+Q4pFdI7V1DCxUknZi2bvzFESQqNUOZ/sjm0WyxTHSr+lXBMIaatJD cz3FcUh/Pa6IC3NLmMqmJVXhsAADNEXzsW1XnNKWB3RYm9TI3vlE5qASyd3iqOHrFlku Cy42dgaNEjWsjNeVzmyWUrxo0hxVeFfB0cXs73jGJ2lmN8qBulBb7pxlqDkpKbWCyDlG X3BGSEDx178qirfhey4wSflQ9prfX5kKxM8e8K6BnRHxWZUrtTh2MRMHA0zasT5OhuL8 t1/JX2xrUtIQXzWj8PwXVs95c7TEKPfxa4sL84MbyzuLE/qgatlIu3Jw5eNrgF6poP2I kbvA== X-Gm-Message-State: AOAM531UbycHvZdYaCpVZfT2DVhVdfScOITfTdoX7u5gxHWu6Sg1D6cF 93K08nYrtlWF68WmRL9h1FOczA== X-Google-Smtp-Source: ABdhPJyC/bMU8enieCExPqMGGvVINf9J+YdHsRgtgg57gRVB06c6oeDKHVZwlWLsky9sQunaICaWDQ== X-Received: by 2002:a17:90b:4d84:: with SMTP id oj4mr9558127pjb.58.1634081131906; Tue, 12 Oct 2021 16:25:31 -0700 (PDT) Received: from posk-g1.lan (23-118-52-46.lightspeed.sntcca.sbcglobal.net. [23.118.52.46]) by smtp.gmail.com with ESMTPSA id v20sm12675026pgc.38.2021.10.12.16.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 16:25:31 -0700 (PDT) From: Peter Oskolkov X-Google-Original-From: Peter Oskolkov To: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Andrew Morton , Dave Hansen , Andy Lutomirski , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Cc: Paul Turner , Ben Segall , Peter Oskolkov , Peter Oskolkov , Andrei Vagin , Jann Horn , Thierry Delisle Subject: [PATCH v0.7 1/5] sched/umcg: add WF_CURRENT_CPU and externise ttwu Date: Tue, 12 Oct 2021 16:25:18 -0700 Message-Id: <20211012232522.714898-2-posk@google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211012232522.714898-1-posk@google.com> References: <20211012232522.714898-1-posk@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E5671900013E X-Stat-Signature: wg6i5wprmfiwqspir5hpzyqbgpbjh7iu Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=posk.io header.s=google header.b=AOOMDKLE; dmarc=none; spf=pass (imf29.hostedemail.com: domain of posk@posk.io designates 209.85.214.171 as permitted sender) smtp.mailfrom=posk@posk.io X-HE-Tag: 1634081132-954139 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add WF_CURRENT_CPU wake flag that advices the scheduler to move the wakee to the current CPU. This is useful for fast on-CPU context switching use cases such as UMCG. In addition, make ttwu external rather than static so that the flag could be passed to it from outside of sched/core.c. Signed-off-by: Peter Oskolkov --- kernel/sched/core.c | 3 +-- kernel/sched/fair.c | 4 ++++ kernel/sched/sched.h | 15 +++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 935c2da00339..d6da1efb5ce6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3944,8 +3944,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success) * Return: %true if @p->state changes (an actual wakeup was done), * %false otherwise. */ -static int -try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) +int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) { unsigned long flags; int cpu, success = 0; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 87db481e8a56..c900a3f16607 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6890,6 +6890,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags) if (wake_flags & WF_TTWU) { record_wakee(p); + if ((wake_flags & WF_CURRENT_CPU) && + cpumask_test_cpu(cpu, p->cpus_ptr)) + return cpu; + if (sched_energy_enabled()) { new_cpu = find_energy_efficient_cpu(p, prev_cpu); if (new_cpu >= 0) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index a00fc7057d97..4b566607952b 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2036,13 +2036,14 @@ static inline int task_on_rq_migrating(struct task_struct *p) } /* Wake flags. The first three directly map to some SD flag value */ -#define WF_EXEC 0x02 /* Wakeup after exec; maps to SD_BALANCE_EXEC */ -#define WF_FORK 0x04 /* Wakeup after fork; maps to SD_BALANCE_FORK */ -#define WF_TTWU 0x08 /* Wakeup; maps to SD_BALANCE_WAKE */ +#define WF_EXEC 0x02 /* Wakeup after exec; maps to SD_BALANCE_EXEC */ +#define WF_FORK 0x04 /* Wakeup after fork; maps to SD_BALANCE_FORK */ +#define WF_TTWU 0x08 /* Wakeup; maps to SD_BALANCE_WAKE */ -#define WF_SYNC 0x10 /* Waker goes to sleep after wakeup */ -#define WF_MIGRATED 0x20 /* Internal use, task got migrated */ -#define WF_ON_CPU 0x40 /* Wakee is on_cpu */ +#define WF_SYNC 0x10 /* Waker goes to sleep after wakeup */ +#define WF_MIGRATED 0x20 /* Internal use, task got migrated */ +#define WF_ON_CPU 0x40 /* Wakee is on_cpu */ +#define WF_CURRENT_CPU 0x80 /* Prefer to move the wakee to the current CPU. */ #ifdef CONFIG_SMP static_assert(WF_EXEC == SD_BALANCE_EXEC); @@ -3060,6 +3061,8 @@ static inline bool is_per_cpu_kthread(struct task_struct *p) extern void swake_up_all_locked(struct swait_queue_head *q); extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait); +extern int try_to_wake_up(struct task_struct *tsk, unsigned int state, int wake_flags); + #ifdef CONFIG_PREEMPT_DYNAMIC extern int preempt_dynamic_mode; extern int sched_dynamic_mode(const char *str);