oprofile_files.c 3.4 KB

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