1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
/*COPYRIGHT**
Copyright (C) 2005-2014 Intel Corporation. All Rights Reserved.
This file is part of SEP Development Kit
SEP Development Kit is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
SEP Development Kit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SEP Development Kit; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
As a special exception, you may use this file as part of a free software
library without restriction. Specifically, if other files instantiate
templates or use macros or inline functions from this file, or you compile
this file and link it with other files to produce an executable, this
file does not by itself cause the resulting executable to be covered by
the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
**COPYRIGHT*/
#include "lwpmudrv_defines.h"
#include <linux/version.h>
#include <linux/percpu.h>
#include "lwpmudrv_types.h"
#include "rise_errors.h"
#include "lwpmudrv_ecb.h"
#include "lwpmudrv_struct.h"
#include "lwpmudrv.h"
#include "control.h"
#include "core2.h"
#include "utility.h"
#include "pebs.h"
static PEBS_DISPATCH pebs_dispatch = NULL;
static PVOID pebs_global_memory = NULL;
static size_t pebs_global_memory_size = 0;
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Corei7_Initialize_Threshold (dts, pebs_record_size)
*
* @brief The nehalem specific initialization
*
* @param NONE
*
* @return NONE
*
* <I>Special Notes:</I>
*/
static VOID
pebs_Corei7_Initialize_Threshold (
DTS_BUFFER_EXT dts,
U32 pebs_record_size
)
{
DTS_BUFFER_EXT_pebs_threshold(dts) = DTS_BUFFER_EXT_pebs_base(dts) + pebs_record_size;
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Corei7_Overflow ()
*
* @brief The Nehalem specific overflow check
*
* @param NONE
*
* @return NONE
*
* <I>Special Notes:</I>
* Check the global overflow field of the buffer descriptor.
* Precise events can be allocated on any of the 4 general purpose
* registers.
*/
static U64
pebs_Corei7_Overflow (
S32 this_cpu,
U64 overflow_status
)
{
DTS_BUFFER_EXT dtes = CPU_STATE_dts_buffer(&pcb[this_cpu]);
U8 status = FALSE;
PEBS_REC_EXT pebs_base;
if (!dtes) {
return overflow_status;
}
status = (U8)((dtes) && (DTS_BUFFER_EXT_pebs_index(dtes) != DTS_BUFFER_EXT_pebs_base(dtes)));
if (status) {
pebs_base = (PEBS_REC_EXT)(UIOP)DTS_BUFFER_EXT_pebs_base(dtes);
overflow_status |= PEBS_REC_EXT_glob_perf_overflow(pebs_base);
}
return overflow_status;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Core2_Initialize_Threshold (dts, pebs_record_size)
*
* @brief The Core2 specific initialization
*
* @param NONE
*
* @return NONE
*
* <I>Special Notes:</I>
*/
static VOID
pebs_Core2_Initialize_Threshold (
DTS_BUFFER_EXT dts,
U32 pebs_record_size
)
{
DTS_BUFFER_EXT_pebs_threshold(dts) = DTS_BUFFER_EXT_pebs_base(dts);
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Core2_Overflow (dts, pebs_record_size)
*
* @brief The Core2 specific overflow check
*
* @param NONE
*
* @return NONE
*
* <I>Special Notes:</I>
* Check the base and the index fields of the circular buffer, if they are
* not the same, then a precise event has overflowed. Precise events are
* allocated only on register#0.
*/
static U64
pebs_Core2_Overflow (
S32 this_cpu,
U64 overflow_status
)
{
DTS_BUFFER_EXT dtes = CPU_STATE_dts_buffer(&pcb[this_cpu]);
U8 status = FALSE;
if (!dtes) {
return overflow_status;
}
status = (U8)((dtes) && (DTS_BUFFER_EXT_pebs_index(dtes) != DTS_BUFFER_EXT_pebs_base(dtes)));
if (status) {
// Merom allows only for general purpose register 0 to be precise capable
overflow_status |= 0x1;
}
return overflow_status;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Modify_IP (sample, is_64bit_addr)
*
* @brief Change the IP field in the sample to that in the PEBS record
*
* @param sample - sample buffer
* @param is_64bit_addr - are we in a 64 bit module
*
* @return NONE
*
* <I>Special Notes:</I>
* <NONE>
*/
static VOID
pebs_Modify_IP (
void *sample,
DRV_BOOL is_64bit_addr
)
{
SampleRecordPC *psamp = sample;
DTS_BUFFER_EXT dtes = CPU_STATE_dts_buffer(&pcb[CONTROL_THIS_CPU()]);
if (dtes && psamp) {
S8 *pebs_base = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_base(dtes);
S8 *pebs_index = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_index(dtes);
SEP_PRINT_DEBUG("In PEBS Fill Buffer: cpu %d\n", CONTROL_THIS_CPU());
if (pebs_base != pebs_index) {
PEBS_REC_EXT pb = (PEBS_REC_EXT)pebs_base;
if (is_64bit_addr) {
SAMPLE_RECORD_iip(psamp) = PEBS_REC_EXT_linear_ip(pb);
SAMPLE_RECORD_ipsr(psamp) = PEBS_REC_EXT_r_flags(pb);
}
else {
SAMPLE_RECORD_eip(psamp) = PEBS_REC_EXT_linear_ip(pb) & 0xFFFFFFFF;
SAMPLE_RECORD_eflags(psamp) = PEBS_REC_EXT_r_flags(pb) & 0xFFFFFFFF;
}
}
}
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Modify_IP_With_Eventing_IP (sample, is_64bit_addr)
*
* @brief Change the IP field in the sample to that in the PEBS record
*
* @param sample - sample buffer
* @param is_64bit_addr - are we in a 64 bit module
*
* @return NONE
*
* <I>Special Notes:</I>
* <NONE>
*/
static VOID
pebs_Modify_IP_With_Eventing_IP (
void *sample,
DRV_BOOL is_64bit_addr
)
{
SampleRecordPC *psamp = sample;
DTS_BUFFER_EXT dtes = CPU_STATE_dts_buffer(&pcb[CONTROL_THIS_CPU()]);
if (dtes && psamp) {
S8 *pebs_base = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_base(dtes);
S8 *pebs_index = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_index(dtes);
SEP_PRINT_DEBUG("In PEBS Fill Buffer: cpu %d\n", CONTROL_THIS_CPU());
if (pebs_base != pebs_index) {
PEBS_REC_EXT1 pb = (PEBS_REC_EXT1)pebs_base;
if (is_64bit_addr) {
SAMPLE_RECORD_iip(psamp) = PEBS_REC_EXT1_eventing_ip(pb);
SAMPLE_RECORD_ipsr(psamp) = PEBS_REC_EXT1_r_flags(pb);
}
else {
SAMPLE_RECORD_eip(psamp) = PEBS_REC_EXT1_eventing_ip(pb) & 0xFFFFFFFF;
SAMPLE_RECORD_eflags(psamp) = PEBS_REC_EXT1_r_flags(pb) & 0xFFFFFFFF;
}
}
}
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Modify_TSC (sample)
*
* @brief Change the TSC field in the sample to that in the PEBS record
*
* @param sample - sample buffer
*
* @return NONE
*
* <I>Special Notes:</I>
* <NONE>
*/
static VOID
pebs_Modify_TSC (
void *sample
)
{
SampleRecordPC *psamp = sample;
DTS_BUFFER_EXT dtes = CPU_STATE_dts_buffer(&pcb[CONTROL_THIS_CPU()]);
S8 *pebs_base, *pebs_index;
PEBS_REC_EXT2 pb;
if (dtes && psamp) {
pebs_base = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_base(dtes);
pebs_index = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_index(dtes);
SEP_PRINT_DEBUG("In PEBS Fill Buffer: cpu %d\n", CONTROL_THIS_CPU());
if (pebs_base != pebs_index) {
pb = (PEBS_REC_EXT2)pebs_base;
SAMPLE_RECORD_tsc(psamp) = PEBS_REC_EXT2_tsc(pb);
}
}
return;
}
/*
* Initialize the pebs micro dispatch tables
*/
PEBS_DISPATCH_NODE core2_pebs =
{
pebs_Core2_Initialize_Threshold,
pebs_Core2_Overflow,
pebs_Modify_IP,
NULL
};
PEBS_DISPATCH_NODE core2p_pebs =
{
pebs_Corei7_Initialize_Threshold,
pebs_Core2_Overflow,
pebs_Modify_IP,
NULL
};
PEBS_DISPATCH_NODE corei7_pebs =
{
pebs_Corei7_Initialize_Threshold,
pebs_Corei7_Overflow,
pebs_Modify_IP,
NULL
};
PEBS_DISPATCH_NODE haswell_pebs =
{
pebs_Corei7_Initialize_Threshold,
pebs_Corei7_Overflow,
pebs_Modify_IP_With_Eventing_IP,
NULL
};
PEBS_DISPATCH_NODE perfver4_pebs =
{
pebs_Corei7_Initialize_Threshold,
pebs_Corei7_Overflow,
pebs_Modify_IP_With_Eventing_IP,
pebs_Modify_TSC
};
#define PER_CORE_BUFFER_SIZE(record_size) (sizeof(DTS_BUFFER_EXT_NODE) + 2 * (record_size) + 64)
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID* pebs_Alloc_DTS_Buffer (VOID)
*
* @brief Allocate buffers used for latency and pebs sampling
*
* @param NONE
*
* @return NONE
*
* <I>Special Notes:</I>
* Allocate the memory needed to hold the DTS and PEBS records buffer.
* This routine is called by a thread that corresponds to a single core
*/
static VOID*
pebs_Alloc_DTS_Buffer (
U32 pebs_record_size
)
{
UIOP pebs_base;
U32 buffer_size;
U32 dts_size;
VOID *dts_buffer;
DTS_BUFFER_EXT dts;
int this_cpu;
/*
* one PEBS record... need 2 records so that
* threshold can be less than absolute max
*/
preempt_disable();
this_cpu = CONTROL_THIS_CPU();
preempt_enable();
dts_size = sizeof(DTS_BUFFER_EXT_NODE);
/*
* account for extra bytes to align PEBS base to cache line boundary
*/
buffer_size = PER_CORE_BUFFER_SIZE(pebs_record_size);
dts_buffer = (char *)pebs_global_memory + (this_cpu * buffer_size);
if (!dts_buffer) {
SEP_PRINT_ERROR("Failed to allocate space for DTS buffer.\n");
return NULL;
}
pebs_base = (UIOP)(dts_buffer) + dts_size;
// Make 32 byte aligned
if ((pebs_base & 0x000001F) != 0x0) {
pebs_base = ALIGN_32(pebs_base);
}
/*
* Program the DTES Buffer for Precise EBS.
* Set PEBS buffer for one PEBS record
*/
dts = (DTS_BUFFER_EXT)dts_buffer;
DTS_BUFFER_EXT_base(dts) = 0;
DTS_BUFFER_EXT_index(dts) = 0;
DTS_BUFFER_EXT_max(dts) = 0;
DTS_BUFFER_EXT_threshold(dts) = 0;
DTS_BUFFER_EXT_pebs_base(dts) = pebs_base;
DTS_BUFFER_EXT_pebs_index(dts) = pebs_base;
DTS_BUFFER_EXT_pebs_max(dts) = pebs_base + 2 * pebs_record_size;
pebs_dispatch->initialize_threshold(dts, pebs_record_size);
SEP_PRINT_DEBUG("base --- %p\n", DTS_BUFFER_EXT_pebs_base(dts));
SEP_PRINT_DEBUG("index --- %p\n", DTS_BUFFER_EXT_pebs_index(dts));
SEP_PRINT_DEBUG("max --- %p\n", DTS_BUFFER_EXT_pebs_max(dts));
SEP_PRINT_DEBUG("threahold --- %p\n", DTS_BUFFER_EXT_pebs_threshold(dts));
SEP_PRINT_DEBUG("DTES buffer allocated for PEBS: %p\n", dts_buffer);
return dts_buffer;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID* pebs_Allocate_Buffers (VOID *params)
*
* @brief Allocate memory and set up MSRs in preparation for PEBS
*
* @param NONE
*
* @return NONE
*
* <I>Special Notes:</I>
* Set up the DS area and program the DS_AREA msrs in preparation
* for a PEBS run. Save away the old value in the DS_AREA.
* This routine is called via the parallel thread call.
*/
static VOID
pebs_Allocate_Buffers (
VOID *params
)
{
U64 value;
CPU_STATE pcpu = &pcb[CONTROL_THIS_CPU()];
U32 pebs_record_size;
pebs_record_size = *((U32*)(params));
SYS_Write_MSR(IA32_PEBS_ENABLE, 0LL);
value = SYS_Read_MSR(IA32_MISC_ENABLE);
if ((value & 0x80) && !(value & 0x1000)) {
CPU_STATE_old_dts_buffer(pcpu) = (PVOID)(UIOP)SYS_Read_MSR(IA32_DS_AREA);
CPU_STATE_dts_buffer(pcpu) = pebs_Alloc_DTS_Buffer(pebs_record_size);
SEP_PRINT_DEBUG("Old dts buffer - %p\n", CPU_STATE_old_dts_buffer(pcpu));
SEP_PRINT_DEBUG("New dts buffer - %p\n", CPU_STATE_dts_buffer(pcpu));
SYS_Write_MSR(IA32_DS_AREA, (U64)(UIOP)CPU_STATE_dts_buffer(pcpu));
}
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID pebs_Dellocate_Buffers (VOID *params)
*
* @brief Clean up PEBS buffers and restore older values into the DS_AREA
*
* @param NONE
*
* @return NONE
*
* <I>Special Notes:</I>
* Clean up the DS area and all restore state prior to the sampling run
* This routine is called via the parallel thread call.
*/
static VOID
pebs_Deallocate_Buffers (
VOID *params
)
{
CPU_STATE pcpu = &pcb[CONTROL_THIS_CPU()];
SEP_PRINT_DEBUG("Entered deallocate buffers\n");
SYS_Write_MSR(IA32_DS_AREA, (U64)(UIOP)CPU_STATE_old_dts_buffer(pcpu));
CPU_STATE_dts_buffer(pcpu) = NULL;
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn U64 PEBS_Overflowed (this_cpu, overflow_status)
*
* @brief Figure out if the PEBS event caused an overflow
*
* @param this_cpu -- the current cpu
* overflow_status -- current value of the global overflow status
*
* @return updated overflow_status
*
* <I>Special Notes:</I>
* Figure out if the PEBS area has data that need to be transferred
* to the output sample.
* Update the overflow_status that is passed and return this value.
* The overflow_status defines the events/status to be read
*/
extern U64
PEBS_Overflowed (
S32 this_cpu,
U64 overflow_status
)
{
return pebs_dispatch->overflow(this_cpu, overflow_status);
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID PEBS_Reset_Index (this_cpu)
*
* @brief Reset the PEBS index pointer
*
* @param this_cpu -- the current cpu
*
* @return NONE
*
* <I>Special Notes:</I>
* reset index to next PEBS record to base of buffer
*/
extern VOID
PEBS_Reset_Index (
S32 this_cpu
)
{
DTS_BUFFER_EXT dtes = CPU_STATE_dts_buffer(&pcb[this_cpu]);
if (dtes) {
SEP_PRINT_DEBUG("PEBS Reset Index: %d\n", this_cpu);
DTS_BUFFER_EXT_pebs_index(dtes) = DTS_BUFFER_EXT_pebs_base(dtes);
}
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID PEBS_Modify_IP (sample, is_64bit_addr)
*
* @brief Change the IP field in the sample to that in the PEBS record
*
* @param sample - sample buffer
* @param is_64bit_addr - are we in a 64 bit module
*
* @return NONE
*
* <I>Special Notes:</I>
* <NONE>
*/
extern VOID
PEBS_Modify_IP (
void *sample,
DRV_BOOL is_64bit_addr
)
{
pebs_dispatch->modify_ip(sample, is_64bit_addr);
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID PEBS_Modify_TSC (sample)
*
* @brief Change the TSC field in the sample to that in the PEBS record
*
* @param sample - sample buffer
*
* @return NONE
*
* <I>Special Notes:</I>
* <NONE>
*/
extern VOID
PEBS_Modify_TSC (
void *sample
)
{
if (pebs_dispatch->modify_tsc != NULL) {
pebs_dispatch->modify_tsc(sample);
}
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID PEBS_Fill_Buffer (S8 *buffer, EVENT_CONFIG ec)
*
* @brief Fill the buffer with the pebs data
*
* @param buffer - area to write the data into
* ec - current event config
*
* @return NONE
*
* <I>Special Notes:</I>
* <NONE>
*/
extern VOID
PEBS_Fill_Buffer (
S8 *buffer,
EVENT_DESC evt_desc,
DRV_BOOL virt_phys_translation_ena
)
{
DTS_BUFFER_EXT dtes = CPU_STATE_dts_buffer(&pcb[CONTROL_THIS_CPU()]);
DEAR_INFO_NODE dear_info = {0};
PEBS_REC_EXT1 pebs_base_ext1;
PEBS_REC_EXT2 pebs_base_ext2;
if (dtes) {
S8 *pebs_base = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_base(dtes);
S8 *pebs_index = (S8 *)(UIOP)DTS_BUFFER_EXT_pebs_index(dtes);
SEP_PRINT_DEBUG("In PEBS Fill Buffer: cpu %d\n", CONTROL_THIS_CPU());
if (pebs_base != pebs_index){
if (EVENT_DESC_pebs_offset(evt_desc)) {
SEP_PRINT_DEBUG("PEBS buffer has data available\n");
memcpy(buffer + EVENT_DESC_pebs_offset(evt_desc),
pebs_base,
EVENT_DESC_pebs_size(evt_desc));
}
if (EVENT_DESC_eventing_ip_offset(evt_desc)) {
pebs_base_ext1 = (PEBS_REC_EXT1)pebs_base;
*(U64*)(buffer + EVENT_DESC_eventing_ip_offset(evt_desc)) = PEBS_REC_EXT1_eventing_ip(pebs_base_ext1);
}
if (EVENT_DESC_hle_offset(evt_desc)) {
pebs_base_ext1 = (PEBS_REC_EXT1)pebs_base;
*(U64*)(buffer + EVENT_DESC_hle_offset(evt_desc)) = PEBS_REC_EXT1_hle_info(pebs_base_ext1);
}
if (EVENT_DESC_latency_offset_in_sample(evt_desc)) {
memcpy(&dear_info,
pebs_base + EVENT_DESC_latency_offset_in_pebs_record(evt_desc),
EVENT_DESC_latency_size_from_pebs_record(evt_desc));
DEAR_INFO_nodeid(&dear_info) = 0xFFFF;
memcpy(buffer + EVENT_DESC_latency_offset_in_sample(evt_desc),
&dear_info,
sizeof(DEAR_INFO_NODE) );
}
if (EVENT_DESC_pebs_tsc_offset(evt_desc)) {
pebs_base_ext2 = (PEBS_REC_EXT2)pebs_base;
*(U64*)(buffer + EVENT_DESC_pebs_tsc_offset(evt_desc)) = PEBS_REC_EXT2_tsc(pebs_base_ext2);
}
}
}
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID PEBS_Initialize (DRV_CONFIG pcfg)
*
* @brief Initialize the pebs buffers
*
* @param pcfg - Driver Configuration
*
* @return NONE
*
* <I>Special Notes:</I>
* If the user is asking for PEBS information. Allocate the DS area
*/
extern VOID
PEBS_Initialize (
DRV_CONFIG pcfg
)
{
U32 pebs_record_size =0;
if (DRV_CONFIG_pebs_mode(pcfg)) {
switch (DRV_CONFIG_pebs_mode(pcfg)) {
case 1:
SEP_PRINT_DEBUG("Set up the Core2 dispatch table\n");
pebs_dispatch = &core2_pebs;
pebs_record_size = sizeof(PEBS_REC_NODE);
break;
case 2:
SEP_PRINT_DEBUG("Set up the Nehalem dispatch\n");
pebs_dispatch = &corei7_pebs;
pebs_record_size = sizeof(PEBS_REC_EXT_NODE);
break;
case 3:
SEP_PRINT_DEBUG("Set up the Core2 (PNR) dispatch table\n");
pebs_dispatch = &core2p_pebs;
pebs_record_size = sizeof(PEBS_REC_NODE);
break;
case 4:
SEP_PRINT_DEBUG("Set up the Haswell dispatch table\n");
pebs_dispatch = &haswell_pebs;
pebs_record_size = sizeof(PEBS_REC_EXT1_NODE);
break;
case 5:
SEP_PRINT_DEBUG("Set up the Perf version4 dispatch table\n");
pebs_dispatch = &perfver4_pebs;
pebs_record_size = sizeof(PEBS_REC_EXT2_NODE);
break;
default:
SEP_PRINT_DEBUG("Unknown PEBS type. Will not collect PEBS information\n");
break;
}
if (pebs_dispatch) {
pebs_global_memory_size = GLOBAL_STATE_num_cpus(driver_state) * PER_CORE_BUFFER_SIZE(pebs_record_size);
pebs_global_memory = (PVOID)CONTROL_Allocate_KMemory(pebs_global_memory_size);
CONTROL_Invoke_Parallel(pebs_Allocate_Buffers, (VOID *)&pebs_record_size);
}
}
return;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID PEBS_Destroy (DRV_CONFIG pcfg)
*
* @brief Clean up the pebs related buffers
*
* @param pcfg - Driver Configuration
*
* @return NONE
*
* <I>Special Notes:</I>
* Deallocated the DS area used for PEBS capture
*/
extern VOID
PEBS_Destroy (
DRV_CONFIG pcfg
)
{
if (DRV_CONFIG_pebs_mode(pcfg)) {
CONTROL_Invoke_Parallel(pebs_Deallocate_Buffers, (VOID *)(size_t)0);
pebs_global_memory = CONTROL_Free_Memory(pebs_global_memory);
pebs_global_memory_size = 0;
}
return;
}
|