oprofile_files.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #define BUFFER_SIZE_DEFAULT 131072
  15. #define CPU_BUFFER_SIZE_DEFAULT 8192
  16. #define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
  17. unsigned long oprofile_buffer_size;
  18. unsigned long oprofile_cpu_buffer_size;
  19. unsigned long oprofile_buffer_watershed;
  20. static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  21. {
  22. return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
  23. offset);
  24. }
  25. static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
  26. {
  27. unsigned long val;
  28. int retval;
  29. if (*offset)
  30. return -EINVAL;
  31. retval = oprofilefs_ulong_from_user(&val, buf, count);
  32. if (retval)
  33. return retval;
  34. retval = oprofile_set_backtrace(val);
  35. if (retval)
  36. return retval;
  37. return count;
  38. }
  39. static const struct file_operations depth_fops = {
  40. .read = depth_read,
  41. .write = depth_write
  42. };
  43. static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  44. {
  45. return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
  46. }
  47. static const struct file_operations pointer_size_fops = {
  48. .read = pointer_size_read,
  49. };
  50. static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  51. {
  52. return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
  53. }
  54. static const struct file_operations cpu_type_fops = {
  55. .read = cpu_type_read,
  56. };
  57. static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  58. {
  59. return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
  60. }
  61. static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
  62. {
  63. unsigned long val;
  64. int retval;
  65. if (*offset)
  66. return -EINVAL;
  67. retval = oprofilefs_ulong_from_user(&val, buf, count);
  68. if (retval)
  69. return retval;
  70. if (val)
  71. retval = oprofile_start();
  72. else
  73. oprofile_stop();
  74. if (retval)
  75. return retval;
  76. return count;
  77. }
  78. static const struct file_operations enable_fops = {
  79. .read = enable_read,
  80. .write = enable_write,
  81. };
  82. static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
  83. {
  84. wake_up_buffer_waiter();
  85. return count;
  86. }
  87. static const struct file_operations dump_fops = {
  88. .write = dump_write,
  89. };
  90. void oprofile_create_files(struct super_block *sb, struct dentry *root)
  91. {
  92. /* reinitialize default values */
  93. oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
  94. oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
  95. oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
  96. oprofilefs_create_file(sb, root, "enable", &enable_fops);
  97. oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
  98. oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
  99. oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
  100. oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
  101. oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
  102. oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
  103. oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
  104. oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
  105. oprofile_create_stats_files(sb, root);
  106. if (oprofile_ops.create_files)
  107. oprofile_ops.create_files(sb, root);
  108. }