Skip to contentSkip to conversation

RTDM fixes and reworks

GIT PULL In review Jan Kiszka 3 participants 33 messages Apr 19, 2010 – Apr 20, 2010 Generic include/asm header files

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

The following changes since commit 2bed24477882dd7937d59f4e33a0811981c7362c:
Gilles Chanteperdrix (1):
arm: declare the VFP inline asm snippets as volatile.

are available in the git repository at:

git://git.xenomai.org/xenomai-jki.git for-upstream

Changes in v4:
- fixed rtdm_rt_capable()
- renamed rttesting subclasses to switchtest and timerbench
- added non-atomic used_fildes patch
- fixed false-positive deprecated warnings for open_rt
- fixed test device name regressions of v3

Changes in v3:
- extended RTDM unit test to check for returned file descriptor number

Changes in v2:
- compat support for rttest device names
- documented RTDM close procedure
- internal rework of the close procedure
- basic RTDM unit test, so far targeting at the close rework
- some additional small cleanup patches

Jan Kiszka (24):
RTDM: Add rtdm_rt_capable() service
RTDM: Bump API version and document changes
Revert "rtdm: tag syscalls as conforming"
RTDM: Deprecate open_rt, socket_rt, and close_rt
RTIPC: Fix memory leak on failing socket creation
RTIPC: Drop support for RT socket creation/deletion
RTCAN: Drop support for socket creation/deletion in real-time 16550A: Drop support for device opening/closing in real-time
Analogy: Drop support for opening/closing in real-time
RTDM: Instrument rtdm_context_lock/unlock to detect misuses
RTDM: Add rtdm_context_put()
Fix historic msleep wrapping
irqbench: Fix x86-64 build
irqbench: Refactor user space helpers
irqbench: Auto-detect bases of port address and IRQ values
rttest: Resolved test device conflicts via separate name spaces
testing: Clean up Kconfig rules
RTIPC: Drop unused wrapper around close_lock_count
RTDM: Document device close procedure
Add list_first_entry wrapper for older kernels
Add legacy kernel support for delayed_work
RTDM: Early fd release with poll-free context reference tracking
RTDM: Add basic unit test
RTDM: Use non-atomic bitops for used_fildes

Wolfgang Mauerer (1):
RTDM: Fix potential NULL pointer dereference

 configure.in                          |    2 +-
 include/asm-generic/wrappers.h        |   10 +-
 include/compat/linux/workqueue.h      |   13 +
 include/rtdm/rtdm.h                   |    4 +-
 include/rtdm/rtdm_driver.h            |   50 +++-
 include/rtdm/rttesting.h              |   19 ++-
 ksrc/drivers/analogy/rtdm_interface.c |    2 -
 ksrc/drivers/can/rtcan_raw.c          |    2 -
 ksrc/drivers/ipc/internal.h           |    5 -
 ksrc/drivers/ipc/rtipc.c              |   13 +-
 ksrc/drivers/serial/16550A.c          |   51 +---
 ksrc/drivers/testing/Config.in        |    6 +-
 ksrc/drivers/testing/Kconfig          |   27 ++-
 ksrc/drivers/testing/Makefile         |   12 +-
 ksrc/drivers/testing/irqbench.c       |    9 +-
 ksrc/drivers/testing/klat.c           |    8 +-
 ksrc/drivers/testing/rtdmtest.c       |  191 +++++++++++++
 ksrc/drivers/testing/switchtest.c     |    7 +-
 ksrc/drivers/testing/timerbench.c     |    7 +-
 ksrc/skins/rtdm/API.CHANGES           |    9 +
 ksrc/skins/rtdm/core.c                |  209 ++++++++++----
 ksrc/skins/rtdm/device.c              |   59 ++++-
 ksrc/skins/rtdm/drvlib.c              |   25 ++
 ksrc/skins/rtdm/internal.h            |    8 +-
 ksrc/skins/rtdm/syscall.c             |   10 +-
 src/testsuite/irqbench/Makefile.am    |    2 +-
 src/testsuite/irqbench/irqbench.c     |  480 ++++++++++++++++-----------------
 src/testsuite/irqbench/irqloop.c      |  312 +++++++++++----------
 src/testsuite/latency/latency.c       |   12 +-
 src/testsuite/switchtest/switchtest.c |   15 +-
 src/testsuite/unit/Makefile.am        |   17 ++-
 src/testsuite/unit/rtdm.c             |  114 ++++++++
 32 files changed, 1158 insertions(+), 552 deletions(-)
 create mode 100644 ksrc/drivers/testing/rtdmtest.c
 create mode 100644 src/testsuite/unit/rtdm.c
author
#1 lore raw

PATCH v4 1/25 RTDM: Fix potential NULL pointer dereference

From: Wolfgang Mauerer <[email protected]>

The rework in 95278926edc559d4 misses the case that context can be NULL, which can (and has) triggered a kernel oops. Take care of this case.

---
 ksrc/skins/rtdm/core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
ksrc/skins/rtdm/core.c +1 -1
index 8677c47..8cccf52 100644
@@ -175,7 +175,7 @@ static int cleanup_instance(struct rtdm_device *device,
 
 	xnlock_get_irqsave(&rt_fildes_lock, s);
 
-	if (unlikely(atomic_read(&context->close_lock_count) > 1)) {
+	if (context && unlikely(atomic_read(&context->close_lock_count) > 1)) {
 		xnlock_put_irqrestore(&rt_fildes_lock, s);
 		return -EAGAIN;
 	}
Signature · 1 line
1.6.0.2
author
#2 lore raw

PATCH v4 2/25 RTDM: Add rtdm_rt_capable() service

In reply to Jan Kiszka

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 <[email protected]>
CC Alexis Berlemont <[email protected]>
---
 include/rtdm/rtdm_driver.h |    6 ++++++
 ksrc/skins/rtdm/drvlib.c   |   25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
include/rtdm/rtdm_driver.h +6 -0
index 0fc1496..d124157 100644
@@ -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_root_p() || xnshadow_thread(current) != NULL);
+}
+
 #endif /* !DOXYGEN_CPP */
 
 int rtdm_exec_in_rt(struct rtdm_dev_context *context,
ksrc/skins/rtdm/drvlib.c +25 -0
index 3b04493..6e26501 100644
@@ -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 */
Signature · 1 line
1.6.0.2
#3 lore raw

Re: [Xenomai-core] [PATCH v4 02/25] RTDM: Add rtdm_rt_capable() service

Quoted 19 lines · Jan Kiszka

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 <[email protected]>
CC Alexis Berlemont <[email protected]>
---
 include/rtdm/rtdm_driver.h |    6 ++++++
 ksrc/skins/rtdm/drvlib.c   |   25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
include/rtdm/rtdm_driver.h +0 -0
index 0fc1496..d124157 100644

include/rtdm/rtdm_driver.h static inline int rtdm_in_rt_context(void) · line 1304

Quoted 9 lines
include/rtdm/rtdm_driver.h +6 -0
@@ -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_root_p() || xnshadow_thread(current) != NULL);
+}
+

This patch still has fundamental flaw, the service would not work correctly and would actually return the wrong value, in case it is used deeply buried into some helper code, traversed by asynchronous Xenomai contexts. At the very least, you should avoid this by binding that service to a valid rtdm_dev_context, so that you know that it is called from a context that is correct in the first place, where a rtdm_dev_context reference is available.

I.e.
static inline int rtdm_rt_capable(struct rtdm_dev_context *context), and extract the information from that context structure. That would avoid a lot of headaches down the road to your user base.

Signature · 1 line
Philippe.
author
#4 lore raw

Re: [Xenomai-core] [PATCH v4 02/25] RTDM: Add rtdm_rt_capable() service

Quoted 26 lines · Philippe Gerum
Quoted 25 lines · Jan Kiszka

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 <[email protected]>
CC Alexis Berlemont <[email protected]>
---
 include/rtdm/rtdm_driver.h |    6 ++++++
 ksrc/skins/rtdm/drvlib.c   |   25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
include/rtdm/rtdm_driver.h +3 -0
index 0fc1496..d124157 100644
@@ -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)
+{
Quoted 8 lines

include/rtdm/rtdm_driver.h static inline int rtdm_in_rt_context(void) · line 1304

Quoted 3 lines
include/rtdm/rtdm_driver.h +3 -0
+	return (!xnpod_root_p() || xnshadow_thread(current) != NULL);
+}
+

This patch still has fundamental flaw, the service would not work correctly and would actually return the wrong value, in case it is used deeply buried into some helper code, traversed by asynchronous Xenomai contexts.

Using it from that contexts would be the fundamental flaw. We can catch this, though.

Quoted 9 lines

At the very least, you should avoid this by binding that service to a valid rtdm_dev_context, so that you know that it is called from a context that is correct in the first place, where a rtdm_dev_context reference is available.

I.e.
static inline int rtdm_rt_capable(struct rtdm_dev_context *context), and extract the information from that context structure. That would avoid a lot of headaches down the road to your user base.

The context is not that helpful here.

But instead of using current, we can force the caller to pass the user_info which is only available in helper context:

static inline int rtdm_rt_capable(rtdm_user_info_t *user_info)

{
	XENO_ASSERT(RTDM, !xnpod_asynch_p(), return 0;);

	return (!xnpod_root_p() ||
		(user_info && xnshadow_thread(user_info) != NULL));
}

Pushed a corresponding patch.

Jan

#5 lore raw

Re: [Xenomai-core] [PATCH v4 02/25] RTDM: Add rtdm_rt_capable() service

Quoted 36 lines · Jan Kiszka
Quoted 26 lines · Philippe Gerum
Quoted 25 lines · Jan Kiszka

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 <[email protected]>
CC Alexis Berlemont <[email protected]>
---
 include/rtdm/rtdm_driver.h |    6 ++++++
 ksrc/skins/rtdm/drvlib.c   |   25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
include/rtdm/rtdm_driver.h +3 -0
index 0fc1496..d124157 100644
@@ -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)
+{
Quoted 8 lines

include/rtdm/rtdm_driver.h static inline int rtdm_in_rt_context(void) · line 1304

Quoted 3 lines
include/rtdm/rtdm_driver.h +3 -0
+	return (!xnpod_root_p() || xnshadow_thread(current) != NULL);
+}
+

This patch still has fundamental flaw, the service would not work correctly and would actually return the wrong value, in case it is used deeply buried into some helper code, traversed by asynchronous Xenomai contexts.

Quoted 3 lines

Using it from that contexts would be the fundamental flaw. We can catch this, though.

Sure, but this API is supposed to help people to deal with context issues by providing unambiguous services.

Quoted 15 lines
Quoted 9 lines

At the very least, you should avoid this by binding that service to a valid rtdm_dev_context, so that you know that it is called from a context that is correct in the first place, where a rtdm_dev_context reference is available.

I.e.
static inline int rtdm_rt_capable(struct rtdm_dev_context *context), and extract the information from that context structure. That would avoid a lot of headaches down the road to your user base.

The context is not that helpful here.

But instead of using current, we can force the caller to pass the user_info which is only available in helper context:

Quoted 7 lines

static inline int rtdm_rt_capable(rtdm_user_info_t *user_info)

{
	XENO_ASSERT(RTDM, !xnpod_asynch_p(), return 0;);

	return (!xnpod_root_p() ||
		(user_info && xnshadow_thread(user_info) != NULL));
}

This is now correct in a Xenomai context. Thanks.

Quoted 5 lines

Pushed a corresponding patch.

Jan

Signature · 1 line
Philippe.
author
#6 lore raw

PATCH v4 3/25 RTDM: Bump API version and document changes

In reply to Jan Kiszka
---
 include/rtdm/rtdm.h         |    4 ++--
 ksrc/skins/rtdm/API.CHANGES |    6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
include/rtdm/rtdm.h +2 -2
index 6e02083..1e6e41e 100644
@@ -31,7 +31,7 @@
  * RT/non-RT systems like Xenomai. RTDM conforms to POSIX
  * semantics (IEEE Std 1003.1) where available and applicable.
  *
- * @b API @b Revision: 7
+ * @b API @b Revision: 8
  */
 
 /*!
@@ -76,7 +76,7 @@ typedef struct task_struct rtdm_user_info_t;
  * @anchor api_versioning @name API Versioning
  * @{ */
 /** Common user and driver API version */
-#define RTDM_API_VER			7
+#define RTDM_API_VER			8
 
 /** Minimum API revision compatible with the current release */
 #define RTDM_API_MIN_COMPAT_VER		6
ksrc/skins/rtdm/API.CHANGES +6 -0
index ca9012b..84487f7 100644
@@ -5,6 +5,12 @@ Scheduled modifications (unsorted):
  o Support for deferring IRQ line re-enabling from handler to thread context.
  o Support for user-space drivers.
 
+Revision 8:
+ o Added rtdm_rt_capable.
+
+Revision 7:
+ o Added callbacks and services to enable select support.
+
 Revision 6:
  o Added profile_version field to rtdm_device.
  o Requested IRQ lines are now enabled on return of rtdm_irq_request.
Signature · 1 line
1.6.0.2
author
#7 lore raw

PATCH v4 4/25 Revert "rtdm: tag syscalls as conforming"

In reply to Jan Kiszka

This reverts commit 13bfdd477ab880499d2e8f3b82c49ef4d2cccff0. We better let the driver trigger the confoming switch once it detects such a case by using the new service rtdm_rt_capable(). Always being comforming caused regressions for existing designs.

CC Philippe Gerum <[email protected]>
CC Alexis Berlemont <[email protected]>
---
 ksrc/skins/rtdm/syscall.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
ksrc/skins/rtdm/syscall.c +5 -5
index d869887..80785ab 100644
@@ -154,14 +154,14 @@ static xnsysent_t __systab[] = {
 	[__rtdm_close] =
 	    {sys_rtdm_close, __xn_exec_current | __xn_exec_adaptive},
 	[__rtdm_ioctl] =
-	    {sys_rtdm_ioctl, __xn_exec_conforming | __xn_exec_adaptive},
-	[__rtdm_read] = {sys_rtdm_read, __xn_exec_conforming | __xn_exec_adaptive},
+	    {sys_rtdm_ioctl, __xn_exec_current | __xn_exec_adaptive},
+	[__rtdm_read] = {sys_rtdm_read, __xn_exec_current | __xn_exec_adaptive},
 	[__rtdm_write] =
-	    {sys_rtdm_write, __xn_exec_conforming | __xn_exec_adaptive},
+	    {sys_rtdm_write, __xn_exec_current | __xn_exec_adaptive},
 	[__rtdm_recvmsg] =
-	    {sys_rtdm_recvmsg, __xn_exec_conforming | __xn_exec_adaptive},
+	    {sys_rtdm_recvmsg, __xn_exec_current | __xn_exec_adaptive},
 	[__rtdm_sendmsg] =
-	    {sys_rtdm_sendmsg, __xn_exec_conforming | __xn_exec_adaptive},
+	    {sys_rtdm_sendmsg, __xn_exec_current | __xn_exec_adaptive},
 };
 
 static struct xnskin_props __props = {
Signature · 1 line
1.6.0.2
author
#8 lore raw

PATCH v4 5/25 RTDM: Deprecate open_rt, socket_rt, and close_rt

In reply to Jan Kiszka

Support for RTDM device creation and destruction in RT context will be removed in the future. Start warning the users about this when loading a driver that makes use of it.

CC Philippe Gerum <[email protected]>
---
 include/rtdm/rtdm_driver.h  |   12 +++++++++---
 ksrc/skins/rtdm/API.CHANGES |    2 ++
 ksrc/skins/rtdm/device.c    |   14 +++++++++++++-
 3 files changed, 24 insertions(+), 4 deletions(-)
include/rtdm/rtdm_driver.h +9 -3
index d124157..d68f542 100644
@@ -328,7 +328,8 @@ typedef int (*rtdm_rt_handler_t)(struct rtdm_dev_context *context,
 struct rtdm_operations {
 	/*! @name Common Operations
 	 * @{ */
-	/** Close handler for real-time contexts (optional) */
+	/** 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;
@@ -468,14 +469,19 @@ struct rtdm_device {
 	int socket_type;
 
 	/** Named device instance creation for real-time contexts,
-	 *  optional if open_nrt is non-NULL, ignored for protocol devices */
+	 *  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;
 
 	/** Protocol socket creation for real-time contexts,
-	 *  optional if socket_nrt is non-NULL, ignored for named devices */
+	 *  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 */
ksrc/skins/rtdm/API.CHANGES +2 -0
index 84487f7..64a4b38 100644
@@ -4,6 +4,8 @@ Scheduled modifications (unsorted):
  o Threaded IRQ handlers.
  o Support for deferring IRQ line re-enabling from handler to thread context.
  o Support for user-space drivers.
+ o Removal of open_rt, socket_rt, and close_rt, ie. support for device
+   creation and destruction in RT context.
 
 Revision 8:
  o Added rtdm_rt_capable.
ksrc/skins/rtdm/device.c +13 -1
index e927ce7..e229932 100644
@@ -219,6 +219,10 @@ int rtdm_dev_register(struct rtdm_device *device)
 		XENO_ASSERT(RTDM, ANY_HANDLER(*device, open),
 			    xnlogerr("RTDM: missing open handler\n");
 			    return -EINVAL;);
+		if (device->open_rt &&
+		    device->socket_rt != (void *)rtdm_no_support)
+			xnlogerr("RTDM: RT open handler is deprecated, "
+				 "driver requires update.\n");
 		SET_DEFAULT_OP_IF_NULL(*device, open);
 		SET_DEFAULT_OP(*device, socket);
 		break;
@@ -228,6 +232,10 @@ int rtdm_dev_register(struct rtdm_device *device)
 		XENO_ASSERT(RTDM, ANY_HANDLER(*device, socket),
 			    xnlogerr("RTDM: missing socket handler\n");
 			    return -EINVAL;);
+		if (device->socket_rt &&
+		    device->socket_rt != (void *)rtdm_no_support)
+			xnlogerr("RTDM: RT socket creation handler is "
+				 "deprecated, driver requires update.\n");
 		SET_DEFAULT_OP_IF_NULL(*device, socket);
 		SET_DEFAULT_OP(*device, open);
 		break;
@@ -242,7 +250,11 @@ int rtdm_dev_register(struct rtdm_device *device)
 		xnlogerr("RTDM: missing non-RT close handler\n");
 		return -EINVAL;
 	}
-	if (!device->ops.close_rt)
+	if (device->ops.close_rt &&
+	    device->ops.close_rt != (void *)rtdm_no_support)
+		xnlogerr("RTDM: RT close handler is deprecated, driver "
+			 "requires update.\n");
+	else
 		device->ops.close_rt = (void *)rtdm_no_support;
 
 	SET_DEFAULT_OP_IF_NULL(device->ops, ioctl);
Signature · 1 line
1.6.0.2
author
#9 lore raw

PATCH v4 6/25 RTIPC: Fix memory leak on failing socket creation

In reply to Jan Kiszka
CC Philippe Gerum <[email protected]>
---
 ksrc/drivers/ipc/rtipc.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
ksrc/drivers/ipc/rtipc.c +6 -1
index d529912..563cc4e 100644
@@ -143,6 +143,7 @@ static int rtipc_socket(struct rtdm_dev_context *context,
 {
 	struct rtipc_protocol *proto;
 	struct rtipc_private *p;
+	int ret;
 
 	if (protocol < 0 || protocol >= IPCPROTO_MAX)
 		return -EPROTONOSUPPORT;
@@ -161,7 +162,11 @@ static int rtipc_socket(struct rtdm_dev_context *context,
 	if (p->state == NULL)
 		return -ENOMEM;
 
-	return proto->proto_ops.socket(p, user_info);
+	ret = proto->proto_ops.socket(p, user_info);
+	if (ret)
+		xnfree(p->state);
+
+	return ret;
 }
 
 static int rtipc_close(struct rtdm_dev_context *context,
Signature · 1 line
1.6.0.2
author
#10 lore raw

PATCH v4 7/25 RTIPC: Drop support for RT socket creation/deletion

In reply to Jan Kiszka

This is deprecated now, RT callers will automatically be migrated to NRT to perform the requests. Moreover, dropping it allows us to allocate resources from Linux instead of using the precious system heap.

CC Philippe Gerum <[email protected]>
---
 ksrc/drivers/ipc/rtipc.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
ksrc/drivers/ipc/rtipc.c +3 -5
index 563cc4e..71629cb 100644
@@ -158,13 +158,13 @@ static int rtipc_socket(struct rtdm_dev_context *context,
 
 	p = rtdm_context_to_private(context);
 	p->proto = proto;
-	p->state = xnmalloc(proto->proto_statesz);
+	p->state = kmalloc(proto->proto_statesz, GFP_KERNEL);
 	if (p->state == NULL)
 		return -ENOMEM;
 
 	ret = proto->proto_ops.socket(p, user_info);
 	if (ret)
-		xnfree(p->state);
+		kfree(p->state);
 
 	return ret;
 }
@@ -180,7 +180,7 @@ static int rtipc_close(struct rtdm_dev_context *context,
 	if (ret)
 		return ret;
 
-	xnfree(p->state);
+	kfree(p->state);
 
 	return 0;
 }
@@ -232,10 +232,8 @@ static struct rtdm_device device = {
 	.device_name	=	"rtipc",
 	.protocol_family=	PF_RTIPC,
 	.socket_type	=	SOCK_DGRAM,
-	.socket_rt	=	rtipc_socket,
 	.socket_nrt	=	rtipc_socket,
 	.ops = {
-		.close_rt	=	NULL,
 		.close_nrt	=	rtipc_close,
 		.recvmsg_rt	=	rtipc_recvmsg,
 		.recvmsg_nrt	=	NULL,
Signature · 1 line
1.6.0.2
author
#11 lore raw

PATCH v4 8/25 RTCAN: Drop support for socket creation/deletion in real-time

In reply to Jan Kiszka

This is deprecated now, RT callers will automatically be migrated to NRT to perform the requests.

CC Wolfgang Grandegger <[email protected]>
---
 ksrc/drivers/can/rtcan_raw.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
ksrc/drivers/can/rtcan_raw.c +0 -2
index 0cf0bb9..9ee0950 100644
@@ -999,11 +999,9 @@ static struct rtdm_device rtcan_proto_raw_dev = {
     protocol_family:    PF_CAN,
     socket_type:        SOCK_RAW,
 
-    socket_rt:          rtcan_raw_socket,
     socket_nrt:         rtcan_raw_socket,
 
     ops: {
-        close_rt:       rtcan_raw_close,
         close_nrt:      rtcan_raw_close,
 
         ioctl_rt:       rtcan_raw_ioctl,
Signature · 1 line
1.6.0.2
author
#12 lore raw

PATCH v4 9/25 16550A: Drop support for device opening/closing in real-time

In reply to Jan Kiszka

This is deprected now, RT callers will automatically be switched to non-RT. Along this, simplify the allocation logic for the RX timestamp history buffer. We only support allocations from non-RT now and migrate RT callers as required.

---
 ksrc/drivers/serial/16550A.c |   51 +++++++++++------------------------------
 1 files changed, 14 insertions(+), 37 deletions(-)
ksrc/drivers/serial/16550A.c +14 -37
index db8a515..4c46d86 100644
@@ -297,7 +297,7 @@ static int rt_16550_interrupt(rtdm_irq_t * irq_context)
 
 static int rt_16550_set_config(struct rt_16550_context *ctx,
 			       const struct rtser_config *config,
-			       uint64_t ** in_history_ptr)
+			       uint64_t **in_history_ptr)
 {
 	rtdm_lockctx_t lock_ctx;
 	unsigned long base = ctx->base_addr;
@@ -537,12 +537,7 @@ int rt_16550_close(struct rtdm_dev_context *context,
 
 	rt_16550_cleanup_ctx(ctx);
 
-	if (in_history) {
-		if (test_bit(RTDM_CREATED_IN_NRT, &context->context_flags))
-			kfree(in_history);
-		else
-			rtdm_free(in_history);
-	}
+	kfree(in_history);
 
 	return 0;
 }
@@ -602,40 +597,24 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
 
 		if (testbits(config->config_mask,
 			     RTSER_SET_TIMESTAMP_HISTORY)) {
-			if (test_bit(RTDM_CREATED_IN_NRT,
-				     &context->context_flags)
-			    && rtdm_in_rt_context()) {
-				/* Already fail here if we MAY allocate or
-				   release a non-RT buffer in RT context. */
-				return -EPERM;
-			}
+			/*
+			 * Reflect the call to non-RT as we will likely
+			 * allocate or free the buffer.
+			 */
+			if (rtdm_in_rt_context())
+				return -ENOSYS;
 
 			if (testbits(config->timestamp_history,
-				     RTSER_RX_TIMESTAMP_HISTORY)) {
-				if (test_bit(RTDM_CREATED_IN_NRT,
-					     &context->context_flags))
-					hist_buf =
-					    kmalloc(IN_BUFFER_SIZE *
-						    sizeof(nanosecs_abs_t),
-						    GFP_KERNEL);
-				else
-					hist_buf =
-					    rtdm_malloc(IN_BUFFER_SIZE *
-						sizeof(nanosecs_abs_t));
-					if (!hist_buf)
-						return -ENOMEM;
-			}
+				     RTSER_RX_TIMESTAMP_HISTORY))
+				hist_buf = kmalloc(IN_BUFFER_SIZE *
+						   sizeof(nanosecs_abs_t),
+						   GFP_KERNEL);
 		}
 
 		rt_16550_set_config(ctx, config, &hist_buf);
 
-		if (hist_buf) {
-			if (test_bit(RTDM_CREATED_IN_NRT,
-				     &context->context_flags))
-				kfree(hist_buf);
-			else
-				rtdm_free(hist_buf);
-		}
+		if (hist_buf)
+			kfree(hist_buf);
 
 		break;
 	}
@@ -1107,11 +1086,9 @@ static const struct rtdm_device __initdata device_tmpl = {
 	.context_size		= sizeof(struct rt_16550_context),
 	.device_name		= "",
 
-	.open_rt		= rt_16550_open,
 	.open_nrt		= rt_16550_open,
 
 	.ops = {
-		.close_rt	= rt_16550_close,
 		.close_nrt	= rt_16550_close,
 
 		.ioctl_rt	= rt_16550_ioctl,
Signature · 1 line
1.6.0.2
author
#13 lore raw

PATCH v4 10/25 Analogy: Drop support for opening/closing in real-time

In reply to Jan Kiszka

This is deprected now, RT callers will automatically be switched to non-RT.

CC Alexis Berlemont <[email protected]>
---
 ksrc/drivers/analogy/rtdm_interface.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
ksrc/drivers/analogy/rtdm_interface.c +0 -2
index f769e4a..99abf2f 100644
@@ -227,11 +227,9 @@ static struct rtdm_device rtdm_devs[A4L_NB_DEVICES] =
 		.context_size =		sizeof(struct a4l_dummy_context),
 		.device_name = 		"",
 
-		.open_rt =		a4l_rt_open,
 		.open_nrt =		a4l_rt_open,
 
 		.ops = {
-			.close_rt =	a4l_rt_close,
 			.ioctl_rt =	a4l_rt_ioctl,
 			.read_rt =	a4l_rt_read,
 			.write_rt =	a4l_rt_write,
Signature · 1 line
1.6.0.2
author
#14 lore raw

PATCH v4 11/25 RTDM: Instrument rtdm_context_lock/unlock to detect misuses

In reply to Jan Kiszka

rtdm_context_lock must only be called on context structures that are already locked, and rtdm_context_unlock must be kept in balance with rtdm_context_get/rtdm_context_lock. Try to check for mistakes by requiring non-null clock_lock_count on entry of both services.

Also fix a typo and clarify the use cases and restrictions of rtdm_context_lock.

CC Philippe Gerum <[email protected]>
---
 include/rtdm/rtdm_driver.h |    4 ++++
 ksrc/skins/rtdm/core.c     |   10 +++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)
include/rtdm/rtdm_driver.h +4 -0
index d68f542..3fc9071 100644
@@ -555,11 +555,15 @@ struct rtdm_dev_context *rtdm_context_get(int fd);
 #ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */
 static inline void rtdm_context_lock(struct rtdm_dev_context *context)
 {
+	XENO_ASSERT(RTDM, atomic_read(&context->close_lock_count) > 0,
+		    /* just warn if context was a dangling pointer */);
 	atomic_inc(&context->close_lock_count);
 }
 
 static inline void rtdm_context_unlock(struct rtdm_dev_context *context)
 {
+	XENO_ASSERT(RTDM, atomic_read(&context->close_lock_count) > 0,
+		    /* just warn if context was a dangling pointer */);
 	smp_mb__before_atomic_dec();
 	atomic_dec(&context->close_lock_count);
 }
ksrc/skins/rtdm/core.c +7 -3
index 8cccf52..ba4dc63 100644
@@ -87,7 +87,7 @@ struct rtdm_dev_context *rtdm_context_get(int fd)
 		return NULL;
 	}
 
-	rtdm_context_lock(context);
+	atomic_inc(&context->close_lock_count);
 
 	xnlock_put_irqrestore(&rt_fildes_lock, s);
 
@@ -328,7 +328,7 @@ again:
 	}
 
 	set_bit(RTDM_CLOSING, &context->context_flags);
-	rtdm_context_lock(context);
+	atomic_inc(&context->close_lock_count);
 
 	xnlock_put_irqrestore(&rt_fildes_lock, s);
 
@@ -588,7 +588,11 @@ EXPORT_SYMBOL(rtdm_select_bind);
  * @param[in] context Device context
  *
  * @note rtdm_context_get() automatically increments the lock counter. You
- * only need to call this function in special scenrios.
+ * only need to call this function in special scenarios, e.g. when keeping
+ * additional references to the context structure that have different
+ * lifetimes. Only use rtdm_context_lock() on contexts that are currently
+ * locked via an earlier rtdm_context_get()/rtdm_contex_lock() or while
+ * running a device operation handler.
  *
  * Environments:
  *
Signature · 1 line
1.6.0.2
author
#15 lore raw

PATCH v4 12/25 RTDM: Add rtdm_context_put()

In reply to Jan Kiszka

As suggested by Philippe: This is an alias of rtdm_context_unlock(), but it is more intuitive to match it with rtdm_context_get() calls.

CC Philippe Gerum <[email protected]>
---
 include/rtdm/rtdm_driver.h  |    5 +++++
 ksrc/skins/rtdm/API.CHANGES |    1 +
 ksrc/skins/rtdm/core.c      |   29 +++++++++++++++++++++++++----
 3 files changed, 31 insertions(+), 4 deletions(-)
include/rtdm/rtdm_driver.h +5 -0
index 3fc9071..07b73a3 100644
@@ -568,6 +568,11 @@ static inline void rtdm_context_unlock(struct rtdm_dev_context *context)
 	atomic_dec(&context->close_lock_count);
 }
 
+static inline void rtdm_context_put(struct rtdm_dev_context *context)
+{
+	rtdm_context_unlock(context);
+}
+
 /* --- clock services --- */
 struct xntbase;
 extern struct xntbase *rtdm_tbase;
ksrc/skins/rtdm/API.CHANGES +1 -0
index 64a4b38..73c1850 100644
@@ -9,6 +9,7 @@ Scheduled modifications (unsorted):
 
 Revision 8:
  o Added rtdm_rt_capable.
+ o Added rtdm_context_put as logic match to rtdm_context_get
 
 Revision 7:
  o Added callbacks and services to enable select support.
ksrc/skins/rtdm/core.c +25 -4
index ba4dc63..e04b3f6 100644
@@ -50,14 +50,14 @@ EXPORT_SYMBOL(rtdm_tbase);
 DEFINE_XNLOCK(rt_fildes_lock);
 
 /**
- * @brief Resolve file descriptor to device context
+ * @brief Retrieve and lock a device context
  *
  * @param[in] fd File descriptor
  *
  * @return Pointer to associated device context, or NULL on error
  *
- * @note The device context has to be unlocked using rtdm_context_unlock()
- * when it is no longer referenced.
+ * @note The device context has to be unlocked using rtdm_context_put() when
+ * it is no longer referenced.
  *
  * Environments:
  *
@@ -612,7 +612,7 @@ void rtdm_context_lock(struct rtdm_dev_context *context);
  *
  * @param[in] context Device context
  *
- * @note Every successful call to rtdm_context_get() must be matched by a
+ * @note Every call to rtdm_context_locked() must be matched by a
  * rtdm_context_unlock() invocation.
  *
  * Environments:
@@ -629,6 +629,27 @@ void rtdm_context_lock(struct rtdm_dev_context *context);
 void rtdm_context_unlock(struct rtdm_dev_context *context);
 
 /**
+ * @brief Release a device context obtained via rtdm_context_get()
+ *
+ * @param[in] context Device context
+ *
+ * @note Every successful call to rtdm_context_get() must be matched by a
+ * rtdm_context_put() invocation.
+ *
+ * Environments:
+ *
+ * This service can be called from:
+ *
+ * - Kernel module initialization/cleanup code
+ * - Interrupt service routine
+ * - Kernel-based task
+ * - User-space task (RT, non-RT)
+ *
+ * Rescheduling: never.
+ */
+void rtdm_context_put(struct rtdm_dev_context *context);
+
+/**
  * @brief Open a device
  *
  * Refer to rt_dev_open() for parameters and return values
Signature · 1 line
1.6.0.2
author
#16 lore raw

PATCH v4 13/25 Fix historic msleep wrapping

In reply to Jan Kiszka

Probably only an academic exercise: Fix the rounding bug in msleep wrapper for kernels < 2.4.28.

---
 include/asm-generic/wrappers.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/asm-generic/wrappers.h +1 -1
index 15d9837..64ec43f 100644
@@ -197,7 +197,7 @@ do {									\
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,28)
 #define msleep(x) do {				 \
 	set_current_state(TASK_UNINTERRUPTIBLE); \
-	schedule_timeout((x)*(HZ/1000));         \
+	schedule_timeout(((x)*HZ)/1000);         \
 } while(0)
 #endif
 
Signature · 1 line
1.6.0.2
author
#17 lore raw

PATCH v4 14/25 irqbench: Fix x86-64 build

In reply to Jan Kiszka
---
 configure.in                       |    2 +-
 src/testsuite/irqbench/Makefile.am |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
configure.in +1 -1
index 0228f51..9d6fe35 100644
@@ -127,7 +127,7 @@ case "$build_for" in
 esac
 
 AC_MSG_RESULT([$XENO_TARGET_ARCH])
-AM_CONDITIONAL(XENO_LINUX_ARCH_I386,[test $XENO_LINUX_ARCH = i386])
+AM_CONDITIONAL(XENO_TARGET_ARCH_X86,[test $XENO_TARGET_ARCH = x86])
 
 case "$XENO_TARGET_ARCH" in
  nios2)
src/testsuite/irqbench/Makefile.am +1 -1
index 27c5ddb..3e531c7 100644
@@ -5,7 +5,7 @@ CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 
 test_PROGRAMS = irqloop
 
-if XENO_LINUX_ARCH_I386
+if XENO_TARGET_ARCH_X86
 test_PROGRAMS += irqbench
 endif
 
Signature · 1 line
1.6.0.2
author
#18 lore raw

PATCH v4 15/25 irqbench: Refactor user space helpers

In reply to Jan Kiszka

Indent according to our style, push irqbench's inner loop into separate function. No functional changes.

---
 src/testsuite/irqbench/irqbench.c |  480 ++++++++++++++++++-------------------
 src/testsuite/irqbench/irqloop.c  |  303 ++++++++++++------------
 2 files changed, 393 insertions(+), 390 deletions(-)
src/testsuite/irqbench/irqbench.c +239 -241
index 6b22711..844f187 100644
@@ -51,268 +51,266 @@
 #define STAT(base) (base + 1) /* Status register */
 #define CTRL(base) (base + 2) /* Control register */
 
-double tsc2ns_scale;
-long long min_lat = LONG_MAX;
-long long max_lat = LONG_MIN;
-long long avg_lat = 0;
-long outer_loops = 0;
-int warmup = 1;
-int terminate = 0;
+static double tsc2ns_scale;
+static long long min_lat = LONG_MAX;
+static long long max_lat = LONG_MIN;
+static long long avg_lat;
+static long outer_loops;
+static int warmup = 1;
+static int terminate;
+static unsigned long port_ioaddr = 0x3F8;
+static int port_type = SERPORT;
+static unsigned int toggle;
+static long loop_avg;
+static long long period = 100000;
+static int trigger_trace;
 
 static inline long long rdtsc(void)
 {
-    unsigned long long tsc;
+	unsigned long long tsc;
 
-    __asm__ __volatile__("rdtsc" : "=A" (tsc));
-    return tsc;
+	__asm__ __volatile__("rdtsc" : "=A" (tsc));
+	return tsc;
 }
 
-
 static long tsc2ns(long long tsc)
 {
-    if ((tsc > LONG_MAX) || (tsc < LONG_MIN)) {
-        fprintf(stderr, "irqbench: overflow (%lld ns)!\n",
-                (long long)(tsc2ns_scale * (double)tsc));
-        exit(2);
-    }
-    return (long)(tsc2ns_scale * (double)tsc);
+	if (tsc > LONG_MAX || tsc < LONG_MIN) {
+		fprintf(stderr, "irqbench: overflow (%lld ns)!\n",
+			(long long)(tsc2ns_scale * (double)tsc));
+		exit(2);
+	}
+	return (long)(tsc2ns_scale * (double)tsc);
 }
 
-
 static inline long long ns2tsc(long long ns)
 {
-    return (long long)(((double)ns) / tsc2ns_scale);
+	return (long long)(((double)ns) / tsc2ns_scale);
 }
 
-
-void calibrate_tsc(void)
+static void calibrate_tsc(void)
 {
-    FILE *proc;
-    char *lineptr = NULL;
-    size_t len;
-    double cpu_mhz;
-
-    proc = fopen("/proc/cpuinfo", "r");
-    if (proc == NULL) {
-        perror("irqbench: Unable to open /proc/cpuinfo");
-        exit(1);
-    }
-
-    while (getline(&lineptr, &len, proc) != -1)
-        if (strncmp(lineptr, "cpu MHz", 7) == 0) {
-            sscanf(strchr(lineptr, ':') + 1, "%lf", &cpu_mhz);
-            break;
-        }
-
-    if (lineptr)
-        free(lineptr);
-    fclose(proc);
-
-    printf("CPU frequency: %.3lf MHz\n", cpu_mhz);
-
-    tsc2ns_scale = 1000.0 / cpu_mhz;
+	FILE *proc;
+	char *lineptr = NULL;
+	size_t len;
+	double cpu_mhz;
+
+	proc = fopen("/proc/cpuinfo", "r");
+	if (proc == NULL) {
+		perror("irqbench: Unable to open /proc/cpuinfo");
+		exit(1);
+	}
+
+	while (getline(&lineptr, &len, proc) != -1)
+		if (strncmp(lineptr, "cpu MHz", 7) == 0) {
+			sscanf(strchr(lineptr, ':') + 1, "%lf", &cpu_mhz);
+			break;
+		}
+
+	if (lineptr)
+		free(lineptr);
+	fclose(proc);
+
+	printf("CPU frequency: %.3lf MHz\n", cpu_mhz);
+
+	tsc2ns_scale = 1000.0 / cpu_mhz;
 }
 
-
-void sighand(int signal)
+static void sighand(int signal)
 {
-    if (warmup)
-        exit(0);
-    else
-        terminate = 1;
+	if (warmup)
+		exit(0);
+	else
+		terminate = 1;
 }
 
+static void do_inner_loop(void)
+{
+	long long start, delay, timeout;
+	long lat;
+
+	__asm__ __volatile__("cli");
+
+	if (port_type ==  SERPORT) {
+		start = rdtsc();
+
+		toggle ^= MCR_RTS;
+		outb(toggle, MCR(port_ioaddr));
+
+		timeout = start + period * 100;
+		while ((inb(MSR(port_ioaddr)) & MSR_DELTA) == 0 &&
+		       rdtsc() < timeout);
+
+		delay = rdtsc() - start;
+	} else {
+		int status = inb(STAT(port_ioaddr));
+
+		outb(0x08, DATA(port_ioaddr));
+
+		start = rdtsc();
+
+		outb(0x00, DATA(port_ioaddr));
+
+		timeout = start + period * 100;
+		while (inb(STAT(port_ioaddr)) == status &&
+		       rdtsc() < timeout);
+
+		delay = rdtsc() - start;
+	}
+
+	if (!warmup) {
+		lat = tsc2ns(delay);
+
+		loop_avg += lat;
+		if (lat < min_lat)
+			min_lat = lat;
+		if (lat > max_lat) {
+			max_lat = lat;
+			if (trigger_trace) {
+				if (port_type == SERPORT) {
+					toggle ^= MCR_DTR;
+					outb(toggle, MCR(port_ioaddr));
+				} else {
+					outb(0x18, DATA(port_ioaddr));
+					outb(0x10, DATA(port_ioaddr));
+				}
+			}
+		}
+	}
+
+	__asm__ __volatile__("sti");
+
+	while (rdtsc() < start + period);
+}
 
 int main(int argc, char *argv[])
 {
-    int                 port_type   = SERPORT;
-    unsigned long       port_ioaddr = 0x3F8;
-    int                 ioaddr_set = 0;
-    long long           period = 100000;
-    long long           timeout;
-    long long           start, delay;
-    unsigned long long  count = 1;
-    unsigned int        toggle = 0;
-    int                 trigger_trace = 0;
-    int                 c;
-
-
-    signal(SIGINT, sighand);
-    signal(SIGTERM, sighand);
-    signal(SIGHUP, sighand);
-    signal(SIGALRM, sighand);
-
-    calibrate_tsc();
-
-    while ((c = getopt(argc,argv,"p:T:o:a:f")) != EOF)
-        switch (c) {
-            case 'p':
-                period = atoi(optarg) * 1000;
-                break;
-
-            case 'T':
-                alarm(atoi(optarg));
-                break;
-
-            case 'o':
-                port_type = atoi(optarg);
-                break;
-
-            case 'a':
-                port_ioaddr = strtol(optarg, NULL,
-                    (strncmp(optarg, "0x", 2) == 0) ? 16 : 10);
-                ioaddr_set = 1;
-                break;
-
-            case 'f':
-                trigger_trace = 1;
-                break;
-
-            default:
-                fprintf(stderr, "usage: irqbench [options]\n"
-                        "  [-p <period_us>]             # signal period, default=100 us\n"
-                        "  [-T <test_duration_seconds>] # default=0, so ^C to end\n"
-                        "  [-o <port_type>]             # 0=serial (default), 1=parallel\n"
-                        "  [-a <port_io_address>]       # default=0x3f8/0x378\n"
-                        "  [-f]                         # freeze trace for each new max latency\n");
-                exit(2);
-        }
-
-    /* set defaults for parallel port */
-    if (port_type == 1 && !ioaddr_set)
-        port_ioaddr = 0x378;
-
-    if (iopl(3) < 0) {
-        fprintf(stderr, "irqbench: superuser permissions required\n");
-        exit(1);
-    }
-    mlockall(MCL_CURRENT | MCL_FUTURE);
-
-    switch (port_type) {
-        case SERPORT:
-            toggle = MCR_OUT2;
-            inb(MSR(port_ioaddr));
-            break;
-
-        case PARPORT:
-            outb(CTRL_INIT, CTRL(port_ioaddr));
-            break;
-
-        default:
-            fprintf(stderr, "irqbench: invalid port type\n");
-            exit(1);
-    }
-
-    period = ns2tsc(period);
-
-    printf("Port type:     %s\n"
-           "Port address:  0x%lx\n\n",
-           (port_type == SERPORT) ? "serial" : "parallel", port_ioaddr);
-
-    printf("Waiting on target...\n");
-
-    while (1)
-        if (port_type ==  SERPORT) {
-            toggle ^= MCR_RTS;
-            outb(toggle, MCR(port_ioaddr));
-            usleep(100000);
-            if ((inb(MSR(port_ioaddr)) & MSR_DELTA) != 0)
-                break;
-        } else {
-            int status = inb(STAT(port_ioaddr));
-
-            outb(0x08, DATA(port_ioaddr));
-            outb(0x00, DATA(port_ioaddr));
-            usleep(100000);
-            if (inb(STAT(port_ioaddr)) != status)
-                break;
-        }
-
-    printf("Warming up...\n");
-
-    while (!terminate) {
-        long long loop_timeout = rdtsc() + ns2tsc(1000000000LL);
-        long loop_avg = 0;
-        int inner_loops = 0;
-
-        while (rdtsc() < loop_timeout) {
-            long lat;
-
-            __asm__ __volatile__("cli");
-
-            if (port_type ==  SERPORT) {
-                start = rdtsc();
-
-                toggle ^= MCR_RTS;
-                outb(toggle, MCR(port_ioaddr));
-
-                timeout = start + period * 100;
-                while (((inb(MSR(port_ioaddr)) & MSR_DELTA) == 0) &&
-                       (rdtsc() < timeout));
-
-                delay = rdtsc() - start;
-            } else {
-                int status = inb(STAT(port_ioaddr));
-
-                outb(0x08, DATA(port_ioaddr));
-
-                start = rdtsc();
-
-                outb(0x00, DATA(port_ioaddr));
-
-                timeout = start + period * 100;
-                while ((inb(STAT(port_ioaddr)) == status) &&
-                       (rdtsc() < timeout));
-
-                delay = rdtsc() - start;
-            }
-
-            if (!warmup) {
-                lat = tsc2ns(delay);
-
-                loop_avg += lat;
-                if (lat < min_lat)
-                    min_lat = lat;
-                if (lat > max_lat) {
-                    max_lat = lat;
-                    if (trigger_trace) {
-                        if (port_type == SERPORT) {
-                            toggle ^= MCR_DTR;
-                            outb(toggle, MCR(port_ioaddr));
-                        } else {
-                            outb(0x18, DATA(port_ioaddr));
-                            outb(0x10, DATA(port_ioaddr));
-                        }
-                    }
-                }
-            }
-
-            __asm__ __volatile__("sti");
-
-            inner_loops++;
-
-            while (rdtsc() < start + period);
-        }
-
-        count += inner_loops;
-
-        if (!warmup && !terminate) {
-            loop_avg /= inner_loops;
-
-            printf("%llu: %.3f / %.3f / %.3f us\n", count,
-                ((double)min_lat) / 1000.0, ((double)loop_avg) / 1000.0,
-                ((double)max_lat) / 1000.0);
-
-            avg_lat += loop_avg;
-            outer_loops++;
-        } else
-            warmup = 0;
-    }
-
-    avg_lat /= outer_loops;
-    printf("---\n%llu: %.3f / %.3f / %.3f us\n", count,
-           ((double)min_lat) / 1000.0, ((double)avg_lat) / 1000.0,
-           ((double)max_lat) / 1000.0);
-
-    return 0;
+	int ioaddr_set = 0;
+	unsigned long long count = 1;
+	int c;
+
+	signal(SIGINT, sighand);
+	signal(SIGTERM, sighand);
+	signal(SIGHUP, sighand);
+	signal(SIGALRM, sighand);
+
+	calibrate_tsc();
+
+	while ((c = getopt(argc, argv, "p:T:o:a:f")) != EOF)
+		switch (c) {
+		case 'p':
+			period = atoi(optarg) * 1000;
+			break;
+
+		case 'T':
+			alarm(atoi(optarg));
+			break;
+
+		case 'o':
+			port_type = atoi(optarg);
+			break;
+
+		case 'a':
+			port_ioaddr = strtol(optarg, NULL, (strncmp(optarg, "0x", 2) == 0) ? 16 : 10);
+			ioaddr_set = 1;
+			break;
+
+		case 'f':
+			trigger_trace = 1;
+			break;
+
+		default:
+			fprintf(stderr, "usage: irqbench [options]\n"
+				"  [-p <period_us>]             # signal period, default=100 us\n"
+				"  [-T <test_duration_seconds>] # default=0, so ^C to end\n"
+				"  [-o <port_type>]             # 0=serial (default), 1=parallel\n"
+				"  [-a <port_io_address>]       # default=0x3f8/0x378\n"
+				"  [-f]                         # freeze trace for each new max latency\n");
+			exit(2);
+		}
+
+	/* set defaults for parallel port */
+	if (port_type == 1 && !ioaddr_set)
+		port_ioaddr = 0x378;
+
+	if (iopl(3) < 0) {
+		fprintf(stderr, "irqbench: superuser permissions required\n");
+		exit(1);
+	}
+	mlockall(MCL_CURRENT | MCL_FUTURE);
+
+	switch (port_type) {
+	case SERPORT:
+		toggle = MCR_OUT2;
+		inb(MSR(port_ioaddr));
+		break;
+
+	case PARPORT:
+		outb(CTRL_INIT, CTRL(port_ioaddr));
+		break;
+
+	default:
+		fprintf(stderr, "irqbench: invalid port type\n");
+		exit(1);
+	}
+
+	period = ns2tsc(period);
+
+	printf("Port type:     %s\n"
+	       "Port address:  0x%lx\n\n",
+	       (port_type == SERPORT) ? "serial" : "parallel", port_ioaddr);
+
+	printf("Waiting on target...\n");
+
+	while (1)
+		if (port_type ==  SERPORT) {
+			toggle ^= MCR_RTS;
+			outb(toggle, MCR(port_ioaddr));
+			usleep(100000);
+			if ((inb(MSR(port_ioaddr)) & MSR_DELTA) != 0)
+				break;
+		} else {
+			int status = inb(STAT(port_ioaddr));
+
+			outb(0x08, DATA(port_ioaddr));
+			outb(0x00, DATA(port_ioaddr));
+			usleep(100000);
+			if (inb(STAT(port_ioaddr)) != status)
+				break;
+		}
+
+	printf("Warming up...\n");
+
+	while (!terminate) {
+		long long loop_timeout = rdtsc() + ns2tsc(1000000000LL);
+		int inner_loops = 0;
+
+		loop_avg = 0;
+		while (rdtsc() < loop_timeout) {
+			do_inner_loop();
+			inner_loops++;
+		}
+
+		count += inner_loops;
+
+		if (!warmup && !terminate) {
+			loop_avg /= inner_loops;
+
+			printf("%llu: %.3f / %.3f / %.3f us\n", count,
+			       ((double)min_lat) / 1000.0,
+			       ((double)loop_avg) / 1000.0,
+			       ((double)max_lat) / 1000.0);
+
+			avg_lat += loop_avg;
+			outer_loops++;
+		} else
+			warmup = 0;
+	}
+
+	avg_lat /= outer_loops;
+	printf("---\n%llu: %.3f / %.3f / %.3f us\n", count,
+	       ((double)min_lat) / 1000.0, ((double)avg_lat) / 1000.0,
+	       ((double)max_lat) / 1000.0);
+
+	return 0;
 }
src/testsuite/irqbench/irqloop.c +154 -149

319 lines not on this page · raw message

Signature · 1 line
1.6.0.2
author
#19 lore raw

PATCH v4 16/25 irqbench: Auto-detect bases of port address and IRQ values

In reply to Jan Kiszka
---
 src/testsuite/irqbench/irqbench.c |    2 +-
 src/testsuite/irqbench/irqloop.c  |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
src/testsuite/irqbench/irqbench.c +1 -1
index 844f187..ca7a313 100644
@@ -211,7 +211,7 @@ int main(int argc, char *argv[])
 			break;
 
 		case 'a':
-			port_ioaddr = strtol(optarg, NULL, (strncmp(optarg, "0x", 2) == 0) ? 16 : 10);
+			port_ioaddr = strtol(optarg, NULL, 0);
 			ioaddr_set = 1;
 			break;
 
src/testsuite/irqbench/irqloop.c +2 -2
index 3b4de4f..d4623b4 100644
@@ -101,12 +101,12 @@ int main(int argc, char *argv[])
 			break;
 
 		case 'a':
-			config.port_ioaddr = strtol(optarg, NULL, (strncmp(optarg, "0x", 2) == 0) ? 16 : 10);
+			config.port_ioaddr = strtol(optarg, NULL, 0);
 			ioaddr_set = 1;
 			break;
 
 		case 'i':
-			config.port_irq = atoi(optarg);
+			config.port_irq = strtol(optarg, NULL, 0);
 			irq_set = 1;
 			break;
 
Signature · 1 line
1.6.0.2
author
#20 lore raw

PATCH v4 17/25 rttest: Resolved test device conflicts via separate name spaces

In reply to Jan Kiszka

Usually, all devices of some RTDM class use the same naming scheme. But as test devices are different as they do not provide compatible APIs, let's give them separate name space for their device names. That finally resolves all the detection troubles that showed up once more than one test device was registered.

To allow addressing old drivers with new user space and vice versa, a config switch is added to the former to select the naming scheme, and the latter will try to open under both names.

---
 include/rtdm/rttesting.h              |   10 +++++++---
 ksrc/drivers/testing/Config.in        |    2 ++
 ksrc/drivers/testing/Kconfig          |    9 +++++++++
 ksrc/drivers/testing/irqbench.c       |    9 +++++++--
 ksrc/drivers/testing/klat.c           |    8 +++++++-
 ksrc/drivers/testing/switchtest.c     |    7 ++++++-
 ksrc/drivers/testing/timerbench.c     |    7 ++++++-
 src/testsuite/irqbench/irqloop.c      |   11 ++++++++++-
 src/testsuite/latency/latency.c       |   12 +++++++++++-
 src/testsuite/switchtest/switchtest.c |   15 +++++++++++++--
 10 files changed, 78 insertions(+), 12 deletions(-)
include/rtdm/rttesting.h +7 -3
index ce0418e..a660139 100644
@@ -29,13 +29,14 @@
  * Feel free to comment on this profile via the Xenomai mailing list
  * ([email protected]) or directly to the author ([email protected]).
  *
- * @b Profile @b Revision: 1
+ * @b Profile @b Revision: 2
  * @n
  * @n
  * @par Device Characteristics
  * @ref rtdm_device.device_flags "Device Flags": @c RTDM_NAMED_DEVICE @n
  * @n
- * @ref rtdm_device.device_name "Device Name": @c "rttest<N>", N >= 0 @n
+ * @ref rtdm_device.device_name "Device Name": @c "rttest[-<subclass>]<N>",
+ * N >= 0, optional subclass name to simplify device discovery @n
  * @n
  * @ref rtdm_device.device_class "Device Class": @c RTDM_CLASS_TESTING @n
  * @n
@@ -61,7 +62,7 @@
 
 #include <rtdm/rtdm.h>
 
-#define RTTST_PROFILE_VER		1
+#define RTTST_PROFILE_VER		2
 
 typedef struct rttst_bench_res {
 	long long avg;
@@ -145,8 +146,11 @@ struct rttst_swtest_error {
 /*!
  * @name Sub-Classes of RTDM_CLASS_TESTING
  * @{ */
+/** subclass name: "timerbench" */
 #define RTDM_SUBCLASS_TIMERBENCH	0
+/** subclass name: "irqbench" */
 #define RTDM_SUBCLASS_IRQBENCH		1
+/** subclass name: "switchtest" */
 #define RTDM_SUBCLASS_SWITCHTEST	2
 /** @} */
 
ksrc/drivers/testing/Config.in +2 -0
index 07bd900..3552670 100644
@@ -5,6 +5,8 @@
 mainmenu_option next_comment
 comment 'Testing drivers'
 
+bool 'Use legacy names for testing drivers' CONFIG_XENO_DRIVERS_TESTING_LEGACY_NAMES $CONFIG_XENO_SKIN_RTDM
+
 dep_tristate 'Timer benchmark driver' CONFIG_XENO_DRIVERS_TIMERBENCH $CONFIG_XENO_SKIN_RTDM
 
 dep_tristate 'IRQ benchmark driver' CONFIG_XENO_DRIVERS_IRQBENCH $CONFIG_XENO_SKIN_RTDM
ksrc/drivers/testing/Kconfig +9 -0
index 7ca2eb1..05d6a49 100644
@@ -4,6 +4,15 @@ config XENO_TESTING_MODULE
         depends on MODULES
 	def_tristate m
 
+config XENO_DRIVERS_TESTING_LEGACY_NAMES
+	depends on XENO_SKIN_RTDM
+	bool "Use legacy names for testing drivers"
+	help
+	This lets the testing drivers register under legacy names
+	("rttest<N>") instead of the new scheme ("rttest-<subclass><N>").
+	Only enable this if you plan to use old userspace tools with the
+	drivers.
+
 config XENO_DRIVERS_TIMERBENCH
 	depends on XENO_SKIN_RTDM
 	tristate "Timer benchmark driver"
ksrc/drivers/testing/irqbench.c +7 -2
index 3dfb646..ab9686a 100644
@@ -515,8 +515,13 @@ static int __init __irqbench_init(void)
 	int err;
 
 	do {
-		snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN, "rttest%d",
-			 start_index);
+		snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN,
+#ifdef CONFIG_XENO_DRIVERS_TESTING_LEGACY_NAMES
+			 "rttest%d",
+#else
+			 "rttest-irqbench%d",
+#endif
+			  start_index);
 		err = rtdm_dev_register(&device);
 
 		start_index++;
ksrc/drivers/testing/klat.c +7 -1
index 6070c26..9e3613e 100644
@@ -99,7 +99,13 @@ static int __init klat_mod_init(void)
 	pkt.config.freeze_max = freeze_max;
 
 	for (dev_nr = 0; dev_nr < DEV_NR_MAX; dev_nr++) {
-		snprintf(devname, sizeof(devname), "rttest%d", dev_nr);
+		snprintf(devname, sizeof(devname),
+#ifdef CONFIG_XENO_DRIVERS_TESTING_LEGACY_NAMES
+			 "rttest%d",
+#else
+			 "rttest-timerbench%d",
+#endif
+			 dev_nr);
 		fd = rt_dev_open(devname, O_RDONLY);
 		if (fd < 0)
 			continue;
ksrc/drivers/testing/switchtest.c +6 -1
index 057094b..e335bfb 100644
@@ -750,7 +750,12 @@ int __init __switchtest_init(void)
 	int err;
 
 	do {
-		snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN, "rttest%d",
+		snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN,
+#ifdef CONFIG_XENO_DRIVERS_TESTING_LEGACY_NAMES
+			 "rttest%d",
+#else
+			 "rttest-switchtest%d",
+#endif
 			 start_index);
 		err = rtdm_dev_register(&device);
 
ksrc/drivers/testing/timerbench.c +6 -1
index 0946a04..fcd040d 100644
@@ -508,7 +508,12 @@ static int __init __timerbench_init(void)
 	int err;
 
 	do {
-		snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN, "rttest%d",
+		snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN,
+#ifdef CONFIG_XENO_DRIVERS_TESTING_LEGACY_NAMES
+			 "rttest%d",
+#else
+			 "rttest-timerbench%d",
+#endif
 			 start_index);
 		err = rtdm_dev_register(&device);
 
src/testsuite/irqbench/irqloop.c +10 -1
index d4623b4..9298575 100644
@@ -26,6 +26,11 @@
 #include <sys/mman.h>
 #include <rtdm/rttesting.h>
 
+static const char *devname_fmt[] = {
+	"/dev/rttest-irqbench%d",
+	"/dev/rttest%d",
+};
+
 static int benchdev;
 static int terminate;
 
@@ -81,6 +86,7 @@ int main(int argc, char *argv[])
 	int irq_set = 0;
 	int c;
 	int timeout = 10;
+	int fmt = 0;
 
 	while ((c = getopt(argc, argv, "D:t:P:o:a:i:")) != EOF)
 		switch (c) {
@@ -136,9 +142,12 @@ int main(int argc, char *argv[])
 
 	mlockall(MCL_CURRENT|MCL_FUTURE);
 
-	snprintf(devname, RTDM_MAX_DEVNAME_LEN, "/dev/rttest%d", benchdev_no);
+retry:
+	snprintf(devname, RTDM_MAX_DEVNAME_LEN, devname_fmt[fmt], benchdev_no);
 	benchdev = open(devname, O_RDWR);
 	if (benchdev < 0) {
+		if (fmt++ == 0)
+			goto retry;
 		perror("irqloop: failed to open benchmark device");
 		fprintf(stderr, "(modprobe xeno_irqbench?)\n");
 		return 1;
src/testsuite/latency/latency.c +11 -1
index e9e741e..8c3ca87 100644
@@ -67,6 +67,11 @@ long *histogram_avg = NULL, *histogram_max = NULL, *histogram_min = NULL;
 int do_histogram = 0, do_stats = 0, finished = 0;
 int bucketsize = 1000;		/* default = 1000ns, -B <size> to override */
 
+static const char *devname_fmt[] = {
+	"rttest-timerbench%d",
+	"rttest%d",
+};
+
 static inline void add_histogram(long *histogram, long addval)
 {
 	/* bucketsize steps */
@@ -473,6 +478,7 @@ int main(int argc, char **argv)
 	int cpu = 0, c, err, sig;
 	char task_name[16];
 	sigset_t mask;
+	int fmt = 0;
 
 	while ((c = getopt(argc, argv, "hp:l:T:qH:B:sD:t:fc:P:b")) != EOF)
 		switch (c) {
@@ -622,11 +628,15 @@ int main(int argc, char **argv)
 	if (test_mode != USER_TASK) {
 		char devname[RTDM_MAX_DEVNAME_LEN];
 
-		snprintf(devname, RTDM_MAX_DEVNAME_LEN, "rttest%d",
+retry:
+		snprintf(devname, RTDM_MAX_DEVNAME_LEN, devname_fmt[fmt],
 			 benchdev_no);
 		benchdev = rt_dev_open(devname, O_RDWR);
 
 		if (benchdev < 0) {
+			if (fmt++ == 0)
+				goto retry;
+
 			fprintf(stderr,
 				"latency: failed to open benchmark device, code %d\n"
 				"(modprobe xeno_timerbench?)\n", benchdev);
src/testsuite/switchtest/switchtest.c +13 -2
index 9e4df10..7114a9f 100644
@@ -888,13 +888,19 @@ static int task_create(struct cpu_tasks *cpu,
 
 #define DEV_NR_MAX 256
 
+static const char *devname_fmt[] = {
+	"/dev/rttest-switchtest%d",
+	"/dev/rttest%d",
+};
+
 static int open_rttest(char *buf, size_t size, unsigned count)
 {
 	static unsigned dev_nr = 0;
 	int fd, status;
+	int fmt = 0;
 
 	do {
-		snprintf(buf, size, "/dev/rttest%u", dev_nr);
+		snprintf(buf, size, devname_fmt[fmt], dev_nr);
 
 		status = fd = open(buf, O_RDWR);
 
@@ -913,6 +919,11 @@ static int open_rttest(char *buf, size_t size, unsigned count)
 		if (++dev_nr != DEV_NR_MAX)
 			continue;
 
+		if (fmt++ == 0) {
+			dev_nr = 0;
+			continue;
+		}
+
 		fprintf(stderr, "switchtest: Unable to open switchtest device.\n"
 			"(modprobe xeno_switchtest ?)\n");
 
@@ -1110,7 +1121,7 @@ int main(int argc, const char *argv[])
 	const char *progname = argv[0];
 	struct cpu_tasks *cpus;
 	struct sched_param sp;
-	char devname[21];
+	char devname[RTDM_MAX_DEVNAME_LEN+1];
 	sigset_t mask;
 	int sig;
 
Signature · 1 line
1.6.0.2
author
#21 lore raw

PATCH v4 18/25 testing: Clean up Kconfig rules

In reply to Jan Kiszka

To exclude modules from built-in, make them depend on 'm' is sufficient.

---
 ksrc/drivers/testing/Config.in |    2 +-
 ksrc/drivers/testing/Kconfig   |   14 +++++---------
 2 files changed, 6 insertions(+), 10 deletions(-)
ksrc/drivers/testing/Config.in +1 -1
index 3552670..215c38d 100644
@@ -15,6 +15,6 @@ dep_tristate 'Context switches test driver' CONFIG_XENO_DRIVERS_SWITCHTEST $CONF
 
 dep_tristate 'Kernel-only latency measurement module' CONFIG_XENO_DRIVERS_KLATENCY $CONFIG_XENO_DRIVERS_TIMERBENCH m
 
-dep_tristate 'User-space real-time signals testing module' CONFIG_XENO_DRIVERS_SIGTEST $CONFIG_MODULES m
+dep_tristate 'User-space real-time signals testing module' CONFIG_XENO_DRIVERS_SIGTEST m
 
 endmenu
ksrc/drivers/testing/Kconfig +5 -9
index 05d6a49..883ede1 100644
@@ -1,9 +1,5 @@
 menu "Testing drivers"
 
-config XENO_TESTING_MODULE
-        depends on MODULES
-	def_tristate m
-
 config XENO_DRIVERS_TESTING_LEGACY_NAMES
 	depends on XENO_SKIN_RTDM
 	bool "Use legacy names for testing drivers"
@@ -22,7 +18,7 @@ config XENO_DRIVERS_TIMERBENCH
 	See testsuite/latency for a possible front-end.
 
 config XENO_DRIVERS_KLATENCY
-	depends on XENO_DRIVERS_TIMERBENCH && XENO_TESTING_MODULE
+	depends on XENO_DRIVERS_TIMERBENCH && m
 	tristate "Kernel-only latency measurement module"
 	help
 	Kernel module for kernel-only latency measurement.
@@ -44,9 +40,9 @@ config XENO_DRIVERS_SWITCHTEST
 	FPU switches.
 
 config XENO_DRIVERS_SIGTEST
-       depends on XENO_TESTING_MODULE
-       tristate "User-space real-time signals testing module"
-       help
-       Elementary skin for unit testing user-space real-time signals.
+	depends on m
+	tristate "User-space real-time signals testing module"
+	help
+	Elementary skin for unit testing user-space real-time signals.
 
 endmenu
Signature · 1 line
1.6.0.2
author
#22 lore raw

PATCH v4 19/25 RTIPC: Drop unused wrapper around close_lock_count

In reply to Jan Kiszka
CC Philippe Gerum <[email protected]>
---
 ksrc/drivers/ipc/internal.h |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
ksrc/drivers/ipc/internal.h +0 -5
index 296a988..ed8c103 100644
@@ -127,9 +127,4 @@ extern struct xnptree rtipc_ptree;
 #define rtipc_enter_atomic(lockctx)	xnlock_get_irqsave(&nklock, (lockctx))
 #define rtipc_leave_atomic(lockctx)	xnlock_put_irqrestore(&nklock, (lockctx))
 
-static inline int rtipc_socket_locked(struct rtdm_dev_context *context)
-{
-	return atomic_read(&context->close_lock_count);
-}
-
 #endif /* !_RTIPC_INTERNAL_H */
Signature · 1 line
1.6.0.2
author
#23 lore raw

PATCH v4 20/25 RTDM: Document device close procedure

In reply to Jan Kiszka

Interating over the close handler when it returns -EAGAIN or in case a pending reference to the device context exists is RTDM practice since day one. Documenting this is seriously overdue.

CC Philippe Gerum <[email protected]>
---
 include/rtdm/rtdm_driver.h |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
include/rtdm/rtdm_driver.h +9 -2
index 07b73a3..380d752 100644
@@ -193,11 +193,18 @@ typedef int (*rtdm_socket_handler_t)(struct rtdm_dev_context *context,
  *
  * @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
+ * 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, or another negative error code.
+ * 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 */
Signature · 1 line
1.6.0.2
author
#24 lore raw

PATCH v4 21/25 Add list_first_entry wrapper for older kernels

In reply to Jan Kiszka
CC Philippe Gerum <[email protected]>
---
 include/asm-generic/wrappers.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
include/asm-generic/wrappers.h +5 -0
index 64ec43f..d864397 100644
@@ -559,6 +559,11 @@ static inline void wrap_proc_dir_entry_owner(struct proc_dir_entry *entry)
 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
 #endif /* CONFIG_PROC_FS */
 
+#ifndef list_first_entry
+#define list_first_entry(ptr, type, member) \
+	list_entry((ptr)->next, type, member)
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
 #define rthal_irq_descp(irq)	(irq_desc + (irq))
 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32) */
Signature · 1 line
1.6.0.2
author
#25 lore raw

PATCH v4 22/25 Add legacy kernel support for delayed_work

In reply to Jan Kiszka

Note that the kernel 2.4 version of schedule_delayed_work is not universally usable.

CC Philippe Gerum <[email protected]>
---
 include/asm-generic/wrappers.h   |    3 +++
 include/compat/linux/workqueue.h |   13 +++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
include/asm-generic/wrappers.h +3 -0
index d864397..7513781 100644
@@ -192,6 +192,7 @@ do {									\
 #define DECLARE_WORK(n,f,d)      	struct tq_struct n = __WORK_INITIALIZER(n, f, d)
 #define DECLARE_WORK_NODATA(n, f)	DECLARE_WORK(n, f, NULL)
 #define DECLARE_WORK_FUNC(f)		void f(void *cookie)
+#define DECLARE_DELAYED_WORK_NODATA(n, f) DECLARE_WORK(n, f, NULL)
 
 /* Msleep is unknown before 2.4.28 */
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,28)
@@ -436,9 +437,11 @@ unsigned long find_next_bit(const unsigned long *addr,
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
 #define DECLARE_WORK_NODATA(f, n)	DECLARE_WORK(f, n, NULL)
 #define DECLARE_WORK_FUNC(f)		void f(void *cookie)
+#define DECLARE_DELAYED_WORK_NODATA(n, f) DECLARE_DELAYED_WORK(n, f, NULL)
 #else /* >= 2.6.20 */
 #define DECLARE_WORK_NODATA(f, n)	DECLARE_WORK(f, n)
 #define DECLARE_WORK_FUNC(f)		void f(struct work_struct *work)
+#define DECLARE_DELAYED_WORK_NODATA(n, f) DECLARE_DELAYED_WORK(n, f)
 #endif /* >= 2.6.20 */
 
 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) */
include/compat/linux/workqueue.h +13 -0
index 3ac37aa..6fad03c 100644
@@ -28,4 +28,17 @@
 #define schedule_work(x)         schedule_task(x)
 #define flush_scheduled_work()   flush_scheduled_tasks()
 
+/*
+ * WARNING: This is not identical to 2.6 schedule_delayed_work as it delayes
+ * the caller to schedule the task after the specified delay. That's fine for
+ * our current use cases, though.
+ */
+#define schedule_delayed_work(work, delay) do {			\
+	if (delay) {						\
+		set_current_state(TASK_UNINTERRUPTIBLE);	\
+		schedule_timeout(delay);			\
+	}							\
+	schedule_task(work);					\
+} while (0)
+
 #endif /* _XENO_COMPAT_LINUX_WORKQUEUE_H */
Signature · 1 line
1.6.0.2
author
#26 lore raw

PATCH v4 23/25 RTDM: Early fd release with poll-free context reference tracking

In reply to Jan Kiszka

Two changes in one as they are tightly related: Once close is called, remove the file descriptor from open table, allowing its reuse while close for the previous user proceeds.

The second and major part of the patch avoids time-based polling while waiting for context references to be dropped. This specifically helps in scenarios where references can be held for a longer time beyond the first close.

CC Philippe Gerum <[email protected]>
---
 include/rtdm/rtdm_driver.h |   16 ++++-
 ksrc/skins/rtdm/core.c     |  168 ++++++++++++++++++++++++++++++-------------
 ksrc/skins/rtdm/device.c   |   45 ++++++++++--
 ksrc/skins/rtdm/internal.h |    8 +--
 4 files changed, 170 insertions(+), 67 deletions(-)
include/rtdm/rtdm_driver.h +13 -3
index 380d752..1a4097b 100644
@@ -379,6 +379,7 @@ struct rtdm_operations {
 
 struct rtdm_devctx_reserved {
 	void *owner;
+	struct list_head cleanup;
 };
 
 /**
@@ -560,19 +561,28 @@ int rtdm_dev_unregister(struct rtdm_device *device, unsigned int poll_delay);
 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)
 {
-	XENO_ASSERT(RTDM, atomic_read(&context->close_lock_count) > 0,
+	XENO_ASSERT(RTDM, CONTEXT_IS_LOCKED(context),
 		    /* just warn if context was a dangling pointer */);
 	atomic_inc(&context->close_lock_count);
 }
 
+extern int rtdm_apc;
+
 static inline void rtdm_context_unlock(struct rtdm_dev_context *context)
 {
-	XENO_ASSERT(RTDM, atomic_read(&context->close_lock_count) > 0,
+	XENO_ASSERT(RTDM, CONTEXT_IS_LOCKED(context),
 		    /* just warn if context was a dangling pointer */);
 	smp_mb__before_atomic_dec();
-	atomic_dec(&context->close_lock_count);
+	if (unlikely(atomic_dec_and_test(&context->close_lock_count)))
+		rthal_apc_schedule(rtdm_apc);
 }
 
 static inline void rtdm_context_put(struct rtdm_dev_context *context)
ksrc/skins/rtdm/core.c +117 -51

276 lines not on this page · raw message

ksrc/skins/rtdm/device.c +38 -7

77 lines not on this page · raw message

ksrc/skins/rtdm/internal.h +2 -6
index 69299f8..3d39def 100644
@@ -80,15 +80,11 @@ static inline void rtdm_dereference_device(struct rtdm_device *device)
 }
 
 int __init rtdm_dev_init(void);
-
-static inline void rtdm_dev_cleanup(void)
-{
-	kfree(rtdm_named_devices);
-	kfree(rtdm_protocol_devices);
-}
+void __exit rtdm_dev_cleanup(void);
 
 int rtdm_proc_register_device(struct rtdm_device *device);
 int __init rtdm_proc_init(void);
 void rtdm_proc_cleanup(void);
+void rtdm_apc_handler(void *cookie);
 
 #endif /* _RTDM_INTERNAL_H */
Signature · 1 line
1.6.0.2
author
#27 lore raw

PATCH v4 24/25 RTDM: Add basic unit test

In reply to Jan Kiszka

This unit test for RTDM validates deferred device closing and driver deregistration due to pending references. Further tests can be added in the future.

CC Philippe Gerum <[email protected]>
---
 include/rtdm/rttesting.h        |    9 ++
 ksrc/drivers/testing/Config.in  |    2 +
 ksrc/drivers/testing/Kconfig    |    6 ++
 ksrc/drivers/testing/Makefile   |   12 +++-
 ksrc/drivers/testing/rtdmtest.c |  191 +++++++++++++++++++++++++++++++++++++++
 src/testsuite/unit/Makefile.am  |   17 ++++-
 src/testsuite/unit/rtdm.c       |  114 +++++++++++++++++++++++
 7 files changed, 349 insertions(+), 2 deletions(-)
 create mode 100644 ksrc/drivers/testing/rtdmtest.c
 create mode 100644 src/testsuite/unit/rtdm.c
include/rtdm/rttesting.h +9 -0
index a660139..e936630 100644
@@ -141,6 +141,10 @@ struct rttst_swtest_error {
 	unsigned fp_val;
 };
 
+#define RTTST_RTDM_NORMAL_CLOSE		0
+#define RTTST_RTDM_DEFER_CLOSE_HANDLER	1
+#define RTTST_RTDM_DEFER_CLOSE_CONTEXT	2
+
 #define RTIOC_TYPE_TESTING		RTDM_CLASS_TESTING
 
 /*!
@@ -152,6 +156,8 @@ struct rttst_swtest_error {
 #define RTDM_SUBCLASS_IRQBENCH		1
 /** subclass name: "switchtest" */
 #define RTDM_SUBCLASS_SWITCHTEST	2
+/** subclase name: "rtdm" */
+#define RTDM_SUBCLASS_RTDMTEST		3
 /** @} */
 
 /*!
@@ -208,6 +214,9 @@ struct rttst_swtest_error {
 
 #define RTTST_RTIOC_SWTEST_SET_PAUSE \
 	_IOW(RTIOC_TYPE_TESTING, 0x38, unsigned long)
+
+#define RTTST_RTIOC_RTDM_DEFER_CLOSE \
+	_IOW(RTIOC_TYPE_TESTING, 0x40, unsigned long)
 /** @} */
 
 /** @} */
ksrc/drivers/testing/Config.in +2 -0
index 215c38d..4f81cf9 100644
@@ -17,4 +17,6 @@ dep_tristate 'Kernel-only latency measurement module' CONFIG_XENO_DRIVERS_KLATEN
 
 dep_tristate 'User-space real-time signals testing module' CONFIG_XENO_DRIVERS_SIGTEST m
 
+dep_tristate 'RTDM unit tests driver' CONFIG_XENO_DRIVERS_RTDMTEST $CONFIG_XENO_SKIN_RTDM m
+
 endmenu
ksrc/drivers/testing/Kconfig +6 -0
index 883ede1..28504dc 100644
@@ -45,4 +45,10 @@ config XENO_DRIVERS_SIGTEST
 	help
 	Elementary skin for unit testing user-space real-time signals.
 
+config XENO_DRIVERS_RTDMTEST
+	depends on XENO_SKIN_RTDM && m
+	tristate "RTDM unit tests driver"
+	help
+	Kernel driver for performing RTDM unit tests.
+
 endmenu
ksrc/drivers/testing/Makefile +11 -1
index 7878cd5..17a6cf1 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_XENO_DRIVERS_IRQBENCH)   += xeno_irqbench.o
 obj-$(CONFIG_XENO_DRIVERS_SWITCHTEST) += xeno_switchtest.o
 obj-$(CONFIG_XENO_DRIVERS_KLATENCY)   += xeno_klat.o
 obj-$(CONFIG_XENO_DRIVERS_SIGTEST)    += xeno_sigtest.o
+obj-$(CONFIG_XENO_DRIVERS_RTDMTEST)   += xeno_rtdmtest.o
 
 xeno_timerbench-y := timerbench.o
 
@@ -20,6 +21,8 @@ xeno_klat-y := klat.o
 
 xeno_sigtest-y := sigtest_module.o
 
+xeno_rtdmtest-y := rtdmtest.o
+
 EXTRA_CFLAGS += -D__IN_XENOMAI__ -Iinclude/xenomai
 
 else
@@ -33,6 +36,7 @@ obj-$(CONFIG_XENO_DRIVERS_IRQBENCH)   += xeno_irqbench.o
 obj-$(CONFIG_XENO_DRIVERS_SWITCHTEST) += xeno_switchtest.o
 obj-$(CONFIG_XENO_DRIVERS_KLATENCY)   += xeno_klat.o
 obj-$(CONFIG_XENO_DRIVERS_SIGTEST)    += xeno_sigtest.o
+obj-$(CONFIG_XENO_DRIVERS_RTDMTEST)   += xeno_rtdmtest.o
 
 xeno_timerbench-objs := timerbench.o
 
@@ -44,8 +48,11 @@ xeno_klat-objs := klat.o
 
 xeno_sigtest-objs := sigtest_module.o
 
+xeno_rtdmtest-objs := rtdmtest.o
+
 export-objs := $(xeno_timerbench-objs) $(xeno_irqbench-objs) \
-	$(xeno_switchtest-objs) $(xeno_klat-objs) $(xeno_sigtest-objs)
+	$(xeno_switchtest-objs) $(xeno_klat-objs) $(xeno_sigtest-objs) \
+	$(xeno_rtdmtest-objs)
 
 EXTRA_CFLAGS += -D__IN_XENOMAI__ -I$(TOPDIR)/include/xenomai -I$(TOPDIR)/include/xenomai/compat
 
@@ -66,4 +73,7 @@ xeno_klat.o: $(xeno_klat-objs)
 xeno_sigtest.o: $(xeno_sigtest-objs)
 	$(LD) -r -o $@ $(xeno_sigtest-objs)
 
+xeno_rtdmtest.o: $(xeno_rtdmtest-objs)
+	$(LD) -r -o $@ $(xeno_rtdmtest-objs)
+
 endif
ksrc/drivers/testing/rtdmtest.c new file +191 -0

191 lines not on this page · raw message

src/testsuite/unit/Makefile.am +16 -1
index 8966883..f37ec33 100644
@@ -10,7 +10,8 @@ test_PROGRAMS = \
 	mutex-torture-native \
 	cond-torture-posix \
 	cond-torture-native \
-	check-vdso
+	check-vdso \
+	rtdm
 
 arith_SOURCES = arith.c arith-noinline.c arith-noinline.h
 
@@ -105,6 +106,20 @@ check_vdso_LDADD = \
 	../../skins/common/libxenomai.la \
 	-lpthread -lm
 
+rtdm_SOURCES = rtdm.c
+
+rtdm_CPPFLAGS = \
+	-I$(top_srcdir)/include/posix @XENO_USER_CFLAGS@ -g -DXENO_POSIX \
+	-I$(top_srcdir)/include
+
+rtdm_LDFLAGS = $(XENO_POSIX_WRAPPERS) @XENO_USER_LDFLAGS@
+
+rtdm_LDADD = \
+	../../skins/posix/libpthread_rt.la \
+	../../skins/native/libnative.la \
+	../../skins/common/libxenomai.la \
+	-lpthread -lrt -lm
+
 install-data-local:
 	$(mkinstalldirs) $(DESTDIR)$(rundir)
 	@sed -e's,@exec_prefix\@,$(exec_prefix),g' $(srcdir)/runinfo.in > $(DESTDIR)$(rundir)/.runinfo
src/testsuite/unit/rtdm.c new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
1.6.0.2
author
#28 lore raw

PATCH v4 25/25 RTDM: Use non-atomic bitops for used_fildes

In reply to Jan Kiszka

All bit manipulations happen under rt_fildes_lock, so there is no need for atomic ops.

---
 ksrc/skins/rtdm/core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
ksrc/skins/rtdm/core.c +2 -2
index bf905df..11102e2 100644
@@ -125,7 +125,7 @@ static int create_instance(struct rtdm_device *device,
 	}
 
 	fd = find_first_zero_bit(used_fildes, RTDM_FD_MAX);
-	set_bit(fd, used_fildes);
+	__set_bit(fd, used_fildes);
 	open_fildes++;
 
 	xnlock_put_irqrestore(&rt_fildes_lock, s);
@@ -175,7 +175,7 @@ static int create_instance(struct rtdm_device *device,
 
 static void __cleanup_fildes(struct rtdm_fildes *fildes)
 {
-	clear_bit((fildes - fildes_table), used_fildes);
+	__clear_bit((fildes - fildes_table), used_fildes);
 	fildes->context = NULL;
 	open_fildes--;
 }
Signature · 1 line
1.6.0.2
#29 lore raw
In reply to Jan Kiszka
Quoted 7 lines · Jan Kiszka

The following changes since commit 2bed24477882dd7937d59f4e33a0811981c7362c:
Gilles Chanteperdrix (1):
arm: declare the VFP inline asm snippets as volatile.

are available in the git repository at:

git://git.xenomai.org/xenomai-jki.git for-upstream

Ok, seems this merge broke the build test:
http://sisyphus.hd.free.fr/~gilles/bx/

Could you please have a look?

Signature · 1 line
					    Gilles.
author
#30 lore raw
Quoted 5 lines · Gilles Chanteperdrix
Quoted 4 lines · Jan Kiszka

The following changes since commit 2bed24477882dd7937d59f4e33a0811981c7362c:
Gilles Chanteperdrix (1):
arm: declare the VFP inline asm snippets as volatile.

Quoted 8 lines
Quoted 3 lines

are available in the git repository at:

git://git.xenomai.org/xenomai-jki.git for-upstream

Ok, seems this merge broke the build test:
http://sisyphus.hd.free.fr/~gilles/bx/

Could you please have a look?

The section mismatch should be resolved in my queue.

Regarding the other bug:

In file included from ./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/workqueue.h:14,

                 from core.c:29:

./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/tqueue.h: In function `queue_task':
./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/tqueue.h:105: warning: implicit declaration of function barrier' core.c: In function close_callback':
core.c:257: warning: implicit declaration of function `schedule_delayed_work'

Does that kernel come with a linux/workqueue.h? What does it include? That's a custom patch, isn't it?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#31 lore raw
Quoted 18 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix
Quoted 4 lines · Jan Kiszka

The following changes since commit 2bed24477882dd7937d59f4e33a0811981c7362c:
Gilles Chanteperdrix (1):
arm: declare the VFP inline asm snippets as volatile.

Quoted 7 lines
Quoted 3 lines

are available in the git repository at:

git://git.xenomai.org/xenomai-jki.git for-upstream

Ok, seems this merge broke the build test:
http://sisyphus.hd.free.fr/~gilles/bx/

Could you please have a look?

The section mismatch should be resolved in my queue.

Regarding the other bug:

Quoted 8 lines

In file included from ./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/workqueue.h:14,

                 from core.c:29:

./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/tqueue.h: In function `queue_task':
./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/tqueue.h:105: warning: implicit declaration of function barrier' core.c: In function close_callback':
core.c:257: warning: implicit declaration of function `schedule_delayed_work'

Does that kernel come with a linux/workqueue.h? What does it include?

I guess either this kernel containes a workqueue.h or it gets it via the compat directory.

Quoted 1 line

That's a custom patch, isn't it?

This kernel is generated as explained in the README:
git clone git://www.denx.de/git/linuxppc_2_4_devel
git checkout 5bab6d641ff5ba139f9f41869502cb7c96d785bc patch -p1 < adeos-ipipe-2.4.25-ppc-DENX-2.2-01.patch

Nothing custom about it,

Signature · 1 line
					    Gilles.
author
#32 lore raw
Quoted 25 lines · Gilles Chanteperdrix
Quoted 24 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix
Quoted 4 lines · Jan Kiszka

The following changes since commit 2bed24477882dd7937d59f4e33a0811981c7362c:
Gilles Chanteperdrix (1):
arm: declare the VFP inline asm snippets as volatile.

Quoted 7 lines
Quoted 3 lines

are available in the git repository at:

git://git.xenomai.org/xenomai-jki.git for-upstream

Ok, seems this merge broke the build test:
http://sisyphus.hd.free.fr/~gilles/bx/

Could you please have a look?

The section mismatch should be resolved in my queue.

Regarding the other bug:

In file included from ./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/workqueue.h:14,

                 from core.c:29:

./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/tqueue.h: In function `queue_task':
./2.4.25-DENX-ppc_6xx-gcc-3.3.3/include/linux/tqueue.h:105: warning: implicit declaration of function barrier' core.c: In function close_callback':
core.c:257: warning: implicit declaration of function `schedule_delayed_work'

Quoted 4 lines
Quoted 1 line

Does that kernel come with a linux/workqueue.h? What does it include?

I guess either this kernel containes a workqueue.h or it gets it via the compat directory.

It has MTD compat workqueue under central include/linux/workqueue.h. I tend to consider this a bug of that tree, but we can workaround it. See for-upstream.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux