Hi,
i have implemented a tty driver in a unix like fashion. It have 2 queues, one input queue (filled by the keyboard driver) and one output queue (filed by the user during a write to the tty or indirectly by the keyboard driver if ECHO is enabled).
I wonder if this design is correct from a high level point of view and when to flush the output queue to the destination driver (for example to the screen).
This image represents the design that i'm talking about:
[img]
http://marcocorvi.altervista.org/games/ ... /ttyio.gif
[/img]
I have a pointer in the tty structure to the function of the driver that, for example, prints characters to the screen.
The biggest dubt is "the tty driver must immediatly send a character to the lower level driver or send it in the timer interrupt handler (the same used for the task switch"?!
Thanks for your help.
Dave
tty output queue question
- daveATseclogs
- Posts: 9
- Joined: Sat Feb 18, 2012 4:54 am
- Location: Italy
- Contact:
Re: tty output queue question
IMO to keep things simple, I recommend tty just immediately send a character to the IO manager. If there is threading it should be on the IO manager or driver itself.
The same goes for reading input - IO manager dispatch the input event and send message to the destination process's tty event handler, the tty itself has no thread - it's the process's thread that runs the handler
The same goes for reading input - IO manager dispatch the input event and send message to the destination process's tty event handler, the tty itself has no thread - it's the process's thread that runs the handler
- daveATseclogs
- Posts: 9
- Joined: Sat Feb 18, 2012 4:54 am
- Location: Italy
- Contact:
Re: tty output queue question
So you are suggesting to eliminate the output queue at all...mmm...there isn't another way?! i can't find any document about THIS problem
Re: tty output queue question
No I'm not suggesting to eliminate any queue. Just discourage any kind of threading/branch of control flow. (including "send it in the timer interrupt handler")
It's easier to handle the event in place, and finish with it upon return - a linear control flow.
It's easier to handle the event in place, and finish with it upon return - a linear control flow.
- daveATseclogs
- Posts: 9
- Joined: Sat Feb 18, 2012 4:54 am
- Location: Italy
- Contact:
Re: tty output queue question
So there is no one that uses an output queue?! I can't figure out how Linux do that since the code in that section is too messy... So a quick answere is welcome
Re: tty output queue question
Some devices need an output buffer because the device can't send every character synchronously. For example serial devices.daveATseclogs wrote:So there is no one that uses an output queue?! I can't figure out how Linux do that since the code in that section is too messy... So a quick answere is welcome
But 'where' exactly the buffer is, depends on your architecture. Some designs have those buffers, if required, in the TTY layer. In my opinion, since the buffer is required by the driver, the buffer should be in the driver.
Finally since generally the screen doesn't need buffering, then I agree with bluemoon - send immediately.
If a trainstation is where trains stop, what is a workstation ?
Re: tty output queue question
Well, I use queues, but only one per thread. Output queue is the destination thread's input queue. I've first implemented a message queue system (I've a microkernel, or sort of). Then I built IPC and stdin/stdout on top of that.daveATseclogs wrote:So there is no one that uses an output queue?! I can't figure out how Linux do that since the code in that section is too messy... So a quick answere is welcome
So when a key is pressed, the following queues involved:
1. ps2 driver transforms scancode to keyname and place it in user interface mqueue as a key press/release event
2. user interface reads it's mqueue, and transfers the message to the focused app's mqueue if keyeventreq flag is set (still keyname)
3. user app reads it's mqueue, transforms keyname to escape sequence, and echoes back to user interface's mqueue
4. user interface reads it's mqueue and prints character on focused window at current cursor position.
So as you can see, I use queues heavily. Not the only solution though, as bluemoon suggested you can left it out entirely. It depends what you wanna achieve and what characteristics are important to your design.