oprofile_files.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 <linux/jiffies.h>
  12. #include "event_buffer.h"
  13. #include "oprofile_stats.h"
  14. #include "oprof.h"
  15. #define BUFFER_SIZE_DEFAULT 131072
  16. #define CPU_BUFFER_SIZE_DEFAULT 8192
  17. #define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
  18. unsigned long oprofile_buffer_size;
  19. unsigned long oprofile_cpu_buffer_size;
  20. unsigned long oprofile_buffer_watershed;
  21. #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
  22. static ssize_t timeout_read(struct file *file, char __user *buf,
  23. size_t count, loff_t *offset)
  24. {
  25. return oprofilefs_ulong_to_user(jiffies_to_msecs(timeout_jiffies),
  26. buf, count, offset);
  27. }
  28. static ssize_t timeout_write(struct file *file, char const __user *buf,
  29. size_t count, loff_t *offset)
  30. {
  31. unsigned long val;
  32. int retval;
  33. if (*offset)
  34. return -EINVAL;
  35. retval = oprofilefs_ulong_from_user(&val, buf, count);
  36. if (retval)
  37. return retval;
  38. retval = oprofile_set_timeout(val);
  39. if (retval)
  40. return retval;
  41. return count;
  42. }
  43. static const struct file_operations timeout_fops = {
  44. .read = timeout_read,
  45. .write = timeout_write,
  46. };
  47. #endif
  48. static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  49. {
  50. return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
  51. offset);
  52. }
  53. static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
  54. {
  55. unsigned long val;
  56. int retval;
  57. if (*offset)
  58. return -EINVAL;
  59. retval = oprofilefs_ulong_from_user(&val, buf, count);
  60. if (retval)
  61. return retval;
  62. retval = oprofile_set_backtrace(val);
  63. if (retval)
  64. return retval;
  65. return count;
  66. }
  67. static const struct file_operations depth_fops = {
  68. .read = depth_read,
  69. .write = depth_write
  70. };
  71. static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  72. {
  73. return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
  74. }
  75. static const struct file_operations pointer_size_fops = {
  76. .read = pointer_size_read,
  77. };
  78. static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  79. {
  80. return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
  81. }
  82. static const struct file_operations cpu_type_fops = {
  83. .read = cpu_type_read,
  84. };
  85. static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  86. {
  87. return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
  88. }
  89. static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
  90. {
  91. unsigned long val;
  92. int retval;
  93. if (*offset)
  94. return -EINVAL;
  95. retval = oprofilefs_ulong_from_user(&val, buf, count);
  96. if (retval)
  97. return retval;
  98. if (val)
  99. retval = oprofile_start();
  100. else
  101. oprofile_stop();
  102. if (retval)
  103. return retval;
  104. return count;
  105. }
  106. static const struct file_operations enable_fops = {
  107. .read = enable_read,
  108. .write = enable_write,
  109. };
  110. static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
  111. {
  112. wake_up_buffer_waiter();
  113. return count;
  114. }
  115. static const struct file_operations dump_fops = {
  116. .write = dump_write,
  117. };
  118. void oprofile_create_files(struct super_block *sb, struct dentry *root)
  119. {
  120. /* reinitialize default values */
  121. oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
  122. oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
  123. oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
  124. oprofilefs_create_file(sb, root, "enable", &enable_fops);
  125. oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
  126. oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
  127. oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
  128. oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
  129. oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
  130. oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
  131. oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
  132. oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
  133. #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
  134. oprofilefs_create_file(sb, root, "time_slice", &timeout_fops);
  135. #endif
  136. oprofile_create_stats_files(sb, root);
  137. if (oprofile_ops.create_files)
  138. oprofile_ops.create_files(sb, root);
  139. }