Imagining RISC OS and PMTBy Chris Williams. Published: 26th Jul 2003, 21:10:57 | Permalink | Printable
Wimp2 illustrates what it'd be like [Updated]Editorial Recent discussion in the drobe.co.uk comments and forums has resulted in recurring calls for RISC OS to gain fundamental operating system features enjoyed by other platforms, notably pre-emptive multitasking (PMT) and full memory protection. Whilst the RISC OS desktop is a cooperative multitasking (CMT) affair, a PMT solution does exist in the form of Niall Douglas' Wimp2 which we'll look at in a moment.
Firstly, we'll briefly explain the differences between PMT and CMT. The RISC OS desktop is a multitasking one as it allows many applications to seemingly run at the same time, from the user's point of view. The computer's processor can execute only one program at a time but the operating system can step in so a given program executes for a while before another program gets time with the processor. This sharing of processor time among programs creates the illusion that multiple programs are running simultaneously.
CMT and PMT are merely different ways of going about and both methods have their advantages and disadvantages. With cooperative multitasking (CMT), individual applications determine how much processor time they receive. Once an application has finished responding to an event, such as a mouse click, or when the application feels it's had its fair share of the processor, the application tells the operating system to move onto the next program waiting for processor time. The OS then pauses that application and tells the processor to resume executing the next application. This passing of control is almost cyclic, as eventually the processor will return to continue executing the original application. The downside to CMT is that if an application crashes or gets greedy and doesn't allow other applications to have time with the processor, the desktop grinds to a halt and multitasking ceases - RISC OS users will be painfully aware of this.
On the other hand, in pre-emptive multitasking (PMT), it's the OS that decides when an application begins and ceases executing. Usually, the OS employs a hardware based timer to measure how much time an application has spent with the processor. When an application has been running for a defined amount of time, the operating system steps in to pause the application and resume the execution of another application. The benefit of PMT is that no application can hog the processor as each application is generally given an equal amount of processor time.
As previously stated, RISC OS uses CMT to acheive multitasking while other operating systems like Microsoft Windows and the Linux kernel use PMT. PMT does indeed appear to be far more beneficial than CMT and if RISC OS adopted a PMT environment, we would see the end to situations like !ChangeFSI hogging the processor whilst processing images.
So with that in mind, we gave Wimp2 a shot. Wimp2 is a module that works with RISC OS 2 to RISC OS 4 (it's not 32 bit yet) and it basically enables pre-emptive multitasking on RISC OS. Applications can either talk to Wimp2 to set themselves up to multitask pre-emptively or a supplied patch by Andrew Teirney can be run which transparently converts CMT based software to PMT on the fly. This means software like Oregano and StrongED can be made to multitask pre-emptively without any modifications.
Wimp2 has quite a history, which is worth reading. Its author, Niall Douglas, started development back in 1994 as part of his "regeneration of RISC OS" project called Tornado. Version 0.36, the latest version online, was completed in 1999.
Photodesk running over Wimp2 and multitasking pre-emptively
The good news is that the sources to Wimp2 and the aforementioned patch are available and Wimp2 appears to be released under the GPL, so a 32 bit version is possible and it's also possible for people to improve it and fix it. The source came in handy when I tried running the patch on my RISC OS 4.36 RiscPC as I had to comment out the code that checks for the OS version.
Attempting to run Wimp2 from my boot sequence resulted in multiple aborts and crashes so I decided to play it safe and try it out once the desktop had been fully reached and set up. Once Wimp2 and Andrew's patch are running, CMT based applications can be filtered to be executed as PMT tasks when first run (see screenshot below), and your choices are saved to disc as appropriate if you don't wish to be asked again. Alternatively, application names can be manually added to a textfile to define behaviour like how much processor time each application should ideally be given or to exclude some applications from being run as PMT tasks. This is useful if a CMT based application crashes when forced to run as a PMT application although some applications refuse to be excluded from being run as PMT tasks which leads to problems.
Would you like fries with that?
RISC OS 4 users may wish to exclude !Configure and its 'Generic plug-in' task from being executed as PMT tasks. To be honest, you will need to set aside some time to configure and set up the Wimp2 package to be just right, excluding software that crashes with Wimp2 and finding software that massively benefits from it. Any applications that use the Toolbox run in to problems, which includes OvationPro. It was beautiful, however, to see a ChangeFSI (running as a PMT task) processing a 1600x1200 32k colour spritefile whilst the rest of the desktop continued to multitask smoothly. Another processor hog tamed by PMT, Oregano formatted a huge HTML file whilst the rest of the desktop happily multitasked.
Toolbox issues aside, another problem was redraw. When a window in the RISC OS desktop needs updating or redrawing, the window manager orders the application, to which the window belongs, to find out which areas of its window need redrawing and to do the necessary graphics operations. Under CMT, the application would normally update its window and pass control to the next application. Under PMT with Wimp2, it would appear an application redrawing its window is being forced to multitask every so often when it should be redrawing. This reduces window redraw speed and also causes flickering. Scrolling this StrongED text window or dragging a window over an image being edited in Photodesk is slower than when the applications are running in CMT mode.
Despite these problems, Wimp2 is certainly entertaining to play with if you have the time and the sources are available if you want to improve the modules. The GPL nature of the module rules out any possibility of including the module code in RISC OS but Wimp2 does give a good indication of what RISC OS would be like if the OS were to adopt a PMT environment to replace the CMT system in place at the moment.
Wimp2 author Niall Douglas kindly sent us these comments, regarding this article:
"Actually the redraws are slow because Wimp_UpdateWindow is used instead of Wimp_RedrawWindow plus the Wimp actually makes a special case with window redraw requests (it calls the app directly from the "move window" or "close window" implementation code).
"Wimp2 does nothing for redraw requests, just saves the area into a buffer which it then passes to the app when it's ready for it.
"I should mention that if you write your RO application to natively use Wimp2 then all the problems just go away. Flaky behaviour is 100% caused by the patch which has to do really nasty things under the bonnet. While I never actually wrote a large program using Wimp2, I did port RO2 Maestro to it and it ran very nicely indeed. Things like display redraw speed are much faster if your app is aware it's being preempted and you take the appropriate steps."
Niall also pointed out that only user level code can be pre-empted by Wimp2 and therefore operating system level code can't be. That is, when an application asks RISC OS to perform a lengthy task, like load a file from disc into memory, multitasking ceases until the operating system is done. Wimp2 does make an attempt to at least keep multitasking going when an application uses the OS provided
Previous: Future ARM based processors for RISC OS?
Next: Repairing, restoring legacy Acorn kit
DiscussionViewing threaded comments | View comments unthreaded, listed by date | Skip to the end
Please login before posting a comment. Use the form on the right to do so or create a free account.
Search the archives
Today's featured article
Star Fighter 3000: The Next Generation review
Star Fighter 3000: The Next Generation was born from the 3D0 version of the original SF3K that was ported back to RISC OS and this year freed from programmers' hard discs for the platform to enjoy, writes Andrew Weston. In this review Andrew weighs up much-improved graphics and sound against playability and stability.
19 comments, latest by AW on 9/12/08 8:45PM. Published: 17 Nov 2008
Advanced Sudoku game bug-fixed
SuperDoku now up to version 1.14
Discuss this. Published: 24 Sep 2007
News and media:
RISCOS Ltd •
RISC OS Open •
MW Software •
Advantage Six •
CJE Micros •
Liquid Silicon •
Chris Why's Acorn/RISC OS collection •
The Register •
The Inquirer •
Apple Insider •
BBC News •
Sky News •
Google News •