common.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * arch/sh/oprofile/init.c
  3. *
  4. * Copyright (C) 2003 - 2008 Paul Mundt
  5. *
  6. * Based on arch/mips/oprofile/common.c:
  7. *
  8. * Copyright (C) 2004, 2005 Ralf Baechle
  9. * Copyright (C) 2005 MIPS Technologies, Inc.
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file "COPYING" in the main directory of this archive
  13. * for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/oprofile.h>
  17. #include <linux/init.h>
  18. #include <linux/errno.h>
  19. #include <linux/smp.h>
  20. #include <linux/perf_event.h>
  21. #include <asm/processor.h>
  22. #ifdef CONFIG_HW_PERF_EVENTS
  23. extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth);
  24. char *op_name_from_perf_id(void)
  25. {
  26. const char *pmu;
  27. char buf[20];
  28. int size;
  29. pmu = perf_pmu_name();
  30. if (!pmu)
  31. return NULL;
  32. size = snprintf(buf, sizeof(buf), "sh/%s", pmu);
  33. if (size > -1 && size < sizeof(buf))
  34. return buf;
  35. return NULL;
  36. }
  37. int __init oprofile_arch_init(struct oprofile_operations *ops)
  38. {
  39. ops->backtrace = sh_backtrace;
  40. return oprofile_perf_init(ops);
  41. }
  42. void __exit oprofile_arch_exit(void)
  43. {
  44. oprofile_perf_exit();
  45. }
  46. #else
  47. int __init oprofile_arch_init(struct oprofile_operations *ops)
  48. {
  49. pr_info("oprofile: hardware counters not available\n");
  50. return -ENODEV;
  51. }
  52. void __exit oprofile_arch_exit(void) {}
  53. #endif /* CONFIG_HW_PERF_EVENTS */