mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arjan van de Ven <arjan@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: Arjan van de Ven <arjan@infradead.org>,
	linux-fs@vger.kernel.org, torvalds@linux-foundation.org
Subject: [PATCH 1/2] async: allow for multiple independent synchronization domains
Date: Tue, 6 Jan 2009 13:07:33 -0800	[thread overview]
Message-ID: <20090106130733.751fe2c3@infradead.org> (raw)
In-Reply-To: <20090106130628.59d63bee@infradead.org>

>From 6353d3c8c9e11127961c2f366abc8ea0c7cb0e92 Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjan@linux.intel.com>
Date: Tue, 6 Jan 2009 07:19:33 -0800
Subject: [PATCH] async: allow for multiple independent synchronization domains

for a wider use of async function calls it's nice to have multiple
domains for synchronization, for example, in the VFS world each superblock
would be its own domain.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 include/linux/async.h |    4 ++++
 kernel/async.c        |   49 +++++++++++++++++++++++++++++++++++--------------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/include/linux/async.h b/include/linux/async.h
index 678d4fd..6f0a3ba 100644
--- a/include/linux/async.h
+++ b/include/linux/async.h
@@ -11,11 +11,15 @@
  */
 
 #include <linux/types.h>
+#include <linux/list.h>
 
 typedef u64 async_cookie_t;
 typedef void (async_func_ptr) (void *data, async_cookie_t cookie);
 
 extern async_cookie_t async_schedule(async_func_ptr *ptr, void *data);
+extern async_cookie_t async_schedule_special(async_func_ptr *ptr, void *data, struct list_head *list);
 extern void async_synchronize_full(void);
+extern void async_synchronize_full_special(struct list_head *list);
 extern void async_synchronize_cookie(async_cookie_t cookie);
+extern void async_synchronize_cookie_special(async_cookie_t cookie, struct list_head *list);
 
diff --git a/kernel/async.c b/kernel/async.c
index 8ecebf5..652804b 100644
--- a/kernel/async.c
+++ b/kernel/async.c
@@ -57,7 +57,6 @@ asynchronous and synchronous parts of the kernel.
 #include <asm/atomic.h>
 
 static async_cookie_t next_cookie = 1;
-static async_cookie_t lowest_in_progress = 1;
 
 
 static LIST_HEAD(async_pending);
@@ -69,6 +68,7 @@ struct async_entry {
 	async_cookie_t   cookie;
 	async_func_ptr	 *func;
 	void             *data;
+	struct list_head *running;
 };
 
 static DECLARE_WAIT_QUEUE_HEAD(async_done);
@@ -83,20 +83,20 @@ extern int initcall_debug;
 /*
  * MUST be called with the lock held!
  */
-static void __recalc_lowest_in_progress(void)
+static async_cookie_t  __lowest_in_progress(struct list_head *running)
 {
 	struct async_entry *entry;
 	if (!list_empty(&async_pending)) {
 		entry = list_first_entry(&async_pending,
 			struct async_entry, list);
-		lowest_in_progress = entry->cookie;
-	} else if (!list_empty(&async_running)) {
-		entry = list_first_entry(&async_running,
+		return entry->cookie;
+	} else if (!list_empty(running)) {
+		entry = list_first_entry(running,
 			struct async_entry, list);
-		lowest_in_progress = entry->cookie;
+		return entry->cookie;
 	} else {
 		/* nothing in progress... next_cookie is "infinity" */
-		lowest_in_progress = next_cookie;
+		return next_cookie;
 	}
 
 }
@@ -142,12 +142,9 @@ static void run_one_entry(void)
 	kfree(entry);
 	atomic_dec(&entry_count);
 
-	/* 6) update the lowest_in_progress value */
-	__recalc_lowest_in_progress();
-
 	spin_unlock_irqrestore(&async_lock, flags);
 
-	/* 7) wake up any waiters. */
+	/* 6) wake up any waiters. */
 	wake_up(&async_done);
 	return;
 
@@ -156,7 +153,7 @@ out:
 }
 
 
-async_cookie_t async_schedule(async_func_ptr *ptr, void *data)
+static async_cookie_t __async_schedule(async_func_ptr *ptr, void *data, struct list_head *running)
 {
 	struct async_entry *entry;
 	unsigned long flags;
@@ -176,6 +173,7 @@ async_cookie_t async_schedule(async_func_ptr *ptr, void *data)
 	}
 	entry->func = ptr;
 	entry->data = data;
+	entry->running = running;
 
 	spin_lock_irqsave(&async_lock, flags);
 	newcookie = entry->cookie = next_cookie++;
@@ -185,15 +183,32 @@ async_cookie_t async_schedule(async_func_ptr *ptr, void *data)
 	wake_up(&async_new);
 	return newcookie;
 }
+
+async_cookie_t async_schedule(async_func_ptr *ptr, void *data)
+{
+	return __async_schedule(ptr, data, &async_pending);
+}
 EXPORT_SYMBOL_GPL(async_schedule);
 
+async_cookie_t async_schedule_special(async_func_ptr *ptr, void *data, struct list_head *running)
+{
+	return __async_schedule(ptr, data, running);
+}
+EXPORT_SYMBOL_GPL(async_schedule_special);
+
 void async_synchronize_full(void)
 {
 	async_synchronize_cookie(next_cookie);
 }
 EXPORT_SYMBOL_GPL(async_synchronize_full);
 
-void async_synchronize_cookie(async_cookie_t cookie)
+void async_synchronize_full_special(struct list_head *list)
+{
+	async_synchronize_cookie_special(next_cookie, list);
+}
+EXPORT_SYMBOL_GPL(async_synchronize_full_special);
+
+void async_synchronize_cookie_special(async_cookie_t cookie, struct list_head *running)
 {
 	ktime_t starttime, delta, endtime;
 
@@ -202,7 +217,7 @@ void async_synchronize_cookie(async_cookie_t cookie)
 		starttime = ktime_get();
 	}
 
-	wait_event(async_done, lowest_in_progress >= cookie);
+	wait_event(async_done, __lowest_in_progress(running) >= cookie);
 
 	if (initcall_debug) {
 		endtime = ktime_get();
@@ -212,6 +227,12 @@ void async_synchronize_cookie(async_cookie_t cookie)
 			task_pid_nr(current), ktime_to_ns(delta) >> 10);
 	}
 }
+EXPORT_SYMBOL_GPL(async_synchronize_cookie_special);
+
+void async_synchronize_cookie(async_cookie_t cookie)
+{
+	async_synchronize_cookie_special(cookie, &async_running);
+}
 EXPORT_SYMBOL_GPL(async_synchronize_cookie);
 
 
-- 
1.5.5.1



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

  reply	other threads:[~2009-01-06 21:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-06 21:06 [PATCH 0/2] Push the asynchronous function call concept a little further Arjan van de Ven
2009-01-06 21:07 ` Arjan van de Ven [this message]
2009-01-06 21:08 ` [PATCH 2/2] async: make the final inode deletion an asynchronous event Arjan van de Ven

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=20090106130733.751fe2c3@infradead.org \
    --to=arjan@infradead.org \
    --cc=linux-fs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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