**************************************************************************** * TaskTool.c * * Dynamic Task Priority Manager * * © E.F.Pritchard 1991 * * Version 0.9 * **************************************************************************** 22:35:20 14-10-91 Yes, here it is, the second (and still not finished 8) version of TaskTool, the Dynamic Task Priority Manager. Throw away ChangeTaskPri and get down to some real Priority Management! Index 39 A Bit on Tasks, Processes and Priorities 89 TaskTool - The Dynamic Task Priority Manager (using TaskTool) 109 TaskTool Layout and Gadgets 175 TaskTool Menus 235 Extra Features 242 Leaving TaskTool 250 A Warning (on changing priorities) 265 Recompiling TaskTool 286 A Note from the Author (copyright, terms, thanks, address) 332 Tools Used to Engineer TaskTool 355 Glossary (a useful, often satirical and sometimes accurate jargon guide) A Bit on Tasks, Processes and Priorities (also see Glossary at end of file) The Amiga is one of the best, if not THE best multitasking computers around. This is because of very clever part of the operating system called Exec. Exec manages the many program tasks by metering out CPU time according to both the priority of the task, and the activity of the task. This is where Exec wins over most other multitasking systems such as those on Macs and Ataris, Arcs and even to some extent UNIX. Tasks only get CPU time if they need it, i.e. can usefully use it. Typical interactive applications (i.e. those which do things as and when the user chooses) spend most of their time waiting around for some event from the user, or on say the serial port. Now, on most multitasking systems, this means that most of the time the program is busy-looping - It is using up processor time saying 'is there an event yet?' over and over again until one happens. This is obviously very inefficient. The time could be better used by other programs who have got the events they want to act on. On the Amiga, this is the case. A task can Wait() (an Exec function) for one or many signals from one or many sources, sleeping and not using processor time until that/those events happen, at which time the task can be given CPU time. Real efficiency! The other factor governing CPU time flow is the Priority. Although a task may have the signals it is waiting for, it will only get CPU time if a more important task doesn't want it. This way, important things like keyboard presses and disk access don't fall over or get missed. Most of the time they too are dormant, allowing 'less important' tasks to use the CPU, but if a user hits a key, they wake up and grab it before it disappears. Keyboard input doesn't fail just because your favorite fractal scene generator wants CPU time! Priority is measured on a scale of -128 to +127, the lower the priority number the 'less important' the task. Most user launched tasks hang about at a priority of 0. CPU time is shared between those tasks at the same priority on a time basis. If a task wants CPU time, and a more important task doesn't need it, it and other tasks at the same priority get a quantum of time each (currently I believe about 20 milliseconds, but don't quote me on that!). This is called time-slicing (N.B. many computer multitasking systems use only time-slicing (without Priority or Activity) which is why they are so trash at it :-). The result is a very efficient multitasking computer, with real-time response (i.e. it's fast). All this falls down when user launched tasks have too high a priority for what they do. Also of course sometimes you don't care if a program works at its absolute peak speed, and want the best response yourself. The solution: TaskTool (well there's got to be some ego boosting...) TaskTool - The Dynamic Task Priority Manager TaskTool displays a list of all Tasks (and Processes) on the system, and allows you to view, and change their priorities: either i) Run TaskTool from the CLI or Shell by simply typing 'TaskTool' (assuming that you are in the right directory, or TaskTool is on your Path. TaskTool uses cback.o, which basically means that it disattaches itself from the CLI window so that you can issue other commands. There are (as yet) no command line options. or ii) Run TaskTool from the WorkBench by double clicking on its icon in the normal way. iii) TaskTool will open a nice (I hope!) window in the middle of the screen and display up to the first eight Task Names. It looks a bit like this: o TaskTool Layout and Gadgets _________________________________ |o| TaskTool OO| |--------------------------------| | __ |Name Slider | Name 1 ------------ | | / Name | Name 2 ------------ | | /| Gadgets____|__ Name 3 ------------ | |/ | | Name 4 ------------ | / | | Name 5 ------------ | | | | Name 6 ------------ |__| | | Name 7 ------------ |/\|__|___Name Arrows | Name 8 ------------ |\/| | | ---- | | ___ | | |R|__|___Manual Refresh Gadget | --- | | Priority | | ___________________________ | | |0 | * |<|>|__|___Priority Arrows | /----------\--------------- | |__/____________\_______________ | / \ / \ Priority String Gadget Priority Slider If there are more than eight Tasks, part of the Name Slider bar will be blue. Use the Name Slider, or the Name Arrows below it to move through the list. Note that the first task (the TaskTool) task is highlighted (even when the list does not display that portion of the list). This is the currently selected Task, and so its priority is displayed below the names list, in the priority section. To select another Task, simply display it using the Name Slider or arrows, and click on its name. This will now highlight, and its priority will be displayed. Now, to change a Tasks' Priority, simply either click on the Priority String gadget, and enter a new priority, or use the Priority Slider or Arrows to adjust it. Users of the old TaskTool v0.8 will notice that the Priority arrows are a little more tactile than before, to facilitate the commonest operation- raising or lowering the priority by just one or two. Use the gadgets like so: i) If you want to make a big change, either type the number in, or drag the slider bar to the right value. ii) For a change of one or two, either click briefly on the Arrows, or click in the container (i.e. not on the knob) of the Priority arrow, on the side that you want the priority to advance towards. The priority will change by 1 for each click. iii) For medium size changes, click and hold the priority arrows. The speed of the change will start slow, and speed up as you hold the gadget down longer, up to a maximum speed. The changes still go through all the values, just faster than at first. The other gadget, the Refresh gadget, tells TaskTool to re-read and display the list of tasks, something you will need to do after starting a new task, or ending an old one. If you should try to adjust a task which has ended, TaskTool will refresh automatically. TaskTool will now (v0.9) track the Task after a Refresh (i.e. it will try to find the Task again in the Task List, and if it exists, will highlight it and display it in the window). Menus TaskTool also has a menu bar: o TaskTool Menus TaskTool______ Refresh____ Task__________ _____________ |About... | |/Manual | |Send Break » | Ctrl C |A|C | |Iconify |A|I | | Timed »»_|_________ | Suspend | Ctrl D |A|C | |Print |A|P | |______| 5 Seconds||Remove | Ctrl E |A|C | |Quit | | 30 Seconds||_____________| Ctrl F |A|C | |_____________| | 60 Seconds| | All |A|C | | 300 Seconds| |_____________| |_____________| Here is what they do: Note: * = Not Yet Implemented TaskTool About - Display Short About text (current version, author etc.) Iconify - Close main window and open small Bar Window. Saves some memory and lots of screen space. Click on window and press menu button to get old window back (positions remembered). Shortcut: Right Amiga I *Print - Print names/priorities/Stack Info of tasks Quit - Leave TaskTool (no verify). Refresh - How TaskTool is refreshed Manual - Only refreshed by Refresh Gadget. Timed - Refreshed every n seconds. (FIXED v0.9) Task - Nasty things you can do to naughty Tasks Send Break - Send a SIGBREAKF signals to the selected Task. Can send any or all of Signals Ctrl-C thru Ctrl-F. Like CLI BREAK command, but signals Tasks which the CLI can't see. Shortcuts: Right Amiga-C|D|E|F|A. (NEW v0.9) *Suspend - Remove Task from Ready list so _never_ gets processor time. I'm looking for a legal way of doing this. For the moment simply lower the Task Priority to -128; the task will only get time when you or anything else doesn't need it. *Remove - Remove Task altogether. Again I need a legal beagle. It can be done, but I have an acute adversion to it- no libraries/devices/windows/ports closed, no memory reclaimed, but I promise I will get round to it... Extra Features TaskTool recognises SIGBREAK flags itself. Sending TaskTool a Ctrl-F signal causes it it refresh, just as if the Refresh Gadget were pressed. A Ctrl-C causes TaskTool to Quit. Leaving TaskTool To leave TaskTool, either Select Quit from the TaskTool menu, or click on the close gadget at the top left of the TaskTool Window. Remember: you can always Iconify TaskTool (Iconify from TaskTool Menu, or Amiga-I), if you simply want to save screen space. A Warning WARNING: Needlessly changing the priority of Tasks and Processes running on the Amiga can crash or make unusable your machine. The Amiga has a very cleverly designed multi-tasking system, and system Tasks (such as trackdisk.device and input.device) are at the priority that they are because they need to be! TaskTool was primarily intended for lowering Task priorities of User Launched Tasks and Processes which are set at too high a priority (specifically TUC by Magic C - priority of 20?? Come on!! (pleasurable program though - Thanks C !)). I do not recommend raising any task to a priority above 20. You have been warned, but feel free to experiment if you wish... Recompiling TaskTool If you wish to do this (and if it's legal - see 'A Note From The Author' below), TaskTool was compiled with Lattice C 5.0 (old but cheap second hand!). Use the following compiler options: lc -b1 -cfist -v -y And Blink with: blink FROM lib:cback.o+TaskList.o+ TaskToolMenuCode.o+TaskRTimer.o+TaskTool.o TO TaskTool LIBRARY lib:amiga.lib+lib:lc.lib DEFINE __main=__tinymain cback.o makes TaskTool disattach itself from a CLI or Shell, the DEFINE stops a default I/O window from opening when running from the WorkBench. A Note From The Author TaskTool is something I mostly wrote for myself, as an education in programming the Amiga, and also as a useful tool. For release details see file 'TaskTool.ReleaseNotes'. TaskTool is Freely Distributable Public Domain Software with one proviso: I MUST remain as the author of the program. If you want to change something, by all means change it on your own copy, but please don't distribute it. If it is a good idea, tell me and I will endorse it and add it to the code (with credit in the source and documents). Also you MUST distribute the ReadMe! file and TaskTool.ReleaseNotes (post v0.8) with the main TaskTool program. I would also like to ask that the source (.c .h and .o files) are also distributed with TaskTool, especially if TaskTool goes onto any BBS or PD disks or any other wide distribution system or company. PD libraries and BBS managers do have my permission to distribute TaskTool, but no more than the cost of services and materials must be charged (i.e. NO PROFIT!). I must thank Scott Ellis at this point, for being one of the original Guinea Pigs for TaskTool, for helpful feedback, and not minding when I sent him a corrupt archive!! Please send any comments, suggestions, ideas, or spare Amiga 3500T's to me by land-mail or e-mail at the addresses below. I will try to release new versions as and when I finish them, and all ideas are welcome for inclusion. Thank you for your time and interest, and for using Amiga. I am: E.F.Pritchard, (Mr. !) a second year Computer Science Student at The University of Southampton. Real Address: Flat 3, Hanlor Court, Broadlands Road, Southampton, England, SO2 3AS. Virtual Address (e-mail): efp90@uk.ac.soton.ecs Tools Used To Engineer TaskTool Editor: AZ v1.40 by JM Forgeas - excellent multi-tasking editor (PD) Gadget/Window Design: Deluxe Paint II (the co-ordinates start at a useful location unlike DPIII). (Commercial and vital! Electronic Arts) IFF Brush to C conversion: VGAD v1.00 by Stephen Vermeulen - loads of options, and does those rather nice character pictures as comments... (PD) IFF Brush to Icon conversion: MakeIcon by Paul Blum - Confusing to use at first but very useful. If anyone has the time to draw a better icon for TaskTool, please do so and send it to me. The current one is not offensive, but not perfect either. (Freely Distributable, but not saleable) C Compiler: Lattice or SAS C - well fresh. (Commercial and vital! SAS) Glossary Task - A program running under Exec Process - A higher level program, which is also a Task, but has more power, e.g. it can call the DOS library. User launched programs which come from the Shell, CLI or WorkBench are Processes. CPU - Central Processing Unit. The main Chip which makes computers work. The Amiga family currently use the Motorola 68000 family, of which the current tasty one is the 68040. Library - A collection of useful routines for use in programs. Exec libraries are very clever in that more than one program can use them at the same time, without more than one copy in memory. Port - An Exec Port is a place where a Task can send and receive Messages from other Tasks. Messages are queued at a Port in a FIFO (first in, first out) order, until the Task reads those Messages and removes them. The arrival of a Message can automatically send a Signal to a Task, or even trigger a Software interrupt, for immediate processing of the Message. Example Messages are IDCMP messages containing Mouse, Menu and Gadget activity information, and Device messages containing, say, bytes read at the Serial Port. Message - A two part block of information, consisting of a Header, with standard information about the message, and a Body which can contain many sorts of information. Messages arrive at Ports and are in effect a temporary licence to use another Tasks' memory, as messages are not copied for speed; they are simply refered to. Signal - Another Exec device. Signals are the simplest communication device in Exec, and very useful they are too. A Task can Send and Receive Signals from other Tasks, recieving a signal can cause a Task to wake up from a Wait() if the Task is looking for a Signal of that type. Typical signals include those which happen when a Message is passed to one of the Tasks Ports, and those set by the user by pressing Ctrl-C. IDCMP - The Intuition Direct Communications Message Port. This is where Messages from Intuition, the Window interface system, arrive. The IDCMP can be set up to receive all sorts of events, ranging from Gadget Up/Down movements to Intuiticks: a regular prompting sync from Intuition. Zark - The NSE (Non-Swearing Expletive). Can be used without causing offence in many varied situations and contexts. Originated by Douglas Adams in his 'Hitch-Hikers Guide to the Galaxy' four book trilogy. Try out 'Zark-city' and 'Zarking-crazy' during a polite after-dinner conversation. UNIX - A multi-user, multi-tasking operating system which runs on large and small systems. It does have Priorities, but users can only have limited use of them, and there is a sort of Wait() command, but its rather less efficient. Still it's a nice powerful, if unwieldy system... check out the Amiga 3500UX. MINIX - A sad subset of UNIX that makes MSDOS look powerful. Used to teach Computer Science students about operating systems. IBM - A company who sells computers whos' technology is fundamentally over ten years out of date. It gets away with it because a) it is so big b) because the mark ups on its products are so great, and c) because the public at large don't know the first thing about computers. Who said we don't need no education? (Pink Floyd actually). Atari - reference to Atari ST. Once thought of as the Spectrum of the 90's, proved to be as cr*p as the Spectrum and now hardly thought of at all (at least not thought of nicely). Arc - the first RISC (Reduced instruction set as opposed to conventional CISC - Complex instruction set) home computer; basically it is so bloody fast that it can even run its' own sloppy operating system at an acceptable speed. Only availiable in Britain, and only sold because schools thought that it was the best upgrade path from the ancient BBC computers which the Government bought them. Mac - the ubiquitous Apple Macintosh. Quite a nice Graphical User Interface (the original one, or so Apple Sues), and just 'cos it costs losts, thought of as superior to the Amiga (or any other computer on earth) by owners who want to protect their (considerable) investment. Was never designed with multi-tasking in mind, and is therefore zarking useless at it. Now joined forces with IBM. Say no more.