Repository navigation
printspool.device: the idle spooler waits instead of spinning - #2375
Open
terminills wants to merge 1 commit into
Open
terminills wants to merge 1 commit into
terminills wants to merge 1 commit into
Conversation
Once its first job was printed, the spooler process never slept again: it looked through the spool directory and rewrote PrintSpool/Status with "idle" some twenty thousand times a second in a QEMU guest, on one CPU, until the system was shut down. A file monitor showed the directory being locked without pause, and the Status file, made anew at every pass, was not there for one look in five. With nothing to print the spooler waits for its signal or for a two-second timer, and aborts the timer when the signal came first. AbortIO() replies the request, which sets the reply port's signal, and WaitIO() takes the reply off the port without clearing it. The next Wait() returned at once on that signal, the timer just started was aborted in turn, and so on. The signal is now cleared after WaitIO(). That alone leaves a look at the queue and a write of the state every two seconds for as long as the system runs. Both go: - The state is written when it changes. A write fails while a program that shows the state has the file open; the idle spooler then tries again every two seconds until it went through. - The spooler asks for notification on the spool directory, where the spooler UI holds, releases and cancels jobs with control files and without a signal. It follows the directory when SPOOL: is assigned or removed. - Apart from that the timer is only used where the file system of the spool directory has no notification, and then only while there are jobs in the queue: control files are about jobs, and a new job comes with a signal. The device is 1.2 with this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After its first job, the print spooler's process uses a whole CPU for as long as the system runs. A user saw it as a file monitor flooded with locks from the spooler, and as a
Statusfile that a directory listing does not show.What was wrong
With nothing to print,
spooler_main()waits for its signal or for a two-second timer, and aborts the timer when the signal came first.AbortIO()replies the request, which sets the signal of the reply port;WaitIO()takes the reply off the port and leaves the signal set. The nextWait()returns at once, the timer that was just started is aborted in turn, and the loop never sleeps again. Each pass looks through the spool directory twice and writesENV:PrintSpool/Status.Measured in a guest (QEMU/KVM, two CPUs), counting the RAM disk's notifications for
ENV:PrintSpool/Status:Statusin the 20 s after one job was printedStatusthat did not find the file, of 200The change
WaitIO(). With only this line added to master the spooler makes one pass every 2.0 s and the guest is back at its idle load, so this is the cause.PrintSpool/Statusis now written when the state changes.StartNotify(), a signal to the spooler). That is where PrintQueue holds, releases and cancels jobs, with control files and without a signal; it was the reason for the timer. The request follows the directory whenSPOOL:is assigned or removed.SetVar()fails while another program has the file open to read it, and with no pass every two seconds nothing would write it again.Not changed
Tested
pc-x86_64 (SMP) and pc-i386, GCC 15.2.0. The guests are a full build of master with
printspool.devicereplaced by the one under test; the test programs are built against that build's SDK. Jobs go toparallel.deviceunit 0, the spool directory isT:PrintSpool. One program writes a job through the device and does what PrintQueue does (CMD_STOP and CMD_START on a unit opened withPRDOF_SETTINGS,.holdand.cancelfiles); another counts notifications and date changes ofT:PrintSpool,ENV:PrintSpoolandENV:PrintSpool/Status. x86_64:Statusin 20 s, nothing to print"Notification refused" is a test build in which
StartNotify()is taken as failed. On i386, master and this change were run: 253946 and 0 writes, 100 % and 4 % of a CPU, cancel and release seen after 0.0 s. In every run a single job, a job sent into a paused queue and cancelled, a job held and released, and three jobs in a row were printed or dropped as asked, and the state readidleafterwards.The counting program looks at
Statusten times a second, and in some runs of the one-line build its look made the spooler's write fail (5 and 0 writes counted in 20 s instead of 10). Builds that print a line before and after the idleWait()give the count without that: the one-line build wakes every 2.0 s; this change does not wake in the 24 s after a job, and afterwards only for a job, a control file or a resume, never with a timer sent.Statusopen for 14 s, the job is cancelled meanwhile. Without the second try the state saidwaiting, cannot open nosuch.device unit 0for good; with it,idleonce the file was closed (x86_64 and i386).SPOOL:assigned to a directory in RAM: while the system runs, a job queued there was dropped when its.cancelfile was written by hand; afterSPOOL:was removed the same inT:PrintSpool. Both wake-ups came from the notification, no timer sent.Not tested:
SPOOL:on a disk file system, a network printer (ipp.device) as the target, PrintQueue's window itself, real hardware, and other architectures.