common.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * arch/metag/oprofile/common.c
  3. *
  4. * Copyright (C) 2013 Imagination Technologies Ltd.
  5. *
  6. * Based on arch/sh/oprofile/common.c:
  7. *
  8. * Copyright (C) 2003 - 2010 Paul Mundt
  9. *
  10. * Based on arch/mips/oprofile/common.c:
  11. *
  12. * Copyright (C) 2004, 2005 Ralf Baechle
  13. * Copyright (C) 2005 MIPS Technologies, Inc.
  14. *
  15. * This file is subject to the terms and conditions of the GNU General Public
  16. * License. See the file "COPYING" in the main directory of this archive
  17. * for more details.
  18. */
  19. #include <linux/errno.h>
  20. #include <linux/init.h>
  21. #include <linux/oprofile.h>
  22. #include <linux/perf_event.h>
  23. #include <linux/slab.h>
  24. #include "backtrace.h"
  25. #ifdef CONFIG_HW_PERF_EVENTS
  26. /*
  27. * This will need to be reworked when multiple PMUs are supported.
  28. */
  29. static char *metag_pmu_op_name;
  30. char *op_name_from_perf_id(void)
  31. {
  32. return metag_pmu_op_name;
  33. }
  34. int __init oprofile_arch_init(struct oprofile_operations *ops)
  35. {
  36. ops->backtrace = metag_backtrace;
  37. if (perf_num_counters() == 0)
  38. return -ENODEV;
  39. metag_pmu_op_name = kasprintf(GFP_KERNEL, "metag/%s",
  40. perf_pmu_name());
  41. if (unlikely(!metag_pmu_op_name))
  42. return -ENOMEM;
  43. return oprofile_perf_init(ops);
  44. }
  45. void oprofile_arch_exit(void)
  46. {
  47. oprofile_perf_exit();
  48. kfree(metag_pmu_op_name);
  49. }
  50. #else
  51. int __init oprofile_arch_init(struct oprofile_operations *ops)
  52. {
  53. ops->backtrace = metag_backtrace;
  54. /* fall back to timer interrupt PC sampling */
  55. return -ENODEV;
  56. }
  57. void oprofile_arch_exit(void) {}
  58. #endif /* CONFIG_HW_PERF_EVENTS */