Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shutting down cleanly



On Thursday, August 15, 2002, at 02:06 PM, Ethan Bold wrote:

We designed the driver shutdown notifications as a VERY lightweight mechanism. We made the assumption that there would be a few (2-3) clients and that each of them would take a very short time to complete (<500msec).

In short, the shutdown notification mechanism isn't designed for your use.

Does your drive have a filesystem associated with it? Could you flush the cache to the drive when the fs is unmounted, instead of in the very penultimate stages of shutdown? Is there another, earlier hook you can use instead?


Unfortunately, I don't think so.

The cache is a copy-back cache for a CD-RW drive. It collects writes to the drive, re-arranges them into linear order, and writes them out in the background. If I clean the cache when the volume is unmounted, it will tie up that portion of the operating system for as long as it takes to finish writing the CD (As long as 20 minutes on older (4x) media). Since portions of the unmount and eject process are synchronous, other processes can end up being blocked for the entire time :-(. For the user, this would be like having DiscBurner lock up your system for the entire time that it took to burn each disc.

Instead, the driver ignores flush cache calls, and implements eject calls asynchronously. When an eject is received, a monitor application is launched to show progress information, the cache is written (asynchronously, in the background) and the disc is ejected when the writes complete.

This means that for sleep and shutdown, there can be a background task reading blocks from cache, and writing them to the CD-RW. This task has to suspend or terminate cleanly when sleep or shutdown occurs. More often than not, the task is blocked waiting for the CD-RW drive to accept data into its buffer - the write command has been issued, and the task is blocked waiting for the data phase. We need to block the shutdown until after the write has occurred. Also, since the drive's power may also be turned off, we need to issue a synchronize cache command to the drive to make sure that its write buffer is empty before the power goes off.

This whole process can take several seconds (considerably more than the 500ms limit you designed for).

(BTW, I've given up on the idea of flushing the entire cache when the system shuts down, Now, I just want to make sure that I suspend the flush operation properly so that data won't be lost).

What problems do you forsee if a sleep or shutdown requires something between 7 and 15 seconds to complete? What if there were 2 or three of those tasks queued? Would they be run concurrently?

Thanks for your time,

Ron Aldrich
Software Architects, Inc.
_______________________________________________
darwin-drivers mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-drivers
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Shutting down cleanly (From: Ethan Bold <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.