[PATCH 05/33] cputime: Use accessors to read task cputime stats

2013-01-07 Thread Frederic Weisbecker
This is in preparation for the full dynticks feature. While
remotely reading the cputime of a task running in a full
dynticks CPU, we'll need to do some extra-computation. This
way we can account the time it spent tickless in userspace
since its last cputime snapshot.

Signed-off-by: Frederic Weisbecker 
Cc: Alessio Igor Bogani 
Cc: Andrew Morton 
Cc: Chris Metcalf 
Cc: Christoph Lameter 
Cc: Geoff Levand 
Cc: Gilad Ben Yossef 
Cc: Hakan Akkan 
Cc: Ingo Molnar 
Cc: Li Zhong 
Cc: Namhyung Kim 
Cc: Paul E. McKenney 
Cc: Paul Gortmaker 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
---
 arch/alpha/kernel/osf_sys.c |6 --
 arch/x86/kernel/apm_32.c|   11 ++-
 drivers/isdn/mISDN/stack.c  |7 ++-
 fs/binfmt_elf.c |8 ++--
 fs/binfmt_elf_fdpic.c   |7 +--
 include/linux/sched.h   |   18 ++
 kernel/acct.c   |6 --
 kernel/cpu.c|4 +++-
 kernel/delayacct.c  |7 +--
 kernel/exit.c   |6 --
 kernel/posix-cpu-timers.c   |   28 ++--
 kernel/sched/cputime.c  |9 +
 kernel/signal.c |   12 
 kernel/tsacct.c |   19 +--
 14 files changed, 109 insertions(+), 39 deletions(-)

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 14db93e..dbc1760 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1139,6 +1139,7 @@ struct rusage32 {
 SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
 {
struct rusage32 r;
+   cputime_t utime, stime;
 
if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
return -EINVAL;
@@ -1146,8 +1147,9 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 
__user *, ru)
memset(, 0, sizeof(r));
switch (who) {
case RUSAGE_SELF:
-   jiffies_to_timeval32(current->utime, _utime);
-   jiffies_to_timeval32(current->stime, _stime);
+   task_cputime(current, , );
+   jiffies_to_timeval32(utime, _utime);
+   jiffies_to_timeval32(stime, _stime);
r.ru_minflt = current->min_flt;
r.ru_majflt = current->maj_flt;
break;
diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
index d65464e..8d7012b 100644
--- a/arch/x86/kernel/apm_32.c
+++ b/arch/x86/kernel/apm_32.c
@@ -899,6 +899,7 @@ static void apm_cpu_idle(void)
static int use_apm_idle; /* = 0 */
static unsigned int last_jiffies; /* = 0 */
static unsigned int last_stime; /* = 0 */
+   cputime_t stime;
 
int apm_idle_done = 0;
unsigned int jiffies_since_last_check = jiffies - last_jiffies;
@@ -906,23 +907,23 @@ static void apm_cpu_idle(void)
 
WARN_ONCE(1, "deprecated apm_cpu_idle will be deleted in 2012");
 recalc:
+   task_cputime(current, NULL, );
if (jiffies_since_last_check > IDLE_CALC_LIMIT) {
use_apm_idle = 0;
-   last_jiffies = jiffies;
-   last_stime = current->stime;
} else if (jiffies_since_last_check > idle_period) {
unsigned int idle_percentage;
 
-   idle_percentage = current->stime - last_stime;
+   idle_percentage = stime - last_stime;
idle_percentage *= 100;
idle_percentage /= jiffies_since_last_check;
use_apm_idle = (idle_percentage > idle_threshold);
if (apm_info.forbid_idle)
use_apm_idle = 0;
-   last_jiffies = jiffies;
-   last_stime = current->stime;
}
 
+   last_jiffies = jiffies;
+   last_stime = stime;
+
bucket = IDLE_LEAKY_MAX;
 
while (!need_resched()) {
diff --git a/drivers/isdn/mISDN/stack.c b/drivers/isdn/mISDN/stack.c
index 5f21f62..deda591 100644
--- a/drivers/isdn/mISDN/stack.c
+++ b/drivers/isdn/mISDN/stack.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "core.h"
 
 static u_int   *debug;
@@ -202,6 +203,9 @@ static int
 mISDNStackd(void *data)
 {
struct mISDNstack *st = data;
+#ifdef MISDN_MSG_STATS
+   cputime_t utime, stime;
+#endif
int err = 0;
 
sigfillset(>blocked);
@@ -303,9 +307,10 @@ mISDNStackd(void *data)
   "msg %d sleep %d stopped\n",
   dev_name(>dev->dev), st->msg_cnt, st->sleep_cnt,
   st->stopped_cnt);
+   task_cputime(st->thread, , );
printk(KERN_DEBUG
   "mISDNStackd daemon for %s utime(%ld) stime(%ld)\n",
-  dev_name(>dev->dev), st->thread->utime, st->thread->stime);
+  dev_name(>dev->dev), utime, stime);
printk(KERN_DEBUG
   "mISDNStackd daemon for %s nvcsw(%ld) nivcsw(%ld)\n",
   dev_name(>dev->dev), st->thread->nvcsw, st->thread->nivcsw);
diff --git 

[PATCH 05/33] cputime: Use accessors to read task cputime stats

2013-01-07 Thread Frederic Weisbecker
This is in preparation for the full dynticks feature. While
remotely reading the cputime of a task running in a full
dynticks CPU, we'll need to do some extra-computation. This
way we can account the time it spent tickless in userspace
since its last cputime snapshot.

Signed-off-by: Frederic Weisbecker fweis...@gmail.com
Cc: Alessio Igor Bogani abog...@kernel.org
Cc: Andrew Morton a...@linux-foundation.org
Cc: Chris Metcalf cmetc...@tilera.com
Cc: Christoph Lameter c...@linux.com
Cc: Geoff Levand ge...@infradead.org
Cc: Gilad Ben Yossef gi...@benyossef.com
Cc: Hakan Akkan hakanak...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Li Zhong zh...@linux.vnet.ibm.com
Cc: Namhyung Kim namhyung@lge.com
Cc: Paul E. McKenney paul...@linux.vnet.ibm.com
Cc: Paul Gortmaker paul.gortma...@windriver.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
---
 arch/alpha/kernel/osf_sys.c |6 --
 arch/x86/kernel/apm_32.c|   11 ++-
 drivers/isdn/mISDN/stack.c  |7 ++-
 fs/binfmt_elf.c |8 ++--
 fs/binfmt_elf_fdpic.c   |7 +--
 include/linux/sched.h   |   18 ++
 kernel/acct.c   |6 --
 kernel/cpu.c|4 +++-
 kernel/delayacct.c  |7 +--
 kernel/exit.c   |6 --
 kernel/posix-cpu-timers.c   |   28 ++--
 kernel/sched/cputime.c  |9 +
 kernel/signal.c |   12 
 kernel/tsacct.c |   19 +--
 14 files changed, 109 insertions(+), 39 deletions(-)

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 14db93e..dbc1760 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1139,6 +1139,7 @@ struct rusage32 {
 SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
 {
struct rusage32 r;
+   cputime_t utime, stime;
 
if (who != RUSAGE_SELF  who != RUSAGE_CHILDREN)
return -EINVAL;
@@ -1146,8 +1147,9 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 
__user *, ru)
memset(r, 0, sizeof(r));
switch (who) {
case RUSAGE_SELF:
-   jiffies_to_timeval32(current-utime, r.ru_utime);
-   jiffies_to_timeval32(current-stime, r.ru_stime);
+   task_cputime(current, utime, stime);
+   jiffies_to_timeval32(utime, r.ru_utime);
+   jiffies_to_timeval32(stime, r.ru_stime);
r.ru_minflt = current-min_flt;
r.ru_majflt = current-maj_flt;
break;
diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
index d65464e..8d7012b 100644
--- a/arch/x86/kernel/apm_32.c
+++ b/arch/x86/kernel/apm_32.c
@@ -899,6 +899,7 @@ static void apm_cpu_idle(void)
static int use_apm_idle; /* = 0 */
static unsigned int last_jiffies; /* = 0 */
static unsigned int last_stime; /* = 0 */
+   cputime_t stime;
 
int apm_idle_done = 0;
unsigned int jiffies_since_last_check = jiffies - last_jiffies;
@@ -906,23 +907,23 @@ static void apm_cpu_idle(void)
 
WARN_ONCE(1, deprecated apm_cpu_idle will be deleted in 2012);
 recalc:
+   task_cputime(current, NULL, stime);
if (jiffies_since_last_check  IDLE_CALC_LIMIT) {
use_apm_idle = 0;
-   last_jiffies = jiffies;
-   last_stime = current-stime;
} else if (jiffies_since_last_check  idle_period) {
unsigned int idle_percentage;
 
-   idle_percentage = current-stime - last_stime;
+   idle_percentage = stime - last_stime;
idle_percentage *= 100;
idle_percentage /= jiffies_since_last_check;
use_apm_idle = (idle_percentage  idle_threshold);
if (apm_info.forbid_idle)
use_apm_idle = 0;
-   last_jiffies = jiffies;
-   last_stime = current-stime;
}
 
+   last_jiffies = jiffies;
+   last_stime = stime;
+
bucket = IDLE_LEAKY_MAX;
 
while (!need_resched()) {
diff --git a/drivers/isdn/mISDN/stack.c b/drivers/isdn/mISDN/stack.c
index 5f21f62..deda591 100644
--- a/drivers/isdn/mISDN/stack.c
+++ b/drivers/isdn/mISDN/stack.c
@@ -18,6 +18,7 @@
 #include linux/slab.h
 #include linux/mISDNif.h
 #include linux/kthread.h
+#include linux/sched.h
 #include core.h
 
 static u_int   *debug;
@@ -202,6 +203,9 @@ static int
 mISDNStackd(void *data)
 {
struct mISDNstack *st = data;
+#ifdef MISDN_MSG_STATS
+   cputime_t utime, stime;
+#endif
int err = 0;
 
sigfillset(current-blocked);
@@ -303,9 +307,10 @@ mISDNStackd(void *data)
   msg %d sleep %d stopped\n,
   dev_name(st-dev-dev), st-msg_cnt, st-sleep_cnt,
   st-stopped_cnt);
+   task_cputime(st-thread, utime, stime);