alternative dev patch
From: Roman Zippel <[email protected]>
Quoted 1 line
Here is a more detailed explanation of the patch
Thanks!
However, I am unconvinced.
(i)
There was some unused code, and you decide to start using that in order to speed up the open() of a chardev. Is that urgent? Is the speed of opening a chardev a bottleneck?
I think something is wrong with this philosophy.
Look at what happens on open("/dev/ttyS1") - there is a hash lookup of the "dev", then a hash lookup of the "ttyS1", then we find that this is device (4,65) and do a hash lookup for (4,65). You want to eliminate this last hash lookup by building infrastructure to cache it? That is possible of course. Some extra code, an extra slab cache, a field i_cdev in struct inode, a semaphore, refcounting..
I have not benchmarked anything but it sure feels like a lot of machinery to avoid a simple hash lookup.
I very much doubt that Al had speeding up the open() in mind when he wrote that (so far unused) infrastructure.
(ii)
Quoted 3 lines
Further he introduces a new function
register_chrdev_region(), which is only needed by the tty code and rather hides the problem than solves it.
What does one want? A driver announces the device number regions that it wants to cover. Simple and straightforward. Hardly a new idea. How is this done for block devices? Using blk_register_region(). How is register_chrdev_region() hiding problems? It eliminates the tty kludges that you only move to a different file.
[Al muttered for an entirely different reason:
He wants to specify the region like "dev_t dev, unsigned long range", where I left the parts of dev separate. I plan (eventually, there is no hurry) to turn the dev_t here into a kdev_t since that is much faster, and once that is done both blk_register_region() and register_chrdev_region() can get a kdev_t as first parameter.]
(iii)
Quoted 2 lines
this patch helps drivers to manage them without huge tables (this latter part is also missing in Andries patch).
I am not sure I understand. Where are these huge tables? And how did you remove them?
Andries
Hi,
Quoted 4 lines · On Thu, 20 Mar 2003 [email protected] wrote:
(i)
There was some unused code, and you decide to start using that in order to speed up theopen()of a chardev. Is that urgent? Is the speed of opening a chardev a bottleneck?
Currently it isn't, but it shouldn't become one?
I'm unsure how your code will scale. It depends on how that code will be used. If drivers register a lot of devices, your lookup function has to scan a possibly very long list of minor devices and that function is difficult to optimize. If drivers want to avoid this they have to implement their own lookup function.
One other major reason for the "unused" code is to convert the 16/32/64bit dev_t as early as possible to either struct block_device/struct char_device, so the kernel mostly doesn't care about the dev_t resolution, the character device core would match here the behaviour of the block device core.
Quoted 10 lines
Quoted 3 lines
Further he introduces a new function
register_chrdev_region(), which is only needed by the tty code and rather hides the problem than solves it.What does one want? A driver announces the device number regions that it wants to cover. Simple and straightforward. Hardly a new idea. How is this done for block devices? Using
blk_register_region(). How isregister_chrdev_region()hiding problems? It eliminates the tty kludges that you only move to a different file.
char devices don't have partitions, so you hardly need regions. The problem with the tty layer is that the console and the serial devices should have different majors.
Even for block devices blk_register_region() is not the preferred interface, you should use alloc_disk/add_disk instead. This will make it easier to assign dynamic device numbers later.
Quoted 6 lines
(iii)
Quoted 2 lines
this patch helps drivers to manage them without huge tables (this latter part is also missing in Andries patch).
I am not sure I understand. Where are these huge tables? And how did you remove them?
See the misc device example. It doesn't have a table, but the list is now only needed to generate /proc/misc. As soon as character devices are better integrated into the driver model, even this list is not needed anymore. This means for simple character devices, we can easily add a alloc_chardev/add_chardev interface similiar to block devices.
bye, Roman
Quoted 4 lines · Roman Zippel
I'm unsure how your code will scale. It depends on how that code will be used. If drivers register a lot of devices, your lookup function has to scan a possibly very long list of minor devices and that function is difficult to optimize.
And then we grab the BKL :(
Hint, optimizing the open() path for char devices is not anything we will probably be doing in 2.6, due to the BKL usage there. It's also not anything anyone has seen on any known benchmarks as a point of contention, so I would not really worry about this for now.
For 2.7, when we want to drop the BKL, then we can worry about this.
Quoted 3 lines
char devices don't have partitions, so you hardly need regions. The problem with the tty layer is that the console and the serial devices should have different majors.
There are a number of char drivers that have "regions". The tty layer support them, and the usb core supports them as two examples. I'm sure there are others. Personally, I like the symmetry with the block device function the way Andries did it.
Quoted 3 lines
Even for block devices
blk_register_region()is not the preferred interface, you should use alloc_disk/add_disk instead. This will make it easier to assign dynamic device numbers later.
True, but dynamic device numbers can be built on top of the *_region() calls as it is today. Anyway, dynamic numbers are for 2.7 :)
Quoted 8 lines
Quoted 2 lines
I am not sure I understand. Where are these huge tables? And how did you remove them?
See the misc device example. It doesn't have a table, but the list is now only needed to generate
/proc/misc. As soon as character devices are better integrated into the driver model, even this list is not needed anymore. This means for simple character devices, we can easily add a alloc_chardev/add_chardev interface similiar to block devices.
No, I don't see /proc/misc going away due to the driver model, I imagine there are too many users of it to disappear. Also, the driver model doesn't care a thing about major/minor numbers so I don't understand how you think it can help in this situation.
thanks,
greg k-h
Quoted 8 lines
bye, Roman
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Hi,
Quoted 7 lines · Greg KH
Quoted 4 lines · Roman Zippel
I'm unsure how your code will scale. It depends on how that code will be used. If drivers register a lot of devices, your lookup function has to scan a possibly very long list of minor devices and that function is difficult to optimize.
And then we grab the BKL :(
This is currently required for either implementation and needs to be moved to the driver.
Quoted 4 lines
Hint, optimizing the
open()path for char devices is not anything we will probably be doing in 2.6, due to the BKL usage there. It's also not anything anyone has seen on any known benchmarks as a point of contention, so I would not really worry about this for now.
The BKL also shouldn't be a reason to make it unnecessary expensive? I don't understand your argument.
Quoted 8 lines
Quoted 3 lines
char devices don't have partitions, so you hardly need regions. The problem with the tty layer is that the console and the serial devices should have different majors.
There are a number of char drivers that have "regions". The tty layer support them, and the usb core supports them as two examples. I'm sure there are others. Personally, I like the symmetry with the block device function the way Andries did it.
Every single call to usb_register_dev in 2.5.65 uses exactly 1 minor number. Block device drivers need regions because they have partitions and we need to find out which device a partition belongs to. Where have character devices such requirements?
Quoted 10 lines
Quoted 5 lines
See the misc device example. It doesn't have a table, but the list is now only needed to generate
/proc/misc. As soon as character devices are better integrated into the driver model, even this list is not needed anymore. This means for simple character devices, we can easily add a alloc_chardev/add_chardev interface similiar to block devices.No, I don't see
/proc/miscgoing away due to the driver model, I imagine there are too many users of it to disappear. Also, the driver model doesn't care a thing about major/minor numbers so I don't understand how you think it can help in this situation.
I didn't mean that /proc/misc goes away, I meant the misc_list in misc.c. They could be other ways to generate /proc/misc. /proc/devices, /proc/misc, /proc/tty/drivers, ... is currently mostly needed to generate device nodes for dynamic device numbers. This badly needs a more generic mechanism.
bye, Roman
Quoted 10 lines · Roman Zippel
Hi,
Quoted 6 lines · Greg KH
Quoted 4 lines · Roman Zippel
I'm unsure how your code will scale. It depends on how that code will be used. If drivers register a lot of devices, your lookup function has to scan a possibly very long list of minor devices and that function is difficult to optimize.
Quoted 4 lines
Quoted 1 line
And then we grab the BKL :(
This is currently required for either implementation and needs to be moved to the driver.
Heh, that is definiatly a 2.7 thing, too many drivers rely on this functionality :(
Quoted 7 lines
Quoted 4 lines
Hint, optimizing the
open()path for char devices is not anything we will probably be doing in 2.6, due to the BKL usage there. It's also not anything anyone has seen on any known benchmarks as a point of contention, so I would not really worry about this for now.The BKL also shouldn't be a reason to make it unnecessary expensive? I don't understand your argument.
I was trying to point out that pre-mature optimiziation of this code should not be done before we get rid of the most expensive portion, the bkl. That's all.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
char devices don't have partitions, so you hardly need regions. The problem with the tty layer is that the console and the serial devices should have different majors.
There are a number of char drivers that have "regions". The tty layer support them, and the usb core supports them as two examples. I'm sure there are others. Personally, I like the symmetry with the block device function the way Andries did it.
Quoted 4 lines
Every single call to
usb_register_devin 2.5.65 uses exactly 1 minor number. Block device drivers need regions because they have partitions and we need to find out which device a partition belongs to. Where have character devices such requirements?
Oh yeah, I forgot I had cleaned up that api to not reserve minors in chunks, sorry. It used to do that :)
So only tty drivers currently do this. But that might just be because it's pretty hard to get a range of minors right now, as the api hasn't been present. Once we expand the range, I bet it will get quite common (most character drivers only want from 1-16 minors normally.)
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
only needed to generate
/proc/misc. As soon as character devices are better integrated into the driver model, even this list is not needed anymore. This means for simple character devices, we can easily add a alloc_chardev/add_chardev interface similiar to block devices.No, I don't see
/proc/miscgoing away due to the driver model, I imagine there are too many users of it to disappear. Also, the driver model doesn't care a thing about major/minor numbers so I don't understand how you think it can help in this situation.
Quoted 5 lines
I didn't mean that
/proc/miscgoes away, I meant themisc_listinmisc.c. They could be other ways to generate/proc/misc./proc/devices,/proc/misc,/proc/tty/drivers, ... is currently mostly needed to generate device nodes for dynamic device numbers. This badly needs a more generic mechanism.
I agree. But again, 2.7. Remember our feature freeze?
thanks,
greg k-h
Hi,
Quoted 6 lines · Greg KH
Quoted 2 lines
The BKL also shouldn't be a reason to make it unnecessary expensive? I don't understand your argument.
I was trying to point out that pre-mature optimiziation of this code should not be done before we get rid of the most expensive portion, the bkl. That's all.
Can we at least note, that my patch has a performance advantage? We can still deal with the BKL later.
I hope we can agree, that we should avoid adding premature new interfaces, which can be expensive later?
Quoted 4 lines
So only tty drivers currently do this. But that might just be because it's pretty hard to get a range of minors right now, as the api hasn't been present. Once we expand the range, I bet it will get quite common (most character drivers only want from 1-16 minors normally.)
There are a few options:
1. Drivers can implement that themselves:
a) The driver allocates the major itself and opens the real minor device in its open function, (e.g. see the misc driver example). Especially tape drivers have to do this anyway, because they encoded the open mode in higher bits, so regions won't help you here at all.
b) The driver allocates the major itself and installs the file_operations directly in the char_device, e.g. that is something you might want to do in the usb driver:
register_usb_device(...)
{
...
cdev = cdget(dev);
down(&cdev->sem);
if (cdev->fops)
...;
cdev->fops = fops;
up(&cdev->sem);
}(see the misc driver again for a detailed example.)
2. If it should be really needed, we can add simple region support by adding a minor_shift argument to the major device, so get_chrfops() would first try (major, minor & ((1 << shift) - 1)), before it tries directly (major, 0).
So I really don't see why we should support arbitrary regions, since currently nobody needs it and if someone should need it in the future, he can easily do it himself.
Quoted 5 lines
Quoted 3 lines
/proc/devices,/proc/misc,/proc/tty/drivers, ... is currently mostly needed to generate device nodes for dynamic device numbers. This badly needs a more generic mechanism.I agree. But again, 2.7. Remember our feature freeze?
I agree too and nowhere in my patch did I change something about this.
bye, Roman
Quoted 7 lines · Roman Zippel
Quoted 4 lines
So only tty drivers currently do this. But that might just be because it's pretty hard to get a range of minors right now, as the api hasn't been present. Once we expand the range, I bet it will get quite common (most character drivers only want from 1-16 minors normally.)
There are a few options:
1. Drivers can implement that themselves:
Yeah, but as I know, it's a big pain in the butt. Let's make it easy to do this, don't make writing a driver tougher than it has to be (it's already much harder than it used to be.) Andries's patch makes it easy, which is a good thing in my book.
Quoted 18 lines
a) The driver allocates the major itself and opens the real minor device in its open function, (e.g. see the misc driver example). Especially tape drivers have to do this anyway, because they encoded the open mode in higher bits, so regions won't help you here at all.
b) The driver allocates the major itself and installs thefile_operationsdirectly in thechar_device, e.g. that is something you might want to do in the usb driver:
register_usb_device(...){ ... cdev = cdget(dev); down(&cdev->sem); if (cdev->fops) ...; cdev->fops = fops; up(&cdev->sem); }
Quoted 1 line
(see the misc driver again for a detailed example.)
Look at drivers/usb/core/file.c::usb_open(), it does much the same thing. Well, functionally the same, not identical in any way :)
thanks,
greg k-h
Quoted 2 lines · Greg KH
Look at drivers/usb/core/file.c::usb_open(), it does much the same thing. Well, functionally the same, not identical in any way :)
And sound (well, not actually ranges), input, v4l, tty, etc.. ->i_cdev together with char device probes would have solved that nicely and without the linear list serach in ->open that we got now, which will bite us much more once 32bit dev_ts are actually used.
Hi,
Quoted 7 lines · Greg KH
Quoted 2 lines
There are a few options:
1. Drivers can implement that themselves:Yeah, but as I know, it's a big pain in the butt. Let's make it easy to do this, don't make writing a driver tougher than it has to be (it's already much harder than it used to be.) Andries's patch makes it easy, which is a good thing in my book.
Andries' patch doesn't help at all and only makes things worse. Only very few drivers should have to deal with the major/minor business. Most drivers should just do add_serial_device/add_tape_device/... and these function will do the right thing (e.g. announce the new device via sysfs).
Quoted 12 lines
Quoted 11 lines
register_usb_device(...){ ... cdev = cdget(dev); down(&cdev->sem); if (cdev->fops) ...; cdev->fops = fops; up(&cdev->sem); }(see the misc driver again for a detailed example.)
Quoted 2 lines
Look at drivers/usb/core/file.c::usb_open(), it does much the same thing. Well, functionally the same, not identical in any way :)
No, with my patch usb_open() and usb_minors[] could go away completely, you just setup everything in usb_register_dev() and the rest is done for you.
With Andries' patch you will not get rid of this.
bye, Roman
Quoted 9 lines · Roman Zippel
Quoted 4 lines
Yeah, but as I know, it's a big pain in the butt. Let's make it easy to do this, don't make writing a driver tougher than it has to be (it's already much harder than it used to be.) Andries's patch makes it easy, which is a good thing in my book.
Andries' patch doesn't help at all and only makes things worse. Only very few drivers should have to deal with the major/minor business. Most drivers should just do add_serial_device/add_tape_device/... and these function will do the right thing (e.g. announce the new device via sysfs).
Yupp. The add_serial_device/add_tape_device/ would also have the benefit that they could keept track of devfs like the gendisk handling when GENHD_FL_DEVFS is set by the drivers - lots of cruft can be remove from drivers and midlayers incrementally.
Quoted 7 lines · Greg KH
Quoted 4 lines · Roman Zippel
I'm unsure how your code will scale. It depends on how that code will be used. If drivers register a lot of devices, your lookup function has to scan a possibly very long list of minor devices and that function is difficult to optimize.
And then we grab the BKL :(
You're thinking the wrnog way around. Locking reduction / splitting is trivial, getting the algorithms right is the hard part. Getting rid of BKL in chardev open is a matter of simple search and replace and I expect it to happen before 2.6.
Quoted 4 lines
There are a number of char drivers that have "regions". The tty layer support them, and the usb core supports them as two examples. I'm sure there are others. Personally, I like the symmetry with the block device function the way Andries did it.
No, Andries did not do it symmetric to the block devices.
Quoted 6 lines
Quoted 3 lines
Even for block devices
blk_register_region()is not the preferred interface, you should use alloc_disk/add_disk instead. This will make it easier to assign dynamic device numbers later.True, but dynamic device numbers can be built on top of the
*_region()calls as it is today. Anyway, dynamic numbers are for 2.7 :)
Dynamic numbers are there today and have been for ages.
Quoted 1 line
No, I don't see
/proc/miscgoing away due to the driver model,
I do see it going away. Dito for /proc/devices. They already are inaccurate for those midlevel drivers that partition their major number themselves and having the ranges properly exported like it's already done for block devices is the proper replacement. Yes, this breaks userspace and we'll have to live with it.
Quoted 3 lines · Roman Zippel
char devices don't have partitions, so you hardly need regions. The problem with the tty layer is that the console and the serial devices should have different majors.
That;s not exactly true. A tradition major device is nothing but a region with a fixed size, and we need to get rid of this major/minor thinking. Converting a dev_t to struct char_device * / struct block_device * early is the way we wan't to go for that. It helped the block layer a lot..
Hi,
Quoted 5 lines · Christoph Hellwig
That;s not exactly true. A tradition major device is nothing but a region with a fixed size, and we need to get rid of this major/minor thinking. Converting a
dev_tto structchar_device* / structblock_device* early is the way we wan't to go for that. It helped the block layer a lot..
I basically agree, I only want to note that the block layer only has to deal with disks, where we have different types of character devices. So having one major per serial/tape/tty/... devices might not be necessary, but it could makes things bit easier. In any case the actual drivers should not see any of this.
bye, Roman