Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1112946pxy; Sun, 1 Aug 2021 13:08:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCmxslKLPcFK6MbFSWKeZmsa7gL5i+2/nap3QYXZfJI3wxSj/7NWTeYcvFAl2fU9iPL0tF X-Received: by 2002:a05:6402:53:: with SMTP id f19mr15514337edu.200.1627848489553; Sun, 01 Aug 2021 13:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627848489; cv=none; d=google.com; s=arc-20160816; b=CAwdce7P5MUTclL1lz0c7PrOpwtEO/asPDtsKmyjk21L8IXJrIXLiB/8VUElP4WiRY wEj1/Q5iYuHJXCAyaEA/NWhyEc6hqomOsnW1zkSMWs6M5Aao8LGwbU9xC8TJAgA2IElc B7EBBPvlo86shpxip7J1555tZ9yMkUMGZcEqURHqrLa3Ffll8blbwDShh36AEFG5nCLP 62UEL2ZG1NrnRJSIPUzdVGlX1QBx+qJH2tTKnWj+8KgcNYe10GM5fe630T8wxPtgdwfV gQXRkBqnwQGMJqDAKJRfdrmTy2PqNWNZTcqTe+FamVL4bBzvZclr5wbTOO4lc5Qj+4+G D2FQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vCPnqnwkhUpJbwG5YpNTPwxxCuigLKiLFFGzIuCOfoc=; b=ICG2gCyoa/ffU1VGeFmSlwUS+JhJvHAAZBYHGtUNiFxVLgPQQjngqbsA0qeF/Pbn6j CM3vnbsijIzlUf330hB2QkLZrri8bt4IiNij9+m2q5icYohxGBfMhDBvTyNZzE5n6BqY CX5oiVLFlQ4/Zne6plimiGkZ+SlJtm9FTCs4yV6maxuMhxcbg1MCYDyQLxSo0B++eOZq Xuz8y8dYYR5eqELRFN353LKGrS/tSjbgK8buDOcgJK7bqABNYcJ7fxVK5Ha2VGtuccsE Mw765oBZkGWI2/m2IL8W3EweAQDth0jrwmuawsKc9TipkFmUJdFmif5UDIVBW0upKn2r gbsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=IpSW8r9z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si2111909edz.248.2021.08.01.13.07.45; Sun, 01 Aug 2021 13:08:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=IpSW8r9z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230388AbhHAUGc (ORCPT + 99 others); Sun, 1 Aug 2021 16:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbhHAUGc (ORCPT ); Sun, 1 Aug 2021 16:06:32 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AFA2C06175F for ; Sun, 1 Aug 2021 13:06:23 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d1so17248694pll.1 for ; Sun, 01 Aug 2021 13:06:23 -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=vCPnqnwkhUpJbwG5YpNTPwxxCuigLKiLFFGzIuCOfoc=; b=IpSW8r9zaSH4oRDUs3Pg0es824Pb7yXKWxj281dCKHHkF5SlVQxracuMrevOuJf6ZS 1R4Z8elXmy8leUdqpJhWlmHJ7Q9MWDxbiGTWCerQJBKGwL0glZ7LFy3X7s7e+t88n+3g YM22THFp3KWGl8aXUJBdIDOpGkXI5BvgPnCFdt7OzxcfF6jp5CStY1sfXgunp3LTpXIl zg7ONpyyCeioW1yqyNi6sTNJ365FZD6KWpUwvGtv0p/qRJkUFTjskayjYBdsdN7cR2NH NR4VDWwJMfK0RltVZOGDcwJHjC6Dchtw7nGzh2wDYipBn99ZSMvETBa5XkN3Ldw0y4qu gUXA== 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:mime-version:content-transfer-encoding; bh=vCPnqnwkhUpJbwG5YpNTPwxxCuigLKiLFFGzIuCOfoc=; b=OVO1d3Mr63wV1/riD0VEqdDUElA6eRuLOnMdk4T+YZDvq7aR45cvtXjpu6/3x8Jy0i Tf/GVaXqlFllO5hM3YslS+Hwk8eWwE/kMb6Nsh6k//N1IZyV6rRTWVkIhUmNNnO72i7m QOK2wv2c4PAqw1C1uQYn9TAFZylAx7TqBc3rCCfRwl4GuTuy59sHHJEuHLUSO4IkQF8D MFua+bLWa3cHXDhdDAtNSifBlUDirN1Nr4Xnbi2GisqtoFvz98zOOnb5TnDiJXelAi0g cMx9xs6a4+tjW8jr0F/GY9sVsKet2XxRXwpiR5sa4+OoOUXE43cGoeiN88BvyZtbc4SZ hruQ== X-Gm-Message-State: AOAM531SwvQZ2s6CrDkVxz9g9Q7zeZyDSD3RTU0gPpzZYVl297oZ7Ros 0Gcl8I+QRUg9geuedkK9GYXj1Q== X-Received: by 2002:a65:4307:: with SMTP id j7mr4588063pgq.387.1627848382865; Sun, 01 Aug 2021 13:06:22 -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 b3sm9293714pfi.179.2021.08.01.13.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 13:06:22 -0700 (PDT) From: Peter Oskolkov X-Google-Original-From: Peter Oskolkov To: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , 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 1/4 v0.4] sched/umcg: add WF_CURRENT_CPU and externise ttwu Date: Sun, 1 Aug 2021 13:06:14 -0700 Message-Id: <20210801200617.623745-2-posk@google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210801200617.623745-1-posk@google.com> References: <20210801200617.623745-1-posk@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0c22cd026440..293f5801bf81 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3680,8 +3680,7 @@ static void ttwu_queue(struct task_struct *p, int cpu, int wake_flags) * 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 11d22943753f..16a9c93e6e82 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6836,6 +6836,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 9a1c6aeb9165..80de6836f8ae 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2031,13 +2031,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); @@ -3037,6 +3038,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); -- 2.25.1