oprofile_files.c 4.5 KB

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