cgroup_debug.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * kernel/ccontainer_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. cgroup_lock();
  35. count = cgroup_task_count(cont);
  36. cgroup_unlock();
  37. return count;
  38. }
  39. static u64 current_css_set_read(struct cgroup *cont, struct cftype *cft)
  40. {
  41. return (u64)(long)current->cgroups;
  42. }
  43. static u64 current_css_set_refcount_read(struct cgroup *cont,
  44. struct cftype *cft)
  45. {
  46. u64 count;
  47. rcu_read_lock();
  48. count = atomic_read(&current->cgroups->ref.refcount);
  49. rcu_read_unlock();
  50. return count;
  51. }
  52. static struct cftype files[] = {
  53. {
  54. .name = "cgroup_refcount",
  55. .read_uint = cgroup_refcount_read,
  56. },
  57. {
  58. .name = "taskcount",
  59. .read_uint = taskcount_read,
  60. },
  61. {
  62. .name = "current_css_set",
  63. .read_uint = current_css_set_read,
  64. },
  65. {
  66. .name = "current_css_set_refcount",
  67. .read_uint = current_css_set_refcount_read,
  68. },
  69. };
  70. static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont)
  71. {
  72. return cgroup_add_files(cont, ss, files, ARRAY_SIZE(files));
  73. }
  74. struct cgroup_subsys debug_subsys = {
  75. .name = "debug",
  76. .create = debug_create,
  77. .destroy = debug_destroy,
  78. .populate = debug_populate,
  79. .subsys_id = debug_subsys_id,
  80. };