2222
2323#include "op_x86_model.h"
2424#include "op_counter.h"
25+ #include "../../../drivers/oprofile/cpu_buffer.h"
2526
2627#define NUM_COUNTERS 4
2728#define NUM_CONTROLS 4
@@ -60,51 +61,16 @@ static unsigned long reset_value[NUM_COUNTERS];
6061#define IBS_OP_LOW_VALID_BIT (1ULL<<18) /* bit 18 */
6162#define IBS_OP_LOW_ENABLE (1ULL<<17) /* bit 17 */
6263
63- /* Codes used in cpu_buffer.c */
64- /* This produces duplicate code, need to be fixed */
65- #define IBS_FETCH_BEGIN (1UL << 4)
66- #define IBS_OP_BEGIN (1UL << 5)
67-
6864/*
6965 * The function interface needs to be fixed, something like add
7066 * data. Should then be added to linux/oprofile.h.
7167 */
72- extern void
73- oprofile_add_ibs_sample (struct pt_regs * const regs ,
74- unsigned int * const ibs_sample , int ibs_code );
75-
76- struct ibs_fetch_sample {
77- /* MSRC001_1031 IBS Fetch Linear Address Register */
78- unsigned int ibs_fetch_lin_addr_low ;
79- unsigned int ibs_fetch_lin_addr_high ;
80- /* MSRC001_1030 IBS Fetch Control Register */
81- unsigned int ibs_fetch_ctl_low ;
82- unsigned int ibs_fetch_ctl_high ;
83- /* MSRC001_1032 IBS Fetch Physical Address Register */
84- unsigned int ibs_fetch_phys_addr_low ;
85- unsigned int ibs_fetch_phys_addr_high ;
86- };
68+ extern
69+ void oprofile_add_data (struct op_entry * entry , struct pt_regs * const regs ,
70+ unsigned long pc , int code , int size );
8771
88- struct ibs_op_sample {
89- /* MSRC001_1034 IBS Op Logical Address Register (IbsRIP) */
90- unsigned int ibs_op_rip_low ;
91- unsigned int ibs_op_rip_high ;
92- /* MSRC001_1035 IBS Op Data Register */
93- unsigned int ibs_op_data1_low ;
94- unsigned int ibs_op_data1_high ;
95- /* MSRC001_1036 IBS Op Data 2 Register */
96- unsigned int ibs_op_data2_low ;
97- unsigned int ibs_op_data2_high ;
98- /* MSRC001_1037 IBS Op Data 3 Register */
99- unsigned int ibs_op_data3_low ;
100- unsigned int ibs_op_data3_high ;
101- /* MSRC001_1038 IBS DC Linear Address Register (IbsDcLinAd) */
102- unsigned int ibs_dc_linear_low ;
103- unsigned int ibs_dc_linear_high ;
104- /* MSRC001_1039 IBS DC Physical Address Register (IbsDcPhysAd) */
105- unsigned int ibs_dc_phys_low ;
106- unsigned int ibs_dc_phys_high ;
107- };
72+ #define IBS_FETCH_SIZE 6
73+ #define IBS_OP_SIZE 12
10874
10975static int has_ibs ; /* AMD Family10h and later */
11076
@@ -197,31 +163,29 @@ static inline int
197163op_amd_handle_ibs (struct pt_regs * const regs ,
198164 struct op_msrs const * const msrs )
199165{
200- unsigned int low , high ;
201- struct ibs_fetch_sample ibs_fetch ;
202- struct ibs_op_sample ibs_op ;
166+ u32 low , high ;
167+ u64 msr ;
168+ struct op_entry entry ;
203169
204170 if (!has_ibs )
205171 return 1 ;
206172
207173 if (ibs_config .fetch_enabled ) {
208174 rdmsr (MSR_AMD64_IBSFETCHCTL , low , high );
209175 if (high & IBS_FETCH_HIGH_VALID_BIT ) {
210- ibs_fetch .ibs_fetch_ctl_high = high ;
211- ibs_fetch .ibs_fetch_ctl_low = low ;
212- rdmsr (MSR_AMD64_IBSFETCHLINAD , low , high );
213- ibs_fetch .ibs_fetch_lin_addr_high = high ;
214- ibs_fetch .ibs_fetch_lin_addr_low = low ;
215- rdmsr (MSR_AMD64_IBSFETCHPHYSAD , low , high );
216- ibs_fetch .ibs_fetch_phys_addr_high = high ;
217- ibs_fetch .ibs_fetch_phys_addr_low = low ;
218-
219- oprofile_add_ibs_sample (regs ,
220- (unsigned int * )& ibs_fetch ,
221- IBS_FETCH_BEGIN );
176+ rdmsrl (MSR_AMD64_IBSFETCHLINAD , msr );
177+ oprofile_add_data (& entry , regs , msr , IBS_FETCH_CODE ,
178+ IBS_FETCH_SIZE );
179+ op_cpu_buffer_add_data (& entry , (u32 )msr );
180+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
181+ op_cpu_buffer_add_data (& entry , low );
182+ op_cpu_buffer_add_data (& entry , high );
183+ rdmsrl (MSR_AMD64_IBSFETCHPHYSAD , msr );
184+ op_cpu_buffer_add_data (& entry , (u32 )msr );
185+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
186+ op_cpu_buffer_write_commit (& entry );
222187
223188 /* reenable the IRQ */
224- rdmsr (MSR_AMD64_IBSFETCHCTL , low , high );
225189 high &= ~IBS_FETCH_HIGH_VALID_BIT ;
226190 high |= IBS_FETCH_HIGH_ENABLE ;
227191 low &= IBS_FETCH_LOW_MAX_CNT_MASK ;
@@ -232,30 +196,29 @@ op_amd_handle_ibs(struct pt_regs * const regs,
232196 if (ibs_config .op_enabled ) {
233197 rdmsr (MSR_AMD64_IBSOPCTL , low , high );
234198 if (low & IBS_OP_LOW_VALID_BIT ) {
235- rdmsr (MSR_AMD64_IBSOPRIP , low , high );
236- ibs_op .ibs_op_rip_low = low ;
237- ibs_op .ibs_op_rip_high = high ;
238- rdmsr (MSR_AMD64_IBSOPDATA , low , high );
239- ibs_op .ibs_op_data1_low = low ;
240- ibs_op .ibs_op_data1_high = high ;
241- rdmsr (MSR_AMD64_IBSOPDATA2 , low , high );
242- ibs_op .ibs_op_data2_low = low ;
243- ibs_op .ibs_op_data2_high = high ;
244- rdmsr (MSR_AMD64_IBSOPDATA3 , low , high );
245- ibs_op .ibs_op_data3_low = low ;
246- ibs_op .ibs_op_data3_high = high ;
247- rdmsr (MSR_AMD64_IBSDCLINAD , low , high );
248- ibs_op .ibs_dc_linear_low = low ;
249- ibs_op .ibs_dc_linear_high = high ;
250- rdmsr (MSR_AMD64_IBSDCPHYSAD , low , high );
251- ibs_op .ibs_dc_phys_low = low ;
252- ibs_op .ibs_dc_phys_high = high ;
199+ rdmsrl (MSR_AMD64_IBSOPRIP , msr );
200+ oprofile_add_data (& entry , regs , msr , IBS_OP_CODE ,
201+ IBS_OP_SIZE );
202+ op_cpu_buffer_add_data (& entry , (u32 )msr );
203+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
204+ rdmsrl (MSR_AMD64_IBSOPDATA , msr );
205+ op_cpu_buffer_add_data (& entry , (u32 )msr );
206+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
207+ rdmsrl (MSR_AMD64_IBSOPDATA2 , msr );
208+ op_cpu_buffer_add_data (& entry , (u32 )msr );
209+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
210+ rdmsrl (MSR_AMD64_IBSOPDATA3 , msr );
211+ op_cpu_buffer_add_data (& entry , (u32 )msr );
212+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
213+ rdmsrl (MSR_AMD64_IBSDCLINAD , msr );
214+ op_cpu_buffer_add_data (& entry , (u32 )msr );
215+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
216+ rdmsrl (MSR_AMD64_IBSDCPHYSAD , msr );
217+ op_cpu_buffer_add_data (& entry , (u32 )msr );
218+ op_cpu_buffer_add_data (& entry , (u32 )(msr >> 32 ));
219+ op_cpu_buffer_write_commit (& entry );
253220
254221 /* reenable the IRQ */
255- oprofile_add_ibs_sample (regs ,
256- (unsigned int * )& ibs_op ,
257- IBS_OP_BEGIN );
258- rdmsr (MSR_AMD64_IBSOPCTL , low , high );
259222 high = 0 ;
260223 low &= ~IBS_OP_LOW_VALID_BIT ;
261224 low |= IBS_OP_LOW_ENABLE ;
0 commit comments