mali_kbase_mem_profile_debugfs.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. *
  3. * (C) COPYRIGHT 2012-2015 ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * A copy of the licence is included with the program, and can also be obtained
  11. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  12. * Boston, MA 02110-1301, USA.
  13. *
  14. */
  15. #include <mali_kbase_gpu_memory_debugfs.h>
  16. #ifdef CONFIG_DEBUG_FS
  17. /** Show callback for the @c mem_profile debugfs file.
  18. *
  19. * This function is called to get the contents of the @c mem_profile debugfs
  20. * file. This is a report of current memory usage and distribution in userspace.
  21. *
  22. * @param sfile The debugfs entry
  23. * @param data Data associated with the entry
  24. *
  25. * @return 0 if it successfully prints data in debugfs entry file, non-zero otherwise
  26. */
  27. static int kbasep_mem_profile_seq_show(struct seq_file *sfile, void *data)
  28. {
  29. struct kbase_context *kctx = sfile->private;
  30. mutex_lock(&kctx->mem_profile_lock);
  31. seq_write(sfile, kctx->mem_profile_data, kctx->mem_profile_size);
  32. seq_putc(sfile, '\n');
  33. mutex_unlock(&kctx->mem_profile_lock);
  34. return 0;
  35. }
  36. /*
  37. * File operations related to debugfs entry for mem_profile
  38. */
  39. static int kbasep_mem_profile_debugfs_open(struct inode *in, struct file *file)
  40. {
  41. return single_open(file, kbasep_mem_profile_seq_show, in->i_private);
  42. }
  43. static const struct file_operations kbasep_mem_profile_debugfs_fops = {
  44. .open = kbasep_mem_profile_debugfs_open,
  45. .read = seq_read,
  46. .llseek = seq_lseek,
  47. .release = single_release,
  48. };
  49. int kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
  50. size_t size)
  51. {
  52. int err = 0;
  53. mutex_lock(&kctx->mem_profile_lock);
  54. dev_dbg(kctx->kbdev->dev, "initialised: %d",
  55. kctx->mem_profile_initialized);
  56. if (!kctx->mem_profile_initialized) {
  57. if (!debugfs_create_file("mem_profile", S_IRUGO,
  58. kctx->kctx_dentry, kctx,
  59. &kbasep_mem_profile_debugfs_fops)) {
  60. err = -EAGAIN;
  61. } else {
  62. kctx->mem_profile_initialized = true;
  63. }
  64. }
  65. if (kctx->mem_profile_initialized) {
  66. kfree(kctx->mem_profile_data);
  67. kctx->mem_profile_data = data;
  68. kctx->mem_profile_size = size;
  69. }
  70. dev_dbg(kctx->kbdev->dev, "returning: %d, initialised: %d",
  71. err, kctx->mem_profile_initialized);
  72. mutex_unlock(&kctx->mem_profile_lock);
  73. return err;
  74. }
  75. void kbasep_mem_profile_debugfs_remove(struct kbase_context *kctx)
  76. {
  77. mutex_lock(&kctx->mem_profile_lock);
  78. dev_dbg(kctx->kbdev->dev, "initialised: %d",
  79. kctx->mem_profile_initialized);
  80. kfree(kctx->mem_profile_data);
  81. kctx->mem_profile_data = NULL;
  82. kctx->mem_profile_size = 0;
  83. mutex_unlock(&kctx->mem_profile_lock);
  84. }
  85. #else /* CONFIG_DEBUG_FS */
  86. int kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
  87. size_t size)
  88. {
  89. kfree(data);
  90. return 0;
  91. }
  92. #endif /* CONFIG_DEBUG_FS */