From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752560AbcGLWDQ (ORCPT ); Tue, 12 Jul 2016 18:03:16 -0400 Received: from mga02.intel.com ([134.134.136.20]:62251 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750816AbcGLWDO (ORCPT ); Tue, 12 Jul 2016 18:03:14 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,353,1464678000"; d="scan'208";a="138071750" From: "Fenghua Yu" To: "Thomas Gleixner" , "Ingo Molnar" , "H. Peter Anvin" , "Tony Luck" , "Tejun Heo" , "Borislav Petkov" , "Stephane Eranian" , "Peter Zijlstra" , "Marcelo Tosatti" , "David Carrillo-Cisneros" , "Ravi V Shankar" , "Vikas Shivappa" , "Sai Prakhya" Cc: "linux-kernel" , "x86" , "Fenghua Yu" Subject: [PATCH 24/32] Task fork and exit for rdtgroup Date: Tue, 12 Jul 2016 18:02:57 -0700 Message-Id: <1468371785-53231-25-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1468371785-53231-1-git-send-email-fenghua.yu@intel.com> References: <1468371785-53231-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fenghua Yu When a task is forked, it inherites its parent rdtgroup. The task can be moved to other rdtgroup during its run time. When the task exits, it's deleted from it's current rdtgroup's task list. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- arch/x86/include/asm/intel_rdt.h | 1 + arch/x86/kernel/cpu/intel_rdt.c | 22 ++++++++++++++++++++++ kernel/exit.c | 2 ++ kernel/fork.c | 4 ++++ 4 files changed, 29 insertions(+) diff --git a/arch/x86/include/asm/intel_rdt.h b/arch/x86/include/asm/intel_rdt.h index 5aacc4a..f2298f3 100644 --- a/arch/x86/include/asm/intel_rdt.h +++ b/arch/x86/include/asm/intel_rdt.h @@ -22,6 +22,7 @@ enum resource_type { DECLARE_PER_CPU_READ_MOSTLY(int, cpu_l3_domain); DECLARE_PER_CPU_READ_MOSTLY(struct rdtgroup *, cpu_rdtgroup); +extern spinlock_t rdtgroup_task_lock; extern struct static_key rdt_enable_key; void __intel_rdt_sched_in(void *dummy); extern bool use_rdtgroup_tasks; diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c index 017c833..901156d 100644 --- a/arch/x86/kernel/cpu/intel_rdt.c +++ b/arch/x86/kernel/cpu/intel_rdt.c @@ -812,3 +812,25 @@ static int __init intel_rdt_late_init(void) } late_initcall(intel_rdt_late_init); + +void rdtgroup_fork(struct task_struct *child) +{ + INIT_LIST_HEAD(&child->rg_list); + child->rdtgroup = NULL; +} + +void rdtgroup_post_fork(struct task_struct *child) +{ + if (!use_rdtgroup_tasks) + return; + + spin_lock_irq(&rdtgroup_task_lock); + if (list_empty(&child->rg_list)) { + struct rdtgroup *rdtgrp = current->rdtgroup; + + list_add_tail(&child->rg_list, &rdtgrp->pset.tasks); + child->rdtgroup = rdtgrp; + atomic_inc(&rdtgrp->pset.refcount); + } + spin_unlock_irq(&rdtgroup_task_lock); +} diff --git a/kernel/exit.c b/kernel/exit.c index 9e6e135..04346b6 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -59,6 +59,7 @@ #include #include #include +#include static void __unhash_process(struct task_struct *p, bool group_dead) { @@ -757,6 +758,7 @@ void do_exit(long code) perf_event_exit_task(tsk); cgroup_exit(tsk); + rdtgroup_exit(tsk); /* * FIXME: do that only when needed, using sched_exit tracepoint diff --git a/kernel/fork.c b/kernel/fork.c index 4a7ec0c..d9bb373 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -84,6 +84,8 @@ #include #include +#include + #include #define CREATE_TRACE_POINTS @@ -1408,6 +1410,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, p->audit_context = NULL; threadgroup_change_begin(current); cgroup_fork(p); + rdtgroup_fork(p); #ifdef CONFIG_NUMA p->mempolicy = mpol_dup(p->mempolicy); if (IS_ERR(p->mempolicy)) { @@ -1647,6 +1650,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, proc_fork_connector(p); cgroup_post_fork(p); + rdtgroup_post_fork(p); threadgroup_change_end(current); perf_event_fork(p); -- 2.5.0