oprofile.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * @file oprofile.h
  3. *
  4. * API for machine-specific interrupts to interface
  5. * to oprofile.
  6. *
  7. * @remark Copyright 2002 OProfile authors
  8. * @remark Read the file COPYING
  9. *
  10. * @author John Levon <levon@movementarian.org>
  11. */
  12. #ifndef OPROFILE_H
  13. #define OPROFILE_H
  14. #include <linux/types.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/init.h>
  17. #include <asm/atomic.h>
  18. /* Each escaped entry is prefixed by ESCAPE_CODE
  19. * then one of the following codes, then the
  20. * relevant data.
  21. * These #defines live in this file so that arch-specific
  22. * buffer sync'ing code can access them.
  23. */
  24. #define ESCAPE_CODE ~0UL
  25. #define CTX_SWITCH_CODE 1
  26. #define CPU_SWITCH_CODE 2
  27. #define COOKIE_SWITCH_CODE 3
  28. #define KERNEL_ENTER_SWITCH_CODE 4
  29. #define KERNEL_EXIT_SWITCH_CODE 5
  30. #define MODULE_LOADED_CODE 6
  31. #define CTX_TGID_CODE 7
  32. #define TRACE_BEGIN_CODE 8
  33. #define TRACE_END_CODE 9
  34. #define XEN_ENTER_SWITCH_CODE 10
  35. #define SPU_PROFILING_CODE 11
  36. #define SPU_CTX_SWITCH_CODE 12
  37. #define IBS_FETCH_CODE 13
  38. #define IBS_OP_CODE 14
  39. struct super_block;
  40. struct dentry;
  41. struct file_operations;
  42. struct pt_regs;
  43. /* Operations structure to be filled in */
  44. struct oprofile_operations {
  45. /* create any necessary configuration files in the oprofile fs.
  46. * Optional. */
  47. int (*create_files)(struct super_block * sb, struct dentry * root);
  48. /* Do any necessary interrupt setup. Optional. */
  49. int (*setup)(void);
  50. /* Do any necessary interrupt shutdown. Optional. */
  51. void (*shutdown)(void);
  52. /* Start delivering interrupts. */
  53. int (*start)(void);
  54. /* Stop delivering interrupts. */
  55. void (*stop)(void);
  56. /* Arch-specific buffer sync functions.
  57. * Return value = 0: Success
  58. * Return value = -1: Failure
  59. * Return value = 1: Run generic sync function
  60. */
  61. int (*sync_start)(void);
  62. int (*sync_stop)(void);
  63. /* Initiate a stack backtrace. Optional. */
  64. void (*backtrace)(struct pt_regs * const regs, unsigned int depth);
  65. /* Multiplex between different events. Optional. */
  66. int (*switch_events)(void);
  67. /* CPU identification string. */
  68. char * cpu_type;
  69. };
  70. /**
  71. * One-time initialisation. *ops must be set to a filled-in
  72. * operations structure. This is called even in timer interrupt
  73. * mode so an arch can set a backtrace callback.
  74. *
  75. * If an error occurs, the fields should be left untouched.
  76. */
  77. int oprofile_arch_init(struct oprofile_operations * ops);
  78. /**
  79. * One-time exit/cleanup for the arch.
  80. */
  81. void oprofile_arch_exit(void);
  82. /**
  83. * Add a sample. This may be called from any context.
  84. */
  85. void oprofile_add_sample(struct pt_regs * const regs, unsigned long event);
  86. /**
  87. * Add an extended sample. Use this when the PC is not from the regs, and
  88. * we cannot determine if we're in kernel mode from the regs.
  89. *
  90. * This function does perform a backtrace.
  91. *
  92. */
  93. void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
  94. unsigned long event, int is_kernel);
  95. /* Use this instead when the PC value is not from the regs. Doesn't
  96. * backtrace. */
  97. void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event);
  98. /* add a backtrace entry, to be called from the ->backtrace callback */
  99. void oprofile_add_trace(unsigned long eip);
  100. /**
  101. * Create a file of the given name as a child of the given root, with
  102. * the specified file operations.
  103. */
  104. int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
  105. char const * name, const struct file_operations * fops);
  106. int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
  107. char const * name, const struct file_operations * fops, int perm);
  108. /** Create a file for read/write access to an unsigned long. */
  109. int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
  110. char const * name, ulong * val);
  111. /** Create a file for read-only access to an unsigned long. */
  112. int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
  113. char const * name, ulong * val);
  114. /** Create a file for read-only access to an atomic_t. */
  115. int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
  116. char const * name, atomic_t * val);
  117. /** create a directory */
  118. struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
  119. char const * name);
  120. /**
  121. * Write the given asciz string to the given user buffer @buf, updating *offset
  122. * appropriately. Returns bytes written or -EFAULT.
  123. */
  124. ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset);
  125. /**
  126. * Convert an unsigned long value into ASCII and copy it to the user buffer @buf,
  127. * updating *offset appropriately. Returns bytes written or -EFAULT.
  128. */
  129. ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset);
  130. /**
  131. * Read an ASCII string for a number from a userspace buffer and fill *val on success.
  132. * Returns 0 on success, < 0 on error.
  133. */
  134. int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
  135. /** lock for read/write safety */
  136. extern spinlock_t oprofilefs_lock;
  137. /**
  138. * Add the contents of a circular buffer to the event buffer.
  139. */
  140. void oprofile_put_buff(unsigned long *buf, unsigned int start,
  141. unsigned int stop, unsigned int max);
  142. unsigned long oprofile_get_cpu_buffer_size(void);
  143. void oprofile_cpu_buffer_inc_smpl_lost(void);
  144. /* cpu buffer functions */
  145. struct op_sample;
  146. struct op_entry {
  147. struct ring_buffer_event *event;
  148. struct op_sample *sample;
  149. unsigned long size;
  150. unsigned long *data;
  151. };
  152. void oprofile_write_reserve(struct op_entry *entry,
  153. struct pt_regs * const regs,
  154. unsigned long pc, int code, int size);
  155. int oprofile_add_data(struct op_entry *entry, unsigned long val);
  156. int oprofile_add_data64(struct op_entry *entry, u64 val);
  157. int oprofile_write_commit(struct op_entry *entry);
  158. #ifdef CONFIG_PERF_EVENTS
  159. int __init oprofile_perf_init(struct oprofile_operations *ops);
  160. void __exit oprofile_perf_exit(void);
  161. char *op_name_from_perf_id(void);
  162. #endif /* CONFIG_PERF_EVENTS */
  163. #endif /* OPROFILE_H */