skin RTDM in user mode
Hi,
In ksrc/skins/rtdm/API.CHANGES text file, the TODO list indicates that someone may be working on the development of the user-side RTDM skin (for user-space drivers).
Is anyone working on that ?
I was wondering what was to be done:
- Is it just the porting of the kernel RTDM API (rtdm_task_*, etc.) ?
- Or do you expect a more complete solution like fuse or fusd ?
The last few weeks, I was thinking on a complete solution which would allow to compile and execute an RTDM driver seamlessly on both mode (user and kernel).
That would imply:
- the porting of the kernel RTDM API on user mode;
- the development of a specific layer so as to redirect the RTDM syscalls (open, read, write, close, ioctl) to a user-space process. For that point, I think there are two alternatives: either extending the RTDM skin API (with hidden syscalls for the user-space driver to retrieve the syscalls to execute) or developing a kernel RTDM driver + a library.
- the development of an external library (or header) to implement the minimal Linux API which is used in common RTDM drivers (like vmalloc, kmalloc, ioremap). (And for PCI, USB, DMA, etc. API, ???)
Compared to fuse or fusd, which I consider as user-specific frameworks. The main advantage of such a solution would be the ability to (nearly) seamlessly execute the driver on both spaces. The main issue would be to keep in mind the performance aspect (especially for rtdm_copy_*_user, on that point there are many possibilities I began to investigate).
Do you consider such a work as interesting ?
Alexis.
Hi Alexis,
Quoted 7 lines · Alexis Berlemont
Hi,
In ksrc/skins/rtdm/API.CHANGES text file, the TODO list indicates that someone may be working on the development of the user-side RTDM skin (for user-space drivers).
Is anyone working on that ?
Not that I know.
Quoted 4 lines
I was wondering what was to be done:
- Is it just the porting of the kernel RTDM API (rtdm_task_*, etc.) ?
Nope.
Quoted 1 line
- Or do you expect a more complete solution like fuse or fusd ?
There are a few tricky parts when you want a seamless driver API, allowing to test or even use RTDM drivers in userspace:
- IRQ handling (means: forwarding, acknowledging, sharing). You won't be able to achieve 100% equivalent functionality here, of course.
- Managing the driver context.
When in kernel space, driver code can run in RTDM tasks (that trivial to port), in IRQ context (=> probably some carrier task then) or caller context - and here the problem starts. Single-user drivers could simply run as library within the context of the user, but for shared drivers we need some framework that deals with accessing user data which we could easily in kernel space, but not when the driver has its own process or should run within multiple user space contexts.
- Providing a framework for required Linux kernel services (e.g. DMA handling - yet not even addressed for uio...).
- <things I do not remember anymore>
Quoted 4 lines
The last few weeks, I was thinking on a complete solution which would allow to compile and execute an RTDM driver seamlessly on both mode (user and kernel).
Quoted 10 lines
That would imply:
- the porting of the kernel RTDM API on user mode;
- the development of a specific layer so as to redirect the RTDM syscalls (open, read, write, close, ioctl) to a user-space process. For that point, I think there are two alternatives: either extending the RTDM skin API (with hidden syscalls for the user-space driver to retrieve the syscalls to execute) or developing a kernel RTDM driver + a library.
- the development of an external library (or header) to implement the minimal Linux API which is used in common RTDM drivers (like vmalloc, kmalloc, ioremap). (And for PCI, USB, DMA, etc. API, ???)
USB does not belong into this list (we rather need an RTDM-based USB stack for realtime use cases), but the rest is exactly the point.
Quoted 6 lines
Compared to fuse or fusd, which I consider as user-specific frameworks. The main advantage of such a solution would be the ability to (nearly) seamlessly execute the driver on both spaces. The main issue would be to keep in mind the performance aspect (especially for rtdm_copy_*_user, on that point there are many possibilities I began to investigate).
At least single-user drivers (which are only accessed by one process at a time) should not suffer from too much systematical overhead. But I would not focus too much on performance, because critical drivers belong into the kernel anyway, but rather on seamless portability (=> recompilation without modifications, except for the makefile). If you were able to test the full functionality of some RTDM driver in user space, at _lot_ would already be gained!
Quoted 2 lines
Do you consider such a work as interesting ?
Definitely, yes! I just postponed this long-planned topic due to shifted priorities. Any contribution, even if just addressing parts of the ultimate goal, would be highly appreciated!
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Hi,
Quoted 8 lines
Quoted 1 line
- Or do you expect a more complete solution like fuse or fusd ?
There are a few tricky parts when you want a seamless driver API, allowing to test or even use RTDM drivers in userspace:
- IRQ handling (means: forwarding, acknowledging, sharing). You won't be able to achieve 100% equivalent functionality here, of course.
On that point I thought about some hidden dedicated task(s) / thread(s):
either one task per interrupt or one task per CPU for all interrupt (the second alternative may seem better).
The issue is to be as close as possible from the functioning in kernel mode:
-> This task must work with the highest priority as an IRQ handler cannot be preempted (yet...).
-> The spinlock mechanism could be emulated thanks to an "interrupt" lock (to emulate irq masking and a common mutex. Thus, by taking the "interrupt" lock, any RT task can indirectly prevent the IRQ user-handler execution.
Quoted 9 lines
- Managing the driver context.
When in kernel space, driver code can run in RTDM tasks (that trivial to port), in IRQ context (=> probably some carrier task then) or caller context - and here the problem starts. Single-user drivers could simply run as library within the context of the user, but for shared drivers we need some framework that deals with accessing user data which we could easily in kernel space, but not when the driver has its own process or should run within multiple user space contexts.
The driver code would be executed by a process but this driver context would be hidden behind the context of the application which uses the driver.
Here are the cases, I have in my head:
-> one application uses one device managed by one kernel module (like misc device); => the simplest case: with one thread inside the driver user-process, we emulate the application context;
-> many applications uses the same device managed by one kernel module => if we are on a SMP config, we might need one thread per CPU-core inside the driver user-process;
-> many applications uses many devices managed by the the same kernel module (common char devices) => In this configuration, a driver thread must wait for commands coming many contexts; however, this issue could easily be handled by the kernel module devoted to redirect syscall.
Therefore I think such a development could be divided in two steps:
-> the first one would be the extension of a part of the RTDM API in user-mode (most of the functions located in drvlib.c)
-> the second one would be the syscall redirection.
The second part can be implemented in two ways:
-> the RTDM kernel skin is extended;
-> an RTDM kernel driver is developed (this driver would handle ioctl coming from the user-driver (copy_from_user, register_device, wait_command, etc.) and the user-application (open, read, write, close).
Which one do you think is the best?
On my side, I started the first alternative (kernel skin extension) so as to check that my ideas could be translated in code lines (it is just a POC which does not work yet).
Alexis.
P.S.: I sent the first mail sunday night, I don't know why it took more than one day to reach its destination.
Quoted 6 lines · Alexis Berlemont
Hi,
Quoted 4 lines
Quoted 1 line
- Or do you expect a more complete solution like fuse or fusd ?
There are a few tricky parts when you want a seamless driver API, allowing to test or even use RTDM drivers in userspace:
Quoted 8 lines
Quoted 3 lines
- IRQ handling (means: forwarding, acknowledging, sharing). You won't be able to achieve 100% equivalent functionality here, of course.
On that point I thought about some hidden dedicated task(s) / thread(s):
either one task per interrupt or one task per CPU for all interrupt (the second alternative may seem better).
From the locking perspective, this sounds reasonable. But fault containment will be harder to achieve then.
Quoted 7 lines
The issue is to be as close as possible from the functioning in kernel mode:
-> This task must work with the highest priority as an IRQ handler cannot be preempted (yet...).
-> The spinlock mechanism could be emulated thanks to an "interrupt" lock (to emulate irq masking and a common mutex. Thus, by taking the "interrupt" lock, any RT task can indirectly prevent the IRQ user-handler execution.
The spinlock can remain as is, but the interrupt locking part (as well as its stand-alone version) will require some thoughts. It has some implicit property: no reschedule on the current CPU. That should be preserved for the tasks the driver interacts with.
Quoted 14 lines
Quoted 10 lines
- Managing the driver context.
When in kernel space, driver code can run in RTDM tasks (that trivial to port), in IRQ context (=> probably some carrier task then) or caller context - and here the problem starts. Single-user drivers could simply run as library within the context of the user, but for shared drivers we need some framework that deals with accessing user data which we could easily in kernel space, but not when the driver has its own process or should run within multiple user space contexts.The driver code would be executed by a process but this driver context would be hidden behind the context of the application which uses the driver.
Quoted 11 lines
Here are the cases, I have in my head:
-> one application uses one device managed by one kernel module (like misc device); => the simplest case: with one thread inside the driver user-process, we emulate the application context;
-> many applications uses the same device managed by one kernel module => if we are on a SMP config, we might need one thread per CPU-core inside the driver user-process;
-> many applications uses many devices managed by the the same kernel module (common char devices) => In this configuration, a driver thread must wait for commands coming many contexts; however, this issue could easily be handled by the kernel module devoted to redirect syscall.
The threading model is not the key here, and I don't think we need new threads at all. What is the key is the address space organization. In order to map the model we have with in-kernel drivers to user space, my idea is to have a shared memory between all processes using some driver so that this driver can access its own data from all process contexts it may be called from. That way we could let the driver code run in te context of the application threads under the related processes. And there would be no need to switch the memory mapping on driver entry, which should keep the overhead of multi-user drivers low. But this kind of environment may be tricky to create and may contain some traps and pitfalls I didn't find yet.
Quoted 5 lines
Therefore I think such a development could be divided in two steps:
-> the first one would be the extension of a part of the RTDM API in user-mode (most of the functions located indrvlib.c)
-> the second one would be the syscall redirection.
Having the basic driver lib (also the possibility to [un]register drivers) in user space is surely a good starting point. Then one can start writing first simple demos/test cases.
Quoted 6 lines
The second part can be implemented in two ways:
-> the RTDM kernel skin is extended;
-> an RTDM kernel driver is developed (this driver would handle ioctl coming from the user-driver (copy_from_user,register_device,wait_command, etc.) and the user-application (open, read, write, close).
As a second step I would focus on IRQ handling and the execution model of non-shared (single-user) drivers that can run in the process context of their only user (=> RTDM drivers as application library).
And the third step should then deal with multi-user drivers, maybe exploring what I sketched above.
Quoted 11 lines
Which one do you think is the best?
On my side, I started the first alternative (kernel skin extension) so as to check that my ideas could be translated in code lines (it is just a POC which does not work yet).
Alexis.
P.S.: I sent the first mail sunday night, I don't know why it took more than one day to reach its destination.
No error message on this?
Jan
cover RTDM in user mode
In reply to Jan KiszkaHi,
Il already tried to send this mail to xenomai-core; I have been waiting for it for the past 24 hours. So I tried again with a few changes. Sorry for the noise.
Here are three patches which provide the whole RTDM API to user-land. Thanks to these features, driver code can be executed by common user processes.
- As Jan suggested, this first version is a "single process" driver, it can only be used (many times) by one process as it runs as library within the context of the user process. The multiple user space contexts implementation will follow (if you consider it as interesting).
- The Linux framework for common Linux services (lists, ioremap(), etc. at least) is not available yet. It will follow.
- The RTDM API has not changed... (except the IRQ and NRT sig handlers functions headers...).
- The code has been tested thanks to the examples (available in examples/rtdm/user-api / patch n°2).
Do you find such patches interesting for inclusion ?
Alexis
Patch 0: kernel-side code.
include/rtdm/rtdm.h | 16 include/rtdm/rtdm_driver.h | 781 +++++++++++++++++------- include/rtdm/syscall.h | 61 + ksrc/skins/rtdm/drvlib.c | 613 ++++++++++++++++--- ksrc/skins/rtdm/internal.h | 149 ++++ ksrc/skins/rtdm/module.c | 14 ksrc/skins/rtdm/syscall.c | 1428 ++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 2723 insertions(+), 339 deletions(-)
rtdm/rtdm.h +16 -0
@@ -65,6 +65,22 @@#include <sys/ioctl.h> #include <sys/socket.h> +/* --- Kernel compatibility stuff --- */ + +#define __user + +typedef unsigned long rtdm_user_info_t ; + +struct vm_area_struct { +void *vm_private_data; +}; + +struct vm_operations_struct { +void (*open)(struct vm_area_struct * area); +void (*close)(struct vm_area_struct * area); +}; + +#endif /* !__KERNEL__ */ /*!
rtdm/rtdm_driver.h +545 -236
1,056 lines not on this page · raw message
rtdm/syscall.h +61 -0
68 lines not on this page · raw message
skins/rtdm/drvlib.c +511 -102
900 lines not on this page · raw message
skins/rtdm/internal.h +149 -0
171 lines not on this page · raw message
skins/rtdm/module.c +14 -0
@@ -37,6 +37,8 @@#include "rtdm/internal.h" +struct rtdm_process __rtdm_global_process; +MODULE_DESCRIPTION ("Real-Time Driver Model" );MODULE_AUTHOR ("[email protected]" );MODULE_LICENSE ("GPL" );
@@ -56,6 +58,7 @@#ifdef CONFIG_XENO_OPT_PERVASIVE rtdm_syscall_cleanup ();#endif /* CONFIG_XENO_OPT_PERVASIVE */ +rtdm_task_pkg_cleanup ();xntbase_free (rtdm_tbase);xnpod_shutdown (xtype); }
@@ -64,6 +67,14 @@ {int err; +initq (&__rtdm_global_process.timerq); +initq (&__rtdm_global_process.eventq); +initq (&__rtdm_global_process.semq); +initq (&__rtdm_global_process.mutexq); +initq (&__rtdm_global_process.irq_handleq); +initq (&__rtdm_global_process.nrt_sigq); +initq (&__rtdm_global_process.heapq); + err =xnpod_init ();if (err)
@@ -85,7 +96,10 @@ goto cleanup_dev;#endif /* CONFIG_PROC_FS */ +rtdm_task_pkg_init (); +#ifdef CONFIG_XENO_OPT_PERVASIVE + err =rtdm_syscall_init ();if (err) goto cleanup_proc;
skins/rtdm/syscall.c +1427 -1
744 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Re: [Xenomai-core] [PATCH 0/2] RTDM in user mode
Hi Alexis,
Quoted 17 lines · Alexis Berlemont
Hi,
Il already tried to send this mail to xenomai-core; I have been waiting for it for the past 24 hours. So I tried again with a few changes. Sorry for the noise.
Here are three patches which provide the whole RTDM API to user-land. Thanks to these features, driver code can be executed by common user processes.
- As Jan suggested, this first version is a "single process" driver, it can
only be used (many times) by one process as it runs as library within the context of the user process. The multiple user space contexts implementation will follow (if you consider it as interesting).- The Linux framework for common Linux services (lists,
ioremap(), etc. at least) is not available yet. It will follow.
Quoted 7 lines
- The RTDM API has not changed... (except the IRQ and NRT sig handlers functions headers...).
- The code has been tested thanks to the examples (available in examples/rtdm/user-api / patch n°2).
Do you find such patches interesting for inclusion ?
Very nice stuff! And obviously already fairly complete even in details, which is impressing for the first run.
I already created some local branch with your patches and compiled them. Only minor issues visible: please check for pointer<->int conversion warnings on 64-bit - and please add spaces after if, while, for etc. :). I will look into this in more details soon.
Did you already tried to build or even run some existing single-user driver against your extension? I'm thinking of the 16550A e.g. (it even has a test case). Also the irqbench driver could be a candidate. Is there some standard how-to-convert/build procedure?
Jan
Re: [Xenomai-core] [PATCH 0/2] RTDM in user mode
Hi,
Quoted 4 lines
I already created some local branch with your patches and compiled them. Only minor issues visible: please check for pointer<->int conversion warnings on 64-bit - and please add spaces after if, while, for etc. :). I will look into this in more details soon.
OK.
Quoted 4 lines
Did you already tried to build or even run some existing single-user driver against your extension? I'm thinking of the 16550A e.g. (it even has a test case). Also the irqbench driver could be a candidate. Is there some standard how-to-convert/build procedure?
OK. I will try to port these drivers into user-space. Before doing that, I just have to develop the framework for common kernel API (lists, ioremap, test_*_bit, etc.).
Many thanks for having a look at these patches.
Alexis.