cgroup_debug.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * kernel/cgroup_debug.c - Example cgroup subsystem that
  3. * exposes debug info
  4. *
  5. * Copyright (C) Google Inc, 2007
  6. *
  7. * Developed by Paul Menage (menage@google.com)
  8. *
  9. */
  10. #include <linux/cgroup.h>
  11. #include <linux/fs.h>
  12. #include <linux/slab.h>
  13. #include <linux/rcupdate.h>
  14. #include <asm/atomic.h>
  15. static struct cgroup_subsys_state *debug_create(struct cgroup_subsys *ss,
  16. struct cgroup *cont)
  17. {
  18. struct cgroup_subsys_state *css = kzalloc(sizeof(*css), GFP_KERNEL);
  19. if (!css)
  20. return ERR_PTR(-ENOMEM);
  21. return css;
  22. }
  23. static void debug_destroy(struct cgroup_subsys *ss, struct cgroup *cont)
  24. {
  25. kfree(cont->subsys[debug_subsys_id]);
  26. }
  27. static u64 cgroup_refcount_read(struct cgroup *cont, struct cftype *cft)
  28. {
  29. return atomic_read(&cont->count);
  30. }
  31. static u64 taskcount_read(struct cgroup *cont, struct cftype *cft)
  32. {
  33. u64 count;
  34. count = cgroup_task_count(cont);
  35. return count;
  36. }
  37. static u64 current_css_set_read(struct cgroup *cont, struct cftype *cft)
  38. {
  39. return (u64)(long)current->cgroups;
  40. }
  41. static u64 current_css_set_refcount_read(struct cgroup *cont,
  42. struct cftype *cft)
  43. {
  44. u64 count;
  45. rcu_read_lock();
  46. count = atomic_read(&current->cgroups->refcount);
  47. rcu_read_unlock();
  48. return count;
  49. }
  50. static u64 releasable_read(struct cgroup *cgrp, struct cftype *cft)
  51. {
  52. return test_bit(CGRP_RELEASABLE, &cgrp->flags);
  53. }
  54. static struct cftype files[] = {
  55. {
  56. .name = "cgroup_refcount",
  57. .read_u64 = cgroup_refcount_read,
  58. },
  59. {
  60. .name = "taskcount",
  61. .read_u64 = taskcount_read,
  62. },
  63. {
  64. .name = "current_css_set",
  65. .read_u64 = current_css_set_read,
  66. },
  67. {
  68. .name = "current_css_set_refcount",
  69. .read_u64 = current_css_set_refcount_read,
  70. },
  71. {
  72. .name = "releasable",
  73. .read_u64 = releasable_read,
  74. },
  75. };
  76. static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont)
  77. {
  78. return cgroup_add_files(cont, ss, files, ARRAY_SIZE(files));
  79. }
  80. struct cgroup_subsys debug_subsys = {
  81. .name = "debug",
  82. .create = debug_create,
  83. .destroy = debug_destroy,
  84. .populate = debug_populate,
  85. .subsys_id = debug_subsys_id,
  86. };