cgroup_debug.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. 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->refcount);
  49. rcu_read_unlock();
  50. return count;
  51. }
  52. static u64 releasable_read(struct cgroup *cgrp, struct cftype *cft)
  53. {
  54. return test_bit(CGRP_RELEASABLE, &cgrp->flags);
  55. }
  56. static struct cftype files[] = {
  57. {
  58. .name = "cgroup_refcount",
  59. .read_u64 = cgroup_refcount_read,
  60. },
  61. {
  62. .name = "taskcount",
  63. .read_u64 = taskcount_read,
  64. },
  65. {
  66. .name = "current_css_set",
  67. .read_u64 = current_css_set_read,
  68. },
  69. {
  70. .name = "current_css_set_refcount",
  71. .read_u64 = current_css_set_refcount_read,
  72. },
  73. {
  74. .name = "releasable",
  75. .read_u64 = releasable_read,
  76. },
  77. };
  78. static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont)
  79. {
  80. return cgroup_add_files(cont, ss, files, ARRAY_SIZE(files));
  81. }
  82. struct cgroup_subsys debug_subsys = {
  83. .name = "debug",
  84. .create = debug_create,
  85. .destroy = debug_destroy,
  86. .populate = debug_populate,
  87. .subsys_id = debug_subsys_id,
  88. };