All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: rpm@xenomai.org
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Problem with pthread_setschedparam
Date: Thu, 10 May 2007 17:45:42 +0200	[thread overview]
Message-ID: <46433E26.8040307@domain.hid> (raw)
In-Reply-To: <1178810494.11688.188.camel@domain.hid>

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

Philippe Gerum wrote:
> On Thu, 2007-05-10 at 16:53 +0200, Gilles Chanteperdrix wrote:
> 
>>Philippe Gerum wrote:
>>
>>>On Thu, 2007-05-10 at 11:33 +0200, Gilles Chanteperdrix wrote:
>>>
>>>
>>>>Philippe Gerum wrote:
>>>>
>>>>>xnfreesafe was meant to prevent the caller from releasing some memory it
>>>>>could still rely on, e.g. stack space, by postponing the actual release
>>>>>until the idle thread is resumed. In your case, the problem is that it
>>>>>does not account for the primary/secondary mode of a shadow thread.
>>>>
>>>>I am not so sure. I mean, even if the thread was deleted from the
>>>>context of another thread, the two hooks would be invoked and we would
>>>>need the free operation to be deferred until after the execution of the
>>>>second hook.
>>>>
>>>
>>>
>>>The point is that deletion hooks are always called on behalf of the
>>>exiting thread in secondary mode, so if xnfreesafe properly identifies
>>>the caller as the current thread - regardless of its exec mode - then
>>>the deferral should always take place. But I agree on the fact that we
>>>should always end up running the deferred call in this context anyway,
>>>so we would be better off calling xnheap_schedule_free() directly.
>>
>>That is why, since xnfreesafe was only called in this precise context, I
>>redefined it to call xnheap_schedule_free directly.
>>
> 
> 
> Well, ok. But we may need the xnfreesafe() interface in the future, the
> way it was designed initially, I mean. So let's call
> xnheap_schedule_free directly when needed.
> 

Hence the final patch:

-- 
                                                 Gilles Chanteperdrix

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xeno-use-xnheap_schedule_free.diff --]
[-- Type: text/x-patch; name="xeno-use-xnheap_schedule_free.diff", Size: 4116 bytes --]

Index: v2.3.x/include/nucleus/heap.h
===================================================================
--- v2.3.x/include/nucleus/heap.h	(révision 2429)
+++ v2.3.x/include/nucleus/heap.h	(copie de travail)
@@ -120,7 +120,7 @@
 #define xnfreesync()       xnheap_finalize_free(&kheap)
 #define xnfreesafe(thread,ptr,ln) \
 do { \
-    if (xnpod_current_thread() == thread) \
+    if (xnpod_current_p(thread))	     \
 	xnheap_schedule_free(&kheap,ptr,ln); \
     else \
 	xnheap_free(&kheap,ptr); \
Index: v2.3.x/include/nucleus/pod.h
===================================================================
--- v2.3.x/include/nucleus/pod.h	(révision 2429)
+++ v2.3.x/include/nucleus/pod.h	(copie de travail)
@@ -297,8 +297,16 @@
 #define xnpod_current_root() \
     (&xnpod_current_sched()->rootcb)
 
+#ifdef CONFIG_XENO_OPT_PERVASIVE
+#define xnpod_current_p(thread)					\
+    ({ int __shadow_p = xnthread_test_state(thread, XNSHADOW);		\
+       int __curr_p = __shadow_p ? xnshadow_thread(current) == thread	\
+	   : thread == xnpod_current_thread();				\
+       __curr_p;})
+#else
 #define xnpod_current_p(thread) \
     (xnpod_current_thread() == (thread))
+#endif
 
 #define xnpod_locked_p() \
     (!!xnthread_test_state(xnpod_current_thread(),XNLOCK))
Index: v2.3.x/ksrc/skins/psos+/task.c
===================================================================
--- v2.3.x/ksrc/skins/psos+/task.c	(révision 2429)
+++ v2.3.x/ksrc/skins/psos+/task.c	(copie de travail)
@@ -52,7 +52,7 @@
 	xnarch_delete_display(&task->threadbase);
 	psos_mark_deleted(task);
 
-	xnfreesafe(&task->threadbase, task, &task->link);
+	xnheap_schedule_free(&kheap, task, &task->link);
 }
 
 void psostask_init(u_long rrperiod)
Index: v2.3.x/ksrc/skins/rtai/task.c
===================================================================
--- v2.3.x/ksrc/skins/rtai/task.c	(révision 2429)
+++ v2.3.x/ksrc/skins/rtai/task.c	(copie de travail)
@@ -40,7 +40,7 @@
 	rtai_mark_deleted(task);
 
 	if (xnthread_test_state(&task->thread_base, XNSHADOW))
-		xnfreesafe(&task->thread_base, task, &task->link);
+		xnheap_schedule_free(&kheap, task, &task->link);
 }
 
 static void __task_switch_hook(xnthread_t *thread)
Index: v2.3.x/ksrc/skins/posix/thread.c
===================================================================
--- v2.3.x/ksrc/skins/posix/thread.c	(révision 2429)
+++ v2.3.x/ksrc/skins/posix/thread.c	(copie de travail)
@@ -45,7 +45,7 @@
 	   called from pse51_thread_pkg_cleanup, hence the absence of
 	   xnpod_schedule(). */
 	xnsynch_destroy(&thread->join_synch);
-	xnfree(thread);
+	xnheap_schedule_free(&kheap, thread, &thread->link);
 }
 
 static void thread_trampoline(void *cookie)
Index: v2.3.x/ksrc/skins/vrtx/task.c
===================================================================
--- v2.3.x/ksrc/skins/vrtx/task.c	(révision 2429)
+++ v2.3.x/ksrc/skins/vrtx/task.c	(copie de travail)
@@ -46,7 +46,7 @@
 
 	vrtx_mark_deleted(task);
 
-	xnfreesafe(&task->threadbase, task, &task->link);
+	xnheap_schedule_free(&kheap, task, &task->link);
 }
 
 int vrtxtask_init(u_long stacksize)
Index: v2.3.x/ksrc/skins/vxworks/taskLib.c
===================================================================
--- v2.3.x/ksrc/skins/vxworks/taskLib.c	(révision 2429)
+++ v2.3.x/ksrc/skins/vxworks/taskLib.c	(copie de travail)
@@ -605,7 +605,7 @@
 	wind_mark_deleted(task);
 
 	if (task->auto_delete)
-		xnfreesafe(&task->threadbase, task, &task->link);
+		xnheap_schedule_free(&kheap, task, &task->link);
 }
 
 static void wind_task_trampoline(void *cookie)
Index: v2.3.x/ksrc/skins/native/task.c
===================================================================
--- v2.3.x/ksrc/skins/native/task.c	(révision 2429)
+++ v2.3.x/ksrc/skins/native/task.c	(copie de travail)
@@ -76,7 +76,7 @@
 	xeno_mark_deleted(task);
 
 	if (xnthread_test_state(&task->thread_base, XNSHADOW))
-		xnfreesafe(&task->thread_base, task, &task->link);
+		xnheap_schedule_free(&kheap, task, &task->link);
 }
 
 void __native_task_safe(RT_TASK *task)

  reply	other threads:[~2007-05-10 15:45 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.51.1178704831.10156.xenomai@xenomai.org>
2007-05-09 12:49 ` [Xenomai-help] Problem with pthread_setschedparam Noren, Andrew
2007-05-09 13:32   ` Gilles Chanteperdrix
2007-05-09 13:43     ` Perrine Martignoni
2007-05-09 14:35       ` Perrine Martignoni
2007-05-09 20:37         ` Gilles Chanteperdrix
2007-05-09 21:23           ` Gilles Chanteperdrix
2007-05-09 22:02             ` Philippe Gerum
     [not found]               ` <17986.20728.617772.991566@domain.hid>
     [not found]                 ` <1178784303.11688.108.camel@domain.hid>
2007-05-10  8:34                   ` Gilles Chanteperdrix
2007-05-10  8:41                     ` Gilles Chanteperdrix
2007-05-10  8:58                     ` Daniel Schnell
2007-05-10  9:12                       ` Gilles Chanteperdrix
2007-05-14  9:17                         ` Daniel Schnell
2007-05-14  9:49                           ` Wolfgang Grandegger
2007-05-14  9:56                             ` Daniel Schnell
2007-05-18  9:58                               ` Wolfgang Grandegger
2007-05-10  9:26                     ` Philippe Gerum
2007-05-10  9:33                       ` Gilles Chanteperdrix
2007-05-10 11:41                         ` Perrine Martignoni
2007-05-10 12:06                           ` Gilles Chanteperdrix
2007-05-10 12:47                             ` Perrine Martignoni
2007-05-10 12:53                               ` Gilles Chanteperdrix
2007-05-10 14:40                         ` Philippe Gerum
2007-05-10 14:53                           ` Gilles Chanteperdrix
2007-05-10 15:21                             ` Philippe Gerum
2007-05-10 15:45                               ` Gilles Chanteperdrix [this message]
2007-05-11  7:56                                 ` Perrine Martignoni
2007-05-11  8:17                                   ` Gilles Chanteperdrix
2007-05-11  8:24                                     ` Perrine Martignoni
2007-05-11  8:30                                       ` Perrine Martignoni
2007-05-11  8:50                                 ` Philippe Gerum
2007-05-09  8:55 Perrine Martignoni
2007-05-09  9:05 ` Gilles Chanteperdrix
2007-05-09  9:32 ` Gilles Chanteperdrix
2007-05-09 11:31   ` Perrine Martignoni
2007-05-09 12:34     ` Gilles Chanteperdrix

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=46433E26.8040307@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --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.