All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Philippe Gerum <rpm@xenomai.org>
Cc: xenomai@xenomai.org
Subject: [Xenomai-core] [PATCH v3 2/9] nucleus: Use Linux spin lock for heap list management
Date: Tue, 20 Oct 2009 13:37:25 +0200	[thread overview]
Message-ID: <20091020113725.9069.39805.stgit@domain.hid> (raw)
In-Reply-To: <20091020113724.9069.23594.stgit@domain.hid>

No need for hard nklock protection of kheapq and the map counter, a
normal spin lock suffices as all users must run over the root thread
anyway.

Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---

 ksrc/nucleus/heap.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/ksrc/nucleus/heap.c b/ksrc/nucleus/heap.c
index 9ca2591..9ba5227 100644
--- a/ksrc/nucleus/heap.c
+++ b/ksrc/nucleus/heap.c
@@ -951,8 +951,10 @@ EXPORT_SYMBOL_GPL(xnheap_check_block);
 #include <linux/device.h>
 #include <linux/vmalloc.h>
 #include <linux/mm.h>
+#include <linux/spinlock.h>
 
 static DEFINE_XNQUEUE(kheapq);	/* Shared heap queue. */
+static DEFINE_SPINLOCK(kheapq_lock);
 
 static inline void *__alloc_and_reserve_heap(size_t size, int kmflags)
 {
@@ -1022,14 +1024,13 @@ static void __unreserve_and_free_heap(void *ptr, size_t size, int kmflags)
 static void xnheap_vmclose(struct vm_area_struct *vma)
 {
 	xnheap_t *heap = vma->vm_private_data;
-	spl_t s;
 
-	xnlock_get_irqsave(&nklock, s);
+	spin_lock(&kheapq_lock);
 
 	if (atomic_dec_and_test(&heap->archdep.numaps)) {
 		if (heap->archdep.release) {
 			removeq(&kheapq, &heap->link);
-			xnlock_put_irqrestore(&nklock, s);
+			spin_unlock(&kheapq_lock);
 			__unreserve_and_free_heap(heap->archdep.heapbase,
 						  xnheap_extentsize(heap),
 						  heap->archdep.kmflags);
@@ -1038,7 +1039,7 @@ static void xnheap_vmclose(struct vm_area_struct *vma)
 		}
 	}
 
-	xnlock_put_irqrestore(&nklock, s);
+	spin_unlock(&kheapq_lock);
 }
 
 static struct vm_operations_struct xnheap_vmops = {
@@ -1068,9 +1069,8 @@ static int xnheap_ioctl(struct inode *inode,
 {
 	xnheap_t *heap;
 	int err = 0;
-	spl_t s;
 
-	xnlock_get_irqsave(&nklock, s);
+	spin_lock(&kheapq_lock);
 
 	heap = __validate_heap_addr((void *)arg);
 
@@ -1083,7 +1083,7 @@ static int xnheap_ioctl(struct inode *inode,
 
       unlock_and_exit:
 
-	xnlock_put_irqrestore(&nklock, s);
+	spin_unlock(&kheapq_lock);
 
 	return err;
 }
@@ -1148,7 +1148,6 @@ static int xnheap_mmap(struct file *file, struct vm_area_struct *vma)
 int xnheap_init_mapped(xnheap_t *heap, u_long heapsize, int memflags)
 {
 	void *heapbase;
-	spl_t s;
 	int err;
 
 	/* Caller must have accounted for internal overhead. */
@@ -1172,9 +1171,9 @@ int xnheap_init_mapped(xnheap_t *heap, u_long heapsize, int memflags)
 	heap->archdep.heapbase = heapbase;
 	heap->archdep.release = NULL;
 
-	xnlock_get_irqsave(&nklock, s);
+	spin_lock(&kheapq_lock);
 	appendq(&kheapq, &heap->link);
-	xnlock_put_irqrestore(&nklock, s);
+	spin_unlock(&kheapq_lock);
 
 	return 0;
 }
@@ -1184,20 +1183,19 @@ int xnheap_destroy_mapped(xnheap_t *heap, void (*release)(struct xnheap *heap),
 {
 	int ret = 0, ccheck;
 	unsigned long len;
-	spl_t s;
 
 	ccheck = mapaddr ? 1 : 0;
 
-	xnlock_get_irqsave(&nklock, s);
+	spin_lock(&kheapq_lock);
 
 	if (atomic_read(&heap->archdep.numaps) > ccheck) {
 		heap->archdep.release = release;
-		xnlock_put_irqrestore(&nklock, s);
+		spin_unlock(&kheapq_lock);
 		return -EBUSY;
 	}
 
 	removeq(&kheapq, &heap->link); /* Prevent further mapping. */
-	xnlock_put_irqrestore(&nklock, s);
+	spin_unlock(&kheapq_lock);
 
 	len = xnheap_extentsize(heap);
 



  parent reply	other threads:[~2009-10-20 11:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-20 11:37 [Xenomai-core] [PATCH v3 0/9] heap setup/cleanup fixes, refactorings & more Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 4/9] nucleus: xnheap_destroy does not fail Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 3/9] nucleus: Fix race window in heap mapping procedure Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 6/9] rtai: Try to fix _shm_free Jan Kiszka
2009-10-24 17:25   ` Philippe Gerum
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 5/9] nucleus: Avoid returning errors from xnheap_destroy_mapped Jan Kiszka
2009-10-24 17:22   ` Philippe Gerum
2009-11-02 16:04     ` Philippe Gerum
2009-11-02 16:41       ` Jan Kiszka
2009-11-02 16:51         ` Philippe Gerum
2009-11-02 16:57           ` Jan Kiszka
2009-11-02 18:01             ` Jan Kiszka
2009-11-02 18:19               ` [Xenomai-help] Xenomai on ARMadeus Pierre Ficheux
2009-11-02 18:22                 ` Gilles Chanteperdrix
2009-11-02 18:38                 ` Gilles Chanteperdrix
2009-11-02 19:19                   ` gwenhael.goavec
2009-11-02 22:29                     ` Gilles Chanteperdrix
2009-11-03  7:36                       ` gwenhael.goavec
     [not found]                       ` <20091103082204.248eed59@domain.hid>
2009-11-04 13:14                         ` Gilles Chanteperdrix
     [not found]                           ` <fbc4f538a6f4d84cfe514aba0985a525.squirrel@domain.hid>
2009-11-12 14:59                             ` Gilles Chanteperdrix
2009-11-02 18:26               ` [Xenomai-core] [PATCH v3 5/9] nucleus: Avoid returning errors from xnheap_destroy_mapped Philippe Gerum
2009-11-03  8:26                 ` Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 1/9] native: Release fastlock to the proper heap Jan Kiszka
2009-10-20 11:37 ` Jan Kiszka [this message]
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 8/9] native: Fix memory leak on heap/queue auto-deletion Jan Kiszka
2009-10-22 10:30   ` [Xenomai-core] [PATCH] native: Avoid double release on queue/heap auto-cleanup Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 9/9] nucleus: Include all heaps in statistics Jan Kiszka
2009-10-20 23:41   ` Philippe Gerum
2009-10-22 10:52     ` Jan Kiszka
2009-11-11 12:59       ` Jan Kiszka
2009-11-15 17:38         ` Philippe Gerum
2009-11-16 12:38           ` Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 7/9] native: Do not requeue on auto-cleanup errors Jan Kiszka

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=20091020113725.9069.39805.stgit@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=rpm@xenomai.org \
    --cc=xenomai@xenomai.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.