mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kirill Korotaev <dev@sw.ru>
To: Andrew Morton <akpm@osdl.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	Pavel Emelianov <xemul@openvz.org>, Andrey Savochkin <saw@sw.ru>,
	devel@openvz.org, Rik van Riel <riel@redhat.com>,
	Andi Kleen <ak@suse.de>, Greg KH <greg@kroah.com>,
	Oleg Nesterov <oleg@tv-sign.ru>,
	Matt Helsley <matthltc@us.ibm.com>,
	Rohit Seth <rohitseth@google.com>,
	Chandra Seetharaman <sekharan@us.ibm.com>
Subject: [PATCH 3/6] BC: context inheriting and changing
Date: Wed, 23 Aug 2006 15:05:11 +0400	[thread overview]
Message-ID: <44EC3667.1010800@sw.ru> (raw)
In-Reply-To: <44EC31FB.2050002@sw.ru>

Contains code responsible for setting BC on task,
it's inheriting and setting host context in interrupts.

Task references 2 beancounters:
 1. exec_bc: current context. all resources are
             charged to this beancounter.
 3. fork_bc: beancounter which is inherited by
             task's children on fork

Signed-off-by: Pavel Emelianov <xemul@sw.ru>
Signed-off-by: Kirill Korotaev <dev@sw.ru>

---

 include/linux/sched.h   |    5 ++++
 include/bc/task.h       |   52 ++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/fork.c           |   17 +++++++++++++--
 kernel/irq/handle.c     |    9 ++++++++
 kernel/softirq.c        |    8 +++++++
 kernel/bc/Makefile      |    1 
 kernel/bc/beancounter.c |    3 ++
 kernel/bc/misc.c        |   32 +++++++++++++++++++++++++++++
 8 files changed, 125 insertions(+), 2 deletions(-)

--- ./include/linux/sched.h.ve2	2006-08-21 13:15:39.000000000 +0400
+++ ./include/linux/sched.h	2006-08-21 13:26:03.000000000 +0400
@@ -83,6 +83,8 @@ struct sched_param {
 #include <linux/timer.h>
 #include <linux/hrtimer.h>
 
+#include <bc/task.h>
+
 #include <asm/processor.h>
 
 struct exec_domain;
@@ -1032,6 +1034,9 @@ struct task_struct {
 	spinlock_t delays_lock;
 	struct task_delay_info *delays;
 #endif
+#ifdef CONFIG_BEANCOUNTERS
+	struct task_beancounter	task_bc;
+#endif
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
--- ./include/bc/task.h.ve2	2006-08-21 13:26:03.000000000 +0400
+++ ./include/bc/task.h	2006-08-21 13:35:04.000000000 +0400
@@ -0,0 +1,52 @@
+/*
+ *  include/bc/task.h
+ *
+ *  Copyright (C) 2006 OpenVZ. SWsoft Inc
+ *
+ */
+
+#ifndef __BC_TASK_H_
+#define __BC_TASK_H_
+
+#include <linux/config.h>
+
+struct beancounter;
+
+struct task_beancounter {
+	struct beancounter *exec_bc;
+	struct beancounter *fork_bc;
+};
+
+#ifdef CONFIG_BEANCOUNTERS
+
+#define get_exec_bc()		(current->task_bc.exec_bc)
+#define set_exec_bc(new)			\
+	({					\
+		 struct beancounter *old;	\
+		 struct task_beancounter *tbc;	\
+		 tbc = &current->task_bc;	\
+		 old = tbc->exec_bc;		\
+		 tbc->exec_bc = new;		\
+		 old;				\
+	 })
+#define reset_exec_bc(old, exp)			\
+	do {					\
+		struct task_beancounter *tbc;	\
+		tbc = &current->task_bc;	\
+		BUG_ON(tbc->exec_bc != exp);	\
+		tbc->exec_bc = old;		\
+	} while (0)
+
+int bc_task_charge(struct task_struct *parent, struct task_struct *new);
+void bc_task_uncharge(struct task_struct *tsk);
+
+#else
+
+#define get_exec_bc()		(NULL)
+#define set_exec_bc(new)	(NULL)
+#define reset_exec_bc(new, exp)	do { } while (0)
+#define bc_task_charge(p, t)	(0)
+#define bc_task_uncharge(p)	do { } while (0)
+
+#endif
+#endif
--- ./kernel/fork.c.ve2	2006-08-21 13:15:39.000000000 +0400
+++ ./kernel/fork.c	2006-08-21 13:40:16.000000000 +0400
@@ -48,6 +48,8 @@
 #include <linux/taskstats_kern.h>
 #include <linux/random.h>
 
+#include <bc/task.h>
+
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/uaccess.h>
@@ -102,12 +104,18 @@ kmem_cache_t *vm_area_cachep;
 /* SLAB cache for mm_struct structures (tsk->mm) */
 static kmem_cache_t *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)
+{
+	bc_task_uncharge(tsk);
+	__free_task(tsk);
+}
 EXPORT_SYMBOL(free_task);
 
 void __put_task_struct(struct task_struct *tsk)
@@ -978,6 +986,9 @@ static struct task_struct *copy_process(
 	if (!p)
 		goto fork_out;
 
+	if (bc_task_charge(current, p))
+		goto bad_charge;
+
 #ifdef CONFIG_TRACE_IRQFLAGS
 	DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
 	DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
@@ -1291,7 +1302,9 @@ bad_fork_cleanup_count:
 	atomic_dec(&p->user->processes);
 	free_uid(p->user);
 bad_fork_free:
-	free_task(p);
+	bc_task_uncharge(p);
+bad_charge:
+	__free_task(p);
 fork_out:
 	return ERR_PTR(retval);
 }
--- ./kernel/irq/handle.c.ve2	2006-07-10 12:39:20.000000000 +0400
+++ ./kernel/irq/handle.c	2006-08-21 13:42:13.000000000 +0400
@@ -16,6 +16,9 @@
 #include <linux/interrupt.h>
 #include <linux/kernel_stat.h>
 
+#include <bc/beancounter.h>
+#include <bc/task.h>
+
 #include "internals.h"
 
 /**
@@ -166,6 +169,9 @@ fastcall unsigned int __do_IRQ(unsigned 
 	struct irq_desc *desc = irq_desc + irq;
 	struct irqaction *action;
 	unsigned int status;
+	struct beancounter *bc;
+
+	bc = set_exec_bc(&init_bc);
 
 	kstat_this_cpu.irqs[irq]++;
 	if (CHECK_IRQ_PER_CPU(desc->status)) {
@@ -178,6 +184,8 @@ fastcall unsigned int __do_IRQ(unsigned 
 			desc->chip->ack(irq);
 		action_ret = handle_IRQ_event(irq, regs, desc->action);
 		desc->chip->end(irq);
+
+		reset_exec_bc(bc, &init_bc);
 		return 1;
 	}
 
@@ -246,6 +254,7 @@ out:
 	desc->chip->end(irq);
 	spin_unlock(&desc->lock);
 
+	reset_exec_bc(bc, &init_bc);
 	return 1;
 }
 
--- ./kernel/softirq.c.ve2	2006-08-21 13:15:39.000000000 +0400
+++ ./kernel/softirq.c	2006-08-21 13:41:04.000000000 +0400
@@ -18,6 +18,9 @@
 #include <linux/rcupdate.h>
 #include <linux/smp.h>
 
+#include <bc/beancounter.h>
+#include <bc/task.h>
+
 #include <asm/irq.h>
 /*
    - No shared variables, all the data are CPU local.
@@ -209,6 +212,9 @@ asmlinkage void __do_softirq(void)
 	__u32 pending;
 	int max_restart = MAX_SOFTIRQ_RESTART;
 	int cpu;
+	struct beancounter *bc;
+
+	bc = set_exec_bc(&init_bc);
 
 	pending = local_softirq_pending();
 	account_system_vtime(current);
@@ -247,6 +253,8 @@ restart:
 
 	account_system_vtime(current);
 	_local_bh_enable();
+
+	reset_exec_bc(bc, &init_bc);
 }
 
 #ifndef __ARCH_HAS_DO_SOFTIRQ
--- ./kernel/bc/Makefile.ve2	2006-08-21 13:26:03.000000000 +0400
+++ ./kernel/bc/Makefile	2006-08-21 13:26:03.000000000 +0400
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_BEANCOUNTERS) += beancounter.o
+obj-$(CONFIG_BEANCOUNTERS) += misc.o
--- ./kernel/bc/beancounter.c.ve2	2006-08-21 13:13:11.000000000 +0400
+++ ./kernel/bc/beancounter.c	2006-08-21 13:13:11.000000000 +0400
@@ -280,6 +280,9 @@
 	spin_lock_init(&bc_hash_lock);
 	slot = &bc_hash[bc_hash_fun(bc->bc_id)];
 	hlist_add_head(&bc->hash, slot);
+
+	current->task_bc.exec_bc = get_beancounter(bc);
+	current->task_bc.fork_bc = get_beancounter(bc);
 }
 
 void __init bc_init_late(void)
--- ./kernel/bc/misc.c.ve2	2006-08-21 13:26:03.000000000 +0400
+++ ./kernel/bc/misc.c	2006-08-21 13:39:07.000000000 +0400
@@ -0,0 +1,32 @@
+/*
+ * kernel/bc/misc.c
+ *
+ * Copyright (C) 2006 OpenVZ. SWsoft Inc.
+ *
+ */
+
+#include <linux/sched.h>
+
+#include <bc/beancounter.h>
+#include <bc/task.h>
+
+int bc_task_charge(struct task_struct *parent, struct task_struct *new)
+{
+	struct task_beancounter *old_bc;
+	struct task_beancounter *new_bc;
+	struct beancounter *bc;
+
+	old_bc = &parent->task_bc;
+	new_bc = &new->task_bc;
+
+	bc = old_bc->fork_bc;
+	new_bc->exec_bc = get_beancounter(bc);
+	new_bc->fork_bc = get_beancounter(bc);
+	return 0;
+}
+
+void bc_task_uncharge(struct task_struct *tsk)
+{
+	put_beancounter(tsk->task_bc.exec_bc);
+	put_beancounter(tsk->task_bc.fork_bc);
+}

  parent reply	other threads:[~2006-08-23 11:02 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-23 10:46 [PATCH] BC: resource beancounters (v2) Kirill Korotaev
2006-08-23 11:01 ` [PATCH 1/6] BC: kconfig Kirill Korotaev
2006-08-23 13:04   ` Alexey Dobriyan
2006-08-23 22:04   ` [Devel] " Dave Hansen
2006-08-23 22:13     ` Matt Helsley
2006-08-23 22:32       ` Randy.Dunlap
2006-08-23 22:27         ` Matt Helsley
2006-08-25 11:30       ` Kirill Korotaev
2006-08-25 11:34     ` Kirill Korotaev
2006-08-24  0:23   ` Chandra Seetharaman
2006-08-24 11:47     ` [ckrm-tech] " Kirill Korotaev
2006-08-24 22:23       ` Matt Helsley
2006-08-23 11:03 ` [PATCH 2/6] BC: beancounters core (API) Kirill Korotaev
2006-08-23 11:37   ` Andi Kleen
2006-08-23 13:27     ` Kirill Korotaev
2006-08-23 13:48       ` Andi Kleen
2006-08-23 13:30   ` Alexey Dobriyan
2006-08-23 13:49     ` Kirill Korotaev
2006-08-23 13:53       ` Alexey Dobriyan
2006-08-23 22:05       ` Matt Helsley
2006-08-23 16:42   ` Andrew Morton
2006-08-24 12:06     ` Kirill Korotaev
2006-08-24 15:00       ` Andrew Morton
2006-08-25 10:53         ` Kirill Korotaev
2006-08-24 14:13     ` Oleg Nesterov
2006-08-24 21:33   ` Oleg Nesterov
2006-08-23 11:05 ` Kirill Korotaev [this message]
2006-08-23 11:06 ` [PATCH 4/6] BC: user interface (syscalls) Kirill Korotaev
2006-08-23 13:41   ` Alexey Dobriyan
2006-08-23 13:43   ` Kirill Korotaev
2006-08-23 16:50     ` Andrew Morton
2006-08-23 17:29       ` Alan Cox
2006-08-24  4:35         ` Andrew Morton
2006-08-24 11:04           ` Alan Cox
2006-08-24 13:08             ` Alexey Dobriyan
2006-08-25 10:56               ` Kirill Korotaev
2006-08-24  0:30   ` Chandra Seetharaman
2006-08-23 11:06 ` [PATCH 5/6] BC: kernel memory accounting (core) Kirill Korotaev
2006-08-24  0:36   ` Chandra Seetharaman
2006-08-24 21:23   ` Oleg Nesterov
2006-08-25 10:09     ` Kirill Korotaev
2006-08-23 11:08 ` [PATCH 6/6] BC: kernel memory accounting (marks) Kirill Korotaev
2006-08-23 18:30   ` [Devel] " Dave Hansen
2006-08-29  9:52     ` Kirill Korotaev
2006-08-29 15:48       ` Dave Hansen
2006-08-29 15:56         ` Kirill Korotaev
2006-08-23 23:03   ` Dave Hansen
2006-08-24  9:30     ` Geert Uytterhoeven
2006-08-24 15:52       ` Dave Hansen
2006-08-29 14:37     ` Kirill Korotaev
2006-08-23 17:05 ` [PATCH] BC: resource beancounters (v2) Andrew Morton
2006-08-24  0:17   ` Chandra Seetharaman
2006-08-25 11:49   ` Kirill Korotaev
2006-08-25 14:30     ` Andrew Morton
2006-08-25 14:48       ` Andi Kleen
2006-08-28  8:28         ` Kirill Korotaev
2006-08-25 15:14       ` Nick Piggin
2006-08-25 15:57         ` Alan Cox
2006-08-26  3:55           ` Nick Piggin
2006-08-25 16:30       ` Andrey Savochkin
2006-08-25 17:50         ` Andrew Morton
2006-08-25 19:00         ` Chandra Seetharaman
2006-08-26  2:15         ` Rohit Seth
2006-08-26 16:37           ` Alan Cox
2006-08-28 16:48             ` Rohit Seth
2006-08-28 17:41               ` [Devel] " Kir Kolyshkin
2006-08-28 22:28                 ` Rohit Seth
2006-08-29 10:15                   ` Alan Cox
2006-08-29 17:30                     ` Rohit Seth
2006-08-29 19:06                       ` Alan Cox
2006-08-29 19:15                         ` Rohit Seth
2006-08-29 15:35       ` [PATCH] " Kirill Korotaev
2006-08-29 17:08         ` Balbir Singh
2006-08-23 21:00 ` Cedric Le Goater
2006-08-24  5:52 ` Jan Engelhardt
2006-08-24 10:59   ` Alan Cox

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=44EC3667.1010800@sw.ru \
    --to=dev@sw.ru \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=devel@openvz.org \
    --cc=greg@kroah.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthltc@us.ibm.com \
    --cc=oleg@tv-sign.ru \
    --cc=riel@redhat.com \
    --cc=rohitseth@google.com \
    --cc=saw@sw.ru \
    --cc=sekharan@us.ibm.com \
    --cc=xemul@openvz.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome