Re: [Xenomai-core] [PATCH v3 02/24] RTDM: Add rtdm_rt_capable() service
Philippe Gerum wrote: On Sun, 2010-04-18 at 15:40 +0200, Jan Kiszka wrote: Philippe Gerum wrote: On Sun, 2010-04-18 at 15:26 +0200, Philippe Gerum wrote: On Sun, 2010-04-18 at 15:12 +0200, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com This adds rtdm_rt_capable(), a function that can be used by drivers to detect callers that could issue a service request also from the (typically preferred) real-time context. If that is the case, the driver can trigger a restart of the request if the current context is not real-time. CC: Philippe Gerum r...@xenomai.org CC: Alexis Berlemont berlemont.h...@free.fr Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- include/rtdm/rtdm_driver.h |6 ++ ksrc/skins/rtdm/drvlib.c | 25 + 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h index 0fc1496..45be404 100644 --- a/include/rtdm/rtdm_driver.h +++ b/include/rtdm/rtdm_driver.h @@ -1296,6 +1296,12 @@ static inline int rtdm_in_rt_context(void) { return (rthal_current_domain != rthal_root_domain); } + +static inline int rtdm_rt_capable(void) +{ + return xnpod_shadow_p(); +} + This won't do what your comment states; xnpod_shadow_p() would always return false on behalf of a relaxed shadow, since it tests the status bits of the current Xenomai thread, which has to be the root one in that case. xnpod_shadow_p is to be used in primary context only, to distinguish between kernel-based and userland Xenomai callers. What you want is probably something like: static inline int rtdm_rt_capable(void) { return xnshadow_thread(current) != NULL; } Btw, the predicate as you defined it would not work over kernel-based Xenomai threads. rtdm_rt_capable() is ambiguous here. (!xnpod_root_p() || xnshadow_thread(current) != NULL) ? That would also avoid dereferencing current in a potentially unsafe context (if we still have such problematic archs). Depending on how precise you want that predicate to be, (!xnpod_asynch_p() (!xnpod_root_p() || xnshadow_thread(current) != NULL)) may be better, in a sense that it also excludes IRQ handlers and nucleus callouts. IRQ handlers are not a valid invocation context (as documented). I don't think it's worth bothering. Jan signature.asc Description: OpenPGP digital signature ___ Xenomai-core mailing list Xenomai-core@gna.org https://mail.gna.org/listinfo/xenomai-core
Re: [Xenomai-core] [PATCH v3 02/24] RTDM: Add rtdm_rt_capable() service
On Mon, 2010-04-19 at 09:31 +0200, Jan Kiszka wrote: Philippe Gerum wrote: On Sun, 2010-04-18 at 15:40 +0200, Jan Kiszka wrote: Philippe Gerum wrote: On Sun, 2010-04-18 at 15:26 +0200, Philippe Gerum wrote: On Sun, 2010-04-18 at 15:12 +0200, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com This adds rtdm_rt_capable(), a function that can be used by drivers to detect callers that could issue a service request also from the (typically preferred) real-time context. If that is the case, the driver can trigger a restart of the request if the current context is not real-time. CC: Philippe Gerum r...@xenomai.org CC: Alexis Berlemont berlemont.h...@free.fr Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- include/rtdm/rtdm_driver.h |6 ++ ksrc/skins/rtdm/drvlib.c | 25 + 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h index 0fc1496..45be404 100644 --- a/include/rtdm/rtdm_driver.h +++ b/include/rtdm/rtdm_driver.h @@ -1296,6 +1296,12 @@ static inline int rtdm_in_rt_context(void) { return (rthal_current_domain != rthal_root_domain); } + +static inline int rtdm_rt_capable(void) +{ + return xnpod_shadow_p(); +} + This won't do what your comment states; xnpod_shadow_p() would always return false on behalf of a relaxed shadow, since it tests the status bits of the current Xenomai thread, which has to be the root one in that case. xnpod_shadow_p is to be used in primary context only, to distinguish between kernel-based and userland Xenomai callers. What you want is probably something like: static inline int rtdm_rt_capable(void) { return xnshadow_thread(current) != NULL; } Btw, the predicate as you defined it would not work over kernel-based Xenomai threads. rtdm_rt_capable() is ambiguous here. (!xnpod_root_p() || xnshadow_thread(current) != NULL) ? That would also avoid dereferencing current in a potentially unsafe context (if we still have such problematic archs). Depending on how precise you want that predicate to be, (!xnpod_asynch_p() (!xnpod_root_p() || xnshadow_thread(current) != NULL)) may be better, in a sense that it also excludes IRQ handlers and nucleus callouts. IRQ handlers are not a valid invocation context (as documented). I don't think it's worth bothering. No problem, I think the whole rtdm_rt_capable() approach leads to this kind of ambiguity by design anyway. So people should leave with it and use that predicate in high level handler code only, where the current context can be assessed easily, not deep in their helpers or core routines which might be traversed by a broader set of callers. Jan -- Philippe. ___ Xenomai-core mailing list Xenomai-core@gna.org https://mail.gna.org/listinfo/xenomai-core
Re: [Xenomai-core] [PATCH v3 02/24] RTDM: Add rtdm_rt_capable() service
On Mon, 2010-04-19 at 09:37 +0200, Philippe Gerum wrote: On Mon, 2010-04-19 at 09:31 +0200, Jan Kiszka wrote: Philippe Gerum wrote: On Sun, 2010-04-18 at 15:40 +0200, Jan Kiszka wrote: Philippe Gerum wrote: On Sun, 2010-04-18 at 15:26 +0200, Philippe Gerum wrote: On Sun, 2010-04-18 at 15:12 +0200, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com This adds rtdm_rt_capable(), a function that can be used by drivers to detect callers that could issue a service request also from the (typically preferred) real-time context. If that is the case, the driver can trigger a restart of the request if the current context is not real-time. CC: Philippe Gerum r...@xenomai.org CC: Alexis Berlemont berlemont.h...@free.fr Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- include/rtdm/rtdm_driver.h |6 ++ ksrc/skins/rtdm/drvlib.c | 25 + 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h index 0fc1496..45be404 100644 --- a/include/rtdm/rtdm_driver.h +++ b/include/rtdm/rtdm_driver.h @@ -1296,6 +1296,12 @@ static inline int rtdm_in_rt_context(void) { return (rthal_current_domain != rthal_root_domain); } + +static inline int rtdm_rt_capable(void) +{ + return xnpod_shadow_p(); +} + This won't do what your comment states; xnpod_shadow_p() would always return false on behalf of a relaxed shadow, since it tests the status bits of the current Xenomai thread, which has to be the root one in that case. xnpod_shadow_p is to be used in primary context only, to distinguish between kernel-based and userland Xenomai callers. What you want is probably something like: static inline int rtdm_rt_capable(void) { return xnshadow_thread(current) != NULL; } Btw, the predicate as you defined it would not work over kernel-based Xenomai threads. rtdm_rt_capable() is ambiguous here. (!xnpod_root_p() || xnshadow_thread(current) != NULL) ? That would also avoid dereferencing current in a potentially unsafe context (if we still have such problematic archs). Depending on how precise you want that predicate to be, (!xnpod_asynch_p() (!xnpod_root_p() || xnshadow_thread(current) != NULL)) may be better, in a sense that it also excludes IRQ handlers and nucleus callouts. IRQ handlers are not a valid invocation context (as documented). I don't think it's worth bothering. No problem, I think the whole rtdm_rt_capable() approach leads to this kind of ambiguity by design anyway. So people should leave s,leave,live,g Interesting lapsus. with it and use that predicate in high level handler code only, where the current context can be assessed easily, not deep in their helpers or core routines which might be traversed by a broader set of callers. Jan -- Philippe. ___ Xenomai-core mailing list Xenomai-core@gna.org https://mail.gna.org/listinfo/xenomai-core
Re: [Xenomai-core] [PATCH v3 02/24] RTDM: Add rtdm_rt_capable() service
On Sun, 2010-04-18 at 15:26 +0200, Philippe Gerum wrote: On Sun, 2010-04-18 at 15:12 +0200, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com This adds rtdm_rt_capable(), a function that can be used by drivers to detect callers that could issue a service request also from the (typically preferred) real-time context. If that is the case, the driver can trigger a restart of the request if the current context is not real-time. CC: Philippe Gerum r...@xenomai.org CC: Alexis Berlemont berlemont.h...@free.fr Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- include/rtdm/rtdm_driver.h |6 ++ ksrc/skins/rtdm/drvlib.c | 25 + 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h index 0fc1496..45be404 100644 --- a/include/rtdm/rtdm_driver.h +++ b/include/rtdm/rtdm_driver.h @@ -1296,6 +1296,12 @@ static inline int rtdm_in_rt_context(void) { return (rthal_current_domain != rthal_root_domain); } + +static inline int rtdm_rt_capable(void) +{ + return xnpod_shadow_p(); +} + This won't do what your comment states; xnpod_shadow_p() would always return false on behalf of a relaxed shadow, since it tests the status bits of the current Xenomai thread, which has to be the root one in that case. xnpod_shadow_p is to be used in primary context only, to distinguish between kernel-based and userland Xenomai callers. What you want is probably something like: static inline int rtdm_rt_capable(void) { return xnshadow_thread(current) != NULL; } Btw, the predicate as you defined it would not work over kernel-based Xenomai threads. rtdm_rt_capable() is ambiguous here. #endif /* !DOXYGEN_CPP */ int rtdm_exec_in_rt(struct rtdm_dev_context *context, diff --git a/ksrc/skins/rtdm/drvlib.c b/ksrc/skins/rtdm/drvlib.c index 3b04493..6e26501 100644 --- a/ksrc/skins/rtdm/drvlib.c +++ b/ksrc/skins/rtdm/drvlib.c @@ -2341,6 +2341,31 @@ int rtdm_strncpy_from_user(rtdm_user_info_t *user_info, char *dst, */ int rtdm_in_rt_context(void); +/** + * Test if the caller is capable of running in real-time context + * + * @return Non-zero is returned if the caller is able to execute in real-time + * context (independent of its current execution mode), 0 otherwise. + * + * @note This function can be used by drivers that provide different + * implementations for the same service depending on the execution mode of + * the caller. If a caller requests such a service in non-real-time context + * but is capable of running in real-time as well, it might be appropriate + * for the driver to reject the request via -ENOSYS so that RTDM can switch + * the caller and restart the request in real-time context. + * + * Environments: + * + * This service can be called from: + * + * - Kernel module initialization/cleanup code + * - Kernel-based task + * - User-space task (RT, non-RT) + * + * Rescheduling: never. + */ +int rtdm_rt_capable(void); + #endif /* DOXYGEN_CPP */ /** @} Utility Services */ -- Philippe. ___ Xenomai-core mailing list Xenomai-core@gna.org https://mail.gna.org/listinfo/xenomai-core
Re: [Xenomai-core] [PATCH v3 02/24] RTDM: Add rtdm_rt_capable() service
Philippe Gerum wrote: On Sun, 2010-04-18 at 15:26 +0200, Philippe Gerum wrote: On Sun, 2010-04-18 at 15:12 +0200, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com This adds rtdm_rt_capable(), a function that can be used by drivers to detect callers that could issue a service request also from the (typically preferred) real-time context. If that is the case, the driver can trigger a restart of the request if the current context is not real-time. CC: Philippe Gerum r...@xenomai.org CC: Alexis Berlemont berlemont.h...@free.fr Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- include/rtdm/rtdm_driver.h |6 ++ ksrc/skins/rtdm/drvlib.c | 25 + 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h index 0fc1496..45be404 100644 --- a/include/rtdm/rtdm_driver.h +++ b/include/rtdm/rtdm_driver.h @@ -1296,6 +1296,12 @@ static inline int rtdm_in_rt_context(void) { return (rthal_current_domain != rthal_root_domain); } + +static inline int rtdm_rt_capable(void) +{ + return xnpod_shadow_p(); +} + This won't do what your comment states; xnpod_shadow_p() would always return false on behalf of a relaxed shadow, since it tests the status bits of the current Xenomai thread, which has to be the root one in that case. xnpod_shadow_p is to be used in primary context only, to distinguish between kernel-based and userland Xenomai callers. What you want is probably something like: static inline int rtdm_rt_capable(void) { return xnshadow_thread(current) != NULL; } Btw, the predicate as you defined it would not work over kernel-based Xenomai threads. rtdm_rt_capable() is ambiguous here. (!xnpod_root_p() || xnshadow_thread(current) != NULL) ? That would also avoid dereferencing current in a potentially unsafe context (if we still have such problematic archs). Jan signature.asc Description: OpenPGP digital signature ___ Xenomai-core mailing list Xenomai-core@gna.org https://mail.gna.org/listinfo/xenomai-core