From: Alexander Nikiforov <a.nikiforov-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
To: Alexander Nikiforov
<a.nikiforov-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
KAMEZAWA Hiroyuki
<kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>,
Glauber Costa <glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
Subject: [RFC] patch
Date: Mon, 02 Apr 2012 08:22:14 +0400 [thread overview]
Message-ID: <4F792976.4090503@samsung.com> (raw)
In-Reply-To: <4F7928BE.8000502-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 131 bytes --]
--
Best regards,
Alex Nikiforov,
Mobile SW, Advanced Software Group,
Moscow R&D center, Samsung Electronics
[-- Attachment #2: cgroup-task-event.patch --]
[-- Type: text/x-patch, Size: 3645 bytes --]
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index e9b6021..86b0031 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -192,6 +192,11 @@ struct cgroup_pidlist {
struct rw_semaphore mutex;
};
+struct fe_eventfd_list {
+ struct list_head list;
+ struct eventfd_ctx *eventfd;
+};
+
struct cgroup {
unsigned long flags; /* "unsigned long" so bitops work */
@@ -243,6 +248,10 @@ struct cgroup {
/* List of events which userspace want to receive */
struct list_head event_list;
spinlock_t event_list_lock;
+
+ /* fork-exit event */
+ struct list_head fe_notify;
+ spinlock_t fe_list_lock;
};
/*
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index a5d3b53..6c5dda9 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1336,6 +1336,8 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp)
INIT_LIST_HEAD(&cgrp->css_sets);
INIT_LIST_HEAD(&cgrp->release_list);
INIT_LIST_HEAD(&cgrp->pidlists);
+ INIT_LIST_HEAD(&cgrp->fe_notify);
+ spin_lock_init(&cgrp->fe_list_lock);
mutex_init(&cgrp->pidlist_mutex);
INIT_LIST_HEAD(&cgrp->event_list);
spin_lock_init(&cgrp->event_list_lock);
@@ -3659,6 +3661,38 @@ static int cgroup_clone_children_write(struct cgroup *cgrp,
return 0;
}
+static int tasks_register_event(struct cgroup *cgrp,
+ struct cftype *cft, struct eventfd_ctx *eventfd, const char *args)
+{
+ struct fe_eventfd_list *ev;
+
+ ev = kmalloc(sizeof(*ev), GFP_KERNEL);
+ if(!ev)
+ return -ENOMEM;
+
+ spin_lock(&cgrp->fe_list_lock);
+ ev->eventfd = eventfd;
+ list_add(&ev->list, &cgrp->fe_notify);
+ spin_unlock(&cgrp->fe_list_lock);
+
+ return 0;
+}
+
+static void tasks_unregister_event(struct cgroup *cgrp,
+ struct cftype *cft, struct eventfd_ctx *eventfd)
+{
+ struct fe_eventfd_list *ev, *tmp;
+
+ spin_lock(&cgrp->fe_list_lock);
+ list_for_each_entry_safe(ev, tmp, &cgrp->fe_notify, list) {
+ if (ev->eventfd == eventfd) {
+ list_del(&ev->list);
+ kfree(ev);
+ }
+ }
+ spin_unlock(&cgrp->fe_list_lock);
+}
+
/*
* for the common functions, 'private' gives the type of file
*/
@@ -3670,6 +3704,8 @@ static struct cftype files[] = {
.open = cgroup_tasks_open,
.write_u64 = cgroup_tasks_write,
.release = cgroup_pidlist_release,
+ .register_event = tasks_register_event,
+ .unregister_event = tasks_unregister_event,
.mode = S_IRUGO | S_IWUSR,
},
{
@@ -4558,6 +4594,22 @@ void cgroup_fork(struct task_struct *child)
child->cgroups = current->cgroups;
get_css_set(child->cgroups);
INIT_LIST_HEAD(&child->cg_list);
+
+ struct cgroupfs_root *root;
+
+ /* send event to the userspace */
+ mutex_lock(&cgroup_mutex);
+ for_each_active_root(root) {
+ struct cgroup *cgrp;
+ struct fe_eventfd_list *ev;
+
+ cgrp = task_cgroup_from_root(child, root);
+
+ list_for_each_entry(ev, &cgrp->fe_notify, list) {
+ eventfd_signal(ev->eventfd, 1);
+ }
+ }
+ mutex_unlock(&cgroup_mutex);
}
/**
@@ -4653,6 +4705,7 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
{
struct css_set *cg;
int i;
+ struct cgroupfs_root *root;
/*
* Unlink from the css_set task list if necessary.
@@ -4666,6 +4719,20 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
write_unlock(&css_set_lock);
}
+ /* send event to the userspace */
+ mutex_lock(&cgroup_mutex);
+ for_each_active_root(root) {
+ struct cgroup *cgrp;
+ struct fe_eventfd_list *ev;
+
+ cgrp = task_cgroup_from_root(tsk, root);
+
+ list_for_each_entry(ev, &cgrp->fe_notify, list) {
+ eventfd_signal(ev->eventfd, 1);
+ }
+ }
+ mutex_unlock(&cgroup_mutex);
+
/* Reassign the task to the init_css_set. */
task_lock(tsk);
cg = tsk->cgroups;
next prev parent reply other threads:[~2012-04-02 4:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-02 4:19 [RFC] event about group change Alexander Nikiforov
[not found] ` <4F7928BE.8000502-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-04-02 4:22 ` Alexander Nikiforov [this message]
[not found] ` <4F792976.4090503-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-04-02 10:29 ` [RFC] patch Kirill A. Shutemov
[not found] ` <20120402102931.GA5885-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
2012-04-02 10:17 ` Alexander Nikiforov
2012-04-05 3:38 ` Alexander Nikiforov
[not found] ` <4F7D13AD.3030309-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-04-06 15:43 ` Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F792976.4090503@samsung.com \
--to=a.nikiforov-sze3o3uu22jbdgjk7y7tuq@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org \
--cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.