pmccntr.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. ARM only.
  3. */
  4. #include <linux/debugfs.h>
  5. #include <linux/errno.h> /* EFAULT */
  6. #include <linux/fs.h>
  7. #include <linux/module.h>
  8. #include <linux/printk.h> /* pr_info */
  9. #include <linux/seq_file.h> /* seq_read, seq_lseek, single_release */
  10. #include <linux/uaccess.h> /* copy_from_user, copy_to_user */
  11. #include <uapi/linux/stat.h> /* S_IRUSR */
  12. static struct dentry *debugfs_file;
  13. static int show(struct seq_file *m, void *v)
  14. {
  15. u32 pmccntr;
  16. #if defined(__arm__)
  17. /* Invalid aarch64 asm. */
  18. /* TODO Internal error: Oops - undefined instruction: 0 [#1] ARM */
  19. /* Enable userland access to conter. */
  20. /* PMUSERENR = 1 */
  21. /*__asm__ __volatile__ ("mcr p15, 0, %0, c9, c14, 0" :: "r"(1));*/
  22. /* TODO oops undefined instruction. */
  23. /* PMCR.E (bit 0) = 1 */
  24. /*__asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 0" :: "r"(1));*/
  25. /* TODO oops undefined instruction. */
  26. /* Enable counter. */
  27. /* PMCNTENSET.C (bit 31) = 1 */
  28. /*__asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 1" :: "r"(1 << 31));*/
  29. /* Get counter value. */
  30. __asm__ __volatile__ ("mrc p15, 0, %0, c15, c12, 1" : "=r" (pmccntr));
  31. #else
  32. pmccntr = 0;
  33. #endif
  34. seq_printf(m, "%8.8llX\n", (unsigned long long)pmccntr);
  35. return 0;
  36. }
  37. static int open(struct inode *inode, struct file *file)
  38. {
  39. return single_open(file, show, NULL);
  40. }
  41. static const struct file_operations fops = {
  42. .llseek = seq_lseek,
  43. .open = open,
  44. .owner = THIS_MODULE,
  45. .read = seq_read,
  46. .release = single_release,
  47. };
  48. static int myinit(void)
  49. {
  50. debugfs_file = debugfs_create_file("lkmc_pmccntr", S_IRUSR, NULL, NULL, &fops);
  51. if (!debugfs_file) {
  52. return -1;
  53. }
  54. return 0;
  55. }
  56. static void myexit(void)
  57. {
  58. debugfs_remove(debugfs_file);
  59. }
  60. module_init(myinit)
  61. module_exit(myexit)
  62. MODULE_LICENSE("GPL");