Skip to content

Commit abf917c

Browse files
committed
cputime: Generic on-demand virtual cputime accounting
If we want to stop the tick further idle, we need to be able to account the cputime without using the tick. Virtual based cputime accounting solves that problem by hooking into kernel/user boundaries. However implementing CONFIG_VIRT_CPU_ACCOUNTING require low level hooks and involves more overhead. But we already have a generic context tracking subsystem that is required for RCU needs by archs which plan to shut down the tick outside idle. This patch implements a generic virtual based cputime accounting that relies on these generic kernel/user hooks. There are some upsides of doing this: - This requires no arch code to implement CONFIG_VIRT_CPU_ACCOUNTING if context tracking is already built (already necessary for RCU in full tickless mode). - We can rely on the generic context tracking subsystem to dynamically (de)activate the hooks, so that we can switch anytime between virtual and tick based accounting. This way we don't have the overhead of the virtual accounting when the tick is running periodically. And one downside: - There is probably more overhead than a native virtual based cputime accounting. But this relies on hooks that are already set anyway. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de>
1 parent ae8dda5 commit abf917c

27 files changed

Lines changed: 160 additions & 54 deletions

File tree

‎arch/ia64/include/asm/cputime.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
* as published by the Free Software Foundation; either version
1212
* 2 of the License, or (at your option) any later version.
1313
*
14-
* If we have CONFIG_VIRT_CPU_ACCOUNTING, we measure cpu time in nsec.
14+
* If we have CONFIG_VIRT_CPU_ACCOUNTING_NATIVE, we measure cpu time in nsec.
1515
* Otherwise we measure cpu time in jiffies using the generic definitions.
1616
*/
1717

1818
#ifndef __IA64_CPUTIME_H
1919
#define __IA64_CPUTIME_H
2020

21-
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
21+
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
2222
# include <asm-generic/cputime.h>
2323
#else
2424
# include <asm/processor.h>
2525
# include <asm-generic/cputime_nsecs.h>
2626
extern void arch_vtime_task_switch(struct task_struct *tsk);
27-
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
27+
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
2828

2929
#endif /* __IA64_CPUTIME_H */

‎arch/ia64/include/asm/thread_info.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct thread_info {
3131
mm_segment_t addr_limit; /* user-level address space limit */
3232
int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */
3333
struct restart_block restart_block;
34-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
34+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
3535
__u64 ac_stamp;
3636
__u64 ac_leave;
3737
__u64 ac_stime;
@@ -69,7 +69,7 @@ struct thread_info {
6969
#define task_stack_page(tsk) ((void *)(tsk))
7070

7171
#define __HAVE_THREAD_FUNCTIONS
72-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
72+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
7373
#define setup_thread_stack(p, org) \
7474
*task_thread_info(p) = *task_thread_info(org); \
7575
task_thread_info(p)->ac_stime = 0; \

‎arch/ia64/include/asm/xen/minstate.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
2+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
33
/* read ar.itc in advance, and use it before leaving bank 0 */
44
#define XEN_ACCOUNT_GET_STAMP \
55
MOV_FROM_ITC(pUStk, p6, r20, r2);

‎arch/ia64/kernel/asm-offsets.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void foo(void)
4141
DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
4242
DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
4343
DEFINE(TI_PRE_COUNT, offsetof(struct thread_info, preempt_count));
44-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
44+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
4545
DEFINE(TI_AC_STAMP, offsetof(struct thread_info, ac_stamp));
4646
DEFINE(TI_AC_LEAVE, offsetof(struct thread_info, ac_leave));
4747
DEFINE(TI_AC_STIME, offsetof(struct thread_info, ac_stime));

‎arch/ia64/kernel/entry.S‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ GLOBAL_ENTRY(__paravirt_leave_syscall)
724724
#endif
725725
.global __paravirt_work_processed_syscall;
726726
__paravirt_work_processed_syscall:
727-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
727+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
728728
adds r2=PT(LOADRS)+16,r12
729729
MOV_FROM_ITC(pUStk, p9, r22, r19) // fetch time at leave
730730
adds r18=TI_FLAGS+IA64_TASK_SIZE,r13
@@ -762,7 +762,7 @@ __paravirt_work_processed_syscall:
762762

763763
ld8 r29=[r2],16 // M0|1 load cr.ipsr
764764
ld8 r28=[r3],16 // M0|1 load cr.iip
765-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
765+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
766766
(pUStk) add r14=TI_AC_LEAVE+IA64_TASK_SIZE,r13
767767
;;
768768
ld8 r30=[r2],16 // M0|1 load cr.ifs
@@ -793,7 +793,7 @@ __paravirt_work_processed_syscall:
793793
ld8.fill r1=[r3],16 // M0|1 load r1
794794
(pUStk) mov r17=1 // A
795795
;;
796-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
796+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
797797
(pUStk) st1 [r15]=r17 // M2|3
798798
#else
799799
(pUStk) st1 [r14]=r17 // M2|3
@@ -813,7 +813,7 @@ __paravirt_work_processed_syscall:
813813
shr.u r18=r19,16 // I0|1 get byte size of existing "dirty" partition
814814
COVER // B add current frame into dirty partition & set cr.ifs
815815
;;
816-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
816+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
817817
mov r19=ar.bsp // M2 get new backing store pointer
818818
st8 [r14]=r22 // M save time at leave
819819
mov f10=f0 // F clear f10
@@ -948,7 +948,7 @@ GLOBAL_ENTRY(__paravirt_leave_kernel)
948948
adds r16=PT(CR_IPSR)+16,r12
949949
adds r17=PT(CR_IIP)+16,r12
950950

951-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
951+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
952952
.pred.rel.mutex pUStk,pKStk
953953
MOV_FROM_PSR(pKStk, r22, r29) // M2 read PSR now that interrupts are disabled
954954
MOV_FROM_ITC(pUStk, p9, r22, r29) // M fetch time at leave
@@ -981,23 +981,23 @@ GLOBAL_ENTRY(__paravirt_leave_kernel)
981981
;;
982982
ld8.fill r12=[r16],16
983983
ld8.fill r13=[r17],16
984-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
984+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
985985
(pUStk) adds r3=TI_AC_LEAVE+IA64_TASK_SIZE,r18
986986
#else
987987
(pUStk) adds r18=IA64_TASK_THREAD_ON_USTACK_OFFSET,r18
988988
#endif
989989
;;
990990
ld8 r20=[r16],16 // ar.fpsr
991991
ld8.fill r15=[r17],16
992-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
992+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
993993
(pUStk) adds r18=IA64_TASK_THREAD_ON_USTACK_OFFSET,r18 // deferred
994994
#endif
995995
;;
996996
ld8.fill r14=[r16],16
997997
ld8.fill r2=[r17]
998998
(pUStk) mov r17=1
999999
;;
1000-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
1000+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
10011001
// mmi_ : ld8 st1 shr;; mmi_ : st8 st1 shr;;
10021002
// mib : mov add br -> mib : ld8 add br
10031003
// bbb_ : br nop cover;; mbb_ : mov br cover;;

‎arch/ia64/kernel/fsys.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ GLOBAL_ENTRY(paravirt_fsys_bubble_down)
529529
nop.i 0
530530
;;
531531
mov ar.rsc=0 // M2 set enforced lazy mode, pl 0, LE, loadrs=0
532-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
532+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
533533
MOV_FROM_ITC(p0, p6, r30, r23) // M get cycle for accounting
534534
#else
535535
nop.m 0
@@ -555,7 +555,7 @@ GLOBAL_ENTRY(paravirt_fsys_bubble_down)
555555
cmp.ne pKStk,pUStk=r0,r0 // A set pKStk <- 0, pUStk <- 1
556556
br.call.sptk.many b7=ia64_syscall_setup // B
557557
;;
558-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
558+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
559559
// mov.m r30=ar.itc is called in advance
560560
add r16=TI_AC_STAMP+IA64_TASK_SIZE,r2
561561
add r17=TI_AC_LEAVE+IA64_TASK_SIZE,r2

‎arch/ia64/kernel/head.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ END(ia64_native_sched_clock)
10731073
sched_clock = ia64_native_sched_clock
10741074
#endif
10751075

1076-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
1076+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
10771077
GLOBAL_ENTRY(cycle_to_cputime)
10781078
alloc r16=ar.pfs,1,0,0,0
10791079
addl r8=THIS_CPU(ia64_cpu_info) + IA64_CPUINFO_NSEC_PER_CYC_OFFSET,r0
@@ -1091,7 +1091,7 @@ GLOBAL_ENTRY(cycle_to_cputime)
10911091
shrp r8=r9,r8,IA64_NSEC_PER_CYC_SHIFT
10921092
br.ret.sptk.many rp
10931093
END(cycle_to_cputime)
1094-
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
1094+
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
10951095

10961096
#ifdef CONFIG_IA64_BRL_EMU
10971097

‎arch/ia64/kernel/ivt.S‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ ENTRY(break_fault)
784784

785785
(p8) adds r28=16,r28 // A switch cr.iip to next bundle
786786
(p9) adds r8=1,r8 // A increment ei to next slot
787-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
787+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
788788
;;
789789
mov b6=r30 // I0 setup syscall handler branch reg early
790790
#else
@@ -801,7 +801,7 @@ ENTRY(break_fault)
801801
//
802802
///////////////////////////////////////////////////////////////////////
803803
st1 [r16]=r0 // M2|3 clear current->thread.on_ustack flag
804-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
804+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
805805
MOV_FROM_ITC(p0, p14, r30, r18) // M get cycle for accounting
806806
#else
807807
mov b6=r30 // I0 setup syscall handler branch reg early
@@ -817,7 +817,7 @@ ENTRY(break_fault)
817817
cmp.eq p14,p0=r9,r0 // A are syscalls being traced/audited?
818818
br.call.sptk.many b7=ia64_syscall_setup // B
819819
1:
820-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
820+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
821821
// mov.m r30=ar.itc is called in advance, and r13 is current
822822
add r16=TI_AC_STAMP+IA64_TASK_SIZE,r13 // A
823823
add r17=TI_AC_LEAVE+IA64_TASK_SIZE,r13 // A
@@ -1043,7 +1043,7 @@ END(ia64_syscall_setup)
10431043
DBG_FAULT(16)
10441044
FAULT(16)
10451045

1046-
#if defined(CONFIG_VIRT_CPU_ACCOUNTING) && defined(__IA64_ASM_PARAVIRTUALIZED_NATIVE)
1046+
#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(__IA64_ASM_PARAVIRTUALIZED_NATIVE)
10471047
/*
10481048
* There is no particular reason for this code to be here, other than
10491049
* that there happens to be space here that would go unused otherwise.

‎arch/ia64/kernel/minstate.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "entry.h"
55
#include "paravirt_inst.h"
66

7-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
7+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
88
/* read ar.itc in advance, and use it before leaving bank 0 */
99
#define ACCOUNT_GET_STAMP \
1010
(pUStk) mov.m r20=ar.itc;

‎arch/ia64/kernel/time.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static struct clocksource clocksource_itc = {
7777
};
7878
static struct clocksource *itc_clocksource;
7979

80-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
80+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
8181

8282
#include <linux/kernel_stat.h>
8383

@@ -142,7 +142,7 @@ void vtime_account_idle(struct task_struct *tsk)
142142
account_idle_time(vtime_delta(tsk));
143143
}
144144

145-
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
145+
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
146146

147147
static irqreturn_t
148148
timer_interrupt (int irq, void *dev_id)

0 commit comments

Comments
 (0)