oprofile_files.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * @file oprofile_files.c
  3. *
  4. * @remark Copyright 2002 OProfile authors
  5. * @remark Read the file COPYING
  6. *
  7. * @author John Levon <levon@movementarian.org>
  8. */
  9. #include <linux/fs.h>
  10. #include <linux/oprofile.h>
  11. #include "event_buffer.h"
  12. #include "oprofile_stats.h"
  13. #include "oprof.h"
  14. unsigned long fs_buffer_size = 131072;
  15. unsigned long fs_cpu_buffer_size = 8192;
  16. unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
  17. static ssize_t depth_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
  18. {
  19. return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
  20. }
  21. static ssize_t depth_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
  22. {
  23. unsigned long val;
  24. int retval;
  25. if (*offset)
  26. return -EINVAL;
  27. retval = oprofilefs_ulong_from_user(&val, buf, count);
  28. if (retval)
  29. return retval;
  30. retval = oprofile_set_backtrace(val);
  31. if (retval)
  32. return retval;
  33. return count;
  34. }
  35. static const struct file_operations depth_fops = {
  36. .read = depth_read,
  37. .write = depth_write
  38. };
  39. static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
  40. {
  41. return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
  42. }
  43. static const struct file_operations pointer_size_fops = {
  44. .read = pointer_size_read,
  45. };
  46. static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
  47. {
  48. return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
  49. }
  50. static const struct file_operations cpu_type_fops = {
  51. .read = cpu_type_read,
  52. };
  53. static ssize_t enable_read(struct file * file, char __user * buf, size_t count, loff_t * offset)
  54. {
  55. return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
  56. }
  57. static ssize_t enable_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
  58. {
  59. unsigned long val;
  60. int retval;
  61. if (*offset)
  62. return -EINVAL;
  63. retval = oprofilefs_ulong_from_user(&val, buf, count);
  64. if (retval)
  65. return retval;
  66. if (val)
  67. retval = oprofile_start();
  68. else
  69. oprofile_stop();
  70. if (retval)
  71. return retval;
  72. return count;
  73. }
  74. static const struct file_operations enable_fops = {
  75. .read = enable_read,
  76. .write = enable_write,
  77. };
  78. static ssize_t dump_write(struct file * file, char const __user * buf, size_t count, loff_t * offset)
  79. {
  80. wake_up_buffer_waiter();
  81. return count;
  82. }
  83. static const struct file_operations dump_fops = {
  84. .write = dump_write,
  85. };
  86. void oprofile_create_files(struct super_block * sb, struct dentry * root)
  87. {
  88. oprofilefs_create_file(sb, root, "enable", &enable_fops);
  89. oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
  90. oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
  91. oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
  92. oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
  93. oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
  94. oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
  95. oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
  96. oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
  97. oprofile_create_stats_files(sb, root);
  98. if (oprofile_ops.create_files)
  99. oprofile_ops.create_files(sb, root);
  100. }