oprofile.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. struct super_block;
  18. struct dentry;
  19. struct file_operations;
  20. struct pt_regs;
  21. /* Operations structure to be filled in */
  22. struct oprofile_operations {
  23. /* create any necessary configuration files in the oprofile fs.
  24. * Optional. */
  25. int (*create_files)(struct super_block * sb, struct dentry * root);
  26. /* Do any necessary interrupt setup. Optional. */
  27. int (*setup)(void);
  28. /* Do any necessary interrupt shutdown. Optional. */
  29. void (*shutdown)(void);
  30. /* Start delivering interrupts. */
  31. int (*start)(void);
  32. /* Stop delivering interrupts. */
  33. void (*stop)(void);
  34. /* Initiate a stack backtrace. Optional. */
  35. void (*backtrace)(struct pt_regs * const regs, unsigned int depth);
  36. /* CPU identification string. */
  37. char * cpu_type;
  38. };
  39. /**
  40. * One-time initialisation. *ops must be set to a filled-in
  41. * operations structure. This is called even in timer interrupt
  42. * mode so an arch can set a backtrace callback.
  43. *
  44. * If an error occurs, the fields should be left untouched.
  45. */
  46. int oprofile_arch_init(struct oprofile_operations * ops);
  47. /**
  48. * One-time exit/cleanup for the arch.
  49. */
  50. void oprofile_arch_exit(void);
  51. /**
  52. * Add a sample. This may be called from any context. Pass
  53. * smp_processor_id() as cpu.
  54. */
  55. void oprofile_add_sample(struct pt_regs * const regs, unsigned long event);
  56. /**
  57. * Add an extended sample. Use this when the PC is not from the regs, and
  58. * we cannot determine if we're in kernel mode from the regs.
  59. *
  60. * This function does perform a backtrace.
  61. *
  62. */
  63. void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
  64. unsigned long event, int is_kernel);
  65. /* Use this instead when the PC value is not from the regs. Doesn't
  66. * backtrace. */
  67. void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event);
  68. /* add a backtrace entry, to be called from the ->backtrace callback */
  69. void oprofile_add_trace(unsigned long eip);
  70. /**
  71. * Create a file of the given name as a child of the given root, with
  72. * the specified file operations.
  73. */
  74. int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
  75. char const * name, const struct file_operations * fops);
  76. int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
  77. char const * name, const struct file_operations * fops, int perm);
  78. /** Create a file for read/write access to an unsigned long. */
  79. int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
  80. char const * name, ulong * val);
  81. /** Create a file for read-only access to an unsigned long. */
  82. int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
  83. char const * name, ulong * val);
  84. /** Create a file for read-only access to an atomic_t. */
  85. int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
  86. char const * name, atomic_t * val);
  87. /** create a directory */
  88. struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
  89. char const * name);
  90. /**
  91. * Write the given asciz string to the given user buffer @buf, updating *offset
  92. * appropriately. Returns bytes written or -EFAULT.
  93. */
  94. ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset);
  95. /**
  96. * Convert an unsigned long value into ASCII and copy it to the user buffer @buf,
  97. * updating *offset appropriately. Returns bytes written or -EFAULT.
  98. */
  99. ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset);
  100. /**
  101. * Read an ASCII string for a number from a userspace buffer and fill *val on success.
  102. * Returns 0 on success, < 0 on error.
  103. */
  104. int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
  105. /** lock for read/write safety */
  106. extern spinlock_t oprofilefs_lock;
  107. #endif /* OPROFILE_H */