Add dtl_entry tracepoint
cover Add dtl_entry tracepoint
This is v1 of the patches for providing a tracepoint for processing the dispatch trace log entries from the hypervisor in a shared processor LPAR. The previous RFC can be found here:
https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=66340
Since the RFC, this series has been expanded/generalized to support !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE and has been tested in different configurations. The dispatch distance calculation has also been updated to use the platform provided information better.
Also, patch 3 is new and fixes an issue with stolen time accounting when the dtl debugfs interface is in use.
- Naveen
Naveen N. Rao (5):
powerpc/pseries: Use macros for referring to the DTL enable mask powerpc/pseries: Do not save the previous DTL mask value powerpc/pseries: Fix stolen time accounting when dtl debugfs is used powerpc/pseries: Factor out DTL buffer allocation and registration
routines
powerpc/pseries: Introduce dtl_entry tracepoint
arch/powerpc/include/asm/lppaca.h | 11 + arch/powerpc/include/asm/plpar_wrappers.h | 9 + arch/powerpc/include/asm/trace.h | 55 +++++ arch/powerpc/kernel/entry_64.S | 39 ++++ arch/powerpc/kernel/time.c | 7 +- arch/powerpc/mm/numa.c | 144 ++++++++++++- arch/powerpc/platforms/pseries/dtl.c | 22 +- arch/powerpc/platforms/pseries/lpar.c | 249 ++++++++++++++++++++-- arch/powerpc/platforms/pseries/setup.c | 34 +-- 9 files changed, 502 insertions(+), 68 deletions(-)
Signature · 1 line
2.19.1
PATCH 1/5 powerpc/pseries: Use macros for referring to the DTL enable mask
Introduce macros to encode the DTL enable mask fields and use those instead of hardcoding numbers.
--- arch/powerpc/include/asm/lppaca.h | 11 +++++++++++ arch/powerpc/platforms/pseries/dtl.c | 8 +------- arch/powerpc/platforms/pseries/lpar.c | 2 +- arch/powerpc/platforms/pseries/setup.c | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/lppaca.h +11 -0
@@ -154,6 +154,17 @@ struct dtl_entry {#define DISPATCH_LOG_BYTES 4096/* bytes per cpu */ #define N_DISPATCH_LOG (DISPATCH_LOG_BYTES / sizeof(struct dtl_entry)) +/* +* Dispatch trace log event enable mask: +* 0x1: voluntary virtual processor waits +* 0x2: time-slice preempts +* 0x4: virtual partition memory page faults +*/ +#define DTL_LOG_CEDE 0x1 +#define DTL_LOG_PREEMPT 0x2 +#define DTL_LOG_FAULT 0x4 +#define DTL_LOG_ALL (DTL_LOG_CEDE | DTL_LOG_PREEMPT | DTL_LOG_FAULT) +extern struct kmem_cache *dtl_cache;/*
arch/powerpc/platforms/pseries/dtl.c +1 -7
@@ -40,13 +40,7 @@ struct dtl { }; static DEFINE_PER_CPU(struct dtl, cpu_dtl); -/* -* Dispatch trace log event mask: -* 0x7: 0x1: voluntary virtual processor waits -* 0x2: time-slice preempts -* 0x4: virtual partition memory page faults -*/ -static u8 dtl_event_mask =0x7 ; +static u8 dtl_event_mask =DTL_LOG_ALL ;/*
arch/powerpc/platforms/pseries/lpar.c +1 -1
@@ -125,7 +125,7 @@ void vpa_init(int cpu)pr_err ("WARNING: DTL registration of cpu %d (hw %d) " "failed with %ld\n" ,smp_processor_id (), hwcpu, ret); -lppaca_of (cpu).dtl_enable_mask =2 ; +lppaca_of (cpu).dtl_enable_mask =DTL_LOG_PREEMPT ; } }
arch/powerpc/platforms/pseries/setup.c +1 -1
@@ -306,7 +306,7 @@ static int alloc_dispatch_logs(void)pr_err ("WARNING: DTL registration of cpu %d (hw %d) failed " "with %d\n" ,smp_processor_id (),hard_smp_processor_id (), ret); -get_paca ()->lppaca_ptr->dtl_enable_mask =2 ; +get_paca ()->lppaca_ptr->dtl_enable_mask =DTL_LOG_PREEMPT ;return 0 ; }
Signature · 1 line
2.19.1
PATCH 2/5 powerpc/pseries: Do not save the previous DTL mask value
In reply to Naveen N. RaoWhen CONFIG_VIRT_CPU_ACCOUNTING_NATIVE is enabled, we always initialize DTL enable mask to DTL_LOG_PREEMPT (0x2). There are no other places where the mask is changed. As such, when reading the DTL log buffer through debugfs, there is no need to save and restore the previous mask value.
We don't need to save and restore the earlier mask value if CONFIG_VIRT_CPU_ACCOUNTING_NATIVE is not enabled. So, remove the field from the structure as well.
--- arch/powerpc/platforms/pseries/dtl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/powerpc/platforms/pseries/dtl.c +1 -3
@@ -55,7 +55,6 @@ struct dtl_ring {struct dtl_entry *write_ptr;struct dtl_entry *buf;struct dtl_entry *buf_end; -u8 saved_dtl_mask; }; static DEFINE_PER_CPU(struct dtl_ring, dtl_rings);
@@ -105,7 +104,6 @@ static int dtl_start(struct dtl *dtl) dtlr->write_ptr = dtl->buf;/* enable event logging */ - dtlr->saved_dtl_mask =lppaca_of (dtl->cpu).dtl_enable_mask;lppaca_of (dtl->cpu).dtl_enable_mask |= dtl_event_mask; dtl_consumer = consume_dtle;
@@ -123,7 +121,7 @@ static void dtl_stop(struct dtl *dtl) dtlr->buf =NULL ;/* restore dtl_enable_mask */ -lppaca_of (dtl->cpu).dtl_enable_mask = dtlr->saved_dtl_mask; +lppaca_of (dtl->cpu).dtl_enable_mask =DTL_LOG_PREEMPT ;if (atomic_dec_and_test (&dtl_count)) dtl_consumer =NULL ;
Signature · 1 line
2.19.1
PATCH 3/5 powerpc/pseries: Fix stolen time accounting when dtl debugfs is used
In reply to Naveen N. RaoWhen the dtl debugfs interface is used, we usually set the dtl_enable_mask to 0x7 (DTL_LOG_ALL). When this happens, we start seeing DTL entries for all preempt reasons, including CEDE. In scan_dispatch_log(), we add up the times from all entries and account those towards stolen time. However, we should only be accounting stolen time when the preemption was due to HDEC at the end of our time slice.
Fix this by checking for the dispatch reason in the DTL entry before adding to the stolen time.
--- arch/powerpc/kernel/time.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/kernel/time.c +5 -2
@@ -199,7 +199,7 @@ static u64 scan_dispatch_log(u64 stop_tb)struct lppaca *vpa = local_paca->lppaca_ptr;u64 tb_delta;u64 stolen =0 ; -u64 dtb; +u64 dtb, dispatch_reason;if (!dtl)return 0 ;
@@ -210,6 +210,7 @@ static u64 scan_dispatch_log(u64 stop_tb) dtb =be64_to_cpu (dtl->timebase); tb_delta =be32_to_cpu (dtl->enqueue_to_dispatch_time) +be32_to_cpu (dtl->ready_to_enqueue_time); + dispatch_reason = dtl->dispatch_reason;barrier ();if (i +N_DISPATCH_LOG <be64_to_cpu (vpa->dtl_idx)) {/* buffer has overflowed */
@@ -221,7 +222,9 @@ static u64 scan_dispatch_log(u64 stop_tb)break ;if (dtl_consumer)dtl_consumer (dtl, i); - stolen += tb_delta; +/* 7 indicates that this dispatch follows a time slice preempt */ +if (dispatch_reason ==7 ) + stolen += tb_delta; ++i; ++dtl;if (dtl == dtl_end)
Signature · 1 line
2.19.1
PATCH 4/5 powerpc/pseries: Factor out DTL buffer allocation and registration routines
In reply to Naveen N. RaoIntroduce new helpers for DTL buffer allocation and registration and have the existing code use those.
--- arch/powerpc/include/asm/plpar_wrappers.h | 2 + arch/powerpc/platforms/pseries/lpar.c | 66 ++++++++++++++++------- arch/powerpc/platforms/pseries/setup.c | 34 +----------- 3 files changed, 52 insertions(+), 50 deletions(-)
arch/powerpc/include/asm/plpar_wrappers.h +2 -0
@@ -88,6 +88,8 @@ static inline long register_dtl(unsigned long cpu, unsigned long vpa)return vpa_call (H_VPA_REG_DTL , cpu, vpa); } +extern void alloc_dtl_buffers (void ); +extern void register_dtl_buffer (int cpu);extern void vpa_init (int cpu); static inline long plpar_pte_enter(unsigned long flags,
arch/powerpc/platforms/pseries/lpar.c +48 -18
83 lines not on this page · raw message
arch/powerpc/platforms/pseries/setup.c +2 -32
@@ -267,46 +267,16 @@ struct kmem_cache *dtl_cache;*/ static int alloc_dispatch_logs (void ) { -int cpu, ret; -struct paca_struct *pp; -struct dtl_entry *dtl; -if (!firmware_has_feature (FW_FEATURE_SPLPAR ))return 0 ;if (!dtl_cache)return 0 ; -for_each_possible_cpu (cpu) { - pp = paca_ptrs[cpu]; - dtl =kmem_cache_alloc (dtl_cache,GFP_KERNEL ); -if (!dtl) { -pr_warn ("Failed to allocate dispatch trace log for cpu %d\n" , - cpu); -pr_warn ("Stolen time statistics will be unreliable\n" ); -break ; - } - - pp->dtl_ridx =0 ; - pp->dispatch_log = dtl; - pp->dispatch_log_end = dtl +N_DISPATCH_LOG ; - pp->dtl_curr = dtl; - } +alloc_dtl_buffers ();/* Register the DTL for the current (boot) cpu */ - dtl =get_paca ()->dispatch_log; -get_paca ()->dtl_ridx =0 ; -get_paca ()->dtl_curr = dtl; -get_paca ()->lppaca_ptr->dtl_idx =0 ; - -/* hypervisor reads buffer length from this field */ - dtl->enqueue_to_dispatch_time =cpu_to_be32 (DISPATCH_LOG_BYTES ); - ret =register_dtl (hard_smp_processor_id (),__pa (dtl)); -if (ret) -pr_err ("WARNING: DTL registration of cpu %d (hw %d) failed " -"with %d\n" ,smp_processor_id (), -hard_smp_processor_id (), ret); -get_paca ()->lppaca_ptr->dtl_enable_mask =DTL_LOG_PREEMPT ; +register_dtl_buffer (smp_processor_id ());return 0 ; }
Signature · 1 line
2.19.1
PATCH 5/5 powerpc/pseries: Introduce dtl_entry tracepoint
In reply to Naveen N. RaoThis tracepoint provides access to the fields of each DTL entry in the Dispatch Trace Log buffer. Since the buffer is populated by the hypervisor and since we allocate just a 4k area per cpu for the buffer, we need to process the entries on a regular basis before they are overwritten by the hypervisor. We do this by using a static branch (or a reference counter if we don't have jump labels) in ret_from_except similar to how the hcall/opal tracepoints do.
Apart from making the DTL entries available for processing through the usual trace interface, this tracepoint also adds a new field 'distance' to each DTL entry, enabling enhanced statistics around the vcpu dispatch behavior of the hypervisor.
For Shared Processor LPARs, the POWER Hypervisor maintains a relatively static mapping of LPAR vcpus to physical processor cores and tries to always dispatch vcpus on their associated physical processor core. The LPAR can discover this through the H_VPHN(flags=1) hcall to obtain the associativity of the LPAR vcpus.
However, under certain scenarios, vcpus may be dispatched on a different processor core. The actual physical processor number on which a certain vcpu is dispatched is available to the LPAR in the 'processor_id' field of each DTL entry. The LPAR can then discover the associativity of that physical processor through the H_VPHN(flags=2) hcall. This can then be compared to the home node associativity for that specific vcpu to determine if the vcpu was dispatched on the same core or not. If the vcpu was not dispatched on the home node, it is possible to determine if the vcpu was dispatched in a different chip, socket or drawer.
The tracepoint field 'distance' encodes this information. If distance is 0, then the vcpu was dispatched on its home node/chip. If not, increasing values of 'distance' indicate a dispatch on a different chip in a MCM, different socket or a different drawer.
In terms of the implementation, we update our numa code to retain the vcpu associativity that is retrieved while discovering our numa topology. In addition, on tracepoint registration, we discover the physical cpu associativity. This information is only retrieved during the tracepoint registration and is not expected to change for the duration of the trace.
To support configurations with/without CONFIG_VIRT_CPU_ACCOUNTING_NATIVE selected, we generalize and extend helpers for DTL buffer allocation, freeing and registration. We also introduce a global variable 'dtl_mask' to encode the DTL enable mask to be set for all cpus. This helps ensure that cpus that come online honor the global enable mask.
Finally, to ensure that the new dtl_entry tracepoint usage does not interfere with the dtl debugfs interface, we introduce helpers to ensure only one of the two interfaces are used at any point in time.
--- arch/powerpc/include/asm/plpar_wrappers.h | 7 + arch/powerpc/include/asm/trace.h | 55 +++++++ arch/powerpc/kernel/entry_64.S | 39 +++++ arch/powerpc/mm/numa.c | 144 ++++++++++++++++- arch/powerpc/platforms/pseries/dtl.c | 10 +- arch/powerpc/platforms/pseries/lpar.c | 187 +++++++++++++++++++++- 6 files changed, 434 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/plpar_wrappers.h +7 -0
@@ -88,7 +88,14 @@ static inline long register_dtl(unsigned long cpu, unsigned long vpa)return vpa_call (H_VPA_REG_DTL , cpu, vpa); } +extern void dtl_entry_tracepoint_enable (void ); +extern void dtl_entry_tracepoint_disable (void ); +extern int register_dtl_buffer_access (int global); +extern void unregister_dtl_buffer_access (int global); +extern void set_dtl_mask (u8 mask); +extern void reset_dtl_mask (void );extern void alloc_dtl_buffers (void ); +extern void free_dtl_buffers (void );extern void register_dtl_buffer (int cpu);extern void vpa_init (int cpu);
arch/powerpc/include/asm/trace.h +55 -0
61 lines not on this page · raw message
arch/powerpc/kernel/entry_64.S +39 -0
@@ -46,6 +46,7 @@ #include <asm/exception-64e.h> #endif #include <asm/feature-fixups.h> +#include <linux/jump_label.h> /* * System calls.
@@ -714,6 +715,38 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) addi r1,r1,SWITCH_FRAME_SIZE blr +#if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_PPC_SPLPAR) +#ifdef HAVE_JUMP_LABEL +#define TRACE_DTL_ENTRY_BRANCH(LABEL) \ + ARCH_STATIC_BRANCH(LABEL, dtl_entry_tracepoint_key) +#else + + .pushsection ".toc","aw" + .globl dtl_entry_tracepoint_refcount +dtl_entry_tracepoint_refcount: + .8byte 0 + .popsection + +/* + * We branch around this in early init (eg when populating the MMU + * hashtable) by using an unconditional cpu feature. + */ +#define TRACE_DTL_ENTRY_BRANCH(LABEL) \ +BEGIN_FTR_SECTION; \ + b 1f; \ +END_FTR_SECTION(0, 1); \ + ld r12,dtl_entry_tracepoint_refcount@toc(r2); \ + cmpdi r12,0; \ + bne- LABEL; \ +1: +#endif + +do_trace_dtl_entry: + bl __trace_dtl_entry + b .Lpost_trace_dtl_entry +_ASM_NOKPROBE_SYMBOL(do_trace_dtl_entry); +#endif + .align 7 _GLOBAL(ret_from_except) ld r11,_TRAP(r1)
@@ -734,6 +767,11 @@ _GLOBAL(ret_from_except_lite) mtmsrd r10,1 /* Update machine state */ #endif /* CONFIG_PPC_BOOK3E */ +#if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_PPC_SPLPAR) + TRACE_DTL_ENTRY_BRANCH(do_trace_dtl_entry) +.Lpost_trace_dtl_entry: +#endif + CURRENT_THREAD_INFO(r9, r1) ld r3,_MSR(r1) #ifdef CONFIG_PPC_BOOK3E
@@ -768,6 +806,7 @@ _GLOBAL(ret_from_except_lite) bl restore_math b restore #endif + 1: andi. r0,r4,_TIF_NEED_RESCHED beq 2f bl restore_interrupts
arch/powerpc/mm/numa.c +139 -5
183 lines not on this page · raw message
arch/powerpc/platforms/pseries/dtl.c +9 -1
@@ -193,11 +193,15 @@ static int dtl_enable(struct dtl *dtl)if (dtl->buf)return -EBUSY ; +if (register_dtl_buffer_access (0 )) +return -EBUSY ; + n_entries = dtl_buf_entries; buf =kmem_cache_alloc_node (dtl_cache,GFP_KERNEL ,cpu_to_node (dtl->cpu));if (!buf) {printk (KERN_WARNING "%s: buffer alloc failed for cpu %d\n" , __func__, dtl->cpu); +unregister_dtl_buffer_access (0 );return -ENOMEM ; }
@@ -214,8 +218,11 @@ static int dtl_enable(struct dtl *dtl) }spin_unlock (&dtl->lock); -if (rc) +if (rc) { +unregister_dtl_buffer_access (0 );kmem_cache_free (dtl_cache, buf); + } +return rc; }
@@ -227,6 +234,7 @@ static void dtl_disable(struct dtl *dtl) dtl->buf =NULL ; dtl->buf_entries =0 ;spin_unlock (&dtl->lock); +unregister_dtl_buffer_access (0 ); }/* file interface */
arch/powerpc/platforms/pseries/lpar.c +185 -2
228 lines not on this page · raw message
Signature · 1 line
2.19.1
Re: [PATCH v1 3/5] powerpc/pseries: Fix stolen time accounting when dtl debugfs is used
In reply to Naveen N. RaoQuoted 6 lines · Naveen N. Rao
When the dtl debugfs interface is used, we usually set the
dtl_enable_maskto0x7(DTL_LOG_ALL). When this happens, we start seeing DTL entries for all preempt reasons, including CEDE. Inscan_dispatch_log(), we add up the times from all entries and account those towards stolen time. However, we should only be accounting stolen time when the preemption was due to HDEC at the end of our time slice.
It's always been the case that stolen time when idle has been accounted as idle time, not stolen time. That's why we didn't check for this in the past.
Do you have a test that shows different results (as in reported idle and stolen times) with this patch compared to without?
Paul.
Re: [PATCH v1 3/5] powerpc/pseries: Fix stolen time accounting when dtl debugfs is used
Quoted 8 lines · Paul Mackerras
Quoted 6 lines · Naveen N. Rao
When the dtl debugfs interface is used, we usually set the
dtl_enable_maskto0x7(DTL_LOG_ALL). When this happens, we start seeing DTL entries for all preempt reasons, including CEDE. Inscan_dispatch_log(), we add up the times from all entries and account those towards stolen time. However, we should only be accounting stolen time when the preemption was due to HDEC at the end of our time slice.
Quoted 6 lines
It's always been the case that stolen time when idle has been accounted as idle time, not stolen time. That's why we didn't check for this in the past.
Do you have a test that shows different results (as in reported idle and stolen times) with this patch compared to without?
Ah ok, that makes sense now and explains why I couldn't observe much of a difference in practice. However, I also went by the fact that there are 7 other preemption reasons, which could impact our calculation. Looking at the list again, it looks like H_CONFER/H_PROD and some faults can also have an impact here, though they may be rare?
Thanks,
Naveen