Skip to contentSkip to conversation

cputime: Virtual cputime accounting small cleanups and consolidation

PATCH In review Frederic Weisbecker 5 participants 16 messages Jun 19, 2012 – Aug 3, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover cputime: Virtual cputime accounting small cleanups and consolidation

Not sure to which tree this should go. The scheduler one may be. Anyway if you're fine with it, it is pullable at:

git://github.com/fweisbec/linux-dynticks.git
virt-cputime

This is only built tested on the relevant archs.

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Frederic Weisbecker (4):
cputime: Generalize CONFIG_VIRT_CPU_ACCOUNTING
sched: Move cputime code to its own file
cputime: Consolidate vtime handling on context switch
s390: Remove leftover account_tick_vtime() header

 arch/Kconfig                           |    3 +
 arch/ia64/Kconfig                      |   12 +-
 arch/ia64/include/asm/switch_to.h      |    8 -
 arch/ia64/kernel/time.c                |    4 +-
 arch/powerpc/include/asm/time.h        |    6 -
 arch/powerpc/kernel/process.c          |    3 -
 arch/powerpc/kernel/time.c             |    6 +
 arch/powerpc/platforms/Kconfig.cputype |   16 +-
 arch/s390/Kconfig                      |    5 +-
 arch/s390/include/asm/switch_to.h      |    4 -
 arch/s390/kernel/vtime.c               |    4 +-
 include/linux/kernel_stat.h            |    6 +
 init/Kconfig                           |   13 +
 kernel/sched/Makefile                  |    2 +-
 kernel/sched/core.c                    |  552 +-------------------------------
 kernel/sched/cputime.c                 |  497 ++++++++++++++++++++++++++++
 kernel/sched/sched.h                   |   63 ++++
 17 files changed, 600 insertions(+), 604 deletions(-)
 create mode 100644 kernel/sched/cputime.c
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/4 cputime: Generalize CONFIG_VIRT_CPU_ACCOUNTING

S390, ia64 and powerpc all define their own version of CONFIG_VIRT_CPU_ACCOUNTING. Generalize the config and its description to a single place to avoid duplication.

Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 arch/Kconfig                           |    3 +++
 arch/ia64/Kconfig                      |   12 +-----------
 arch/powerpc/platforms/Kconfig.cputype |   16 +---------------
 arch/s390/Kconfig                      |    5 ++---
 init/Kconfig                           |   13 +++++++++++++
 5 files changed, 20 insertions(+), 29 deletions(-)
arch/Kconfig +3 -0
index 8c3d957..ff712af 100644
@@ -274,4 +274,7 @@ config SECCOMP_FILTER
 
 	  See Documentation/prctl/seccomp_filter.txt for details.
 
+config HAVE_VIRT_CPU_ACCOUNTING
+	bool
+
 source "kernel/gcov/Kconfig"
arch/ia64/Kconfig +1 -11
index 8186ec5..509af14 100644
@@ -25,6 +25,7 @@ config IA64
 	select HAVE_GENERIC_HARDIRQS
 	select HAVE_MEMBLOCK
 	select HAVE_MEMBLOCK_NODE_MAP
+	select HAVE_VIRT_CPU_ACCOUNTING
 	select ARCH_DISCARD_MEMBLOCK
 	select GENERIC_IRQ_PROBE
 	select GENERIC_PENDING_IRQ if SMP
@@ -341,17 +342,6 @@ config FORCE_MAX_ZONEORDER
 	default "17" if HUGETLB_PAGE
 	default "11"
 
-config VIRT_CPU_ACCOUNTING
-	bool "Deterministic task and CPU time accounting"
-	default n
-	help
-	  Select this option to enable more accurate task and CPU time
-	  accounting.  This is done by reading a CPU counter on each
-	  kernel entry and exit and on transitions within the kernel
-	  between system, softirq and hardirq state, so there is a
-	  small performance impact.
-	  If in doubt, say N here.
-
 config SMP
 	bool "Symmetric multi-processing support"
 	select USE_GENERIC_SMP_HELPERS
arch/powerpc/platforms/Kconfig.cputype +1 -15
index 61c9550..2a896de 100644
@@ -1,6 +1,7 @@
 config PPC64
 	bool "64-bit kernel"
 	default n
+	select HAVE_VIRT_CPU_ACCOUNTING
 	help
 	  This option selects whether a 32-bit or a 64-bit kernel
 	  will be built.
@@ -333,21 +334,6 @@ config PPC_MM_SLICES
 	default y if (!PPC_FSL_BOOK3E && PPC64 && HUGETLB_PAGE) || (PPC_STD_MMU_64 && PPC_64K_PAGES)
 	default n
 
-config VIRT_CPU_ACCOUNTING
-	bool "Deterministic task and CPU time accounting"
-	depends on PPC64
-	default y
-	help
-	  Select this option to enable more accurate task and CPU time
-	  accounting.  This is done by reading a CPU counter on each
-	  kernel entry and exit and on transitions within the kernel
-	  between system, softirq and hardirq state, so there is a
-	  small performance impact.  This also enables accounting of
-	  stolen time on logically-partitioned systems running on
-	  IBM POWER5-based machines.
-
-	  If in doubt, say Y here.
-
 config PPC_HAVE_PMU_SUPPORT
        bool
 
arch/s390/Kconfig +2 -3
index a39b469..351aa40 100644
@@ -49,9 +49,6 @@ config GENERIC_LOCKBREAK
 config PGSTE
 	def_bool y if KVM
 
-config VIRT_CPU_ACCOUNTING
-	def_bool y
-
 config ARCH_SUPPORTS_DEBUG_PAGEALLOC
 	def_bool y
 
@@ -88,6 +85,8 @@ config S390
 	select HAVE_MEMBLOCK
 	select HAVE_MEMBLOCK_NODE_MAP
 	select HAVE_CMPXCHG_LOCAL
+	select HAVE_VIRT_CPU_ACCOUNTING
+	select VIRT_CPU_ACCOUNTING
 	select ARCH_DISCARD_MEMBLOCK
 	select ARCH_INLINE_SPIN_TRYLOCK
 	select ARCH_INLINE_SPIN_TRYLOCK_BH
init/Kconfig +13 -0
index d07dcf9..d3f04e1 100644
@@ -267,6 +267,19 @@ config POSIX_MQUEUE_SYSCTL
 	depends on SYSCTL
 	default y
 
+config VIRT_CPU_ACCOUNTING
+	bool "Deterministic task and CPU time accounting"
+	depends on HAVE_VIRT_CPU_ACCOUNTING
+	default y if PPC64
+	help
+	  Select this option to enable more accurate task and CPU time
+	  accounting.  This is done by reading a CPU counter on each
+	  kernel entry and exit and on transitions within the kernel
+	  between system, softirq and hardirq state, so there is a
+	  small performance impact.  This also enables accounting of
+	  stolen time on logically-partitioned systems running on
+	  IBM POWER5-based machines.
+
 config BSD_PROCESS_ACCT
 	bool "BSD Process Accounting"
 	help
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH 2/4 sched: Move cputime code to its own file

In reply to Frederic Weisbecker

Extract cputime code from the giant sched/core.c and put it in its own file. This make it easier to deal with this particular area and de-bloat a bit more core.c

Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/sched/Makefile  |    2 +-
 kernel/sched/core.c    |  551 +-----------------------------------------------
 kernel/sched/cputime.c |  497 +++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/sched.h   |   63 ++++++
 4 files changed, 563 insertions(+), 550 deletions(-)
 create mode 100644 kernel/sched/cputime.c
kernel/sched/Makefile +1 -1
index 173ea52..f06d249 100644
@@ -11,7 +11,7 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
 CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
 endif
 
-obj-y += core.o clock.o idle_task.o fair.o rt.o stop_task.o
+obj-y += core.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o
 obj-$(CONFIG_SMP) += cpupri.o
 obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
 obj-$(CONFIG_SCHEDSTATS) += stats.o
kernel/sched/core.c +2 -549

575 lines not on this page · raw message

kernel/sched/cputime.c new file +497 -0

497 lines not on this page · raw message

kernel/sched/sched.h +63 -0

79 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#3 lore raw

PATCH 3/4 cputime: Consolidate vtime handling on context switch

In reply to Frederic Weisbecker

The archs that implement virtual cputime accounting all flush the cputime of a task when it gets descheduled and sometimes set up some ground initialization for the next task to account its cputime.

These archs all put their own hooks in their context switch callbacks and handle the off-case themselves.

Consolidate this by creating a new account_switch_vtime() callback called in generic code right after a context switch and that these archs must implement to flush the prev task cputime and initialize the next task cputime related state.

Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 arch/ia64/include/asm/switch_to.h |    8 --------
 arch/ia64/kernel/time.c           |    4 ++--
 arch/powerpc/include/asm/time.h   |    6 ------
 arch/powerpc/kernel/process.c     |    3 ---
 arch/powerpc/kernel/time.c        |    6 ++++++
 arch/s390/include/asm/switch_to.h |    2 --
 arch/s390/kernel/vtime.c          |    4 ++--
 include/linux/kernel_stat.h       |    6 ++++++
 kernel/sched/core.c               |    1 +
 9 files changed, 17 insertions(+), 23 deletions(-)
arch/ia64/include/asm/switch_to.h +0 -8
index cb2412f..d38c7ea 100644
@@ -30,13 +30,6 @@ extern struct task_struct *ia64_switch_to (void *next_task);
 extern void ia64_save_extra (struct task_struct *task);
 extern void ia64_load_extra (struct task_struct *task);
 
-#ifdef CONFIG_VIRT_CPU_ACCOUNTING
-extern void ia64_account_on_switch (struct task_struct *prev, struct task_struct *next);
-# define IA64_ACCOUNT_ON_SWITCH(p,n) ia64_account_on_switch(p,n)
-#else
-# define IA64_ACCOUNT_ON_SWITCH(p,n)
-#endif
-
 #ifdef CONFIG_PERFMON
   DECLARE_PER_CPU(unsigned long, pfm_syst_info);
 # define PERFMON_IS_SYSWIDE() (__get_cpu_var(pfm_syst_info) & 0x1)
@@ -49,7 +42,6 @@ extern void ia64_account_on_switch (struct task_struct *prev, struct task_struct
 	 || PERFMON_IS_SYSWIDE())
 
 #define __switch_to(prev,next,last) do {							 \
-	IA64_ACCOUNT_ON_SWITCH(prev, next);							 \
 	if (IA64_HAS_EXTRA_STATE(prev))								 \
 		ia64_save_extra(prev);								 \
 	if (IA64_HAS_EXTRA_STATE(next))								 \
arch/ia64/kernel/time.c +2 -2
index ecc904b..6247197 100644
@@ -88,10 +88,10 @@ extern cputime_t cycle_to_cputime(u64 cyc);
  * accumulated times to the current process, and to prepare accounting on
  * the next process.
  */
-void ia64_account_on_switch(struct task_struct *prev, struct task_struct *next)
+void account_switch_vtime(struct task_struct *prev)
 {
 	struct thread_info *pi = task_thread_info(prev);
-	struct thread_info *ni = task_thread_info(next);
+	struct thread_info *ni = task_thread_info(current);
 	cputime_t delta_stime, delta_utime;
 	__u64 now;
 
arch/powerpc/include/asm/time.h +0 -6
index 3b4b4a8..c1f2676 100644
@@ -197,12 +197,6 @@ struct cpu_usage {
 
 DECLARE_PER_CPU(struct cpu_usage, cpu_usage_array);
 
-#if defined(CONFIG_VIRT_CPU_ACCOUNTING)
-#define account_process_vtime(tsk)		account_process_tick(tsk, 0)
-#else
-#define account_process_vtime(tsk)		do { } while (0)
-#endif
-
 extern void secondary_cpu_time_init(void);
 
 DECLARE_PER_CPU(u64, decrementers_next_tb);
arch/powerpc/kernel/process.c +0 -3
index 710f400..d73fa99 100644
@@ -514,9 +514,6 @@ struct task_struct *__switch_to(struct task_struct *prev,
 
 	local_irq_save(flags);
 
-	account_system_vtime(current);
-	account_process_vtime(current);
-
 	/*
 	 * We can't take a PMU exception inside _switch() since there is a
 	 * window where the kernel stack SLB and the kernel stack are out
arch/powerpc/kernel/time.c +6 -0
index be171ee..49da7f0 100644
@@ -366,6 +366,12 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
 	account_user_time(tsk, utime, utimescaled);
 }
 
+void account_switch_vtime(struct task_struct *prev)
+{
+	account_system_vtime(prev);
+	account_process_tick(prev, 0);
+}
+
 #else /* ! CONFIG_VIRT_CPU_ACCOUNTING */
 #define calc_cputime_factors()
 #endif
arch/s390/include/asm/switch_to.h +0 -2
index f223068..e7f9b3d 100644
@@ -89,12 +89,10 @@ static inline void restore_access_regs(unsigned int *acrs)
 	prev = __switch_to(prev,next);					\
 } while (0)
 
-extern void account_vtime(struct task_struct *, struct task_struct *);
 extern void account_tick_vtime(struct task_struct *);
 
 #define finish_arch_switch(prev) do {					     \
 	set_fs(current->thread.mm_segment);				     \
-	account_vtime(prev, current);					     \
 } while (0)
 
 #endif /* __ASM_SWITCH_TO_H */
arch/s390/kernel/vtime.c +2 -2
index 39ebff5..506e9bd 100644
@@ -86,7 +86,7 @@ static void do_account_vtime(struct task_struct *tsk, int hardirq_offset)
 	}
 }
 
-void account_vtime(struct task_struct *prev, struct task_struct *next)
+void account_switch_vtime(struct task_struct *prev)
 {
 	struct thread_info *ti;
 
@@ -94,7 +94,7 @@ void account_vtime(struct task_struct *prev, struct task_struct *next)
 	ti = task_thread_info(prev);
 	ti->user_timer = S390_lowcore.user_timer;
 	ti->system_timer = S390_lowcore.system_timer;
-	ti = task_thread_info(next);
+	ti = task_thread_info(current);
 	S390_lowcore.user_timer = ti->user_timer;
 	S390_lowcore.system_timer = ti->system_timer;
 }
include/linux/kernel_stat.h +6 -0
index 2fbd905..bbe5d15 100644
@@ -130,4 +130,10 @@ extern void account_process_tick(struct task_struct *, int user);
 extern void account_steal_ticks(unsigned long ticks);
 extern void account_idle_ticks(unsigned long ticks);
 
+#ifdef CONFIG_VIRT_CPU_ACCOUNTING
+extern void account_switch_vtime(struct task_struct *prev);
+#else
+static inline void account_switch_vtime(struct task_struct *prev) { }
+#endif
+
 #endif /* _LINUX_KERNEL_STAT_H */
kernel/sched/core.c +1 -0
index 4f89f42..d34a150 100644
@@ -1796,6 +1796,7 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
 	 *		Manfred Spraul <[email protected]>
 	 */
 	prev_state = prev->state;
+	account_switch_vtime(prev);
 	finish_arch_switch(prev);
 #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
 	local_irq_disable();
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH 4/4 s390: Remove leftover account_tick_vtime() header

In reply to Frederic Weisbecker

The function doesn't seem to exist anymore.

Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 arch/s390/include/asm/switch_to.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
arch/s390/include/asm/switch_to.h +0 -2
index e7f9b3d..314cc94 100644
@@ -89,8 +89,6 @@ static inline void restore_access_regs(unsigned int *acrs)
 	prev = __switch_to(prev,next);					\
 } while (0)
 
-extern void account_tick_vtime(struct task_struct *);
-
 #define finish_arch_switch(prev) do {					     \
 	set_fs(current->thread.mm_segment);				     \
 } while (0)
Signature · 1 line
1.7.5.4
#5 lore raw
In reply to Frederic Weisbecker
Quoted 1 line

This is only built tested on the relevant archs.

Built and run on ia64 ... seems to work (but I don't have any tests that really show the difference between having this turned on/off :-( )

-Tony

maintainer
#6 lore raw
In reply to Frederic Weisbecker
Quoted 5 lines · Frederic Weisbecker

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Yes.. so s390,ia64 use thread_info, ppc uses their paca (arch private precursor to per-cpu data).

So I understand why s390,ia64 want the sched hook, but I don't see why ppc would need it, their account_process_tick() can fold whatever they need on the tick.

So I think reworking s390,ia64 to use per-cpu storage should get rid of this switch hook altogether.

Now everybody using VIRT_CPU_ACCOUNTING has the syscall/__irq_{enter,exit} hooks and uses 64bit cputime_t.

IRQ_TIME_ACCOUNTING only has the __irq_{enter,exit} hook and uses unsigned long cputime_t, it adds cputime_one_jiffy every tick when the per-cpu counter is ahead of the cputime.

We could merge both and do away with the 64bit cputime thing by keeping a (2nd) per-cpu kernel_cpustat which we fill with optional syscall/irq hooks and have account_process_tick() first check if any of the fine-grained fields overflow and if not, fall back to the regular tick accounting (much like an extended irqtime_account_process_tick).

This would merge the fine-grain and tick based code-paths and do away with the whole cputime_t mess, it would also merge the VIRT and IRQ paths and make Frederic's optional syscall accounting trivial.

Or am I missing something obvious here? -- its late after all.

I'll try and write some code tomorrow.

#7 lore raw

2012/6/21 Peter Zijlstra <[email protected]>:

Quoted 6 lines · Frederic Weisbecker
Quoted 5 lines

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Quoted 6 lines

Yes.. so s390,ia64 use thread_info, ppc uses their paca (arch private precursor to per-cpu data).

So I understand why s390,ia64 want the sched hook, but I don't see why ppc would need it, their account_process_tick() can fold whatever they need on the tick.

I think in any case you need to flush the time on a descheduling task otherwise its pending time will be accounted later to the next task when it receives an irq.

So I fear we still need that sched switch hook even with per cpu data. This may be a simple account_system_vtime() call.

Quoted 19 lines

So I think reworking s390,ia64 to use per-cpu storage should get rid of this switch hook altogether.

Now everybody using VIRT_CPU_ACCOUNTING has the syscall/__irq_{enter,exit} hooks and uses 64bit cputime_t.

IRQ_TIME_ACCOUNTING only has the __irq_{enter,exit} hook and uses unsigned long cputime_t, it adds cputime_one_jiffy every tick when the per-cpu counter is ahead of the cputime.

We could merge both and do away with the 64bit cputime thing by keeping a (2nd) per-cpu kernel_cpustat which we fill with optional syscall/irq hooks and have account_process_tick() first check if any of the fine-grained fields overflow and if not, fall back to the regular tick accounting (much like an extended irqtime_account_process_tick).

Quoted 5 lines

This would merge the fine-grain and tick based code-paths and do away with the whole cputime_t mess, it would also merge the VIRT and IRQ paths and make Frederic's optional syscall accounting trivial.

Or am I missing something obvious here? -- its late after all.

No that looks pretty sensible.

Quoted 1 line

I'll try and write some code tomorrow.

Thanks!

#8 lore raw
Quoted 9 lines · On Thu, 21 Jun 2012 02:46:29 +0200 Frederic Weisbecker <[email protected]>…

2012/6/21 Peter Zijlstra <[email protected]>:

Quoted 8 lines · Frederic Weisbecker
Quoted 5 lines

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Yes.. so s390,ia64 use thread_info, ppc uses their paca (arch private precursor to per-cpu data).

s390 uses the prefix page / lowcore to accumulate some accounting information. Which basically is per-cpu data with the advantage that it is accessible with at address 0-8191 for each cpu. The entry code does not have to load a pointer to get to that page, I would prefer NOT to use per-cpu data here.

Quoted 10 lines
Quoted 3 lines

So I understand why s390,ia64 want the sched hook, but I don't see why ppc would need it, their account_process_tick() can fold whatever they need on the tick.

I think in any case you need to flush the time on a descheduling task otherwise its pending time will be accounted later to the next task when it receives an irq.

So I fear we still need that sched switch hook even with per cpu data. This may be a simple account_system_vtime() call.

Indeed, the scheduler hook is needed to add the accumulated values to the correct task.

Quoted 2 lines
Quoted 2 lines

So I think reworking s390,ia64 to use per-cpu storage should get rid of this switch hook altogether.

If we get rid of the switch hook then the quality of the accounting numbers will get significantly worse. Think of the scenario of a long running background process and a task that repeatedly wakes up for a very short time. Without the scheduler hook chances are good that the background task is accounted all the accumulated user time.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
maintainer
#9 lore raw
Quoted 10 lines · Martin Schwidefsky
Quoted 7 lines · On Thu, 21 Jun 2012 02:46:29 +0200 Frederic Weisbecker <[email protected]>…

2012/6/21 Peter Zijlstra <[email protected]>:

Quoted 6 lines · Frederic Weisbecker
Quoted 5 lines

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Yes.. so s390,ia64 use thread_info, ppc uses their paca (arch private precursor to per-cpu data).

s390 uses the prefix page / lowcore to accumulate some accounting information. Which basically is per-cpu data with the advantage that it is accessible with at address 0-8191 for each cpu. The entry code does not have to load a pointer to get to that page, I would prefer NOT to use per-cpu data here.

Yeah, same for ppc and their paca, I just meant to put the data in per-cpu (your lowcore and ppc's paca qualify) storage instead of per-task.

But seeing as I completely overlooked the per-task accounting this doesn't matter anyway.

There being the per-task accounting also completely wrecks the proposal I outlined. That only works if its only per-cpu accounting.

The alternative is going full 64bit ns and having the tick fallback do TICK_NSEC increments. 32bit args that don't do VIRT_TIME or IRQ_TIME won't like that though :/

So yeah, I did miss something obvious.. no cookies for me.

#10 lore raw
Quoted 26 lines · Peter Zijlstra
Quoted 10 lines · Martin Schwidefsky
Quoted 7 lines · On Thu, 21 Jun 2012 02:46:29 +0200 Frederic Weisbecker <[email protected]>…

2012/6/21 Peter Zijlstra <[email protected]>:

Quoted 6 lines · Frederic Weisbecker
Quoted 5 lines

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Yes.. so s390,ia64 use thread_info, ppc uses their paca (arch private precursor to per-cpu data).

s390 uses the prefix page / lowcore to accumulate some accounting information. Which basically is per-cpu data with the advantage that it is accessible with at address 0-8191 for each cpu. The entry code does not have to load a pointer to get to that page, I would prefer NOT to use per-cpu data here.

Yeah, same for ppc and their paca, I just meant to put the data in per-cpu (your lowcore and ppc's paca qualify) storage instead of per-task.

But seeing as I completely overlooked the per-task accounting this doesn't matter anyway.

Quoted 8 lines

There being the per-task accounting also completely wrecks the proposal I outlined. That only works if its only per-cpu accounting.

The alternative is going full 64bit ns and having the tick fallback do TICK_NSEC increments. 32bit args that don't do VIRT_TIME or IRQ_TIME won't like that though :/

So yeah, I did miss something obvious.. no cookies for me.

Yeah but the idea of a dynamic switching between tick based accounting and virtual based one (account_system_vtime()) is still valuable to me.

That of course only makes sense if the arch uses some kind of "on-demand" virtual accounting. Like using TIF flags for syscall slow path and jump labels for exception hooks. Although in the longer term we should rather hook on the syscall fastpath, but you get the idea.

How does that sound?

Another way would be to make the adaptive tickless thing depend on the traditional CONFIG_VIRT_CPU_TIME. So it's simply enabled all the time and we don't care. But we need syscalls/exceptions hooks for RCU anyway, which is why I think an on-demand thing could make sense because both RCU and vtime could use these on-demand hooks.

maintainer
#11 lore raw
In reply to Frederic Weisbecker
Quoted 10 lines · Frederic Weisbecker
Quoted 3 lines

So I understand why s390,ia64 want the sched hook, but I don't see why ppc would need it, their account_process_tick() can fold whatever they need on the tick.

I think in any case you need to flush the time on a descheduling task otherwise its pending time will be accounted later to the next task when it receives an irq.

So I fear we still need that sched switch hook even with per cpu data. This may be a simple account_system_vtime() call.

Did I miss a per-task something in there?

maintainer
#12 lore raw
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Frederic Weisbecker
Quoted 3 lines

So I understand why s390,ia64 want the sched hook, but I don't see why ppc would need it, their account_process_tick() can fold whatever they need on the tick.

Quoted 8 lines
Quoted 6 lines

I think in any case you need to flush the time on a descheduling task otherwise its pending time will be accounted later to the next task when it receives an irq.

So I fear we still need that sched switch hook even with per cpu data. This may be a simple account_system_vtime() call.

Did I miss a per-task something in there?

Gah yeah.. I was staring too hard at the arch code and missed the task accounting in the core code.

OK, so that switch hook stays :-)

#13 lore raw
In reply to Frederic Weisbecker
Quoted 5 lines · Frederic Weisbecker

Not sure to which tree this should go. The scheduler one may be. Anyway if you're fine with it, it is pullable at:

git://github.com/fweisbec/linux-dynticks.git
virt-cputime

Ping. Are you guys fine with the patchset?

Quoted 37 lines

This is only built tested on the relevant archs.

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Frederic Weisbecker (4):
cputime: Generalize CONFIG_VIRT_CPU_ACCOUNTING
sched: Move cputime code to its own file
cputime: Consolidate vtime handling on context switch
s390: Remove leftover account_tick_vtime() header

 arch/Kconfig                           |    3 +
 arch/ia64/Kconfig                      |   12 +-
 arch/ia64/include/asm/switch_to.h      |    8 -
 arch/ia64/kernel/time.c                |    4 +-
 arch/powerpc/include/asm/time.h        |    6 -
 arch/powerpc/kernel/process.c          |    3 -
 arch/powerpc/kernel/time.c             |    6 +
 arch/powerpc/platforms/Kconfig.cputype |   16 +-
 arch/s390/Kconfig                      |    5 +-
 arch/s390/include/asm/switch_to.h      |    4 -
 arch/s390/kernel/vtime.c               |    4 +-
 include/linux/kernel_stat.h            |    6 +
 init/Kconfig                           |   13 +
 kernel/sched/Makefile                  |    2 +-
 kernel/sched/core.c                    |  552 +-------------------------------
 kernel/sched/cputime.c                 |  497 ++++++++++++++++++++++++++++
 kernel/sched/sched.h                   |   63 ++++
 17 files changed, 600 insertions(+), 604 deletions(-)
 create mode 100644 kernel/sched/cputime.c
Signature · 1 line
1.7.5.4
#14 lore raw
Quoted 8 lines · Frederic Weisbecker
Quoted 5 lines · Frederic Weisbecker

Not sure to which tree this should go. The scheduler one may be. Anyway if you're fine with it, it is pullable at:

git://github.com/fweisbec/linux-dynticks.git
virt-cputime

Ping. Are you guys fine with the patchset?

Missed it somewhat. I'll have a look today.

(Poke me on IRC with a stick if you don't hear from me in time)

Cheers,
Ben.

Quoted 37 lines
Quoted 37 lines

This is only built tested on the relevant archs.

I wish we could do more vtime cputime accounting consolidation but archs do the things pretty differently although I bet the behaviour could be more unified.

Frederic Weisbecker (4):
cputime: Generalize CONFIG_VIRT_CPU_ACCOUNTING
sched: Move cputime code to its own file
cputime: Consolidate vtime handling on context switch
s390: Remove leftover account_tick_vtime() header

 arch/Kconfig                           |    3 +
 arch/ia64/Kconfig                      |   12 +-
 arch/ia64/include/asm/switch_to.h      |    8 -
 arch/ia64/kernel/time.c                |    4 +-
 arch/powerpc/include/asm/time.h        |    6 -
 arch/powerpc/kernel/process.c          |    3 -
 arch/powerpc/kernel/time.c             |    6 +
 arch/powerpc/platforms/Kconfig.cputype |   16 +-
 arch/s390/Kconfig                      |    5 +-
 arch/s390/include/asm/switch_to.h      |    4 -
 arch/s390/kernel/vtime.c               |    4 +-
 include/linux/kernel_stat.h            |    6 +
 init/Kconfig                           |   13 +
 kernel/sched/Makefile                  |    2 +-
 kernel/sched/core.c                    |  552 +-------------------------------
 kernel/sched/cputime.c                 |  497 ++++++++++++++++++++++++++++
 kernel/sched/sched.h                   |   63 ++++
 17 files changed, 600 insertions(+), 604 deletions(-)
 create mode 100644 kernel/sched/cputime.c
Signature · 1 line
1.7.5.4
#15 lore raw
In reply to Frederic Weisbecker

2012/7/9 Frederic Weisbecker <[email protected]>:

Quoted 8 lines · Frederic Weisbecker
Quoted 5 lines

Not sure to which tree this should go. The scheduler one may be. Anyway if you're fine with it, it is pullable at:

git://github.com/fweisbec/linux-dynticks.git
virt-cputime

Ping. Are you guys fine with the patchset?

Re-ping :)