All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Emelianov <xemul@sw.ru>
To: Paul Menage <menage@google.com>
Cc: akpm@osdl.org, pj@sgi.com, sekharan@us.ibm.com, dev@sw.ru,
	serue@us.ibm.com, vatsa@in.ibm.com, ebiederm@xmission.com,
	ckrm-tech@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	rohitseth@google.com, mbligh@google.com, winget@google.com,
	containers@lists.osdl.org, devel@openvz.org
Subject: Re: [PATCH 6/7] containers (V7): BeanCounters over generic process containers
Date: Tue, 13 Feb 2007 12:49:36 +0300	[thread overview]
Message-ID: <45D189B0.6090702@sw.ru> (raw)
In-Reply-To: <6599ad830702130137t4bbfcec1ma65a873504796730@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 754 bytes --]

Paul Menage wrote:
> On 2/13/07, Pavel Emelianov <xemul@sw.ru> wrote:
>>
>> I have implementation that moves arbitrary task :)
> 
> Is that the one that calls stop_machine() in order to move a task
> around? That seemed a little heavyweight ...

Nope :) I've rewritten it completely.

>> May be we can do context (container-on-task) handling lockless?
> 
> What did you have in mind?

The example patch is attached. Fits 2.6.20-rc6-mm3.

>> > I thought that we solved that problem by having a tmp_bc field in the
>> > task_struct that would take precedence over the main bc if it was
>> > non-null?
>>
>> Of course, but I'm commenting this patchset which doesn't have
>> this facility.
> 
> OK, I can add the concept in to the example too.
> 
> Paul
> 


[-- Attachment #2: diff-task-context --]
[-- Type: text/plain, Size: 5444 bytes --]

--- ./kernel/bc/misc.c.bcctx	2007-01-31 13:56:45.000000000 +0300
+++ ./kernel/bc/misc.c	2007-01-31 14:20:32.000000000 +0300
@@ -0,0 +1,63 @@
+/*
+ * kernel/bc/misc.c
+ *
+ * Copyright (C) 2007 OpenVZ SWsoft Inc
+ *
+ */
+
+#include <linux/sched.h>
+#include <linux/stop_machine.h>
+#include <linux/module.h>
+
+#include <bc/beancounter.h>
+#include <bc/task.h>
+#include <bc/misc.h>
+
+static DEFINE_MUTEX(task_move_mutex);
+
+int copy_beancounter(struct task_struct *tsk, struct task_struct *parent)
+{
+	struct beancounter *bc;
+
+	bc = parent->exec_bc;
+	tsk->exec_bc = bc_get(bc);
+	BUG_ON(tsk->tmp_exec_bc != NULL);
+	return 0;
+}
+
+void free_beancounter(struct task_struct *tsk)
+{
+	struct beancounter *bc;
+
+	BUG_ON(tsk->tmp_exec_bc != NULL);
+	bc = tsk->exec_bc;
+	bc_put(bc);
+}
+
+int bc_task_move(int pid, struct beancounter *bc)
+{
+	struct task_struct *tsk;
+	struct beancounter *old_bc;
+
+	read_lock(&tasklist_lock);
+	tsk = find_task_by_pid(pid);
+	if (tsk)
+		get_task_struct(tsk);
+	read_unlock(&tasklist_lock);
+	if (tsk == NULL)
+		return -ESRCH;
+
+	mutex_lock(&task_move_mutex);
+	old_bc = tsk->exec_bc;
+
+	bc_get(bc);
+	rcu_assign_pointer(tsk->exec_bc, bc);
+
+	/* wait for all users if any get this beancounter */
+	synchronize_rcu();
+	mutex_unlock(&task_move_mutex);
+	bc_put(old_bc);
+
+	return err;
+}
+EXPORT_SYMBOL(bc_task_move);
--- ./kernel/fork.c.bcctx	2007-01-31 13:35:21.000000000 +0300
+++ ./kernel/fork.c	2007-01-31 13:56:45.000000000 +0300
@@ -51,6 +51,8 @@
 #include <linux/random.h>
 #include <linux/user_namespace.h>
 
+#include <bc/task.h>
+
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/uaccess.h>
@@ -105,12 +107,18 @@ struct kmem_cache *vm_area_cachep;
 /* SLAB cache for mm_struct structures (tsk->mm) */
 static struct kmem_cache *mm_cachep;
 
-void free_task(struct task_struct *tsk)
+static void __free_task(struct task_struct *tsk)
 {
 	free_thread_info(tsk->thread_info);
 	rt_mutex_debug_task_free(tsk);
 	free_task_struct(tsk);
 }
+
+void free_task(struct task_struct *tsk)
+{
+	free_beancounter(tsk);
+	__free_task(tsk);
+}
 EXPORT_SYMBOL(free_task);
 
 void __put_task_struct(struct task_struct *tsk)
@@ -999,6 +1007,10 @@ static struct task_struct *copy_process(
 
 	rt_mutex_init_task(p);
 
+	retval = copy_beancounter(p, current);
+	if (retval < 0)
+		goto bad_fork_bc;
+
 #ifdef CONFIG_TRACE_IRQFLAGS
 	DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
 	DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
@@ -1321,7 +1333,9 @@ bad_fork_cleanup_count:
 	atomic_dec(&p->user->processes);
 	free_uid(p->user);
 bad_fork_free:
-	free_task(p);
+	free_beancounter(p);
+bad_fork_bc:
+	__free_task(p);
 fork_out:
 	return ERR_PTR(retval);
 }
--- ./kernel/softirq.c.bcctx	2007-01-31 13:35:21.000000000 +0300
+++ ./kernel/softirq.c	2007-01-31 14:22:44.000000000 +0300
@@ -19,6 +19,8 @@
 #include <linux/smp.h>
 #include <linux/tick.h>
 
+#include <bc/task.h>
+
 #include <asm/irq.h>
 /*
    - No shared variables, all the data are CPU local.
@@ -210,6 +212,7 @@ asmlinkage void __do_softirq(void)
 	__u32 pending;
 	int max_restart = MAX_SOFTIRQ_RESTART;
 	int cpu;
+	struct beancounter *bc;
 
 	pending = local_softirq_pending();
 	account_system_vtime(current);
@@ -226,6 +229,7 @@ restart:
 
 	h = softirq_vec;
 
+	bc = set_exec_bc(&init_bc);
 	do {
 		if (pending & 1) {
 			h->action(h);
@@ -234,6 +238,7 @@ restart:
 		h++;
 		pending >>= 1;
 	} while (pending);
+	reset_exec_bc(bc, &init_bc);
 
 	local_irq_disable();
 
--- ./include/linux/sched.h.bcctx	2007-01-31 13:35:21.000000000 +0300
+++ ./include/linux/sched.h	2007-01-31 14:06:28.000000000 +0300
@@ -1082,6 +1082,10 @@ struct task_struct {
 #ifdef CONFIG_FAULT_INJECTION
 	int make_it_fail;
 #endif
+#ifdef CONFIG_BEANCOUNTERS
+	struct beancounter *exec_bc;
+	struct beancounter *tmp_exec_bc;
+#endif
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
--- ./include/bc/task.h.bcctx	2007-01-31 13:56:45.000000000 +0300
+++ ./include/bc/task.h	2007-01-31 14:19:33.000000000 +0300
@@ -0,0 +1,68 @@
+/*
+ * include/bc/task.h
+ *
+ * Copyright (C) 2007 OpenVZ SWsoft Inc
+ *
+ */
+
+#ifndef __BC_TASK_H__
+#define __BC_TASK_H__
+
+struct beancounter;
+struct task_struct;
+
+#ifdef CONFIG_BEANCOUNTERS
+extern struct beancounter init_bc;
+
+/*
+ * Caller must be in rcu_read safe section
+ */
+static inline struct beancounter *get_exec_bc(void)
+{
+	struct task_struct *tsk;
+
+	if (in_irq())
+		return &init_bc;
+
+	tsk = current;
+	if (tsk->tmp_exec_bc != NULL)
+		return tsk->tmp_exec_bc;
+
+	return rcu_dereference(tsk->exec_bc);
+}
+
+#define set_exec_bc(bc)	({				\
+		struct task_struct *t;			\
+		struct beancounter *old;		\
+		t = current;				\
+		old = t->tmp_exec_bc;			\
+		t->tmp_exec_bc = bc;			\
+		old;					\
+	})
+
+#define reset_exec_bc(old, expected)	do {		\
+		struct task_struct *t;			\
+		t = current;				\
+		BUG_ON(t->tmp_exec_bc != expected);	\
+		t->tmp_exec_bc = old;			\
+	} while (0)
+
+int __must_check copy_beancounter(struct task_struct *tsk,
+		struct task_struct *parent);
+void free_beancounter(struct task_struct *tsk);
+int bc_task_move(int pid, struct beancounter *bc);
+#else
+static inline int __must_check copy_beancounter(struct task_struct *tsk,
+		struct task_struct *parent)
+{
+	return 0;
+}
+
+static inline void free_beancounter(struct task_struct *tsk)
+{
+}
+
+#define set_exec_bc(bc)		(NULL)
+#define reset_exec_bc(bc, exp)	do { } while (0)
+#endif
+#endif

  reply	other threads:[~2007-02-13  9:55 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-12  8:15 [PATCH 0/7] containers (V7): Generic Process Containers menage
2007-02-12  8:15 ` [PATCH 1/7] containers (V7): Generic container system abstracted from cpusets code menage
2007-02-12 12:33   ` Srivatsa Vaddagiri
2007-02-12 19:26     ` Paul Menage
2007-02-12 19:46       ` Paul Menage
2007-02-13  5:48         ` Srivatsa Vaddagiri
2007-02-13  8:16           ` [ckrm-tech] " Srivatsa Vaddagiri
2007-03-07 12:21   ` Srivatsa Vaddagiri
2007-03-07 14:06     ` [ckrm-tech] " Srivatsa Vaddagiri
2007-03-07 20:50     ` Paul Menage
2007-03-08 10:38       ` [ckrm-tech] " Srivatsa Vaddagiri
2007-03-08 10:40         ` Paul Menage
2007-03-11 19:38         ` Paul Jackson
2007-03-12 14:19           ` Srivatsa Vaddagiri
2007-03-22  9:56   ` Srivatsa Vaddagiri
2007-03-22 10:20     ` Srivatsa Vaddagiri
2007-03-24 15:05   ` Srivatsa Vaddagiri
2007-03-24 19:25     ` Paul Jackson
2007-03-25  0:45       ` Srivatsa Vaddagiri
2007-03-25  1:41         ` Paul Jackson
2007-03-25  2:28           ` Srivatsa Vaddagiri
2007-03-25  4:16             ` Srivatsa Vaddagiri
2007-03-25  5:43               ` Paul Jackson
2007-03-25  8:21                 ` Srivatsa Vaddagiri
2007-03-25  4:45             ` Paul Jackson
2007-03-25  5:05               ` Srivatsa Vaddagiri
2007-03-25  4:59                 ` Paul Jackson
2007-02-12  8:15 ` [PATCH 2/7] containers (V7): Cpusets hooked into containers menage
2007-02-15 20:35   ` Serge E. Hallyn
2007-02-15 20:49     ` Paul Menage
2007-03-07 14:34   ` Srivatsa Vaddagiri
2007-03-07 16:01     ` Paul Menage
2007-03-07 16:31       ` [ckrm-tech] " Srivatsa Vaddagiri
2007-03-07 16:31         ` Paul Menage
2007-03-07 14:52   ` Srivatsa Vaddagiri
2007-03-07 16:12     ` Paul Menage
2007-02-12  8:15 ` [PATCH 4/7] containers (V7): Simple CPU accounting container subsystem menage
2007-02-12  8:15 ` [PATCH 5/7] containers (V7): Resource Groups over generic containers menage
2007-02-12  8:15 ` [PATCH 6/7] containers (V7): BeanCounters over generic process containers menage
2007-02-12 15:34   ` Srivatsa Vaddagiri
2007-02-12 18:49     ` Paul Menage
2007-02-13  8:52   ` Pavel Emelianov
2007-02-13  9:03     ` Paul Menage
2007-02-13  9:18       ` Pavel Emelianov
2007-02-13  9:37         ` Paul Menage
2007-02-13  9:49           ` Pavel Emelianov [this message]
2007-02-12  8:15 ` [PATCH 7/7] containers (V7): Container interface to nsproxy subsystem menage
2007-03-24  5:05   ` [ckrm-tech] " Srivatsa Vaddagiri
2007-03-24 16:23     ` Srivatsa Vaddagiri
2007-03-26 21:57       ` Serge E. Hallyn
2007-03-28 14:55         ` Srivatsa Vaddagiri
2007-03-28 15:26           ` Serge E. Hallyn
2007-03-26 21:55     ` Serge E. Hallyn
2007-03-31  2:47   ` Srivatsa Vaddagiri
2007-04-02 14:09     ` Serge E. Hallyn
2007-04-02 14:27       ` Srivatsa Vaddagiri
2007-04-02 18:02         ` Eric W. Biederman
2007-04-03 14:16           ` Srivatsa Vaddagiri
2007-04-03 15:32           ` Serge E. Hallyn
2007-04-03 15:45             ` Paul Menage
2007-04-03 15:54               ` Serge E. Hallyn
2007-04-03 16:16               ` Srivatsa Vaddagiri
2007-04-03 16:26               ` Kirill Korotaev
2007-04-03 16:46               ` Srivatsa Vaddagiri
2007-04-03 16:52                 ` Paul Menage
2007-04-03 17:11                   ` Srivatsa Vaddagiri
2007-04-03 17:10                     ` Paul Menage
2007-04-03 17:30                       ` Srivatsa Vaddagiri
2007-04-03 17:30                         ` Paul Menage
2007-04-03 17:51                           ` Srivatsa Vaddagiri
2007-04-03 17:49                             ` Paul Menage
2007-04-04  3:07                               ` Srivatsa Vaddagiri
2007-04-04  3:44                                 ` Paul Jackson
2007-04-04  4:04                                 ` Paul Menage
2007-04-04  5:15                                   ` Srivatsa Vaddagiri
2007-04-04  7:00                                     ` Paul Menage
2007-04-04 17:26                                       ` Srivatsa Vaddagiri
2007-04-04 17:42                                         ` Srivatsa Vaddagiri
2007-04-04 18:57                                         ` Paul Menage
2007-04-04 23:02                                           ` Eric W. Biederman
2007-04-05  1:35                                             ` Paul Menage
2007-04-05  1:37                                               ` Paul Menage
2007-04-05 16:57                                           ` Srivatsa Vaddagiri
2007-04-05 17:14                                             ` Srivatsa Vaddagiri
2007-04-06 21:54                                             ` Paul Menage
2007-04-05  2:57                                         ` Paul Menage
2007-04-05  6:39                                           ` Srivatsa Vaddagiri
2007-04-05  6:46                                             ` Srivatsa Vaddagiri
2007-04-05  6:48                                             ` Paul Menage
2007-04-05  8:49                                               ` Srivatsa Vaddagiri
2007-04-05  9:29                                                 ` Paul Menage
2007-04-05 12:43                                                   ` Srivatsa Vaddagiri
2007-04-05 14:13                                                     ` Srivatsa Vaddagiri
2007-04-05 14:13                                                     ` Paul Menage
2007-04-05 14:46                                                       ` Srivatsa Vaddagiri
2007-04-03 17:34                       ` Srivatsa Vaddagiri
2007-04-03 17:29                         ` Paul Menage
2007-04-03 16:10             ` Srivatsa Vaddagiri
2007-04-03 15:41           ` Serge E. Hallyn
2007-02-12  9:18 ` [PATCH 0/7] containers (V7): Generic Process Containers Paul Jackson
2007-02-12  9:32   ` Paul Menage
2007-02-12  9:52     ` Paul Jackson
     [not found] ` <20070212085104.485337000@menage.corp.google.com>
2007-02-12 15:27   ` [PATCH 3/7] containers (V7): Add generic multi-subsystem API to containers Srivatsa Vaddagiri
2007-02-12 18:40     ` Paul Menage
2007-02-13 13:19       ` Srivatsa Vaddagiri
2007-02-15  1:17         ` Paul Menage
2007-02-12 15:39   ` Serge E. Hallyn
2007-02-12 15:56     ` Cedric Le Goater
2007-02-12 18:31       ` Paul Menage
2007-02-14  8:49   ` Balbir Singh
2007-03-08 17:52   ` Srivatsa Vaddagiri
2007-03-24 12:51   ` [ckrm-tech] " Srivatsa Vaddagiri
2007-02-12 22:38 ` [PATCH 0/7] containers (V7): Generic Process Containers Sam Vilain
2007-02-12 22:47   ` Serge E. Hallyn
2007-02-12 23:18     ` Paul Menage
2007-02-12 23:15   ` Paul Menage
2007-02-13  0:30     ` Sam Vilain
2007-02-13  0:42       ` [ckrm-tech] " Paul Menage
2007-02-13  1:13         ` Sam Vilain
2007-02-13  1:47           ` Paul Menage
2007-02-20 17:34     ` Eric W. Biederman
2007-02-20 17:55       ` Paul Menage
2007-02-20 19:29         ` Eric W. Biederman
2007-02-20 22:47           ` Paul Menage
2007-02-20 23:08             ` Sam Vilain
2007-02-20 23:36               ` Paul Menage
2007-02-20 23:32             ` Serge E. Hallyn
2007-02-20 21:58         ` Sam Vilain
2007-02-20 22:19           ` Paul Menage
2007-02-20 22:58             ` Sam Vilain
2007-02-20 23:28               ` Paul Menage
2007-02-20 23:37               ` Serge E. Hallyn

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=45D189B0.6090702@sw.ru \
    --to=xemul@sw.ru \
    --cc=akpm@osdl.org \
    --cc=ckrm-tech@lists.sourceforge.net \
    --cc=containers@lists.osdl.org \
    --cc=dev@sw.ru \
    --cc=devel@openvz.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbligh@google.com \
    --cc=menage@google.com \
    --cc=pj@sgi.com \
    --cc=rohitseth@google.com \
    --cc=sekharan@us.ibm.com \
    --cc=serue@us.ibm.com \
    --cc=vatsa@in.ibm.com \
    --cc=winget@google.com \
    /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.