Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4097813pxb; Mon, 30 Aug 2021 19:02:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzoojiYMhuCCmbP7+FOA+gFXFxL8Gv3Hb8RXlpeQA8wF8s+U/SsiH3isouWd1KMS6pizt3 X-Received: by 2002:a02:cf06:: with SMTP id q6mr540990jar.89.1630375368756; Mon, 30 Aug 2021 19:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630375368; cv=none; d=google.com; s=arc-20160816; b=ZaGmNqvGTos5zW3jJyfd76VcG/c5FYLaeqsZ2R8HcVnH4Gs/2k2vg7J44JweGX0XXj dwc52X3akETCpdlBEsyCVkuymOBwCWvaiIs/GgU4Lt/zMOmkUlhhh3GyhKc3K2q8N5Uc 3AxAy7N044dRKJZNQ7+YhQSwvpPnYWQonbwRx+INBWtFy06ZT8wwBDRnTMPEl/Qsxt6j GiR+6peuORM2jZfQl4jwyJ7NphdVJRPMoGsF3CSjHyRMHPpmPFntPV95C/Krdn6WNPyM gUBcd+E6BYQ+ocBTaKzMunt07Viz2P4DnMJoCu8QdweNfHNFFH2MB0xE81nctq2FU/6U uDaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=bKB4cewv8wnHozRVNcqnWDkFgfbYCFmXk49qCpEId0g=; b=n5zSIY5qejzeFHsX95wjVsIcFpibXi6okEooWElY/0PZvIN/y8AWYEv9ArK+f10ut7 qvmnBoRYXfuIDk81qtkrsPCmjFjSVt6oXQNan1uaHzivvDorv4NhoHnbOQv8/mavIK8I qPuprF+nObBirTs0zGniHPhykprPCHcdVxXEBeHAJSA5p66nWWbrLEFRM8MXV589fzdH fUZ7haPU+di/U3kHrwKvsLkeXudehOn1Uwp5gKuGaDH6FVUz74pbxFoqU5pRUFsSylbF pmKOrgAvMu2/0WpkgAMMfaBxaDXBwA7tKwLorI/AKD7nuZBI6L/5vOx14I4VhXJCgFXk RLCA== ARC-Authentication-Results: i=1; mx.google.com; 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 a5si15713309ioo.37.2021.08.30.19.02.37; Mon, 30 Aug 2021 19:02:48 -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; 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 S239355AbhHaCBV (ORCPT + 99 others); Mon, 30 Aug 2021 22:01:21 -0400 Received: from smtp181.sjtu.edu.cn ([202.120.2.181]:41048 "EHLO smtp181.sjtu.edu.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239357AbhHaCBU (ORCPT ); Mon, 30 Aug 2021 22:01:20 -0400 Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp181.sjtu.edu.cn (Postfix) with ESMTPS id 5E22D1008CBCD; Tue, 31 Aug 2021 10:00:23 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id B8CB4228C9242; Tue, 31 Aug 2021 10:00:21 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id va3NV7d66HyK; Tue, 31 Aug 2021 10:00:21 +0800 (CST) Received: from sky.ipads-lab.se.sjtu.edu.cn (unknown [202.120.40.82]) (Authenticated sender: skyele@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id B4C51228C9235; Tue, 31 Aug 2021 09:59:58 +0800 (CST) From: Tianqiang Xu To: x86@kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, kvm@vger.kernel.org, hpa@zytor.com, jarkko@kernel.org, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, Tianqiang Xu Subject: [PATCH 2/4] Scheduler changes Date: Tue, 31 Aug 2021 09:59:17 +0800 Message-Id: <20210831015919.13006-2-skyele@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210831015919.13006-1-skyele@sjtu.edu.cn> References: <20210831015919.13006-1-skyele@sjtu.edu.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org available_idle_cpu_sched() invokes pcpu_is_idle() to detect whether a pCPU where the preempted vCPU most recently run is idle or not, which is used by the guest OS. get_cpu_nr_running() gets the run queue of current cpu, which is used by the host KVM to know whether a pCPU where the preempted vCPU mostly recently run is idle or not. -- Authors: Tianqiang Xu, Dingji Li, Zeyu Mi Shanghai Jiao Tong University Signed-off-by: Tianqiang Xu --- include/linux/sched.h | 1 + kernel/sched/core.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index ec8d07d88641..dd4c41d2d8d3 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1736,6 +1736,7 @@ extern int can_nice(const struct task_struct *p, const int nice); extern int task_curr(const struct task_struct *p); extern int idle_cpu(int cpu); extern int available_idle_cpu(int cpu); +extern int available_idle_cpu_sched(int cpu); extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *); extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *); extern void sched_set_fifo(struct task_struct *p); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f3b27c6c5153..c777dbcbeb9c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6752,6 +6752,17 @@ int available_idle_cpu(int cpu) return 1; } +int available_idle_cpu_sched(int cpu) +{ + if (!idle_cpu(cpu)) + return 0; + + if (!pcpu_is_idle(cpu)) + return 0; + + return 1; +} + /** * idle_task - return the idle task for a given CPU. * @cpu: the processor in question. @@ -10504,3 +10515,9 @@ void call_trace_sched_update_nr_running(struct rq *rq, int count) { trace_sched_update_nr_running_tp(rq, count); } + +int get_cpu_nr_running(int cpu) +{ + return cpu_rq(cpu)->nr_running; +} +EXPORT_SYMBOL_GPL(get_cpu_nr_running); -- 2.26.0