On Wed, Feb 18, 2009 at 9:58 AM, Alexander Griesser
<[email protected]> wrote:
> Denys Vlasenko wrote:
>>> BTDT, not getting better.
>>
>> So it still takes 4m 30s?
>
> Oh, sorry, well, it actually got better.
> It now takes about 2mins to complete.
>
>> Please add -tt options to make strace timestamp the log.
>
> Done, please find the timestamped strace output attached.
>
>> I don't understand. Is new code running as slow as old? How is
>> this possible?
>
> It's about twice as fast as the old code, but still takes two minutes
> to complete so there's still enough room for improvements :)
>
> Actually, the problem seems to be in the close() and open() calls
> for the floppy drive. open takes about 40 seconds and close takes a bit
> more than a minute.
No, the second long one is read, not close. close is ~instantaneous:
1879 09:52:08.159589 lstat64("/dev/fd0", {st_mode=S_IFBLK|0660,
st_rdev=makedev(2, 0), ...}) = 0
1879 09:52:08.159816 open("/dev/fd0", O_RDONLY) = 4
1879 09:52:46.408532 ioctl(4, BLKGETSIZE64, 0xbfa04e88) = 0
1879 09:52:46.408718 lseek(4, 0, SEEK_SET) = 0
1879 09:52:46.408835 read(4, 0x85031e0, 512) = -1 EIO (Input/output error)
1879 09:54:02.874887 close(4) = 0
1879 09:54:02.875111 lstat64("/dev/input", {st_mode=S_IFDIR|0755,
st_size=180, ...}) = 0
I searched around and looks like O_NONBLOCK may help with open delay,
and then there are some ioctl's we may try t use to find out whether
the disk is there. (I'd prefer /sys/xxx, but there seems to be no such thing
for detecting media presence).
I don't have floppy at hand, I need you to do some testing.
Please try attached program ("gcc -Os floppytest.c" to compile).
Run it with no floppy being inserted. It opens the device with
O_NONBLOCK, then tries some ioctls.
If the output looks like this:
time N probing /dev/fd0
time N opened the device
time N+LOTS did FDGETDRVTYP, result NN
then it means that O_NONBLOCK open is indeed fast as I hope, but
FDGETDRVTYP ioctl is slow. Edit the source:
Now it is:
rc = ioctl(fd, FDGETDRVTYP, name);
printf("time %d did FDGETDRVTYP, result %d\n",
(int)time(NULL), rc);
if (rc) {
close(fd);
continue;
}
printf("name:'%s'\n", name);
rc = ioctl(fd, FDPOLLDRVSTAT, &ds);
printf("time %d did FDPOLLDRVSTAT, result %d\n",
(int)time(NULL), rc);
close(fd);
if (rc) {
close(fd);
continue;
}
printf("ds.track:%d\n", ds.track);
Please move second block of code (FDPOLLDRVSTAT one)
before first, recompile and rerun. If it's still slow,
try making "FDGETPRM" code block first (now it is third).
Show me the output of all three tries.
Basically, I want an ioctl which quickly tells me whether
disk is inserted at all.
If you will find one which works (works fast), make another experiment:
insert the disk, do not access it in any way, and run the program again.
Let be see what it prints in this case. (I am interested whether
it will sense that now disk is present).
--
vda
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fd.h>
int main(int argc, char **argv)
{
char path[32], name[32];
struct floppy_struct param;
struct floppy_drive_struct ds;
int x, fd, rc;
for (x = 0; x < 8; x++) {
snprintf(path, 31, "/dev/fd%d\n", x);
printf("time %d probing %s", (int)time(NULL), path);
fd = open(path, O_RDONLY|O_NONBLOCK);
if (fd < 0)
continue;
printf("time %d opened the device\n", (int)time(NULL));
// rc = ioctl(fd, FDRESET, NULL);
// printf("time %d did FDRESET, result %d\n", (int)time(NULL), rc);
rc = ioctl(fd, FDGETDRVTYP, name);
printf("time %d did FDGETDRVTYP, result %d\n", (int)time(NULL), rc);
if (rc) {
close(fd);
continue;
}
printf("name:'%s'\n", name);
rc = ioctl(fd, FDPOLLDRVSTAT, &ds);
printf("time %d did FDPOLLDRVSTAT, result %d\n", (int)time(NULL), rc);
close(fd);
if (rc) {
close(fd);
continue;
}
printf("ds.track:%d\n", ds.track);
rc = ioctl(fd, FDGETPRM, ¶m);
printf("time %d did FDGETPRM, result %d\n", (int)time(NULL), rc);
if (rc) {
close(fd);
continue;
}
printf("%sle-sided, %d tracks, %d sec/track. Total capacity %d kB.\n",
param.head ? "Doub" : "Sing",
param.track, param.sect, param.size >> 1);
close(fd);
}
return 0;
}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox