Processors, tasks and threads
Several questions about multitasking/multiprocessing in Propeller: (by the way, is this stuff explained anywhere ?)
- Is·there a·multithread core or there is an affinity between tasks and processor(I mean 1 processor=1 task) ?
- Is it possible to have more threads/tasks than processors at the same time (#tasks>=#processors)·?
- Do the same tasks runs all the time in the same processor·?
- Can I create several threads per task ? If so, can these threads run at the same time on several processors ?
- Is there any kind of synchronization between tasks or they run alone without interaction ?
- Is there a way to perform a call from one task/thread to another ?
- Does exist the concept of shared and private areas or to the contrary is it shared all the space ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Is·there a·multithread core or there is an affinity between tasks and processor(I mean 1 processor=1 task) ?
- Is it possible to have more threads/tasks than processors at the same time (#tasks>=#processors)·?
- Do the same tasks runs all the time in the same processor·?
- Can I create several threads per task ? If so, can these threads run at the same time on several processors ?
- Is there any kind of synchronization between tasks or they run alone without interaction ?
- Is there a way to perform a call from one task/thread to another ?
- Does exist the concept of shared and private areas or to the contrary is it shared all the space ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
There is no multithreaded control built into the propeller, but under special circumstances when programming in assembly you can pass control between 2 or more procedures on a single processor but it must be done manually. This process control is abit advanced, and some discussion of it has occured in another thread, so I invite you to look for it if you want more information (hint: the talk is about the JMPRET assembly command), but we have explained its function about as best we can without posting too much detail (Parallax has ask those of us who have seen·the chip not to post the documents since they are not complete), so if how its done is a little over your head, you'll have to wait until the product is availible (with complete documentation) and we can show you real-world examples of its use.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 2/23/2006 5:14:32 PM GMT
When you create a program, all the processors code is contained in a single program or·you must load a single·program·for each processor ?·Can you·use·only the processors you need or there is always something (like some 'do nothing' loop)·running in all the processors ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The running out of code feature is nice, it permits you to run "background" tasks that stop the processor they are run·on·once they are done, freeing up the processor to be allocated to other tasks (this is good for outwards communications, like a SHIFTOUT-like function. You start up a processor, it sends out the data, then shuts itself down when it's finished). Meanwhile your main program is free to continue running other tasks while the other processor handles the communication.
If all cogs end up being shutdown after your program starts executing (either through explicitly stopping a cog, or·a cog running out of instructions), the entire chip's processors are shut down, and a reset must occur to get it running again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 2/23/2006 7:00:39 PM GMT
Daniel
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Suppose you have a processor that is idle (in the shut down status) then, in your 'main' program·you·get something interesting to do, for example·you got·some new·data·from a digital·input. Can you then launch·the processor that was idle to perform a new task ?
In other words, while there are available processors can you 'launch processors' to perform tasks·anytime or they must be launched at·boot time only ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 2/23/2006 7:24:11 PM GMT
1. So there is no built-in to know if all COGS are busy?
2. What happens if a COG is running and another COG "starts" that running COG?· Any errors reported to the initiator COG? Does target COG continue current task or stop immediately and start new task?
3. What is the COG startup latency (how long does it take the target COG to go from idle to executing first instruction), if absolute time is unavailable, what about in terms of HUB rotations?· Does this answer change if the COG is restarting a previously loaded routine or is assigned a new routine?
I understand that using assigned-purpose SlaveCogs might be a possible solution.
Daniel
Post Edited (daniel) : 2/23/2006 7:35:10 PM GMT
2. A cog that is already running cannot be overrun by another COGNEW function, see the answer to your first question.
3. Im not exactly sure, the started cog either loads the interpretor or a block of 512 longs from the hub memory, so the latency will be at least 512 hub rotations, Im not sure of what other latency would be involved.
There are two different ways of starting a task on another cog, the first is COGNEW, which is the suggested method, this will not trample on any already running processes. The second is COGSTART which you specify the cog number, and if there is a process already running on that cog, it will trample it (stop the process and start the newly specified process). The COGSTART method of starting cogs in not the suggested method of doing things, because most objects to be incorporated will be based on the COGNEW method of cog starting. If you rely upon these objects and your program then goes and tramples an already running process, you will experience irratic application behaviour. And dubugging multi-processor applications is a heck of alot harder than single process debugging, so its always best to write programs where your processes behave nicely with other running processes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 2/23/2006 7:47:44 PM GMT
Daniel
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Does COGINIT with D[noparse][[/noparse]3] == 0 just (restart) the named COG, or does it also poke the 512 longwords into the COG?·
If not, is there a way of reactivating a stopped COG without disturbing·its current program state or without incurring the memory transfer latency?· (The negative answer to this question seems to be implied by the COGSTOP description.)
Daniel
Post Edited (daniel) : 2/26/2006 5:07:45 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Eric
Other than stopping a running cog (with COGSTOP) or reinitializing a running cog with a new program (with COGINIT/COGNEW), there is no way to externally control a cog. You can write a program that runs on a cog and looks for a signal to copy into the cog's ram a new program, then the cog transfers control to it, but there's no way to force this from outside the cog.
Perhaps I just think it terminated another cog.· What I see is the hires VGA dispaly vanish when I try to add another cog.· I suppose there are other reasons the display could go dark.
So that I could post code about this problem, I just submitted an object, "MonVarsVGA", to the Propeller Object Exchange.· This is my first formally posted object.· It is used by what I am attaching now, "CogStart.zip".· I think I might be able to create a more minimal demo of the problem, but I wanted to put this out right now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Eric