Path: blob/master/arch/mips/oprofile/op_model_rm9000.c
10818 views
/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 2004 by Ralf Baechle6*/7#include <linux/init.h>8#include <linux/oprofile.h>9#include <linux/interrupt.h>10#include <linux/smp.h>1112#include "op_impl.h"1314#define RM9K_COUNTER1_EVENT(event) ((event) << 0)15#define RM9K_COUNTER1_SUPERVISOR (1ULL << 7)16#define RM9K_COUNTER1_KERNEL (1ULL << 8)17#define RM9K_COUNTER1_USER (1ULL << 9)18#define RM9K_COUNTER1_ENABLE (1ULL << 10)19#define RM9K_COUNTER1_OVERFLOW (1ULL << 15)2021#define RM9K_COUNTER2_EVENT(event) ((event) << 16)22#define RM9K_COUNTER2_SUPERVISOR (1ULL << 23)23#define RM9K_COUNTER2_KERNEL (1ULL << 24)24#define RM9K_COUNTER2_USER (1ULL << 25)25#define RM9K_COUNTER2_ENABLE (1ULL << 26)26#define RM9K_COUNTER2_OVERFLOW (1ULL << 31)2728extern unsigned int rm9000_perfcount_irq;2930static struct rm9k_register_config {31unsigned int control;32unsigned int reset_counter1;33unsigned int reset_counter2;34} reg;3536/* Compute all of the registers in preparation for enabling profiling. */3738static void rm9000_reg_setup(struct op_counter_config *ctr)39{40unsigned int control = 0;4142/* Compute the performance counter control word. */43/* For now count kernel and user mode */44if (ctr[0].enabled)45control |= RM9K_COUNTER1_EVENT(ctr[0].event) |46RM9K_COUNTER1_KERNEL |47RM9K_COUNTER1_USER |48RM9K_COUNTER1_ENABLE;49if (ctr[1].enabled)50control |= RM9K_COUNTER2_EVENT(ctr[1].event) |51RM9K_COUNTER2_KERNEL |52RM9K_COUNTER2_USER |53RM9K_COUNTER2_ENABLE;54reg.control = control;5556reg.reset_counter1 = 0x80000000 - ctr[0].count;57reg.reset_counter2 = 0x80000000 - ctr[1].count;58}5960/* Program all of the registers in preparation for enabling profiling. */6162static void rm9000_cpu_setup(void *args)63{64uint64_t perfcount;6566perfcount = ((uint64_t) reg.reset_counter2 << 32) | reg.reset_counter1;67write_c0_perfcount(perfcount);68}6970static void rm9000_cpu_start(void *args)71{72/* Start all counters on current CPU */73write_c0_perfcontrol(reg.control);74}7576static void rm9000_cpu_stop(void *args)77{78/* Stop all counters on current CPU */79write_c0_perfcontrol(0);80}8182static irqreturn_t rm9000_perfcount_handler(int irq, void *dev_id)83{84unsigned int control = read_c0_perfcontrol();85struct pt_regs *regs = get_irq_regs();86uint32_t counter1, counter2;87uint64_t counters;8889/*90* RM9000 combines two 32-bit performance counters into a single91* 64-bit coprocessor zero register. To avoid a race updating the92* registers we need to stop the counters while we're messing with93* them ...94*/95write_c0_perfcontrol(0);9697counters = read_c0_perfcount();98counter1 = counters;99counter2 = counters >> 32;100101if (control & RM9K_COUNTER1_OVERFLOW) {102oprofile_add_sample(regs, 0);103counter1 = reg.reset_counter1;104}105if (control & RM9K_COUNTER2_OVERFLOW) {106oprofile_add_sample(regs, 1);107counter2 = reg.reset_counter2;108}109110counters = ((uint64_t)counter2 << 32) | counter1;111write_c0_perfcount(counters);112write_c0_perfcontrol(reg.control);113114return IRQ_HANDLED;115}116117static int __init rm9000_init(void)118{119return request_irq(rm9000_perfcount_irq, rm9000_perfcount_handler,1200, "Perfcounter", NULL);121}122123static void rm9000_exit(void)124{125free_irq(rm9000_perfcount_irq, NULL);126}127128struct op_mips_model op_model_rm9000_ops = {129.reg_setup = rm9000_reg_setup,130.cpu_setup = rm9000_cpu_setup,131.init = rm9000_init,132.exit = rm9000_exit,133.cpu_start = rm9000_cpu_start,134.cpu_stop = rm9000_cpu_stop,135.cpu_type = "mips/rm9000",136.num_counters = 2137};138139140