Interrupt generated before setting PxCI/PxACT for AHCI...

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
liaoo
Member
Member
Posts: 36
Joined: Wed Jun 13, 2012 8:37 pm

Interrupt generated before setting PxCI/PxACT for AHCI...

Post by liaoo »

I have one question about the phenomenon in which the interrupt is generated just before config PxCI/PxSACT for AHCI...
This causes the mis-understanding within AHCI interrupt service routine !

@ 2 backgrounds: ( BTW, I tested in DOS, not in OS... )
#1 For AHCI, to issue command SW will config PxCI and PxSACT for NCQ read/write commands. And before this SW will record the desired value of PxSACT for later comparison

Assume SW decides to issue 5 commands on slot 0,1,2,3,4, then:
- SW save 0x0000001F ( this means slot 0,1,2,3,4 have valid command and will be issued )
- SW starts to config PxCI/PxSACT to activate those commands 1 by 1...
( that is, PxCI/PxSACT = 0x00000001; then set to 0x00000002 -> 0x00000004 -> 0x00000008->0x00000010 )

#2 To identify the command completion SW will check the record and the actual register value of PxSACT.

Assume SW decides to issue 5 commands as above then one interrupt is generated due to command completion on slot 1, then
- in interrupt service routine we got PxSACT = 0x0000001D(bit1 = 0 now, indicating command on slot 1 is completed)
- record = 0x0000001F
- obviously bit1 changed from 1 to 0, thus SW concluded command on slot 1 is completed

@ Issue:
But I found below sequence and then the service routine made wrong decision:

a. SW records: "issue command on slot 3"
b. at this time interrupt is generated due to command completion of slot 1 and ISR got called
c. within ISR SW found slot 3 is valid(due to a) and then check bit3 of PxSACT to see if its value is 0...
Unfortunately, the real action of setting bit3 is not executed (due to the interception by interrupt)
d. SW thinks command on slot 3 is completed and ..... this is incorrect :(
e. SW activate command on slot 3 // actual action to set PxSACT bit3 = 1 here.....

I know the interrupt can be generated "asynchronously" (anywhere and anytime) but how can I solve this kind of issue ?

Can I disable interrupts like below:

That is,
- disable interrupts
- SW records how many commands to be issued (sw maintained variable)
- SW configs PxCI/PxSACT actually
- enable interrupts

Is this OK ?
liaoo
Member
Member
Posts: 36
Joined: Wed Jun 13, 2012 8:37 pm

Re: Interrupt generated before setting PxCI/PxACT for AHCI..

Post by liaoo »

- disable interrupts
- SW records how many commands to be issued (sw maintained variable)
- SW configs PxCI/PxSACT actually
- enable interrupts

It works if disabling/enabling by cli/sti ! (But failed by GHC.IE = 0/1)

F.Y.I
Post Reply