aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-20 12:16:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-20 12:16:21 -0500
commit502b24c23b44fbaa01cc2cbd86d8035845b7811f (patch)
tree3096deeb99f6acc2d72ee33f145008ec5e2c68b3 /tools
parentece8e0b2f9c980e5511fe8db2d68c6f1859b9d83 (diff)
parentf169007b2773f285e098cb84c74aac0154d65ff7 (diff)
Merge branch 'for-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup changes from Tejun Heo: "Nothing too drastic. - Removal of synchronize_rcu() from userland visible paths. - Various fixes and cleanups from Li. - cgroup_rightmost_descendant() added which will be used by cpuset changes (it will be a separate pull request)." * 'for-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup: fail if monitored file and event_control are in different cgroup cgroup: fix cgroup_rmdir() vs close(eventfd) race cpuset: fix cpuset_print_task_mems_allowed() vs rename() race cgroup: fix exit() vs rmdir() race cgroup: remove bogus comments in cgroup_diput() cgroup: remove synchronize_rcu() from cgroup_diput() cgroup: remove duplicate RCU free on struct cgroup sched: remove redundant NULL cgroup check in task_group_path() sched: split out css_online/css_offline from tg creation/destruction cgroup: initialize cgrp->dentry before css_alloc() cgroup: remove a NULL check in cgroup_exit() cgroup: fix bogus kernel warnings when cgroup_create() failed cgroup: remove synchronize_rcu() from rebind_subsystems() cgroup: remove synchronize_rcu() from cgroup_attach_{task|proc}() cgroup: use new hashtable implementation cgroups: fix cgroup_event_listener error handling cgroups: move cgroup_event_listener.c to tools/cgroup cgroup: implement cgroup_rightmost_descendant() cgroup: remove unused dummy cgroup_fork_callbacks()
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile19
-rw-r--r--tools/cgroup/.gitignore1
-rw-r--r--tools/cgroup/Makefile11
-rw-r--r--tools/cgroup/cgroup_event_listener.c82
4 files changed, 104 insertions, 9 deletions
diff --git a/tools/Makefile b/tools/Makefile
index 798fa0ef048e..fa36565b209d 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -3,6 +3,7 @@ include scripts/Makefile.include
3help: 3help:
4 @echo 'Possible targets:' 4 @echo 'Possible targets:'
5 @echo '' 5 @echo ''
6 @echo ' cgroup - cgroup tools'
6 @echo ' cpupower - a tool for all things x86 CPU power' 7 @echo ' cpupower - a tool for all things x86 CPU power'
7 @echo ' firewire - the userspace part of nosy, an IEEE-1394 traffic sniffer' 8 @echo ' firewire - the userspace part of nosy, an IEEE-1394 traffic sniffer'
8 @echo ' lguest - a minimal 32-bit x86 hypervisor' 9 @echo ' lguest - a minimal 32-bit x86 hypervisor'
@@ -33,7 +34,7 @@ help:
33cpupower: FORCE 34cpupower: FORCE
34 $(call descend,power/$@) 35 $(call descend,power/$@)
35 36
36firewire lguest perf usb virtio vm: FORCE 37cgroup firewire lguest perf usb virtio vm: FORCE
37 $(call descend,$@) 38 $(call descend,$@)
38 39
39selftests: FORCE 40selftests: FORCE
@@ -45,7 +46,7 @@ turbostat x86_energy_perf_policy: FORCE
45cpupower_install: 46cpupower_install:
46 $(call descend,power/$(@:_install=),install) 47 $(call descend,power/$(@:_install=),install)
47 48
48firewire_install lguest_install perf_install usb_install virtio_install vm_install: 49cgroup_install firewire_install lguest_install perf_install usb_install virtio_install vm_install:
49 $(call descend,$(@:_install=),install) 50 $(call descend,$(@:_install=),install)
50 51
51selftests_install: 52selftests_install:
@@ -54,14 +55,14 @@ selftests_install:
54turbostat_install x86_energy_perf_policy_install: 55turbostat_install x86_energy_perf_policy_install:
55 $(call descend,power/x86/$(@:_install=),install) 56 $(call descend,power/x86/$(@:_install=),install)
56 57
57install: cpupower_install firewire_install lguest_install perf_install \ 58install: cgroup_install cpupower_install firewire_install lguest_install \
58 selftests_install turbostat_install usb_install virtio_install \ 59 perf_install selftests_install turbostat_install usb_install \
59 vm_install x86_energy_perf_policy_install 60 virtio_install vm_install x86_energy_perf_policy_install
60 61
61cpupower_clean: 62cpupower_clean:
62 $(call descend,power/cpupower,clean) 63 $(call descend,power/cpupower,clean)
63 64
64firewire_clean lguest_clean perf_clean usb_clean virtio_clean vm_clean: 65cgroup_clean firewire_clean lguest_clean perf_clean usb_clean virtio_clean vm_clean:
65 $(call descend,$(@:_clean=),clean) 66 $(call descend,$(@:_clean=),clean)
66 67
67selftests_clean: 68selftests_clean:
@@ -70,8 +71,8 @@ selftests_clean:
70turbostat_clean x86_energy_perf_policy_clean: 71turbostat_clean x86_energy_perf_policy_clean:
71 $(call descend,power/x86/$(@:_clean=),clean) 72 $(call descend,power/x86/$(@:_clean=),clean)
72 73
73clean: cpupower_clean firewire_clean lguest_clean perf_clean selftests_clean \ 74clean: cgroup_clean cpupower_clean firewire_clean lguest_clean perf_clean \
74 turbostat_clean usb_clean virtio_clean vm_clean \ 75 selftests_clean turbostat_clean usb_clean virtio_clean \
75 x86_energy_perf_policy_clean 76 vm_clean x86_energy_perf_policy_clean
76 77
77.PHONY: FORCE 78.PHONY: FORCE
diff --git a/tools/cgroup/.gitignore b/tools/cgroup/.gitignore
new file mode 100644
index 000000000000..633cd9b874f9
--- /dev/null
+++ b/tools/cgroup/.gitignore
@@ -0,0 +1 @@
cgroup_event_listener
diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile
new file mode 100644
index 000000000000..b4286196b763
--- /dev/null
+++ b/tools/cgroup/Makefile
@@ -0,0 +1,11 @@
1# Makefile for cgroup tools
2
3CC = $(CROSS_COMPILE)gcc
4CFLAGS = -Wall -Wextra
5
6all: cgroup_event_listener
7%: %.c
8 $(CC) $(CFLAGS) -o $@ $^
9
10clean:
11 $(RM) cgroup_event_listener
diff --git a/tools/cgroup/cgroup_event_listener.c b/tools/cgroup/cgroup_event_listener.c
new file mode 100644
index 000000000000..4eb5507205c9
--- /dev/null
+++ b/tools/cgroup/cgroup_event_listener.c
@@ -0,0 +1,82 @@
1/*
2 * cgroup_event_listener.c - Simple listener of cgroup events
3 *
4 * Copyright (C) Kirill A. Shutemov <kirill@shutemov.name>
5 */
6
7#include <assert.h>
8#include <err.h>
9#include <errno.h>
10#include <fcntl.h>
11#include <libgen.h>
12#include <limits.h>
13#include <stdio.h>
14#include <string.h>
15#include <unistd.h>
16
17#include <sys/eventfd.h>
18
19#define USAGE_STR "Usage: cgroup_event_listener <path-to-control-file> <args>"
20
21int main(int argc, char **argv)
22{
23 int efd = -1;
24 int cfd = -1;
25 int event_control = -1;
26 char event_control_path[PATH_MAX];
27 char line[LINE_MAX];
28 int ret;
29
30 if (argc != 3)
31 errx(1, "%s", USAGE_STR);
32
33 cfd = open(argv[1], O_RDONLY);
34 if (cfd == -1)
35 err(1, "Cannot open %s", argv[1]);
36
37 ret = snprintf(event_control_path, PATH_MAX, "%s/cgroup.event_control",
38 dirname(argv[1]));
39 if (ret >= PATH_MAX)
40 errx(1, "Path to cgroup.event_control is too long");
41
42 event_control = open(event_control_path, O_WRONLY);
43 if (event_control == -1)
44 err(1, "Cannot open %s", event_control_path);
45
46 efd = eventfd(0, 0);
47 if (efd == -1)
48 err(1, "eventfd() failed");
49
50 ret = snprintf(line, LINE_MAX, "%d %d %s", efd, cfd, argv[2]);
51 if (ret >= LINE_MAX)
52 errx(1, "Arguments string is too long");
53
54 ret = write(event_control, line, strlen(line) + 1);
55 if (ret == -1)
56 err(1, "Cannot write to cgroup.event_control");
57
58 while (1) {
59 uint64_t result;
60
61 ret = read(efd, &result, sizeof(result));
62 if (ret == -1) {
63 if (errno == EINTR)
64 continue;
65 err(1, "Cannot read from eventfd");
66 }
67 assert(ret == sizeof(result));
68
69 ret = access(event_control_path, W_OK);
70 if ((ret == -1) && (errno == ENOENT)) {
71 puts("The cgroup seems to have removed.");
72 break;
73 }
74
75 if (ret == -1)
76 err(1, "cgroup.event_control is not accessible any more");
77
78 printf("%s %s: crossed\n", argv[1], argv[2]);
79 }
80
81 return 0;
82}