Thinking ahead: Supporting multicore CPUs
Pages: 1 ... 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ... 26
h0bby1 (2567) 480 posts |
aaaaa |
h0bby1 (2567) 480 posts |
aaaaa |
Rick Murray (539) 13806 posts |
I do believe that I mentioned that “RISC OS is not Linux” once or twice. I point this out only to suggest that you discard any preconceived notions of how you think these things should work and look more closely at how RISC OS actually does work. It is quite different, but necessary to understand at your level, the PMT level, if you aren’t too be bitten by “Filecore in use” and other problems. If you look back at my previous posts, you’ll see me referring to the Wimp as the “task switcher” several times. I was dropping hints. ;-) |
Rick Murray (539) 13806 posts |
To answer a question that was posed earlier – how do you pre-empt a program when it is in a SWI call? To interrupt at that level would imply using CallAfter or CallEvery which you will quickly discover carries numerous restrictions on what you can do when you are called. In my code, I tend to use CallAfter to schedule a Callback, which RISC OS will do when it is “unthreaded” and control returns to the user mode application (the exit of a SWI, etc). It is safer to do many things then. For a start, filesystem access will work… |
WPB (1391) 352 posts |
How did Wimp2 cope with issues of global state changing? Like a program that sets the CSD and expects it to remain set while it does some file operations? (Not that I’m advocating that method, but it is possible when you know the system won’t rip control away from under your feet.) |
h0bby1 (2567) 480 posts |
aaaaa |
h0bby1 (2567) 480 posts |
aaaaa |
h0bby1 (2567) 480 posts |
aaaaa |
Rick Murray (539) 13806 posts |
The same way as usual – it doesn’t; and the application should be using <Meh$Dir> style paths and leaving the CSD alone – for good reason. |
h0bby1 (2567) 480 posts |
aaaaa |
Rick Murray (539) 13806 posts |
Started up the PC as replying longer on a mobile phone is… not the most pleasant (or sane) idea!
I’m not sure we can call RISC OS “multi threaded”. Not in the sense that you mean.
You don’t. There are two ways to port something to an “alien” platform.
Or:
Or, more specifically, to your apache example. You would not expect to build the code and have it run unless you were happy to single-task that one application only.
Depends what you are trying to do. I have written a Teletext interface program with a (really) basic script interpreter in BBC BASIC for RISC OS and VB5 for Windows. In both cases, the software “talks” to the hardware at register level using an intermediary that handles the actual IIC communications. Under RISC OS this is either the system IIC bus, or my PtrIIC module (to fake IIC using the printer port). Under Windows, it is a DLL called PtrIIC. Under NT-kernel Windows it needs GIVEIO.SYS to allow the DLL to access the hardware as I never sussed how to build a hardware driver using lcc or OpenWatcom.
What, you mean when a SWI is being called? Yes, it is all machine code in memory, yet strangely enough RISC OS knows. Hint: Try looking at the “superstack”. But, as I said, there is a world of difference between CallAfter/CallEvery and Callback. The first two are more or less guaranteed to happen after a defined interval of 2cs or more, but you WILL be interrupting whatever is happening including OS routines. You cannot sensibly change things here without a fair degree of pain. Callback, on the other hand, happens at an unspecified time (when RISC OS is “free”) which is usually as soon as the SWI completes – which can be mere nanoseconds later, or not. At this time, a great many more things may be done.
No, I’m saying that unless you want a lot of pain, your pre-emptive system will need to integrate within the Wimp itself. Or possibly the kernel if you think you are going to be capable of running something like apache. Then… As the “service provider”, it will fall upon your PMT code to: Finally, back to this:
No, applications should not have to know about numerous restrictions. But the programmer should. To give a good example, there are numerous things that work by the OS “calling your code”. OS_Claim, the various types of callbacks… It is imperative that an application either remove such claims prior to a poll, or place them in module space that is not paged out. The kernel can help you – OS_DelinkApplication and OS_RelinkApplication, but it is up to you to do this. The Wimp does not. To see what it does and doesn’t do, look at https://www.riscosopen.org/viewer/view/castle/RiscOS/Sources/Desktop/Wimp/s/Wimp03?rev=4.6#l28 and https://www.riscosopen.org/viewer/view/castle/RiscOS/Sources/Desktop/Wimp/s/Wimp03?rev=4.6#l79 and https://www.riscosopen.org/viewer/view/castle/RiscOS/Sources/Desktop/Wimp/s/Wimp03?rev=4.6#l287. |
h0bby1 (2567) 480 posts |
aaaaa |
WPB (1391) 352 posts |
Like I said, I’m not advocating it – clearly it’s not a good idea. But the fact remains, if the program flow can be interrupted by preemption, all global state has to be saved and restored by the system, doesn’t it? I’m sure there are many more subtle examples than the CSD, though I can’t think of them off the top of my head. I have something in the back of my mind telling me that Wimp_OpenTemplate does something silly in this respect, but I can’t remember what it is. EDIT: Ah, right here in this very thread: https://www.riscosopen.org/forum/forums/5/topics/406?page=2#posts-7078, along with a lot of other very interesting information. |
Rick Murray (539) 13806 posts |
<alien language alert>
Google came up with this:
and:
It looks like something like this may work (if not, blame Google, not me!):
Do you really need to do all of that for each line to be drawn? How retrograde.
Uh… Maybe. ;-) </alien> |
Steve Fryatt (216) 2103 posts |
There’s no link between Wimp_OpenTemplate, Wimp_LoadTemplate and Wimp_CloseTemplate. If a switch occurs between calls to Wimp_OpenTemplate and Wimp_CloseTemplate, by the time the task gets control back again there’s a possibility that another task has called Wimp_OpenTemplate or Wimp_CloseTemplate – meaning that remaining attempts to use Wimp_LoadTemplate could be referencing the wrong Templates file, or none at all… |
WPB (1391) 352 posts |
Thanks, Steve. Yes, that’s it. In fact, h0bby1, you might want to go back and re-read the start of this thread. It’s very interesting! |
Rick Murray (539) 13806 posts |
Anything with state. Using OS_GBPB to read a list of directory entries? [it will generally work, but what happens if the directory changes (or is deleted) during the read?] That said, RISC OS does try to mitigate the problems; you can’t do much if files change while data is being read on them. This is why I pointed out the age of RISC OS to h0bby1. If there were big glaring show stoppers, we’ll have crashed into them long before now. One does not need to rely upon the CSD being anything at all. There are other methods that are more appropriate. Interesting reading about the Template Open/Read/Close issue. The Wimp doesn’t even pass back a file handle to give to ReadTemplate. Having said that, in the context of an application, loading templates is supposed to be an “atomic” task performed prior to the first poll. So it was likely never envisaged that a task switch may occur while loading templates. |
h0bby1 (2567) 480 posts |
aaaaa |
Steve Fryatt (216) 2103 posts |
Well, yes. However, the thought had crossed my mind a few times that with the advent of tools like Locate 2 which can run multiple searches on a filing system at once, accidentally deleting something that you’re also searching isn’t an impossible scenario. Especially if you consider networked drives. I suspect that Windows might have similar issues, of course: I’m not aware that searching a drive locks its contents. However it might be relevant that the .NET APIs that I’m aware of all return a directory’s contents in one atomic lump – unlike OS_HeebieJeebie, which allows you to collect the contents of a directory by remembering some opaque state, performing multiple polls and trusting that things don’t change until you’re done1. 1 Those polls could be some time apart, too. Locate 2 grabs something like 1k (off the top of my head) of data from OS_GBPB at a time, and stores it on a stack to allow it to recurse down through directory structures. If your search’s root directory is too large to fit into that 1k, and the first objects returned are all directories containing lots of further objects (and so on), it could be quite a while before OS_GBPB is called for the root directory again with the state it returned right back at the start. By that point, who knows what’s happened (or, indeed, what other tasks might have done on null events – consider things like Transient). |
GavinWraith (26) 1563 posts |
In writing applications that scan directories and alter their contents – say deleting empty subdirectories or renaming files – one has to remember not to make the changes until the scan has completed. Most scripting languages provide functions to scan directories, and they usually do this by returning a table of the directory’s contents (e.g. readdir in Perl or listdir in Python). Such functions consume storage in proportion to the number of items in the directory. By contrast, RiscLua provides a for-loop structure with no such penalty:
The code in the body of the loop should not, of course, be updating or writing to the directory. It should rather gather rainchecks for such activities, to be activated after the loop. This is an extension of the principle of hygiene in BASIC that the body of a FOR-NEXT loop should not contain code updating the iteration variable. |
h0bby1 (2567) 480 posts |
aaaaa |
GavinWraith (26) 1563 posts |
SWI TaskManager_EnumerateTasks (see PRM 3-315) tells you the currently active tasks. As for the current task, that is presumably the one calling this SWI, is it not? ;) |
Jon Abbott (1421) 2641 posts |
You want Wimp Items 5 for the current task handle. |
h0bby1 (2567) 480 posts |
aaaaa |
Steve Pampling (1551) 8155 posts |
“Same time”? One processor, one task at a time, PMT or CMT |
Pages: 1 ... 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ... 26