=== Top of the Swiki === Attachments ===

PowerbooksInSlumberland

From the SqueakList, October 27, 1997:

I'm pleased to say that given a hint from TimOlson lead me on a journey to discover why Squeak 1.22 performance suffered on my PowerBook 3400c. First it seems that each PowerBook has different criteria for how it manages power both on A/C or battery. In general after a period of 'inactivity' various methods are applied to conserve power like putting the CPU to sleep for .5 or .75 seconds every other second or so, or cutting the clock rate to 1Mhz. Some degree of control is given over this via the PowerBook control panel, but all my testing was done with performance set on max. Just to complicate things, this control panel varies from OS version to version and seems to be different for each PowerBook model. I'm sure more complex third party options are available to better tune the PowerManager, but lets live with Apple's generic offering for the moment.

It would seem that my PB 3400c running system 8 has a radical performance problem with the Squeak VM unless Squeak or the user does one of the following:

  • Move the mouse every few seconds or so
  • Do some file I/O
  • Use the keyboard
  • Change the cursor to Apple's official watch cursor (Not likely)
  • Do some other interesting lowlevel I/O call, none of which the VM does directly.

  • Remember official Apple rules state that long running CPU intensive tasks should throw up the Apple watch cursor, thus avoiding sleep/nap time according to rule 4. Since most normal Mac applications follow this rule they are not humbled.

    To examine how Squeak was humbled by the PowerManager I ran this benchmark:

      5000000 // (Time millisecondsToRun: [10 benchmark]) * 1000

    in a loop and collect data on how slow it run from iteration to iteration to get the follow table of results using the 'official' VM1.22 running both on battery or A/C power.

      5662000,5175000,4916000,4347000,4108000,3408000,3261000,
    3156000,1886000,1327000,1250000,1239000,1176000

    As you can see performance degrades, over a time of a minute or two(!), from a high of 5.6 million to a low of 1.1 million. As the computer grows 'less busy' the PowerManager pursues CPU stoppages to conserve power. My note from last Monday stated that SystemTask was taking 1.5 seconds to complete every other call or so when the machine was 'idle'. But of course Squeak is really running a aggressive bytecode benchmark. Other PowerBook owners are welcome to try this out and see how the PowerManager affects their measurements.

    However Apple lets you indicate fake user activity using a system call to let the PowerManager know that activity that doesn't fit it's model of computer busy is going on. This call UpdateSystemActivity() is made with the constant UsrActivity which shows that general user activity is going on, please don't put the computer to sleep or nap it's very busy! Other constants are available but this seem more appropriate.

    To ensure the call is invoked frequently I placed it in sqMacWindow.c HandleEvents() which normally gets called about every 1/30 second, but when user activity stops it gets called every 1/2 seconds. This call rate change is a decision made by Squeak to reduce system call overhead, but what about the impact on foreground applications: my next exploration.

    To ensure we don't call the PowerManager on machines that don't support it good Macintosh hacking calls for a gestalt check, and some other checks, like so:

     void PowerBookCheck(void) {
    long pmgrAttributes;
    tapPowerManager = false;
    if (! Gestalt(gestaltPowerMgrAttr, &pmgrAttributes))
    if (pmgrAttributes & (1gestaltPMgrDispatchExists))
    if (PMSelectorCount() >= 0x24)
    tapPowerManager = true;
    }

    Also I needed to link in the MetroWerks PowerManager library to resolve glue code needed to call the manager. Early in the initialization I use PowerBookCheck() to set the global (ick) variable tapPowerManager which is used later on in the event loop to see if we can call UpdateSystemActivity().

    New benchmarks gave me

      8561000,8333000,7886000

    The numbers are far higher. My version of V1.22 is a good 50% faster than the official version. However I suspect the official version suffers from 'CPU napping' fairly quick, one CPU nap creeping into the benchmark would alter things. Testing on a 604e based 8600 shows equivalent benchmarks between mine and the official release, so the 'nap' issue alters any benchmark figures on the 3400c.

    So what's the cost? Well for one, when Squeak is running we eat energy like mad and reduce battery life. But on the otherhand Morphic animations now run without irritating pauses.

    "Full speed ahead, damm the torpedeos."

    Now I wonder what Windows based laptops behave like? Are there Microsoft guidelines or in true hacker fashion does the user gets to set the Power Management policy based on Hardware options/abilities and his wants.

    For those who remember my note last Monday about calling SystemTask 30 times per second versus twice per second solving the performance problem, know that this result was contaminated with a behavior change. In my instrumented version of Squeak I was dumping data to a external log file in HandleEvents() and when it got called above a certain frequency per second the file I/O activity prevented the PowerManager from napping the CPU. Removing the file I/O dropped me back to the original behavior of napping regardless of the call frequency of SystemTask().

    Much fun, without the ability to instrument the VM source code I would have never found the problem and perhaps passed off my Morphic animation pauses as issues with the GC running.

    -- JohnMcIntosh



    JohnMaloney was kind enought to point out that you can turn CPU power cycling off if you option click on the easy/custom slider on the PowerBook control panel. This feature then shows the checkbox to turn cycling on/off. This little feature has added power to my PowerBook. Sure wish they discussed it upfront.