LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices

Reply
 
Search this Thread
Old 08-16-2011, 06:43 PM   #1
cartman76
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
mdelay erratic behavior


I'm attempting to debug a driver on a code base I've inherited.
One of the drivers which my system reads is causing my entire firmware to hang when the driver reads from a device.

The code goes something like this.

ioctl call to read driver value()
{
Loop 25 times
{
If the is hardware working/readable
read the driver value
break;
If the hardware is not working/readable
mdelay(100);
}

If the hardware wasn't ever working/readable in the last loop
{
printf("Driver Failed\n");
return failure;
}
return success;
}

From the looks of this if the driver isn't readable it should retry for 2.5 seconds then return a failure. I'm seeing that this happens correctly right after I flash and boot the chip. Then I hard power the whole system and let it all boot up again. Now the behavior changes. The system hangs in the ioctl call for ~350 seconds. The odd part is that it prints the Driver Failed message at the beginning of the hang.

One would think that if the Driver Failed message was shown the function would return right away! This is not the case. I've done some timing tests and the hang is directly related to (number of loop retries * mdelay milliseconds).

I was thinking of coding a workaround by creating my own delay function using f_time but before doing that I wanted to see if anyone had a better idea of what is going on first.
 
Old 08-18-2011, 10:32 PM   #2
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 86
The location may be different in your environment, but in my situation the file that describes the rationale behind the choice amongst mdelay(), udelay(), ndelay(), msleep(), or usleep() is:

/usr/src/linux/Documentation/timers/timers-howto.txt

You might wish to consult the corresponding file in your environment.

Also, if you are doing some sort of processor sharing, the timing might be off because certain situations may effectively rely on virtualized timing.

Then too, you might want to consider how closely the exact source code matches the pseudo-code you've provided, and whether or not there is some need to break out a separate test.

For example, is it possible to have a separate test to see if the device is "working", as opposed to whether or not the device is readable at a given instant. After all, when you reboot the machine, in principle, an "init pulse" so to speak, is sent to the hardware devices, which should reset things to a stable state. Whereas during operation, if there is any problem with the device, or driver, the exact state of the physical device may not be known. If I'm understanding you correctly, one or more such factors might provide for the seemingly erratic behavior.
 
1 members found this post helpful.
Old 08-26-2011, 07:31 AM   #3
cartman76
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Found Solution

calling a blocking delay in a driver is a bad idea. It prevents everything else from updating including timers since it is a system level priority.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Erratic Printer Behavior davidstvz Linux - Newbie 2 09-16-2008 03:40 PM
Menudrake: Erratic behavior Jiawen Mandriva 1 09-13-2006 05:33 AM
Erratic Touchpad Behavior usaf_sp Suse/Novell 4 08-16-2006 11:03 AM
erratic mouse behavior loserone Slackware 9 08-31-2004 08:23 PM
Erratic mouse behavior in X rcrules Linux - General 4 12-16-2003 02:02 PM


All times are GMT -5. The time now is 07:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration