30 April 2018, 23:35 | #1 |
Registered User
Join Date: Apr 2013
Location: paris
Posts: 133
|
Atomic operations between CPU & Blitter
Hi,
I wonder if read/write instruction such as EOR dn,<memory> are "atomic", regarding to blitter for instance? In other word, imagine CPU is doing EOR #1,$0 and blitter is doing exacly the same at same address. Therorically result will be 0 ( both are doing EOR #1) but, if operation is not atomic, then it could have a race condition and maybe the result will be 1 instead of 0. Any idea? |
01 May 2018, 01:08 | #2 |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
That sounds a bit strange. My imagination is that only the CPU or a chip can have access to a memory location at a certain time. Only one of them is the owner of the address and data bus for the ChipMem, but never both at the same time. We don't want smoke from the bus drivers.
|
01 May 2018, 01:16 | #3 |
Registered User
Join Date: May 2013
Location: Grimstad / Norway
Posts: 839
|
There is a reason why the atomic 680x00 opcodes are "illegal" to use on the Amiga - you can be locked out of the (chip) bus by DMA.
In the same way any RMW instruction - indeed any store at all - will be conflicting with the blitter. Which is why you have the blitter ready bit to test for. What kind of code do you have if you don't know who is doing what? |
01 May 2018, 01:16 | #4 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Atomic operation in amiga architecture is prohibited, hence the reason TAS is unusable in chip mem and can hang the machine.
There is only consecutive operations so in your example result is everytime 0 (the race can be win by CPU or Blitter, it does not matter). EDIT: hi NorthWay, i lost the race, even if the publication time is the same! Last edited by ross; 01 May 2018 at 08:16. Reason: correction, see meynaf's comment |
01 May 2018, 07:46 | #5 | |||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
If one of the two has enough time to write before the other reads, then you get 0, else you get 1. Quote:
It's just that the operation does not get its lock. But it appears to behave fine and despite my efforts i never caught it red handed. Quote:
First, both have to read the data. If they do it one right after the other, both will read 0. Then they do the eor and both will write 1... You get 0 only if one has the time to write its data before the other performs the read. Of course you may want to run the blitter in nasty mode so cpu does not get any cycle before blitter has ended. But if the blitter is too slow to start, then the cpu still has time to read the memory before... |
|||
01 May 2018, 08:02 | #6 |
Registered User
Join Date: Jun 2008
Location: Boston USA
Posts: 466
|
Try TAS from chip RAM on a 500..Buzzing black screen of death and a trip to the power button!
|
01 May 2018, 08:06 | #7 | ||
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
EDIT: hmm, seems that is not only a question of DMA "lost" cycles, but a bus contention that drive Agnus to write on the address setup by the CPU or bus lock because of undefined control bus state. Hardware tests are needed Maybe fixed on Alice? Quote:
Cycles can be back-to-back and result is two (consecutive) 1 written in same memory cell! Last edited by ross; 01 May 2018 at 08:42. |
||
01 May 2018, 09:14 | #8 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
In my tests (years ago) TAS never hung but it worked incorrectly (wrong results etc) if DMA conflicted with its second memory cycle (write cycle).
It is also possible it depends on used hardware, accelerator board etc.. |
01 May 2018, 09:37 | #9 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
|
Let me expand slightly what Leonard is attempting, so that the discussion does not go off on a generic tangent about the TAS command
He wants to render some things with the Blitter, and also concurently render some things with the CPU. Both will be rendering with EOR. There is a chance that at some point, the CPU and the Blitter will be EORing into the same word at the same time. So depending on the read/write cycles of both the CPU and the Blitter accessing the same word of memory, EORing the same bits into that word (final result *should* be a zero'd bit).. is there a chance that the read/write cycle will cause an incorrect result? |
01 May 2018, 10:03 | #10 | |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Quote:
But it probably is quite difficult to "sync" CPU and blitter to get also "software level" correct results. Perhaps it can be done using unrolled loop (assuming 68000, or code that fully fits in cache if 68020+, to keep accesses identically timed). Blitter will have priority so if CPU only does identically timed accesses, blitter will always stop the CPU when it needs chip ram access = automatic sync |
|
01 May 2018, 10:21 | #11 | |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Quote:
|
|
01 May 2018, 11:07 | #12 | ||
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
The cpu always knows on which areas of memory the blitter works, so it is not enough just to make a check before starting the operation? If the work is spanned in irq you can simply take a look in the global queue job. But whithout detail is impossible to say Quote:
You can drastically reduce the possibility using the BLTPRI bit (if enought blitter channels is used). Actually you can even reduce to null if you deny for the CPU even the first chip access with a custom reg. bus read (like on BlitterWait routine). EDIT: Just to be clear. I realize that the latter is certainly not the best way to use CPU and Blitter competently (is no more a "parallel" task ). But I would not use them to make simple cuncurrent EORs on chip memory areas. All different, however, if they are used together for very different operations (logic for the blitter and ALU advanced with the processor). In that case the performance gain is incredible. Last edited by ross; 01 May 2018 at 11:34. |
||
01 May 2018, 11:30 | #13 |
Registered User
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
|
A more problematic aspect than the blitter intercepting the CPU is the CPU intercepting the blitter.
The blitter will fetch from its source channels, then the data is in transit within the blitter for a couple of cycles, then written out to the D channel. Worst case this is 7 bus cycles (ABCD active, A & D point to the same mem location, latency A -> pipeline -> D) ignoring other DMA. If the CPU modifies the memory location during those 7 bus cycles, the CPU result of the CPU operation will be overwritten by the blitter. |
01 May 2018, 11:40 | #14 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
This is a mandatory (and working) case for BLTPRI. |
|
01 May 2018, 11:46 | #15 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
I only meant there is no hardware side-effects.
It is (or at least should have been) obvious that any RMW cycle can be "interrupted" by higher priority channel or any channel if there are free cycle(s) between read and write. |
01 May 2018, 19:24 | #16 |
Registered User
Join Date: Mar 2018
Location: Prague
Posts: 35
|
What is "TAS"?
|
01 May 2018, 20:21 | #17 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
|
02 May 2018, 04:43 | #18 |
Registered User
Join Date: May 2015
Location: Kirkland, Washington, USA
Posts: 56
|
I think I can guess what you are doing, and have considered the same thing. I concluded the cleanest solution was to add an extra back buffer, so the CPU can draw to buffer x-1 while blitter draws to buffer x.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Blitter vs Cpu on Aga | sandruzzo | Coders. General | 16 | 19 November 2017 13:59 |
Linedraw blitter vs. CPU on 68000 | pmc | Coders. Asm / Hardware | 17 | 29 February 2012 15:02 |
Blitter fighting the CPU | h0ffman | Coders. General | 5 | 05 April 2011 13:18 |
|
|