G1-ATA driver broken

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

G1-ATA driver broken

Post by SWAT » Tue Feb 03, 2015 10:02 pm

Hello everyone!
Approximately after commit http://sourceforge.net/p/cadcdev/kallis ... ded37e9e1/ (I tested all CD-ROM changes from http://sourceforge.net/p/cadcdev/kallis ... a4ba0ca76/) G1-ATA driver works unstable.
Seems the recursive mutex is locked and freezes all code after several readings from HDD/CF.
If I use this revision http://sourceforge.net/p/cadcdev/kallis ... db411efe2/ the G1-ATA driver works fine.
Last edited by SWAT on Mon Mar 02, 2015 1:00 am, edited 1 time in total.
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Thu Feb 05, 2015 6:54 pm

I'm pretty sure that Quzar doesn't have a G1 ATA device, so I'll take a look at it.

That said, what exactly is happening? It sounds like (from what you've described) it works fine for several read operations and then just locks up later waiting on the mutex? Is this all from the same thread, or separate threads?
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by SWAT » Sun Feb 08, 2015 10:38 pm

BlueCrab wrote:...it works fine for several read operations and then just locks up later waiting on the mutex? Is this all from the same thread, or separate threads?


Yep. From the same thread.
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Sun Feb 08, 2015 11:46 pm

Are you doing any operations to the GD-ROM drive in the mean time, or just to the ATA device?
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by SWAT » Mon Feb 09, 2015 4:35 am

Nope, just ATA...

Update: I call cdrom_spin_down
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Tue Feb 10, 2015 9:16 am

If you could provide me with a minimal piece of code that demonstrates the way to freeze things up, it'd help me immensely in debugging. If you can do it with just the g1_ata_* and cdrom_* functions (ie, no filesystem-related stuff), that'd be best.

My suspicion (which I can't back up at all, at the moment) is that it is something going screwy between the mutex being locked in the fs_iso9660 code during vblank interrupts and whatever you're doing in the foreground with the ATA device...

EDIT: Actually, let's see if my suspicion is correct before you try to write an example to show the bug. I've attached a patch that might fix any potential issues with interrupts and recursive mutexes... Try applying that patch ("patch -p1 < mutex.diff" from the $KOS_BASE directory, assuming you put the file attached there too), and see if it fixes the issue. I'd also suggest a full "make clean && make" on both KOS and whatever you're using to test with, just in case there are other funny things that have been changed in the meantime...
Attachments
mutex.diff
(2.64 KiB) Downloaded 45 times
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by SWAT » Wed Feb 11, 2015 6:07 am

Ok I'll try it.
Image
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by SWAT » Wed Feb 11, 2015 10:07 pm

Hmm my application now crashes at new place:

Code: Select all

*** ASSERTION FAILURE ***
Assertion "0" failed at pvr_prim.c:98 in `pvr_poly_compile': Invalid texture U size
Video rendering I have in separate thread. And it's uses normal mutex.
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Thu Feb 12, 2015 7:12 am

That message is entirely unrelated to the g1ata stuff, quite obviously. That error means that you've put in an invalid size for the width of a texture somewhere...

Other than that, it could, of course, be caused by memory corruption elsewhere (outside of your rendering code). :?
User avatar
bogglez
Moderator
Moderator
Posts: 576
Joined: Sun Apr 20, 2014 9:45 am
Has liked: 0
Been liked: 0

Re: G1-ATA driver broken. Quzar it's for you =)

Post by bogglez » Thu Feb 12, 2015 7:33 am

I saw that kind of error message before on these forums when somebody only partially recompiled KOS
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Thu Feb 12, 2015 7:55 am

bogglez wrote:I saw that kind of error message before on these forums when somebody only partially recompiled KOS
That's also entirely possible (and that's also why I suggested doing a full "make clean && make" pass).

@SWAT: Did you do a full "make clean && make" pass on both KOS and your program? Do you use anything from kos-ports (or other external libraries)? If so, you should probably do a "make clean && make" on those too. Basically, clean and remake everything in this order: KOS, any external libraries (in order of any dependencies they have on each other, of course), and then your program that is failing.
User avatar
bogglez
Moderator
Moderator
Posts: 576
Joined: Sun Apr 20, 2014 9:45 am
Has liked: 0
Been liked: 0

Re: G1-ATA driver broken. Quzar it's for you =)

Post by bogglez » Thu Feb 12, 2015 9:29 am

Bluecrab: Out of curiosity, do you know why this error message always occurs in the PVR code? Is it because there was an ABI change in that code recently or something? Funny error that one.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Thu Feb 12, 2015 10:50 am

bogglez wrote:Bluecrab: Out of curiosity, do you know why this error message always occurs in the PVR code? Is it because there was an ABI change in that code recently or something? Funny error that one.
Relatively recently, the pvr_poly_cxt_t was changed, which is what causes it. So, yes, that would be an ABI change.

Since KOS is statically linked, we've never worried about ABI changes. It has always been recommended practice to do a full clean/rebuild pass every time you update. I'll try to be more explicit about it in the commit messages in the future when things like that happen, but yeah, please do a full clean/rebuild pass every time you update. :wink:
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by SWAT » Thu Feb 12, 2015 10:45 pm

Sorry I forget rebuild parallax library, now it's ok. Soon I'll check your patch on HDD.

Update: Your patch did not help :( Still freezing at ATA access. Now even slightly worse, freezes earlier than before the patch.
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Sat Feb 14, 2015 7:14 pm

I doubt that the patch itself made matters worse (I'd guess it's something random happening, at this point).

I'm going to need some sort of example code that demonstrates the issue, since I don't seem to be having this problem... :?
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by SWAT » Mon Feb 16, 2015 2:15 am

It's not easy to make example with this problem. I really don't know why this happen, but if I use cdrom driver before this changes, it's works fine...
Ok, I'll try get more info about this at free time.
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Thu Feb 19, 2015 10:26 pm

So, the only thing you have to revert is the cdrom changes? No other code has to be changed in order to make your code work -- that is to say, if you save the cdrom.[ch] files from when it works and otherwise update everything else to the current version, does it work?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5441
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 3 times
Been liked: 23 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by BlueCrab » Fri Feb 20, 2015 9:15 pm

Also, when you say it's difficult to make an example, does that imply that you don't run into the same issue outside of whatever you're normally using to test it? That actually makes it sound like the problem is elsewhere in your code (or in some other unrelated part of KOS to the g1ata code).

Remember, KOS doesn't give you any memory protection or kernel/userspace separation, so a simple buffer overflow pretty much anywhere can break things in very strange ways. :?
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has liked: 0
Been liked: 0
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by SWAT » Tue Feb 24, 2015 5:51 am

Not easy because need time :) I have not time for any code example :(
But I have some testers, they are help me with debugging.
So, I can say yes for:
BlueCrab wrote:So, the only thing you have to revert is the cdrom changes? No other code has to be changed in order to make your code work -- that is to say, if you save the cdrom.[ch] files from when it works and otherwise update everything else to the current version, does it work?
I just replace cdrom.c and cdrom.h in current KOS rev to 2014-05-01 and it's works.
BlueCrab wrote:Also, when you say it's difficult to make an example, does that imply that you don't run into the same issue outside of whatever you're normally using to test it? That actually makes it sound like the problem is elsewhere in your code (or in some other unrelated part of KOS to the g1ata code).
Remember, KOS doesn't give you any memory protection or kernel/userspace separation, so a simple buffer overflow pretty much anywhere can break things in very strange ways. :?
Not sure what it is my case. I did not touch the code before have this problem, everything worked well with old cdrom driver.
Image
User avatar
Quzar
Dream Coder
Dream Coder
Posts: 7492
Joined: Wed Jul 31, 2002 12:14 am
Location: Miami, FL
Has liked: 0
Been liked: 4 times
Contact:

Re: G1-ATA driver broken. Quzar it's for you =)

Post by Quzar » Fri Feb 27, 2015 4:21 pm

Sorry, I'd been away from internet access for a few weeks. Like bluecrab said, I don't have a g1-ata device to test with. I'll take a look through the driver again, but I don't know what would cause it.
"When you post fewer lines of text than your signature, consider not posting at all." - A Wise Man
Post Reply