RTDM rework
Hi Jan, Philippe,
I have started working on rebasing RTDM on the common fd implementation (xnfd). Before I start changing the drivers, the current state of the changes follow as patches. These patches are based on the commits in the "for-forge" branch in xenomai-gch repository. Please do not pull from this branch just yet, it is probably going to be rebased.
The thing which I know we will discuss, even before you read the patches:
- struct xnfd appears instead of struct rtdm_dev_context in callbacks, we already discussed that, you prefer rtdm typedefs, the thing is, in forge, the habit to typedef structs seems gone, and typedef struct xnfd rtdm_dev_contex_t would be confusing since struct rtdm_dev_context still exists, albeit is no longer exported to drivers;
- the xnfd structure is defined in cobalt, and not cobalt/posix, this was made so that both rtdm and posix can use it, but maybe it makes more sense to move it to posix (after all, file descriptors are a posix thing), and get rtdm to use it anyway;
- doc is probably out of sync, this will be arranged in later commits
- maybe select should be moved to fd.c now, posix/select.c contains 3 functions, and it now supports xnfds exclusively;
- context_flags are gone, since the two flags it used are no longer used, since driver have a private structure, drivers can move their flags to their private structure if they want;
- handling -EAGAIN in the close callback is gone, the close callback now returns void, it is possible to delay file descriptor destruction by using rtdm_lock/rtdm_unlock, so the -EAGAIN return value was IMO redundant.
Regards.
Signature · 1 line
Gilles.
PATCH 1/3 cobalt/rtdm: base protocol devices on xnid
--- include/cobalt/kernel/rtdm/driver.h | 6 +- kernel/cobalt/rtdm/device.c | 103 ++++++++++++----------------------- kernel/cobalt/rtdm/internal.h | 4 +- kernel/cobalt/rtdm/proc.c | 60 ++++++++++---------- 4 files changed, 71 insertions(+), 102 deletions(-)
include/cobalt/kernel/rtdm/driver.h +5 -1
@@ -38,6 +38,7 @@#include <cobalt/kernel/clock.h> #include <cobalt/kernel/apc.h> #include <cobalt/kernel/shadow.h> +#include <cobalt/kernel/tree.h> #include <rtdm/rtdm.h> /* debug support */
@@ -443,7 +444,10 @@ rtdm_private_to_context(void *dev_private) }struct rtdm_dev_reserved { -struct list_head entry; +union { +struct list_head entry; +struct xnid id; + };atomic_t refcount;struct rtdm_dev_context *exclusive_context; };
kernel/cobalt/rtdm/device.c +36 -67
181 lines not on this page · raw message
kernel/cobalt/rtdm/internal.h +2 -2
@@ -23,6 +23,7 @@#include <linux/list.h> #include <linux/sem.h> #include <cobalt/kernel/ppd.h> +#include <cobalt/kernel/tree.h> #include <rtdm/driver.h> #define RTDM_FD_MAX CONFIG_XENO_OPT_RTDM_FILDES
@@ -49,9 +50,8 @@ extern struct rtdm_fildes fildes_table[];extern int open_fildes;extern struct semaphore nrt_dev_lock;extern unsigned int devname_hashtab_size; -extern unsigned int protocol_hashtab_size;extern struct list_head *rtdm_named_devices; -extern struct list_head *rtdm_protocol_devices; +extern struct rb_root rtdm_protocol_devices;extern struct xnpersonality rtdm_personality;extern int rtdm_initialised;
kernel/cobalt/rtdm/proc.c +28 -32
102 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 2/3 cobalt/rtdm: base named devices on nucleus registry
--- include/cobalt/kernel/rtdm/driver.h | 6 +- kernel/cobalt/rtdm/device.c | 115 +++++++++++------------------------ kernel/cobalt/rtdm/internal.h | 2 +- kernel/cobalt/rtdm/proc.c | 94 ++++++++-------------------- 4 files changed, 66 insertions(+), 151 deletions(-)
include/cobalt/kernel/rtdm/driver.h +5 -1
@@ -445,7 +445,10 @@ rtdm_private_to_context(void *dev_private)struct rtdm_dev_reserved {union { -struct list_head entry; +struct { +struct list_head entry; +xnhandle_t handle; + };struct xnid id; };atomic_t refcount;
@@ -460,6 +463,7 @@ struct rtdm_dev_reserved {* not reside in write-protected memory. */ struct rtdm_device { +unsigned magic;/** Revision number of this structure, see * @ref drv_versioning "Driver Versioning" defines */ int struct_version;
kernel/cobalt/rtdm/device.c +34 -81
216 lines not on this page · raw message
kernel/cobalt/rtdm/internal.h +1 -1
@@ -50,7 +50,7 @@ extern struct rtdm_fildes fildes_table[];extern int open_fildes;extern struct semaphore nrt_dev_lock;extern unsigned int devname_hashtab_size; -extern struct list_head *rtdm_named_devices; +extern struct list_head rtdm_named_devices;extern struct rb_root rtdm_protocol_devices;extern struct xnpersonality rtdm_personality;
kernel/cobalt/rtdm/proc.c +26 -68
149 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 3/3 cobalt/rtdm: base on common fd implementation
In reply to Gilles Chanteperdrix--- include/cobalt/kernel/rtdm/driver.h | 328 +++----------------- include/cobalt/kernel/rtdm/rtdm.h | 48 +-- kernel/cobalt/posix/select.c | 30 +- kernel/cobalt/rtdm/core.c | 564 +++++------------------------------ kernel/cobalt/rtdm/device.c | 46 +-- kernel/cobalt/rtdm/drvlib.c | 36 +-- kernel/cobalt/rtdm/internal.h | 6 - kernel/cobalt/rtdm/proc.c | 33 +- kernel/cobalt/rtdm/syscall.c | 80 +---- lib/cobalt/rtdm.c | 501 +++++++++++++------------------ 10 files changed, 394 insertions(+), 1278 deletions(-)
include/cobalt/kernel/rtdm/driver.h +41 -287
@@ -39,6 +39,7 @@#include <cobalt/kernel/apc.h> #include <cobalt/kernel/shadow.h> #include <cobalt/kernel/tree.h> +#include <cobalt/kernel/fd.h> #include <rtdm/rtdm.h> /* debug support */
@@ -77,22 +78,6 @@ enum rtdm_selecttype;/** @} Device Flags */ /*! -* @anchor ctx_flags @name Context Flags -* Dynamic flags describing the state of an open RTDM device (bit numbers) -* @{ -*/ -/** Set by RTDM if the device instance was created in non-real-time -* context. */ -#define RTDM_CREATED_IN_NRT 0 - -/** Set by RTDM when the device is being closed. */ -#define RTDM_CLOSING 1 - -/** Lowest bit number the driver developer can use freely */ -#define RTDM_USER_CONTEXT_FLAG 8/* first user-definable flag */ -/** @} Context Flags */ - -/*! * @anchor drv_versioning @name Driver Versioning * Current revisions of RTDM structures, encoding of driver versions. See * @ref api_versioning "API Versioning" for the interface revision.
@@ -153,9 +138,7 @@ enum rtdm_selecttype {/** * Named device open handler * -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode call +* @param[in] context File descriptor structure associated with opened device instance * @param[in] oflag Open flags as passed by the user * * @return 0 on success. On failure return either -ENOSYS, to request that
@@ -164,15 +147,12 @@ enum rtdm_selecttype {* * @see @c open() in IEEE Std 1003.1, * http://www.opengroup.org/onlinepubs/009695399 */ -typedef int (*rtdm_open_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info,int oflag); +typedef int (*rtdm_open_handler_t )(struct xnfd *context,int oflag);/** * Socket creation handler for protocol devices * -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode call +* @param[in] context File descriptor structure associated with opened device instance * @param[in] protocol Protocol number as passed by the user * * @return 0 on success. On failure return either -ENOSYS, to request that
@@ -181,203 +161,15 @@ typedef int (*rtdm_open_handler_t)(struct rtdm_dev_context *context,* * @see @c socket() in IEEE Std 1003.1, * http://www.opengroup.org/onlinepubs/009695399 */ -typedef int (*rtdm_socket_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info,int protocol); - -/** -* Close handler -* -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode or deferred user mode call -* -* @return 0 on success. On failure return either -ENOSYS, to request that -* this handler be called again from the opposite realtime/non-realtime -* context, -EAGAIN to request a recall after a grace period, or a valid -* negative error code according to IEEE Std 1003.1. -* -* @note Drivers must be prepared for that case that the close handler is -* invoked more than once per open context (even if the handler already -* completed an earlier run successfully). The driver has to avoid releasing -* resources twice as well as returning false errors on successive close -* invocations. -* -* @see @c close() in IEEE Std 1003.1, -* http://www.opengroup.org/onlinepubs/009695399 */ -typedef int (*rtdm_close_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info); +typedef int (*rtdm_socket_handler_t )(struct xnfd *context,int protocol); -/** -* IOCTL handler -* -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode call -* @param[in] request Request number as passed by the user -* @param[in,out] arg Request argument as passed by the user -* -* @return A positive value or 0 on success. On failure return either -* -ENOSYS, to request that the function be called again from the opposite -* realtime/non-realtime context, or another negative error code. -* -* @see @c ioctl() in IEEE Std 1003.1, -* http://www.opengroup.org/onlinepubs/009695399 */ -typedef int (*rtdm_ioctl_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info, -unsigned int request,void __user *arg); - -/** -* Select binding handler -* -* @param[in] context Context structure associated with opened device instance -* @param[in,out] selector Object that shall be bound to the given event -* @param[in] type Event type the selector is interested in -* @param[in] fd_index Opaque value, to be passed to rtdm_event_select_bind or -* rtdm_sem_select_bind unmodfied -* -* @return 0 on success. On failure return either -ENOSYS, to request that -* this handler be called again from the opposite realtime/non-realtime -* context, or another negative error code. -*/ -typedef int (*rtdm_select_bind_handler_t )(struct rtdm_dev_context *context, -rtdm_selector_t *selector, -enum rtdm_selecttype type, -unsigned fd_index); - -/** -* Read handler -* -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode call -* @param[out] buf Input buffer as passed by the user -* @param[in] nbyte Number of bytes the user requests to read -* -* @return On success, the number of bytes read. On failure return either -* -ENOSYS, to request that this handler be called again from the opposite -* realtime/non-realtime context, or another negative error code. -* -* @see @c read() in IEEE Std 1003.1, -* http://www.opengroup.org/onlinepubs/009695399 */ -typedef ssize_t (*rtdm_read_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info, -void *buf,size_t nbyte); - -/** -* Write handler -* -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode call -* @param[in] buf Output buffer as passed by the user -* @param[in] nbyte Number of bytes the user requests to write -* -* @return On success, the number of bytes written. On failure return -* either -ENOSYS, to request that this handler be called again from the -* opposite realtime/non-realtime context, or another negative error code. -* -* @see @c write() in IEEE Std 1003.1, -* http://www.opengroup.org/onlinepubs/009695399 */ -typedef ssize_t (*rtdm_write_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info, -const void *buf,size_t nbyte); - -/** -* Receive message handler -* -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode call -* @param[in,out] msg Message descriptor as passed by the user, automatically -* mirrored to safe kernel memory in case of user mode call -* @param[in] flags Message flags as passed by the user -* -* @return On success, the number of bytes received. On failure return -* either -ENOSYS, to request that this handler be called again from the -* opposite realtime/non-realtime context, or another negative error code. -* -* @see @c recvmsg() in IEEE Std 1003.1, -* http://www.opengroup.org/onlinepubs/009695399 */ -typedef ssize_t (*rtdm_recvmsg_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info, -struct msghdr *msg,int flags); - -/** -* Transmit message handler -* -* @param[in] context Context structure associated with opened device instance -* @param[in] user_info Opaque pointer to information about user mode caller, -* NULL if kernel mode call -* @param[in] msg Message descriptor as passed by the user, automatically -* mirrored to safe kernel memory in case of user mode call -* @param[in] flags Message flags as passed by the user -* -* @return On success, the number of bytes transmitted. On failure return -* either -ENOSYS, to request that this handler be called again from the -* opposite realtime/non-realtime context, or another negative error code. -* -* @see @c sendmsg() in IEEE Std 1003.1, -* http://www.opengroup.org/onlinepubs/009695399 */ -typedef ssize_t (*rtdm_sendmsg_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info, -const struct msghdr *msg,int flags);/** @} Operation Handler Prototypes */ -typedef int (*rtdm_rt_handler_t )(struct rtdm_dev_context *context, -rtdm_user_info_t *user_info,void *arg); -/** -* Device operations -*/ -struct rtdm_operations { -/*! @name Common Operations -* @{ */ -/** Close handler for real-time contexts (optional, deprecated) -* @deprecated Only use non-real-time close handler in new drivers. */ -rtdm_close_handler_t close_rt; -/** Close handler for non-real-time contexts (required) */ -rtdm_close_handler_t close_nrt; - -/** IOCTL from real-time context (optional) */ -rtdm_ioctl_handler_t ioctl_rt; -/** IOCTL from non-real-time context (optional) */ -rtdm_ioctl_handler_t ioctl_nrt; - -/** Select binding handler for any context (optional) */ -rtdm_select_bind_handler_t select_bind; -/** @} Common Operations */ - -/*! @name Stream-Oriented Device Operations -* @{ */ -/** Read handler for real-time context (optional) */ -rtdm_read_handler_t read_rt; -/** Read handler for non-real-time context (optional) */ -rtdm_read_handler_t read_nrt; - -/** Write handler for real-time context (optional) */ -rtdm_write_handler_t write_rt; -/** Write handler for non-real-time context (optional) */ -rtdm_write_handler_t write_nrt; -/** @} Stream-Oriented Device Operations */ - -/*! @name Message-Oriented Device Operations -* @{ */ -/** Receive message handler for real-time context (optional) */ -rtdm_recvmsg_handler_t recvmsg_rt; -/** Receive message handler for non-real-time context (optional) */ -rtdm_recvmsg_handler_t recvmsg_nrt; - -/** Transmit message handler for real-time context (optional) */ -rtdm_sendmsg_handler_t sendmsg_rt; -/** Transmit message handler for non-real-time context (optional) */ -rtdm_sendmsg_handler_t sendmsg_nrt; -/** @} Message-Oriented Device Operations */ -}; -struct rtdm_process ;struct rtdm_devctx_reserved {struct rtdm_process *owner; -struct list_head cleanup; +void (*close)(struct xnfd *fd); };/**
@@ -392,19 +184,9 @@ struct rtdm_devctx_reserved {* device registration. */ struct rtdm_dev_context { -/** Context flags, see @ref ctx_flags "Context Flags" for details */ -unsigned long context_flags; - -/** Associated file descriptor */ -int fd; - -/** Lock counter of context, held while structure is referenced by an -* operation handler */ -atomic_t close_lock_count; +struct xnfd fd;/** Set of active device operation handlers */ -struct rtdm_operations *ops; -/** Reference to owning device */ struct rtdm_device *device;
@@ -415,6 +197,11 @@ struct rtdm_dev_context {char dev_private[0 ]; }; +static inline struct rtdm_dev_context *rtdm_context (struct xnfd *fd) +{ + return container_of(fd, struct rtdm_dev_context, fd); +} +/** * Locate the driver private area associated to a device context structure *
@@ -424,9 +211,9 @@ struct rtdm_dev_context {* context. */ static inline void * -rtdm_context_to_private (struct rtdm_dev_context *context) +rtdm_context_to_private (struct xnfd *context) { -return (void *)context->dev_private; +return (void *)rtdm_context (context)->dev_private; }/**
@@ -437,10 +224,12 @@ rtdm_context_to_private(struct rtdm_dev_context *context)* @return The address of the device context structure defining @a * dev_private. */ -static inline struct rtdm_dev_context * +static inline struct xnfd *rtdm_private_to_context (void *dev_private) { - return container_of(dev_private, struct rtdm_dev_context, dev_private); +struct rtdm_dev_context *ctx; + ctx = container_of(dev_private, struct rtdm_dev_context, dev_private); +return &ctx->fd; }struct rtdm_dev_reserved {
@@ -453,6 +242,7 @@ struct rtdm_dev_reserved { };atomic_t refcount;struct rtdm_dev_context *exclusive_context; +void (*close)(struct xnfd *); };/**
@@ -485,23 +275,17 @@ struct rtdm_device {* optional (but deprecated) if open_nrt is non-NULL, ignored for * protocol devices * @deprecated Only use non-real-time open handler in new drivers. */ -rtdm_open_handler_t open_rt; -/** Named device instance creation for non-real-time contexts, -* optional if open_rt is non-NULL, ignored for protocol devices */ -rtdm_open_handler_t open_nrt; +rtdm_open_handler_t open;/** Protocol socket creation for real-time contexts, * optional (but deprecated) if socket_nrt is non-NULL, ignored for * named devices * @deprecated Only use non-real-time socket creation handler in new * drivers. */ -rtdm_socket_handler_t socket_rt; -/** Protocol socket creation for non-real-time contexts, -* optional if socket_rt is non-NULL, ignored for named devices */ -rtdm_socket_handler_t socket_nrt; +rtdm_socket_handler_t socket;/** Default operations on newly opened device instance */ -struct rtdm_operations ops; +struct xnfd_ops ops;/** Device class ID, see @ref RTDM_CLASS_xxx */ int device_class;
@@ -566,36 +350,16 @@ int rtdm_dev_unregister(struct rtdm_device *device, unsigned int poll_delay);#define rtdm_getpeername rt_dev_getpeername#define rtdm_shutdown rt_dev_shutdown -struct rtdm_dev_context *rtdm_context_get (int fd); -#ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */ -#define CONTEXT_IS_LOCKED (context) \ - (atomic_read(&(context)->close_lock_count) > 1 || \ - (test_bit(RTDM_CLOSING, &(context)->context_flags) && \ - atomic_read(&(context)->close_lock_count) > 0)) - -static inline void rtdm_context_lock (struct rtdm_dev_context *context) +static inline void rtdm_context_lock (struct xnfd *context) { -/* just warn if context was a dangling pointer */ -XENO_ASSERT (RTDM ,CONTEXT_IS_LOCKED (context)); -atomic_inc (&context->close_lock_count); +xnfd_lock (context); } -extern int rtdm_apc; - -static inline void rtdm_context_unlock (struct rtdm_dev_context *context) +static inline void rtdm_context_unlock (struct xnfd *context) { -/* just warn if context was a dangling pointer */ -XENO_ASSERT (RTDM ,CONTEXT_IS_LOCKED (context)); -smp_mb__before_atomic_dec (); -if (unlikely (atomic_dec_and_test (&context->close_lock_count))) -xnapc_schedule (rtdm_apc); -} - -static inline void rtdm_context_put (struct rtdm_dev_context *context) -{ -rtdm_context_unlock (context); +xnfd_unlock (context); }/* --- clock services --- */
@@ -610,14 +374,6 @@ static inline nanosecs_abs_t rtdm_clock_read_monotonic(void) }#endif /* !DOXYGEN_CPP */ -/*! -* @addtogroup rtdmsync -* @{ -*/ - -int rtdm_select_bind (int fd,rtdm_selector_t *selector, -enum rtdm_selecttype type,unsigned fd_index); -/* --- spin lock services --- */ /*! * @name Global Lock across Scheduler Invocation
@@ -1308,38 +1064,38 @@ static inline void rtdm_free(void *ptr)xnfree (ptr); } -int rtdm_mmap_to_user (rtdm_user_info_t *user_info, +int rtdm_mmap_to_user (struct xnfd *context,void *src_addr,size_t len,int prot,void **pptr,struct vm_operations_struct *vm_ops,void *vm_private_data); -int rtdm_iomap_to_user (rtdm_user_info_t *user_info, +int rtdm_iomap_to_user (struct xnfd *context,phys_addr_t src_addr,size_t len,int prot,void **pptr,struct vm_operations_struct *vm_ops,void *vm_private_data); -int rtdm_munmap (rtdm_user_info_t *user_info,void *ptr,size_t len); +int rtdm_munmap (struct xnfd *context,void *ptr,size_t len); -static inline int rtdm_read_user_ok (rtdm_user_info_t *user_info, +static inline int rtdm_read_user_ok (struct xnfd *context,const void __user *ptr,size_t size) {return access_rok (ptr, size); } -static inline int rtdm_rw_user_ok (rtdm_user_info_t *user_info, +static inline int rtdm_rw_user_ok (struct xnfd *context,const void __user *ptr,size_t size) {return access_wok (ptr, size); } -static inline int rtdm_copy_from_user (rtdm_user_info_t *user_info, +static inline int rtdm_copy_from_user (struct xnfd *context,void *dst,const void __user *src,size_t size) {return __xn_copy_from_user (dst, src, size) ? -EFAULT :0 ; } -static inline int rtdm_safe_copy_from_user (rtdm_user_info_t *user_info, +static inline int rtdm_safe_copy_from_user (struct xnfd *context,void *dst,const void __user *src,size_t size) {
@@ -1347,14 +1103,14 @@ static inline int rtdm_safe_copy_from_user(rtdm_user_info_t *user_info, __xn_copy_from_user(dst, src, size)) ? -EFAULT : 0; } -static inline int rtdm_copy_to_user (rtdm_user_info_t *user_info, +static inline int rtdm_copy_to_user (struct xnfd *context,void __user *dst,const void *src,size_t size) {return __xn_copy_to_user (dst, src, size) ? -EFAULT :0 ; } -static inline int rtdm_safe_copy_to_user (rtdm_user_info_t *user_info, +static inline int rtdm_safe_copy_to_user (struct xnfd *context,void __user *dst,const void *src,size_t size) {
@@ -1362,7 +1118,7 @@ static inline int rtdm_safe_copy_to_user(rtdm_user_info_t *user_info, __xn_copy_to_user(dst, src, size)) ? -EFAULT : 0; } -static inline int rtdm_strncpy_from_user (rtdm_user_info_t *user_info, +static inline int rtdm_strncpy_from_user (struct xnfd *context,char *dst,const char __user *src,size_t count) {
@@ -1371,13 +1127,15 @@ static inline int rtdm_strncpy_from_user(rtdm_user_info_t *user_info,return __xn_strncpy_from_user (dst, src, count); } -static inline int rtdm_rt_capable (rtdm_user_info_t *user_info) +static inline int rtdm_rt_capable (struct xnfd *context) {if (!XENO_ASSERT (RTDM , !xnsched_interrupt_p ()))return 0 ; -return (user_info ?xnshadow_thread (user_info) !=NULL - : !xnsched_root_p ()); +if (xnfd_owner (context) == &__xnsys_global_ppd) +return !xnsched_root_p (); + +return xnshadow_thread (current) !=NULL ; }static inline int rtdm_in_rt_context (void )
@@ -1387,8 +1145,4 @@ static inline int rtdm_in_rt_context(void)#endif /* !DOXYGEN_CPP */ -int rtdm_exec_in_rt (struct rtdm_dev_context *context, -rtdm_user_info_t *user_info,void *arg, -rtdm_rt_handler_t handler); -#endif /* _COBALT_RTDM_DRIVER_H */
include/cobalt/kernel/rtdm/rtdm.h +16 -32
80 lines not on this page · raw message
kernel/cobalt/posix/select.c +2 -28
@@ -21,34 +21,13 @@*/ #include <linux/types.h> #include <linux/err.h> -#include <rtdm/driver.h> #include <cobalt/kernel/fd.h> +#include <cobalt/kernel/select.h> #include "internal.h" #include "clock.h" #include "mqueue.h" #include "select.h" -#define RTDM_FD_MAX CONFIG_XENO_OPT_RTDM_FILDES - -static int fd_valid_p (int fd) -{ -const int rtdm_fd_start = __FD_SETSIZE -RTDM_FD_MAX ; -struct rtdm_dev_context *ctx; - -if (xnfd_valid_p (fd)) -return 1 ; - -if (fd >= rtdm_fd_start) { - ctx =rtdm_context_get (fd - rtdm_fd_start); -if (ctx ==NULL ) -return 0 ; -rtdm_context_unlock (ctx); -return 1 ; - } - -return 0 ; -} -static int first_fd_valid_p (fd_set *fds[XNSELECT_MAX_TYPES ],int nfds) {int i, fd;
@@ -56,7 +35,7 @@ static int first_fd_valid_p(fd_set *fds[XNSELECT_MAX_TYPES], int nfds)for (i =0 ; i <XNSELECT_MAX_TYPES ; i++)if (fds[i] && (fd =find_first_bit (fds[i]->fds_bits, nfds)) < nfds) -return fd_valid_p (fd); +return xnfd_valid_p (fd);/* All empty is correct, used as a "sleep" mechanism by strange applications. */
@@ -65,17 +44,12 @@ static int first_fd_valid_p(fd_set *fds[XNSELECT_MAX_TYPES], int nfds)static int select_bind_one (struct xnselector *selector,unsigned type,int fd) { -const int rtdm_fd_start = __FD_SETSIZE -RTDM_FD_MAX ;int rc; rc =xnfd_select_bind (fd, selector, type);if (rc != -ENOENT )return rc; -if (fd >= rtdm_fd_start) -return rtdm_select_bind (fd - rtdm_fd_start, - selector, type, fd); -return -EBADF ; }
kernel/cobalt/rtdm/core.c +79 -485
675 lines not on this page · raw message
kernel/cobalt/rtdm/device.c +12 -34
99 lines not on this page · raw message
kernel/cobalt/rtdm/drvlib.c +18 -18
@@ -1884,7 +1884,7 @@ static struct file_operations rtdm_mmap_fops = { .get_unmapped_area = rtdm_unmapped_area }; -static int rtdm_do_mmap (rtdm_user_info_t *user_info, +static int rtdm_do_mmap (struct xnfd *fd,struct rtdm_mmap_data *mmap_data,size_t len,int prot,void **pptr) {
@@ -1912,7 +1912,7 @@ static int rtdm_do_mmap(rtdm_user_info_t *user_info, filp->f_op = (typeof(filp->f_op))old_fops; filp->private_data = old_priv_data; -filp_close (filp, user_info->files); +filp_close (filp, current->files);if (IS_ERR_VALUE (u_addr))return (int )u_addr;
@@ -1976,7 +1976,7 @@ static int rtdm_do_mmap(rtdm_user_info_t *user_info,* * Rescheduling: possible. */ -int rtdm_mmap_to_user(rtdm_user_info_t *user_info, +int rtdm_mmap_to_user(struct xnfd *fd, void *src_addr, size_t len, int prot, void **pptr, struct vm_operations_struct *vm_ops,
@@ -1989,7 +1989,7 @@ int rtdm_mmap_to_user(rtdm_user_info_t *user_info, .vm_private_data = vm_private_data }; -return rtdm_do_mmap (user_info, &mmap_data, len, prot, pptr); +return rtdm_do_mmap (fd, &mmap_data, len, prot, pptr); }EXPORT_SYMBOL_GPL (rtdm_mmap_to_user);
@@ -2044,7 +2044,7 @@ EXPORT_SYMBOL_GPL(rtdm_mmap_to_user);* * Rescheduling: possible. */ -int rtdm_iomap_to_user(rtdm_user_info_t *user_info, +int rtdm_iomap_to_user(struct xnfd *fd, phys_addr_t src_addr, size_t len, int prot, void **pptr, struct vm_operations_struct *vm_ops,
@@ -2057,7 +2057,7 @@ int rtdm_iomap_to_user(rtdm_user_info_t *user_info, .vm_private_data = vm_private_data }; -return rtdm_do_mmap (user_info, &mmap_data, len, prot, pptr); +return rtdm_do_mmap (fd, &mmap_data, len, prot, pptr); }EXPORT_SYMBOL_GPL (rtdm_iomap_to_user);
@@ -2086,16 +2086,16 @@ EXPORT_SYMBOL_GPL(rtdm_iomap_to_user);* * Rescheduling: possible. */ -int rtdm_munmap (rtdm_user_info_t *user_info,void *ptr,size_t len) +int rtdm_munmap (struct xnfd *fd,void *ptr,size_t len) {int err;if (!XENO_ASSERT (RTDM ,xnsched_root_p ()))return -EPERM ; -down_write (&user_info->mm->mmap_sem); - err =do_munmap (user_info->mm, (unsigned long )ptr, len); -up_write (&user_info->mm->mmap_sem); +down_write (¤t->mm->mmap_sem); + err =do_munmap (current->mm, (unsigned long )ptr, len); +up_write (¤t->mm->mmap_sem);return err; }
@@ -2263,7 +2263,7 @@ void rtdm_free(void *ptr);* * Rescheduling: never. */ -int rtdm_read_user_ok (rtdm_user_info_t *user_info,const void __user *ptr, +int rtdm_read_user_ok (struct xnfd *fd,const void __user *ptr,size_t size);/**
@@ -2287,7 +2287,7 @@ int rtdm_read_user_ok(rtdm_user_info_t *user_info, const void __user *ptr,* * Rescheduling: never. */ -int rtdm_rw_user_ok (rtdm_user_info_t *user_info,const void __user *ptr, +int rtdm_rw_user_ok (struct xnfd *fd,const void __user *ptr,size_t size);/**
@@ -2316,7 +2316,7 @@ int rtdm_rw_user_ok(rtdm_user_info_t *user_info, const void __user *ptr,* * Rescheduling: never. */ -int rtdm_copy_from_user (rtdm_user_info_t *user_info,void *dst, +int rtdm_copy_from_user (struct xnfd *fd,void *dst,const void __user *src,size_t size);/**
@@ -2346,7 +2346,7 @@ int rtdm_copy_from_user(rtdm_user_info_t *user_info, void *dst,* * Rescheduling: never. */ -int rtdm_safe_copy_from_user (rtdm_user_info_t *user_info,void *dst, +int rtdm_safe_copy_from_user (struct xnfd *fd,void *dst,const void __user *src,size_t size);/**
@@ -2375,7 +2375,7 @@ int rtdm_safe_copy_from_user(rtdm_user_info_t *user_info, void *dst,* * Rescheduling: never. */ -int rtdm_copy_to_user (rtdm_user_info_t *user_info,void __user *dst, +int rtdm_copy_to_user (struct xnfd *fd,void __user *dst,const void *src,size_t size);/**
@@ -2405,7 +2405,7 @@ int rtdm_copy_to_user(rtdm_user_info_t *user_info, void __user *dst,* * Rescheduling: never. */ -int rtdm_safe_copy_to_user (rtdm_user_info_t *user_info,void __user *dst, +int rtdm_safe_copy_to_user (struct xnfd *fd,void __user *dst,const void *src,size_t size);/**
@@ -2436,7 +2436,7 @@ int rtdm_safe_copy_to_user(rtdm_user_info_t *user_info, void __user *dst,* * Rescheduling: never. */ -int rtdm_strncpy_from_user (rtdm_user_info_t *user_info,char *dst, +int rtdm_strncpy_from_user (struct xnfd *fd,char *dst,const char __user *src,size_t count);/**
@@ -2482,7 +2482,7 @@ int rtdm_in_rt_context(void);* * Rescheduling: never. */ -int rtdm_rt_capable (rtdm_user_info_t *user_info); +int rtdm_rt_capable (struct xnfd *fd);#endif /* DOXYGEN_CPP */
kernel/cobalt/rtdm/internal.h +0 -6
@@ -31,10 +31,6 @@#define DEF_DEVNAME_HASHTAB_SIZE 256/* entries in name hash table */ #define DEF_PROTO_HASHTAB_SIZE 256/* entries in protocol hash table */ -struct rtdm_fildes { -struct rtdm_dev_context *context; -}; -struct rtdm_process {#ifdef CONFIG_XENO_OPT_VFILE char name[32 ];
@@ -46,10 +42,8 @@ DECLARE_EXTERN_XNLOCK(rt_fildes_lock);DECLARE_EXTERN_XNLOCK (rt_dev_lock);extern int __rtdm_muxid; -extern struct rtdm_fildes fildes_table[];extern int open_fildes;extern struct semaphore nrt_dev_lock; -extern unsigned int devname_hashtab_size;extern struct list_head rtdm_named_devices;extern struct rb_root rtdm_protocol_devices;extern struct xnpersonality rtdm_personality;
kernel/cobalt/rtdm/proc.c +14 -19
@@ -184,40 +184,35 @@ static int openfd_show(struct xnvfile_regular_iterator *it, void *data)struct rtdm_dev_context *context;struct rtdm_device *device;struct rtdm_process owner; -int close_lock_count, fd; -spl_t s; +int close_lock_count, i; +struct xnfd *fd;if (data ==NULL ) {xnvfile_puts (it,"Index\tLocked\tDevice\t\t\t\tOwner [PID]\n" );return 0 ; } - fd = (int )it->pos -1 ; + i = (int )it->pos -1 ; -xnlock_get_irqsave (&rt_fildes_lock, s); - - context = fildes_table[fd].context; -if (context ==NULL ) { -xnlock_put_irqrestore (&rt_fildes_lock, s); + fd =xnfd_get (&__xnsys_global_ppd, i,RTDM_MAGIC ); +if (fd ==NULL )return VFILE_SEQ_SKIP ; - } - close_lock_count =atomic_read (&context->close_lock_count); + context =rtdm_context (fd); + close_lock_count = fd->refs; device = context->device; -if (context->reserved.owner) -memcpy (&owner, context->reserved.owner,sizeof (owner)); -else { -strcpy (owner.name,"<kernel>" ); - owner.pid =-1 ; - } -xnlock_put_irqrestore (&rt_fildes_lock, s); +strcpy (owner.name,"<kernel>" ); + owner.pid =-1 ; -xnvfile_printf (it,"%d\t%d\t%-31s %s [%d]\n" , fd, +xnvfile_printf (it,"%d\t%d\t%-31s %s [%d]\n" , i, close_lock_count, (device->device_flags &RTDM_NAMED_DEVICE ) ? device->device_name : device->proc_name, owner.name, owner.pid); + +xnfd_put (fd); +return 0 ; }
@@ -230,7 +225,7 @@ static ssize_t openfd_store(struct xnvfile_input *input)if (ret <0 )return ret; - cret =__rt_dev_close (current, (int )val); + cret =xnfd_close (&__xnsys_global_ppd, (int )val,RTDM_MAGIC );if (cret <0 )return cret;
kernel/cobalt/rtdm/syscall.c +6 -74
109 lines not on this page · raw message
lib/cobalt/rtdm.c +206 -295
655 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 9 lines · Gilles Chanteperdrix
Hi Jan, Philippe,
I have started working on rebasing RTDM on the common fd implementation (xnfd). Before I start changing the drivers, the current state of the changes follow as patches. These patches are based on the commits in the "for-forge" branch in xenomai-gch repository. Please do not pull from this branch just yet, it is probably going to be rebased.
Quoted 6 lines
The thing which I know we will discuss, even before you read the patches:
- struct xnfd appears instead of structrtdm_dev_contextin callbacks, we already discussed that, you prefer rtdm typedefs, the thing is, in forge, the habit to typedef structs seems gone, and typedef struct xnfdrtdm_dev_contex_twould be confusing since structrtdm_dev_contextstill exists, albeit is no longer exported to drivers;
The simple solution is:
#define rtdm_dev_context xnfd, and rename the real struct rtdm_dev_context to __rtdm_dev_context, since it is internal anyway.
Quoted 5 lines
- the xnfd structure is defined in cobalt, and not cobalt/posix, this was made so that both rtdm and posix can use it, but maybe it makes more sense to move it to posix (after all, file descriptors are a posix thing), and get rtdm to use it anyway;
- doc is probably out of sync, this will be arranged in later commits
Quoted 8 lines
- maybe select should be moved to
fd.cnow,posix/select.ccontains 3 functions, and it now supports xnfds exclusively;
-context_flagsare gone, since the two flags it used are no longer used, since driver have a private structure, drivers can move their flags to their private structure if they want;
- handling-EAGAINin the close callback is gone, the close callback now returns void, it is possible to delay file descriptor destruction by using rtdm_lock/rtdm_unlock, so the-EAGAINreturn value was IMO redundant.
Having read the rtdm test, I noticed that the semantics of "close" has more changed than that: it is no longer possible to delay the close while already in the close callback by calling rtdm_context_lock. rtdm_context_lock should be called before that, to prevent the close callback from even be called. This, I hope, should be more in line with Linux drivers and follow the principle of least surprise.
Signature · 1 line
Gilles.
Quoted 35 lines · Gilles Chanteperdrix
Quoted 9 lines · Gilles Chanteperdrix
Hi Jan, Philippe,
I have started working on rebasing RTDM on the common fd implementation (xnfd). Before I start changing the drivers, the current state of the changes follow as patches. These patches are based on the commits in the "for-forge" branch in xenomai-gch repository. Please do not pull from this branch just yet, it is probably going to be rebased.
Quoted 6 lines
The thing which I know we will discuss, even before you read the patches:
- struct xnfd appears instead of structrtdm_dev_contextin callbacks, we already discussed that, you prefer rtdm typedefs, the thing is, in forge, the habit to typedef structs seems gone, and typedef struct xnfdrtdm_dev_contex_twould be confusing since structrtdm_dev_contextstill exists, albeit is no longer exported to drivers;The simple solution is:
#definertdm_dev_contextxnfd, and rename the real structrtdm_dev_contextto__rtdm_dev_context, since it is internal anyway.Quoted 5 lines
- the xnfd structure is defined in cobalt, and not cobalt/posix, this was made so that both rtdm and posix can use it, but maybe it makes more sense to move it to posix (after all, file descriptors are a posix thing), and get rtdm to use it anyway;
- doc is probably out of sync, this will be arranged in later commitsQuoted 8 lines
- maybe select should be moved to
fd.cnow,posix/select.ccontains 3 functions, and it now supports xnfds exclusively;
-context_flagsare gone, since the two flags it used are no longer used, since driver have a private structure, drivers can move their flags to their private structure if they want;
- handling-EAGAINin the close callback is gone, the close callback now returns void, it is possible to delay file descriptor destruction by using rtdm_lock/rtdm_unlock, so the-EAGAINreturn value was IMO redundant.
Quoted 8 lines
Having read the rtdm test, I noticed that the semantics of "close" has more changed than that: it is no longer possible to delay the close while already in the close callback by calling
rtdm_context_lock.rtdm_context_lockshould be called before that, to prevent the close callback from even be called. This, I hope, should be more in line with Linux drivers and follow the principle of least surprise.
In order to try and tart the discussion on this subject, I pushed my working branch, where switchtest, timerbench, rtdmtest and the rtdm ipc modules have been adapted to the modified RTDM, so that you can see what work this will entail for drivers.
Signature · 1 line
Gilles.
Quoted 76 lines · Jan Kiszka
Quoted 50 lines · Philippe Gerum
Quoted 42 lines · Jan Kiszka
Quoted 33 lines · Gilles Chanteperdrix
Quoted 17 lines · Jan Kiszka
Quoted 17 lines
Quoted 16 lines
I started to read through your patches. The general direction remains valid and beneficial, but I have a few formal issues with some API changes. In a nutshell: We really need to avoid layering violations by
expressing public RTDM interfaces via Xenomai data structures directly.Sometimes it's just a cosmetic thing like wrapping the opaque struct xnfd into something like
rtdm_fd. Butrtdm_operationscannot simply be
replaced withxnfd_ops. We loose RTDM documentation this way (yes, fixable), but we also now logically depend on the internals of Xenomai
Cobalt in the abstract RTDM driver API.rtdm_operationsis not opaque to
driver developers!Quoted 8 lines
Quoted 5 lines
#define
rtdm_dev_contextxnfd
#definertdm_operationsxnfd_ops
should do the trick. Note that I told you about this change in advance,
and proposed to cascade the callbacks.Not for
rtdm_operationsas its content is part of the RTDM API. It is _not_ an opaque type, in contrast to xnfd.With #define
rtdm_operationsxnfd_opsThe user can do:
struct
rtdm_operationsfoo = { /* ... */ };Quoted 7 lines
Without knowing that he is in fact defining an
xnfd_opsstructure.I am sorry, but I do not see the problem, if we keep
rtdm_operationsdocumented. But if you prefer we can, as I said, cascade the callbacks. Or even arrange to definertdm_operationswith members with the same signature asxnfd_ops, and fill anxnfd_opsstructure with thertdm_operationsmembers.Quoted 6 lines
I'd like to avoid that a change to
xnfd_opsfor whatever internal reason breaks the RTDM API subtly. Keep in mind that we will also have to map it on native Linux in a not-too-far future. Probably it is even a good idea to try this mapping right now, at least conceptually, to avoid having to change too much at that point again.Quoted 3 lines
Talking about conceptual issues, we may have a problem with supporting
RTDM_EXECUTE_ATOMICALLY()over native. I don't expect to see this sorted shortly, but this should be part of the API discussion at some point.I think there are two types of
RTDM_EXECUTE_ATOMICALLYusers:1. Testcases and other Xenomai-internal users that could also use platform specific mechanisms, ie. do not depend on a portable solution.
2. Drivers that require this semantic:
RTDM_EXECUTE_ATOMICALLY( register_with_something(); sleep(); unregister_again(); ) vs. RTDM_EXECUTE_ATOMICALLY( for_each_registered_thing() rtdm_task_unblock() )
Quoted 6 lines
The need for
RTDM_EXECUTE_ATOMICALLYin the second case arises from the fact that we cannot wake up a specific task waiting on a shared sync object in advance, i.e. before it is already blocked on that object, without destroying that object for everyone. If we find an alternative unlocked pattern for this scenario, we can drop the nasty macro, I think.
The semantics in this case looks similar to wait_event_* and friends, maybe with an implicit condition on being asleep/awake, although this construct is likely to be used along with an explicit condition to test before going to sleep.
What about introducing rtdm_waitqueue_t and the related helpers? Over a native kernel, we could just map them over the regular kernel/wait interface, and getting the same constructs working over Cobalt does not look like a big issue.
The bonus would be to get rid of the "single lock" semantics which taints RTDM_EXECUTE_ATOMICALLY in the same move, so that we don't kill scalability over single image kernels.
Signature · 1 line
Philippe.