f_ops flag to speed up compatible ioctls in linux kernel
Hi!
Stop being arrogant.
Can you please elaborate on how to make Linux kernel support e.g. motion controllers? They do not fit *any* known to me driver interface. They have several axes, they have about twenty parameters (float or integer), and they have several commands, a-la start, graceful stop, abrupt stop. Plus obviously diagnostics - about ten another commands with absolutely different parameters. And about ten motion monitoring commands. And this is one example I were need to program.
Or take any other freaky device we might got on market tomorrow.
As ioctl() opponent, be kind and give some advice what to do in that kind of situations.
Al Viro written:
Quoted 16 lines
Quoted 6 lines
Hello!
Currently, on thex86_64architecture, its quite tricky to make a char device ioctl work for an x86 executables.
In particular,
1. there is a requirement that ioctl number is unique - which is hard to guarantee especially for out of kernel modulesToo bad.
Quoted 6 lines
2. there's a performance huge overhead for each compat call - there's a hash lookup in a global hash inside a
lock_kernel- and I think compat performance *is* important.Further, adding a command to the ioctl suddenly requires changing two places - registration code and ioctl itself.
Quoted 7 lines
So don't add them. Adding a new ioctl is *NOT* a step to be taken lightly - we used to be far too accepting in that area and as somebody who'd waded through the resulting dungpiles over the last months I can tell you that result is utterly revolting.
Excuse me, but I have zero sympathy to people who complain about obstacles to dumping more into the same piles - it should be hard.
Arjan van de Ven written:
Quoted 6 lines
Quoted 2 lines
Further, adding a command to the ioctl suddenly requires changing two places - registration code and ioctl itself.
adding ioctls SHOULD be painful. Really painful. It's similar to adding syscalls; you'll have to keep compatibility basically forever so adding should not be an easy thing.
--- with respect. best regards.
*** Philips @ Saarbruecken.
Quoted 6 lines · On Wed, Sep 01, 2004 at 03:50:11AM -0600, [email protected] wrote:
Hi!
Stop being arrogant.
Can you please elaborate on how to make Linux kernel support e.g. motion controllers? They do not fit *any* known to me driver interface. They have several axes, they have about twenty parameters (float or integer), and
parameters nicely fit in sysfs.
Quoted 4 lines
they have several commands, a-la start, graceful stop, abrupt stop. Plus obviously diagnostics - about ten another commands with absolutely different parameters. And about ten motion monitoring commands. And this is one example I were need to program.
a write() interface doesn't work???
Hard to believe, you even call them commands.
fd = open("/dev/funkydevice");write(fd, "start");
doesn't sound insane to me
Quoted 8 lines · Arjan van de Ven
Quoted 4 lines · On Wed, Sep 01, 2004 at 03:50:11AM -0600, [email protected] wrote:
Hi!
Stop being arrogant.
Can you please elaborate on how to make Linux kernel support e.g. motion controllers? They do not fit *any* known to me driver interface. They have several axes, they have about twenty parameters (float or integer), andparameters nicely fit in sysfs.
What about errors?
"set di 200000" might fail for lots of reasons.
Quoted 9 lines
Quoted 1 line
they have several commands, a-la start, graceful stop, abrupt stop. Plus obviously diagnostics - about ten another commands with absolutely different parameters. And about ten motion monitoring commands. And this is one example I were need to program.
a
write()interface doesn't work???
Hard to believe, you even call them commands.
fd =open("/dev/funkydevice");write(fd, "start");doesn't sound insane to me
it doesn't, since you didn't tryed to make error handling. every thing can fail - this is control of mechanics - and it fails often and for a lot of reasons. Put here error handling (write(struct whatever) has to return another struct whatever2 filled with error description) and thread-safeness. Pluss some controllers do support multi-dimensional movements "start x,y,z,etc" - and you might have _several_ error structs. Atomicity is important for multi-dimensional moves too - move on given axes starts with single command.
hu?
I do not see much point in renaming ioctl() to write() all over the place - at least when people see ioctl() they understand that it is not standard functionality. write() will for sure confuse a lot of people.
--- with respect. best regards.
*** Philips @ Saarbruecken.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Well. I given an example of device which doesn't fit into
read()/write() interface.
Your imagination is truely appreciated - and you are encouraged to
try to implement it. With full error handling (every write must be checked) and multithreading support (e.g. one user for movement, multiple for monitoring and diagnosis).
I have tryed to some extent impelementing something like this -
amount of code doubled for no real gain. (It was in those times when "ioctl()s are bad. period." topic poped up on lkml first time. long time ago)
No one will ever design interface for sake of interface. what you are
proposing - probably will look nice in academical papers, but no one will do it, and no one will do it in kernel space.
And all this stuff - all this funcy xml-like comlications? - for
what? just call one function of driver with single parameter - void*.
_*Not more*_. Ridiculous indeed.
P.S. As I have said before, it seems to me that using read()/write() instead of ioctl() could be the only choice. I once hacked read(): user must pass two structures: first is input, second is output. It worked - but no one (including me) liked it. ioctl() even by its name fit better.
P.P.S. Hm. Why not implement ioctl2()? which will be linked directly to device by its driver? - numbering will be internal to driver, and provide entry point into driver for user space applications. No one likes mess with ioctl()s in Linux - no device driver developers, nor users. But what is really needed - is just call into driver. Paramenter - single pointer have being proved to be sufficient.
Quoted 61 lines · Helge Hafting
Quoted 28 lines · [email protected] wrote:
Quoted 8 lines · Arjan van de Ven
Quoted 2 lines · On Wed, Sep 01, 2004 at 03:50:11AM -0600, [email protected] wrote:
Hi! Stop being arrogant.
Can you please elaborate on how to make Linux kernel support e.g. motion controllers? They do not fit *any* known to me driver interface. They have several axes, they have about twenty parameters (float or integer), andparameters nicely fit in sysfs.
What about errors?
"set di 200000" might fail for lots of reasons.Quoted 9 lines
Quoted 1 line
they have several commands, a-la start, graceful stop, abrupt stop. Plus obviously diagnostics - about ten another commands with absolutely different parameters. And about ten motion monitoring commands. And this is one example I were need to program.
a
write()interface doesn't work???
Hard to believe, you even call them commands.
fd =open("/dev/funkydevice");write(fd, "start");
doesn't sound insane to meQuoted 1 line
it doesn't, since you didn't tryed to make error handling. every thing can fail - this is control of mechanics - and it fails often and for a lot of reasons. Put here error handling (write(struct whatever)
Well, how about a read-write interface?
Write a command to the driver, read back the response. If the response indicate an error, read more to get error details. Keep reading out possibly several errors until the driver have nothing more to report.Quoted 1 line
has to return another struct whatever2 filled with error description) and thread-safeness. Pluss some controllers do support multi-dimensional movements "start x,y,z,etc" - and you might have _several_ error structs. Atomicity is important for multi-dimensional moves too - move on given axes
The driver can handle atomicity - if it somehow receives a partial command it should buffer it and wait for the rest. If you need several commands for a single movement, consider barriers, i.e.:
write(fd, "barrier start");write(fd, "one kind of movement");write(fd, "other kind of movement");write(fd, "third kind of movement");write(fd, "barrier end"); /* Complex movement starts at this point */read(fd, &error_buffer, size); /* Did this work? */Quoted 3 lines
starts with single command.
hu?
I do not see much point in renamingioctl()towrite()all over the place - at least when people seeioctl()they understand that it is not standard functionality.write()will for sure confuse a lot of people.Isn't motion "standard functionality" for this device? If so, a write interface fits even if the stuff written to it might be special (structs and such)
Helge Hafting
Quoted 4 lines · Ihar 'Philips' Filipau
P.P.S. Hm. Why not implementioctl2()? which will be linked directly to device by its driver? - numbering will be internal to driver, and provide entry point into driver for user space applications. No one likes mess with ioctl()s in Linux - no device driver developers, nor users. But what is really needed - is just call into driver. Paramenter
- single pointer have being proved to be sufficient.
Ok. Now I recalled those mess with ioctl()s - someone have tryed to
implement virtual methods from OO languages with file descriptors and miserably failed.
I have never used ioctl()s for anything asides calling my drivers. I
have seens people using ioctl codes for special functionality for block devices.
Position "ioctl()s bad" is not related to drivers per se. People
decided to not introduce another calls like eject_media(fd) or get_info(fd) - but instead implement ioctl() which will magically work on all fd's of block devices.
That where mistake is. That the kind of ioctl()s, which are bad.ioctl() is for something what doesn't have interface. If something have stable interface - it must be moved over to sys/library calls.
Instead of "painful ioctl()s" - I would rather start with solving
this problem for standard devices: making a way to implement efficiently common functions for device classes. (terminals, block devices, network interfaces, etc). And start obsoleting/removing ioctl()s.
I like aproach of *BSD - they routinely implement library/sys calls
for things like that. I used if_*/getif* calls to find/operate network interfaces - it is much more usable & better documented, than Linux' bunch of magic ioctl()s (again) on _any_ network socket. Why on any? Why we cannot have special device to operate on list of interfaces?
I believe people here on LKML identified problem incorrectly.
Quoted 7 lines · Ihar 'Philips' Filipau
Well. I given an example of device which doesn't fit into
read()/write() interface.Your imagination is truely appreciated - and you are encouraged to
try to implement it. With full error handling (every write must be checked)
Checking every write is up to the program using the device. Not forgetting this is easy. Never write directly to the device, use an interface function in your program that both writes, reads status back, and returns that status.
Quoted 3 lines
and multithreading support (e.g. one user for movement, multiple for
monitoring and diagnosis).
In that case I'd use two device nodes. One for the command/error stuff, and another for monitoring. The monitoring device could be read-only and support several simultaneous openings.
Quoted 2 lines
I have tryed to some extent impelementing something like this -
amount of code doubled for no real gain. (It was in those times when "ioctl()s are bad. period." topic poped up on lkml first time. long time ago)
Of course you _can_ use ioctls. Just do it if that's the only useable way. Wether you can get code like that merged depends on wether you can convince the right people. But your driver will work fine even if you have to distribute it yourself, so it isn't that big a problem.
Quoted 8 lines
No one will ever design interface for sake of interface. what you
are proposing - probably will look nice in academical papers, but no one will do it, and no one will do it in kernel space.And all this stuff - all this funcy xml-like comlications? - for
what? just call one function of driver with single parameter - void*.
_*Not more*_. Ridiculous indeed.
I haven't suggested any xml, perhaps someone else did. A write interface let you pass almost anything into the driver. My example used ascii messages, you might want to pass structs instead. I believe even pointers should work too.
Quoted 1 line
P.S. As I have said before, it seems to me that using read()/write() instead ofioctl()could be the only choice. I once hackedread(): user must pass two structures: first is input, second is output. It worked - but no one (including me) liked it.ioctl()even by its name fit better.
I have to agree it seems to fit.
Helge Hafting
Quoted 3 lines · On Wed, Sep 01, 2004 at 04:16:59AM -0600, [email protected] wrote:
I do not see much point in renaming
ioctl()towrite()all over the place - at least when people seeioctl()they understand that it is not standard functionality.write()will for sure confuse a lot of people.
Because you can encapsulate write while you can't encapsulate ioctl for a start. And because ascii is good and opaque binary is bad. You don't change the target position of your motion device millions of time per second. You can easily send your commands and replies (you're allowed read, too) as text, and immediatly you make logging, debugging and reproducing actions way easier. Plus API portability to 64bits/other endian is free.
OG.