From: Glauber Costa <glommer@parallels.com>
To: linux-kernel@vger.kernel.org
Cc: paul@paulmenage.org, lizf@cn.fujitsu.com, daniel.lezcano@free.fr,
a.p.zijlstra@chello.nl, jbottomley@parallels.com, pjt@google.com,
fweisbec@gmail.com, Glauber Costa <glommer@parallels.com>
Subject: [PATCH v2 10/14] Keep number of context switches per-cgroup
Date: Tue, 1 Nov 2011 19:19:16 -0200 [thread overview]
Message-ID: <1320182360-20043-11-git-send-email-glommer@parallels.com> (raw)
In-Reply-To: <1320182360-20043-1-git-send-email-glommer@parallels.com>
This patch ties the number of context_switches to a cgroup.
No impact is expected when per-cgroup stats collecting is disabled
in the root cgroup.
Signed-off-by: Glauber Costa <glommer@parallels.com>
---
include/linux/kernel_stat.h | 2 ++
kernel/sched.c | 24 ++++++++++++++++++------
kernel/sched_debug.c | 3 ++-
3 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 77e91f6..2c32b24 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -30,6 +30,7 @@ enum cpu_usage_stat {
STEAL_BASE,
IDLE_BASE,
TOTAL_FORKS,
+ NR_SWITCHES,
NR_STATS,
};
@@ -68,6 +69,7 @@ DECLARE_PER_CPU(struct kernel_cpustat, kernel_cpustat);
extern unsigned long long nr_context_switches(void);
+extern unsigned long long nr_context_switches_cpu(int cpu);
#ifndef CONFIG_GENERIC_HARDIRQS
diff --git a/kernel/sched.c b/kernel/sched.c
index 800728e..4f91781 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -611,7 +611,6 @@ struct rq {
/* capture load from *all* tasks on this cpu: */
struct load_weight load;
unsigned long nr_load_updates;
- u64 nr_switches;
struct cfs_rq cfs;
struct rt_rq rt;
@@ -3475,11 +3474,23 @@ unsigned long long nr_context_switches(void)
int i;
unsigned long long sum = 0;
- for_each_possible_cpu(i)
- sum += cpu_rq(i)->nr_switches;
+ for_each_possible_cpu(i) {
+ kstat_lock();
+ sum += per_cpu(kernel_cpustat, i).cpustat[NR_SWITCHES];
+ kstat_unlock();
+ }
return sum;
}
+unsigned long long nr_context_switches_cpu(int cpu)
+{
+ unsigned long long ret;
+
+ kstat_lock();
+ ret = per_cpu(kernel_cpustat, cpu).cpustat[NR_SWITCHES];
+ kstat_unlock();
+ return ret;
+}
unsigned long nr_iowait(void)
{
@@ -4554,9 +4565,9 @@ need_resched:
rq->skip_clock_update = 0;
if (likely(prev != next)) {
- rq->nr_switches++;
rq->curr = next;
++*switch_count;
+ task_group_account_field(prev, 1, NR_SWITCHES);
context_switch(rq, prev, next); /* unlocks the rq */
/*
@@ -9713,6 +9724,7 @@ int cpu_cgroup_proc_stat(struct cgroup *cgrp, struct cftype *cft,
unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
struct timespec boottime;
unsigned long tg_iowait = 0;
+ u64 tg_nr_switches = 0;
#ifdef CONFIG_CGROUP_SCHED
struct task_group *tg;
struct task_group *sib;
@@ -9754,8 +9766,8 @@ int cpu_cgroup_proc_stat(struct cgroup *cgrp, struct cftype *cft,
guest += kcpustat->cpustat[GUEST];
guest_nice += kcpustat->cpustat[GUEST_NICE];
total_forks += kcpustat->cpustat[TOTAL_FORKS];
+ tg_nr_switches += kcpustat->cpustat[NR_SWITCHES];
tg_iowait += atomic_read(&kcpustat->nr_iowait);
-
#ifdef CONFIG_CGROUP_SCHED
if (static_branch(&sched_cgroup_enabled)) {
list_for_each_entry(sib, &tg->siblings, siblings) {
@@ -9858,7 +9870,7 @@ int cpu_cgroup_proc_stat(struct cgroup *cgrp, struct cftype *cft,
"processes %llu\n"
"procs_running %lu\n"
"procs_blocked %lu\n",
- nr_context_switches(),
+ tg_nr_switches,
(unsigned long)jif,
total_forks,
nr_running(),
diff --git a/kernel/sched_debug.c b/kernel/sched_debug.c
index a6710a1..c7464601 100644
--- a/kernel/sched_debug.c
+++ b/kernel/sched_debug.c
@@ -246,6 +246,7 @@ static void print_cpu(struct seq_file *m, int cpu)
{
struct rq *rq = cpu_rq(cpu);
unsigned long flags;
+ unsigned long long nr_switches = nr_context_switches_cpu(cpu);
#ifdef CONFIG_X86
{
@@ -266,8 +267,8 @@ static void print_cpu(struct seq_file *m, int cpu)
P(nr_running);
SEQ_printf(m, " .%-30s: %lu\n", "load",
rq->load.weight);
- P(nr_switches);
P(nr_load_updates);
+ SEQ_printf(m, " .%-30s: %Ld\n","nr_switches", nr_switches);
P(nr_uninterruptible);
PN(next_balance);
P(curr->pid);
--
1.7.6.4
next prev parent reply other threads:[~2011-11-01 21:21 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-01 21:19 [PATCH v2 00/14] per-cgroup /proc/stat Glauber Costa
2011-11-01 21:19 ` [PATCH v2 01/14] trivial: initialize root cgroup's sibling list Glauber Costa
2011-11-11 21:34 ` Paul Turner
2011-11-14 19:44 ` Glauber Costa
2011-11-14 21:44 ` Peter Zijlstra
2011-11-18 23:42 ` [tip:sched/core] sched, trivial: Initialize " tip-bot for Glauber Costa
2011-11-01 21:19 ` [PATCH v2 02/14] Change cpustat fields to an array Glauber Costa
2011-11-01 21:19 ` [PATCH v2 03/14] Move /proc/stat logic inside sched.c Glauber Costa
2011-11-12 1:35 ` Paul Turner
2011-11-12 10:27 ` Glauber Costa
2011-11-01 21:19 ` [PATCH v2 04/14] split kernel stat in two Glauber Costa
2011-11-01 21:19 ` [PATCH v2 05/14] Display /proc/stat information per cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 06/14] Make total_forks per-cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 07/14] per-cgroup boot time Glauber Costa
2011-11-01 21:19 ` [PATCH v2 08/14] Report steal time for cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 09/14] Keep nr_iowait per cgroup Glauber Costa
2011-11-10 10:27 ` Andrew Wagin
2011-11-01 21:19 ` Glauber Costa [this message]
2011-11-01 21:19 ` [PATCH v2 11/14] provide a version of cpuacct statistics inside cpu cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 12/14] Keep number of running processes per-cgroup Glauber Costa
2011-11-14 14:42 ` Andrew Wagin
2011-11-01 21:19 ` [PATCH v2 13/14] provide a version of cpuusage statistics inside cpu cgroup Glauber Costa
2011-11-09 11:51 ` Andrew Wagin
2011-11-09 11:58 ` Glauber Costa
2011-11-09 14:18 ` Andrew Wagin
2011-11-09 15:30 ` Peter Zijlstra
2011-11-09 16:51 ` Glauber Costa
2011-11-10 8:59 ` Andrew Wagin
2011-11-01 21:19 ` [PATCH v2 14/14] Change CPUACCT to default n Glauber Costa
2011-11-11 21:33 ` Paul Turner
2011-11-12 10:29 ` Glauber Costa
2011-11-15 11:02 ` Paul Turner
2011-11-16 10:21 ` Balbir Singh
2011-11-16 23:52 ` KAMEZAWA Hiroyuki
2011-11-17 2:49 ` Glauber Costa
2011-11-17 2:58 ` Balbir Singh
2011-11-17 15:58 ` Glauber Costa
2011-11-21 1:59 ` KAMEZAWA Hiroyuki
2011-11-24 13:24 ` Peter Zijlstra
2011-11-24 16:07 ` Glauber Costa
2011-11-24 16:29 ` Peter Zijlstra
2011-11-24 16:38 ` Glauber Costa
2011-11-24 16:58 ` Peter Zijlstra
2011-11-25 5:38 ` Balbir Singh
2011-11-25 10:19 ` Peter Zijlstra
2011-11-26 13:18 ` Paul Turner
2011-11-28 8:29 ` Balbir Singh
2011-11-25 2:05 ` Li Zefan
2011-11-25 10:09 ` Peter Zijlstra
2011-11-26 13:07 ` Paul Turner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1320182360-20043-11-git-send-email-glommer@parallels.com \
--to=glommer@parallels.com \
--cc=a.p.zijlstra@chello.nl \
--cc=daniel.lezcano@free.fr \
--cc=fweisbec@gmail.com \
--cc=jbottomley@parallels.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=paul@paulmenage.org \
--cc=pjt@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®