Skip to content

Commit c223c90

Browse files
chleroyScott Wood
authored andcommitted
powerpc32: provide VIRT_CPU_ACCOUNTING
This patch provides VIRT_CPU_ACCOUTING to PPC32 architecture. PPC32 doesn't have the PACA structure, so we use the task_info structure to store the accounting data. In order to reuse on PPC32 the PPC64 functions, all u64 data has been replaced by 'unsigned long' so that it is u32 on PPC32 and u64 on PPC64 Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Scott Wood <oss@buserror.net>
1 parent 1afbf61 commit c223c90

15 files changed

Lines changed: 158 additions & 67 deletions

File tree

‎arch/powerpc/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ config PPC
165165
select ARCH_HAS_UBSAN_SANITIZE_ALL
166166
select ARCH_SUPPORTS_DEFERRED_STRUCT_PAGE_INIT
167167
select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
168+
select HAVE_VIRT_CPU_ACCOUNTING
168169

169170
config GENERIC_CSUM
170171
def_bool CPU_LITTLE_ENDIAN
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Common time accounting prototypes and such for all ppc machines.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version
7+
* 2 of the License, or (at your option) any later version.
8+
*/
9+
10+
#ifndef __POWERPC_ACCOUNTING_H
11+
#define __POWERPC_ACCOUNTING_H
12+
13+
/* Stuff for accurate time accounting */
14+
struct cpu_accounting_data {
15+
unsigned long user_time; /* accumulated usermode TB ticks */
16+
unsigned long system_time; /* accumulated system TB ticks */
17+
unsigned long user_time_scaled; /* accumulated usermode SPURR ticks */
18+
unsigned long starttime; /* TB value snapshot */
19+
unsigned long starttime_user; /* TB value on exit to usermode */
20+
unsigned long startspurr; /* SPURR value snapshot */
21+
unsigned long utime_sspurr; /* ->user_time when ->startspurr set */
22+
};
23+
24+
#endif

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ static inline void setup_cputime_one_jiffy(void)
9090
static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
9191
{
9292
u64 ct;
93-
u64 sec;
93+
u64 sec = jif;
9494

9595
/* have to be a little careful about overflow */
96-
ct = jif % HZ;
97-
sec = jif / HZ;
96+
ct = do_div(sec, HZ);
9897
if (ct) {
9998
ct *= tb_ticks_per_sec;
10099
do_div(ct, HZ);
@@ -230,7 +229,16 @@ static inline cputime_t clock_t_to_cputime(const unsigned long clk)
230229

231230
#define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct))
232231

232+
/*
233+
* PPC64 uses PACA which is task independent for storing accounting data while
234+
* PPC32 uses struct thread_info, therefore at task switch the accounting data
235+
* has to be populated in the new task
236+
*/
237+
#ifdef CONFIG_PPC64
233238
static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
239+
#else
240+
void arch_vtime_task_switch(struct task_struct *tsk);
241+
#endif
234242

235243
#endif /* __KERNEL__ */
236244
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */

‎arch/powerpc/include/asm/exception-64s.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ do_kvm_##n: \
287287
std r0,GPR0(r1); /* save r0 in stackframe */ \
288288
std r10,GPR1(r1); /* save r1 in stackframe */ \
289289
beq 4f; /* if from kernel mode */ \
290-
ACCOUNT_CPU_USER_ENTRY(r9, r10); \
290+
ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
291291
SAVE_PPR(area, r9, r10); \
292292
4: EXCEPTION_PROLOG_COMMON_2(area) \
293293
EXCEPTION_PROLOG_COMMON_3(n) \

‎arch/powerpc/include/asm/paca.h‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
2626
#include <asm/kvm_book3s_asm.h>
2727
#endif
28+
#include <asm/accounting.h>
2829

2930
register struct paca_struct *local_paca asm("r13");
3031

@@ -184,13 +185,7 @@ struct paca_struct {
184185
#endif
185186

186187
/* Stuff for accurate time accounting */
187-
u64 user_time; /* accumulated usermode TB ticks */
188-
u64 system_time; /* accumulated system TB ticks */
189-
u64 user_time_scaled; /* accumulated usermode SPURR ticks */
190-
u64 starttime; /* TB value snapshot */
191-
u64 starttime_user; /* TB value on exit to usermode */
192-
u64 startspurr; /* SPURR value snapshot */
193-
u64 utime_sspurr; /* ->user_time when ->startspurr set */
188+
struct cpu_accounting_data accounting;
194189
u64 stolen_time; /* TB ticks taken by hypervisor */
195190
u64 dtl_ridx; /* read index in dispatch log */
196191
struct dtl_entry *dtl_curr; /* pointer corresponding to dtl_ridx */

‎arch/powerpc/include/asm/ppc_asm.h‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@
2424
*/
2525

2626
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
27-
#define ACCOUNT_CPU_USER_ENTRY(ra, rb)
28-
#define ACCOUNT_CPU_USER_EXIT(ra, rb)
27+
#define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb)
28+
#define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb)
2929
#define ACCOUNT_STOLEN_TIME
3030
#else
31-
#define ACCOUNT_CPU_USER_ENTRY(ra, rb) \
31+
#define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb) \
3232
MFTB(ra); /* get timebase */ \
33-
ld rb,PACA_STARTTIME_USER(r13); \
34-
std ra,PACA_STARTTIME(r13); \
33+
PPC_LL rb, ACCOUNT_STARTTIME_USER(ptr); \
34+
PPC_STL ra, ACCOUNT_STARTTIME(ptr); \
3535
subf rb,rb,ra; /* subtract start value */ \
36-
ld ra,PACA_USER_TIME(r13); \
36+
PPC_LL ra, ACCOUNT_USER_TIME(ptr); \
3737
add ra,ra,rb; /* add on to user time */ \
38-
std ra,PACA_USER_TIME(r13); \
38+
PPC_STL ra, ACCOUNT_USER_TIME(ptr); \
3939

40-
#define ACCOUNT_CPU_USER_EXIT(ra, rb) \
40+
#define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb) \
4141
MFTB(ra); /* get timebase */ \
42-
ld rb,PACA_STARTTIME(r13); \
43-
std ra,PACA_STARTTIME_USER(r13); \
42+
PPC_LL rb, ACCOUNT_STARTTIME(ptr); \
43+
PPC_STL ra, ACCOUNT_STARTTIME_USER(ptr); \
4444
subf rb,rb,ra; /* subtract start value */ \
45-
ld ra,PACA_SYSTEM_TIME(r13); \
45+
PPC_LL ra, ACCOUNT_SYSTEM_TIME(ptr); \
4646
add ra,ra,rb; /* add on to system time */ \
47-
std ra,PACA_SYSTEM_TIME(r13)
47+
PPC_STL ra, ACCOUNT_SYSTEM_TIME(ptr)
4848

4949
#ifdef CONFIG_PPC_SPLPAR
5050
#define ACCOUNT_STOLEN_TIME \

‎arch/powerpc/include/asm/reg.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@ static inline unsigned long mfvtb (void)
12941294
asm volatile("mfspr %0, %1" : "=r" (rval) : \
12951295
"i" (SPRN_TBRU)); rval;})
12961296
#endif
1297+
#define mftb() mftbl()
12971298
#endif /* !__powerpc64__ */
12981299

12991300
#define mttbl(v) asm volatile("mttbl %0":: "r"(v))

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <asm/processor.h>
3434
#include <asm/page.h>
3535
#include <linux/stringify.h>
36+
#include <asm/accounting.h>
3637

3738
/*
3839
* low level task data.
@@ -45,6 +46,9 @@ struct thread_info {
4546
unsigned long local_flags; /* private flags for thread */
4647
#ifdef CONFIG_LIVEPATCH
4748
unsigned long *livepatch_sp;
49+
#endif
50+
#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC32)
51+
struct cpu_accounting_data accounting;
4852
#endif
4953
/* low level flags - has atomic operations done on it */
5054
unsigned long flags ____cacheline_aligned_in_smp;

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,28 @@ int main(void)
240240
DEFINE(PACAHWCPUID, offsetof(struct paca_struct, hw_cpu_id));
241241
DEFINE(PACAKEXECSTATE, offsetof(struct paca_struct, kexec_state));
242242
DEFINE(PACA_DSCR_DEFAULT, offsetof(struct paca_struct, dscr_default));
243-
DEFINE(PACA_STARTTIME, offsetof(struct paca_struct, starttime));
244-
DEFINE(PACA_STARTTIME_USER, offsetof(struct paca_struct, starttime_user));
245-
DEFINE(PACA_USER_TIME, offsetof(struct paca_struct, user_time));
246-
DEFINE(PACA_SYSTEM_TIME, offsetof(struct paca_struct, system_time));
243+
DEFINE(ACCOUNT_STARTTIME,
244+
offsetof(struct paca_struct, accounting.starttime));
245+
DEFINE(ACCOUNT_STARTTIME_USER,
246+
offsetof(struct paca_struct, accounting.starttime_user));
247+
DEFINE(ACCOUNT_USER_TIME,
248+
offsetof(struct paca_struct, accounting.user_time));
249+
DEFINE(ACCOUNT_SYSTEM_TIME,
250+
offsetof(struct paca_struct, accounting.system_time));
247251
DEFINE(PACA_TRAP_SAVE, offsetof(struct paca_struct, trap_save));
248252
DEFINE(PACA_NAPSTATELOST, offsetof(struct paca_struct, nap_state_lost));
249253
DEFINE(PACA_SPRG_VDSO, offsetof(struct paca_struct, sprg_vdso));
254+
#else /* CONFIG_PPC64 */
255+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
256+
DEFINE(ACCOUNT_STARTTIME,
257+
offsetof(struct thread_info, accounting.starttime));
258+
DEFINE(ACCOUNT_STARTTIME_USER,
259+
offsetof(struct thread_info, accounting.starttime_user));
260+
DEFINE(ACCOUNT_USER_TIME,
261+
offsetof(struct thread_info, accounting.user_time));
262+
DEFINE(ACCOUNT_SYSTEM_TIME,
263+
offsetof(struct thread_info, accounting.system_time));
264+
#endif
250265
#endif /* CONFIG_PPC64 */
251266

252267
/* RTAS */

‎arch/powerpc/kernel/entry_32.S‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ transfer_to_handler:
175175
addi r12,r12,-1
176176
stw r12,4(r11)
177177
#endif
178+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
179+
CURRENT_THREAD_INFO(r9, r1)
180+
tophys(r9, r9)
181+
ACCOUNT_CPU_USER_ENTRY(r9, r11, r12)
182+
#endif
183+
178184
b 3f
179185

180186
2: /* if from kernel, check interrupted DOZE/NAP mode and
@@ -398,6 +404,13 @@ BEGIN_FTR_SECTION
398404
lwarx r7,0,r1
399405
END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
400406
stwcx. r0,0,r1 /* to clear the reservation */
407+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
408+
andi. r4,r8,MSR_PR
409+
beq 3f
410+
CURRENT_THREAD_INFO(r4, r1)
411+
ACCOUNT_CPU_USER_EXIT(r4, r5, r7)
412+
3:
413+
#endif
401414
lwz r4,_LINK(r1)
402415
lwz r5,_CCR(r1)
403416
mtlr r4
@@ -769,6 +782,10 @@ restore_user:
769782
andis. r10,r0,DBCR0_IDM@h
770783
bnel- load_dbcr0
771784
#endif
785+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
786+
CURRENT_THREAD_INFO(r9, r1)
787+
ACCOUNT_CPU_USER_EXIT(r9, r10, r11)
788+
#endif
772789

773790
b restore
774791

0 commit comments

Comments
 (0)