From patchwork Fri Aug 17 19:46:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirley Ma X-Patchwork-Id: 178341 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 278472C00A1 for ; Sat, 18 Aug 2012 05:47:14 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754291Ab2HQTqr (ORCPT ); Fri, 17 Aug 2012 15:46:47 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:53066 "EHLO e34.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754026Ab2HQTqo (ORCPT ); Fri, 17 Aug 2012 15:46:44 -0400 Received: from /spool/local by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 Aug 2012 13:46:44 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 17 Aug 2012 13:46:42 -0600 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id E25D81FF0026; Fri, 17 Aug 2012 13:46:39 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7HJkHe8123668; Fri, 17 Aug 2012 13:46:21 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7HJkGmP028070; Fri, 17 Aug 2012 13:46:17 -0600 Received: from [9.76.29.64] (sig-9-76-29-64.mts.ibm.com [9.76.29.64]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7HJkBdS027574; Fri, 17 Aug 2012 13:46:13 -0600 Subject: [RFC PATCH 1/1] fair.c: Add/Export find_idlest_perfer_cpu API From: Shirley Ma To: linux-kernel@vger.kernel.org, Peter Zijlstra , mingo@redhat.com Cc: mingo@redhat.com, "Michael S. Tsirkin" , netdev@vger.kernel.org, sri@us.ibm.com, vivek@us.ibm.com Date: Fri, 17 Aug 2012 12:46:10 -0700 Message-ID: <1345232770.16533.234.camel@oc3660625478.ibm.com> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 (2.28.3-24.el6) X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12081719-1780-0000-0000-00000875DC55 X-IBM-ISS-SpamDetectors: X-IBM-ISS-DetailInfo: BY=3.00000292; HX=3.00000196; KW=3.00000007; PH=3.00000001; SC=3.00000007; SDB=6.00166173; UDB=6.00037633; UTC=2012-08-17 19:46:43 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add/Export a new API for per-cpu thread model networking device driver to choose a preferred idlest cpu within allowed cpumask. The receiving CPUs of a networking device are not under cgroup controls. Normally the receiving work will be scheduled on the cpu on which the interrupts are received. When such a networking device uses per-cpu thread model, the cpu which is chose to process the packets might not be part of cgroup cpusets without using such an API here. On NUMA system, by using the preferred cpumask from the same NUMA node would help to reduce expensive cross memory access to/from the other NUMA node. KVM per-cpu vhost will be the first one to use this API. Any other device driver which uses per-cpu thread model and has cgroup cpuset control will use this API later. Signed-off-by: Shirley Ma --- include/linux/sched.h | 2 ++ kernel/sched/fair.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-) thanks Shirley -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/sched.h b/include/linux/sched.h index 64d9df5..46cc4a7 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2806,4 +2806,6 @@ static inline unsigned long rlimit_max(unsigned int limit) #endif /* __KERNEL__ */ +extern int find_idlest_prefer_cpu(struct cpumask *prefer, + struct cpumask *allowed, int prev_cpu); #endif diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c099cc6..d3da151 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -2809,6 +2810,46 @@ unlock: return new_cpu; } + +/* + * This API is used to find the most idle cpu from both preferred and + * allowed cpuset. + * + * allowed: The allowed cpumask is the caller's task allowed cpuset, which could * be from cgroup cpuset control. + * prefer: The perfer cpumask is caller's perferred cpuset choice, which could + * be a cpuset of a NUMA node for better performance. + * + * It helps per-cpu thread model to choose the preferred cpu in the allowed + * cpuset to be scheduled when the work doesn't want to be scheduled on the + * same cpu on which the work is received for better performance. For example + * the network work doesn't want to be on the same cpu on which the + * interrupt is received. + * + * If these two cpusets have intersects, the cpu is chose from the intersects; + * if there is no intersects, then the cpu is chose from the allowed cpuset. + * + * prev_cpu helps to better local cache when prev_cpu is not busy. + */ +int find_idlest_prefer_cpu(struct cpumask *prefer, struct cpumask *allowed, + int prev_cpu) +{ + unsigned long load, min_load = ULONG_MAX; + int check, i, idlest = -1; + + check = cpumask_intersects(prefer, allowed); + /* Traverse only the allowed CPUs */ + if (check == 0) + prefer = allowed; + for_each_cpu_and(i, prefer, allowed) { + load = weighted_cpuload(i); + if (load < min_load || (load == min_load && i == prev_cpu)) { + min_load = load; + idlest = i; + } + } + return idlest; +} +EXPORT_SYMBOL(find_idlest_prefer_cpu); #endif /* CONFIG_SMP */ static unsigned long