oprofile.h 5.6 KB

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