aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/oprofile
diff options
context:
space:
mode:
authorRobert Richter <robert.richter@amd.com>2009-05-25 14:23:23 -0400
committerRobert Richter <robert.richter@amd.com>2009-06-11 13:42:12 -0400
commit1131a478245b00664ae2dbc0f68db987b51fa806 (patch)
treebbe3e63c0853c38b94e9b141242a5ffbaf026a12 /arch/x86/oprofile
parent74c9a5c341bb1f6cbb5095b07c77230f19682ce8 (diff)
x86/oprofile: remove MSR macros for p4 cpus
The macros CTRL_READ() and CTRL_WRITE() make the code hard to read and maintain. This patch replaces them by rdmsr()/wrmsr() functions and simplifies the code. Signed-off-by: Robert Richter <robert.richter@amd.com>
Diffstat (limited to 'arch/x86/oprofile')
-rw-r--r--arch/x86/oprofile/op_model_p4.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c
index 420c15e71237..365d8a9c03d3 100644
--- a/arch/x86/oprofile/op_model_p4.c
+++ b/arch/x86/oprofile/op_model_p4.c
@@ -350,8 +350,6 @@ static struct p4_event_binding p4_events[NUM_EVENTS] = {
350#define ESCR_SET_OS_1(escr, os) ((escr) |= (((os) & 1) << 1)) 350#define ESCR_SET_OS_1(escr, os) ((escr) |= (((os) & 1) << 1))
351#define ESCR_SET_EVENT_SELECT(escr, sel) ((escr) |= (((sel) & 0x3f) << 25)) 351#define ESCR_SET_EVENT_SELECT(escr, sel) ((escr) |= (((sel) & 0x3f) << 25))
352#define ESCR_SET_EVENT_MASK(escr, mask) ((escr) |= (((mask) & 0xffff) << 9)) 352#define ESCR_SET_EVENT_MASK(escr, mask) ((escr) |= (((mask) & 0xffff) << 9))
353#define ESCR_READ(escr, high, ev, i) do {rdmsr(ev->bindings[(i)].escr_address, (escr), (high)); } while (0)
354#define ESCR_WRITE(escr, high, ev, i) do {wrmsr(ev->bindings[(i)].escr_address, (escr), (high)); } while (0)
355 353
356#define CCCR_RESERVED_BITS 0x38030FFF 354#define CCCR_RESERVED_BITS 0x38030FFF
357#define CCCR_CLEAR(cccr) ((cccr) &= CCCR_RESERVED_BITS) 355#define CCCR_CLEAR(cccr) ((cccr) &= CCCR_RESERVED_BITS)
@@ -361,13 +359,9 @@ static struct p4_event_binding p4_events[NUM_EVENTS] = {
361#define CCCR_SET_PMI_OVF_1(cccr) ((cccr) |= (1<<27)) 359#define CCCR_SET_PMI_OVF_1(cccr) ((cccr) |= (1<<27))
362#define CCCR_SET_ENABLE(cccr) ((cccr) |= (1<<12)) 360#define CCCR_SET_ENABLE(cccr) ((cccr) |= (1<<12))
363#define CCCR_SET_DISABLE(cccr) ((cccr) &= ~(1<<12)) 361#define CCCR_SET_DISABLE(cccr) ((cccr) &= ~(1<<12))
364#define CCCR_READ(low, high, i) do {rdmsr(p4_counters[(i)].cccr_address, (low), (high)); } while (0)
365#define CCCR_WRITE(low, high, i) do {wrmsr(p4_counters[(i)].cccr_address, (low), (high)); } while (0)
366#define CCCR_OVF_P(cccr) ((cccr) & (1U<<31)) 362#define CCCR_OVF_P(cccr) ((cccr) & (1U<<31))
367#define CCCR_CLEAR_OVF(cccr) ((cccr) &= (~(1U<<31))) 363#define CCCR_CLEAR_OVF(cccr) ((cccr) &= (~(1U<<31)))
368 364
369#define CTR_READ(l, h, i) do {rdmsr(p4_counters[(i)].counter_address, (l), (h)); } while (0)
370#define CTR_WRITE(l, i) do {wrmsr(p4_counters[(i)].counter_address, -(u32)(l), -1); } while (0)
371#define CTR_OVERFLOW_P(ctr) (!((ctr) & 0x80000000)) 365#define CTR_OVERFLOW_P(ctr) (!((ctr) & 0x80000000))
372 366
373 367
@@ -513,7 +507,7 @@ static void pmc_setup_one_p4_counter(unsigned int ctr)
513 if (ev->bindings[i].virt_counter & counter_bit) { 507 if (ev->bindings[i].virt_counter & counter_bit) {
514 508
515 /* modify ESCR */ 509 /* modify ESCR */
516 ESCR_READ(escr, high, ev, i); 510 rdmsr(ev->bindings[i].escr_address, escr, high);
517 ESCR_CLEAR(escr); 511 ESCR_CLEAR(escr);
518 if (stag == 0) { 512 if (stag == 0) {
519 ESCR_SET_USR_0(escr, counter_config[ctr].user); 513 ESCR_SET_USR_0(escr, counter_config[ctr].user);
@@ -524,10 +518,11 @@ static void pmc_setup_one_p4_counter(unsigned int ctr)
524 } 518 }
525 ESCR_SET_EVENT_SELECT(escr, ev->event_select); 519 ESCR_SET_EVENT_SELECT(escr, ev->event_select);
526 ESCR_SET_EVENT_MASK(escr, counter_config[ctr].unit_mask); 520 ESCR_SET_EVENT_MASK(escr, counter_config[ctr].unit_mask);
527 ESCR_WRITE(escr, high, ev, i); 521 wrmsr(ev->bindings[i].escr_address, escr, high);
528 522
529 /* modify CCCR */ 523 /* modify CCCR */
530 CCCR_READ(cccr, high, VIRT_CTR(stag, ctr)); 524 rdmsr(p4_counters[VIRT_CTR(stag, ctr)].cccr_address,
525 cccr, high);
531 CCCR_CLEAR(cccr); 526 CCCR_CLEAR(cccr);
532 CCCR_SET_REQUIRED_BITS(cccr); 527 CCCR_SET_REQUIRED_BITS(cccr);
533 CCCR_SET_ESCR_SELECT(cccr, ev->escr_select); 528 CCCR_SET_ESCR_SELECT(cccr, ev->escr_select);
@@ -535,7 +530,8 @@ static void pmc_setup_one_p4_counter(unsigned int ctr)
535 CCCR_SET_PMI_OVF_0(cccr); 530 CCCR_SET_PMI_OVF_0(cccr);
536 else 531 else
537 CCCR_SET_PMI_OVF_1(cccr); 532 CCCR_SET_PMI_OVF_1(cccr);
538 CCCR_WRITE(cccr, high, VIRT_CTR(stag, ctr)); 533 wrmsr(p4_counters[VIRT_CTR(stag, ctr)].cccr_address,
534 cccr, high);
539 return; 535 return;
540 } 536 }
541 } 537 }
@@ -582,7 +578,8 @@ static void p4_setup_ctrs(struct op_msrs const * const msrs)
582 if ((counter_config[i].enabled) && (CTRL_IS_RESERVED(msrs, i))) { 578 if ((counter_config[i].enabled) && (CTRL_IS_RESERVED(msrs, i))) {
583 reset_value[i] = counter_config[i].count; 579 reset_value[i] = counter_config[i].count;
584 pmc_setup_one_p4_counter(i); 580 pmc_setup_one_p4_counter(i);
585 CTR_WRITE(counter_config[i].count, VIRT_CTR(stag, i)); 581 wrmsr(p4_counters[VIRT_CTR(stag, i)].counter_address,
582 -(u32)counter_config[i].count, -1);
586 } else { 583 } else {
587 reset_value[i] = 0; 584 reset_value[i] = 0;
588 } 585 }
@@ -622,14 +619,16 @@ static int p4_check_ctrs(struct pt_regs * const regs,
622 619
623 real = VIRT_CTR(stag, i); 620 real = VIRT_CTR(stag, i);
624 621
625 CCCR_READ(low, high, real); 622 rdmsr(p4_counters[real].cccr_address, low, high);
626 CTR_READ(ctr, high, real); 623 rdmsr(p4_counters[real].counter_address, ctr, high);
627 if (CCCR_OVF_P(low) || CTR_OVERFLOW_P(ctr)) { 624 if (CCCR_OVF_P(low) || CTR_OVERFLOW_P(ctr)) {
628 oprofile_add_sample(regs, i); 625 oprofile_add_sample(regs, i);
629 CTR_WRITE(reset_value[i], real); 626 wrmsr(p4_counters[real].counter_address,
627 -(u32)reset_value[i], -1);
630 CCCR_CLEAR_OVF(low); 628 CCCR_CLEAR_OVF(low);
631 CCCR_WRITE(low, high, real); 629 wrmsr(p4_counters[real].cccr_address, low, high);
632 CTR_WRITE(reset_value[i], real); 630 wrmsr(p4_counters[real].counter_address,
631 -(u32)reset_value[i], -1);
633 } 632 }
634 } 633 }
635 634
@@ -651,9 +650,9 @@ static void p4_start(struct op_msrs const * const msrs)
651 for (i = 0; i < num_counters; ++i) { 650 for (i = 0; i < num_counters; ++i) {
652 if (!reset_value[i]) 651 if (!reset_value[i])
653 continue; 652 continue;
654 CCCR_READ(low, high, VIRT_CTR(stag, i)); 653 rdmsr(p4_counters[VIRT_CTR(stag, i)].cccr_address, low, high);
655 CCCR_SET_ENABLE(low); 654 CCCR_SET_ENABLE(low);
656 CCCR_WRITE(low, high, VIRT_CTR(stag, i)); 655 wrmsr(p4_counters[VIRT_CTR(stag, i)].cccr_address, low, high);
657 } 656 }
658} 657}
659 658
@@ -668,9 +667,9 @@ static void p4_stop(struct op_msrs const * const msrs)
668 for (i = 0; i < num_counters; ++i) { 667 for (i = 0; i < num_counters; ++i) {
669 if (!reset_value[i]) 668 if (!reset_value[i])
670 continue; 669 continue;
671 CCCR_READ(low, high, VIRT_CTR(stag, i)); 670 rdmsr(p4_counters[VIRT_CTR(stag, i)].cccr_address, low, high);
672 CCCR_SET_DISABLE(low); 671 CCCR_SET_DISABLE(low);
673 CCCR_WRITE(low, high, VIRT_CTR(stag, i)); 672 wrmsr(p4_counters[VIRT_CTR(stag, i)].cccr_address, low, high);
674 } 673 }
675} 674}
676 675