patch: add delay=<msecs> suboption to -display curses
The attached patch (qemu-curses-delay-1.patch) allows the user to specify that he needs -display curses to insert a delay in between key events. The current behaviour is that it inserts key events immediately, one right after another, which has proven to be too fast for some applications. Please let me know if there are any improvements you'd like me to make to this patch, with the goal that I'm hoping you'll accept it. A more detailed description of this patch is as follows:
Add support for the "-display curses" option to accept suboptions (-display curses[,option...), and add the "delay=<msecs>" suboption. This suboption causes a millisecond-based delay to be inserted in between key events so that they won't be inserted immediately one after another. The delay is performed using a qemu virtual clock timer. If the "delay" option isn't specified, or if "delay=0" is specified, then the timer isn't used, thus making the default be the original behaviour. The "=<msecs>" operand is optional - if it isn't specified then 20 is assumed.
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
include/ui/console.h +1 -0
@@ -338,6 +338,7 @@ static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)#endif /* curses.c */ +void curses_parse_options (const char *options);void curses_display_init (DisplayState *ds,int full_screen);/* input.c */
qemu-options.hx +5 -3
@@ -820,9 +820,11 @@ ETEXI DEF("display", HAS_ARG, QEMU_OPTION_display, "-display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off]\n" - " [,window_close=on|off]|curses|none|\n" - " gtk[,grab_on_hover=on|off]|\n" - " vnc=<display>[,<optargs>]\n" + " [,window_close=on|off]\n" + " none\n" + " curses[,delay[=<msecs>]]\n" + " gtk[,grab_on_hover=on|off]\n" + " vnc=<display>[,<optargs>]\n" " select display type\n", QEMU_ARCH_ALL) STEXI @item -display @var{type}
ui/curses.c +131 -10
175 lines not on this page · raw message
vl.c +1 -0
@@ -2300,6 +2300,7 @@ static DisplayType select_display(const char *p) }else if (strstart (p,"curses" , &opts)) {#ifdef CONFIG_CURSES display =DT_CURSES ; +curses_parse_options (opts);#else fprintf (stderr,"Curses support is disabled\n" );exit (1 );
Quoted 8 lines · Dave Mielke
The attached patch (qemu-curses-delay-1.patch) allows the user to specify that he needs -display curses to insert a delay in between key events. The current behaviour is that it inserts key events immediately, one right after another, which has proven to be too fast for some applications. Please let me know if there are any improvements you'd like me to make to this patch, with the goal that I'm hoping you'll accept it. A more detailed description of this patch is as follows:
Quoted 8 lines
Add support for the "-display curses" option to accept suboptions (-display curses[,option...), and add the "delay=<msecs>" suboption. This suboption causes a millisecond-based delay to be inserted in between key events so that they won't be inserted immediately one after another. The delay is performed using a qemu virtual clock timer. If the "delay" option isn't specified, or if "delay=0" is specified, then the timer isn't used, thus making the default be the original behaviour. The "=<msecs>" operand is optional - if it isn't specified then 20 is assumed.
Why is this a problem only for the curses UI frontend, and not for any of the other UIs which might send key events?
thanks
-- PMM
[quoted lines by Peter Maydell on 2014/05/25 at 01:04 +0100]
Quoted 2 lines
Why is this a problem only for the curses UI frontend, and not for any of the other UIs which might send key events?
One reason is that most UIs send key events as they receive them from the keyboard, one at a time, whereas the curses UI gets a single key event from curses and then sends all of the scancodes which it takes to represent that key. In other words, a single key event from curses could result in as many as 10 actual key events needing to be passed along - both the press and release for the actual key plus up to four modifiers (shift, control, alt, altgr).
Another reason is that it's not a problem for a lot of applications. I happened to hit it in an application, and, therefore, coded a fix for it.
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
Quoted 10 lines · Dave Mielke
[quoted lines by Peter Maydell on 2014/05/25 at 01:04 +0100]
Quoted 2 lines
Why is this a problem only for the curses UI frontend, and not for any of the other UIs which might send key events?
One reason is that most UIs send key events as they receive them from the keyboard, one at a time, whereas the curses UI gets a single key event from curses and then sends all of the scancodes which it takes to represent that key. In other words, a single key event from curses could result in as many as 10 actual key events needing to be passed along - both the press and release for the actual key plus up to four modifiers (shift, control, alt, altgr).
Ah, I see. Still, I think it makes more sense for the queue and delay to be in the common key handling code, not in the curses frontend specifically.
thanks
-- PMM
[quoted lines by Peter Maydell on 2014/05/25 at 10:11 +0100]
Quoted 3 lines
Ah, I see. Still, I think it makes more sense for the queue and delay to be in the common key handling code, not in the curses frontend specifically.
Yes, you're right. While the curses UI is especially vulnerable to the problem, others could be as well, especially if they're driven by a software "user" rather than by a human being. Also, who's to say that there won't be a new UI in the future which won't run into the same problem. I'll move the code and submit a new patch.
Given that this'll require a brand new option, could you please let me know all the places that'll need updating insofar as documentation is concerned?
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
[quoted lines by Peter Maydell on 2014/05/25 at 10:11 +0100]
Quoted 3 lines
Ah, I see. Still, I think it makes more sense for the queue and delay to be in the common key handling code, not in the curses frontend specifically.
The code has been moved. I can see a couple of possibilities insofar as an option for it is concerned. One is to extend the existing -k option to accept language= as an optional prefix for its currnet operand, and to add delay=. The other is to add a brand new -keydelay option. Which would be the better approach?
I'm assuming that qemu-options.hx is the only file that needs to be updated insofar as documentation is concerned. Is that correct?
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
Quoted 3 lines · Dave Mielke
Add support for the "-display curses" option to accept suboptions (-display curses[,option...), and add the "delay=<msecs>" suboption. This suboption causes a millisecond-based delay to be inserted in between key events so that
In addition to what Peter said, I think this suboption is named poorly. Maybe it can be named, say, kbddelay, or keydelay, or something like that. Just "delay" may be interpreted as _video_ delay, ie, delay updating picture for so many millisecs. After all, this is -display, which is about video, and keyboard is a secondary function...
Also, you still haven't told us what application is having problem with it, it is some mystery "some app". And provided this hasn't been a problem for so many years, maybe we shouldn't add it in the first place?
Thanks,
/mjt
[quoted lines by Michael Tokarev on 2014/05/25 at 16:41 +0400]
Quoted 5 lines
In addition to what Peter said, I think this suboption is named poorly. Maybe it can be named, say, kbddelay, or keydelay, or something like that. Just "delay" may be interpreted as _video_ delay, ie, delay updating picture for so many millisecs. After all, this is -display, which is about video, and keyboard is a secondary function...
Yes, that makes good sense.
Quoted 2 lines
Also, you still haven't told us what application is having problem with it, it is some mystery "some app".
Where I ran into it is DJGPP termios input on MS-DOS.
Quoted 1 line
And provided this hasn't been a problem for so many years,
Perhaps it hasn't been observed before because the curses UI may not have that many users. I myself must use it as, being blind, it's much easier for me to work in text mode than in graphics mode.
Quoted 1 line
maybe we shouldn't add it in the first place?
Given that this feature does resolve a problem, given that it's default retains the original behaviour, and given that we have no idea whatsoever regarding when the problem may strike again, my personal opinion is that implementing it now would be a reasonable thing to do, especially since the current situation is that no one is being asked to figure it out, code it, etc.
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
Re: [Qemu-trivial] [Qemu-devel] patch: add -kbddelay option
In reply to Dave MielkeQuoted 5 lines
[quoted lines by Peter Maydell on 2014/05/25 at 10:11 +0100]
Ah, I see. Still, I think it makes more sense for the queue and delay to be in the common key handling code, not in the curses frontend specifically.
This patch, attached as qemu-kbddelay-1.patch, is a rework of the former curses UI patch so that the delay applies to key events in general. A new option, -kbddelay [duration=]msecs, controls it. As before, the default is 0, meaning no delay, in which case the timer and queue aren't used thus retaining the original behaviour.
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
include/ui/input.h +1 -0
@@ -35,6 +35,7 @@ void qemu_input_event_sync(void);InputEvent *qemu_input_event_new_key (KeyValue *key,bool down);void qemu_input_event_send_key (QemuConsole *src,KeyValue *key,bool down);void qemu_input_event_send_key_number (QemuConsole *src,int num,bool down); +void qemu_input_event_set_keyboard_delay (uint64_t duration);void qemu_input_event_send_key_qcode (QemuConsole *src,QKeyCode q,bool down);int qemu_input_key_value_to_number (const KeyValue *value);int qemu_input_key_value_to_qcode (const KeyValue *value);
qemu-options.hx +18 -0
@@ -262,6 +262,24 @@ de en-us fi fr-be hr it lv nl-be pt sl tr The default is @code{en-us}. ETEXI +DEF("kbddelay", HAS_ARG, QEMU_OPTION_kbddelay, + "-kbddelay [duration=]msecs\n" + " ensure a minimum delay between keyboard events\n" + " duration: the minimum delay between keyboard events (default: 0)\n", + QEMU_ARCH_ALL) +STEXI +@item -kbddelay [duration=]@var{msecs} +@findex -kbddelay +Set the minimum delay between keyboard events to @var{msecs} milliseconds. +The default is 0 (no minimum delay). +This option exists in order to deal with problematic applications which run +into trouble when keys are typed too quickly. Certain UIs, like curses, +aggravate the problem because they must turn a single user keyboard action into +several keyboard events being delivered to the virtual machine. Only try this +option if you encounter an unexpected keyboard input issue, for example the +input not being recognized at all. A duration of 20 seems to be reasonable. +ETEXI + DEF("audio-help", 0, QEMU_OPTION_audio_help, "-audio-help print list of audio drivers and their options\n",
ui/input.c +79 -1
92 lines not on this page · raw message
vl.c +40 -0
@@ -77,6 +77,7 @@ int main(int argc, char **argv)#include "net/slirp.h" #include "monitor/monitor.h" #include "ui/console.h" +#include "ui/input.h" #include "sysemu/sysemu.h" #include "exec/gdbstub.h" #include "qemu/timer.h"
@@ -1387,6 +1388,20 @@ static QemuOptsList qemu_smp_opts = { }, }; +static QemuOptsList qemu_kbddelay_opts = { + .name ="kbddelay" , + .implied_opt_name ="duration" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_kbddelay_opts.head), + .merge_lists = true, + .desc = { + { + .name ="duration" , + .type =QEMU_OPT_NUMBER , + }, + {/* end of list */ } + }, +}; +static void smp_parse (QemuOpts *opts) {if (opts) {
@@ -3021,6 +3036,7 @@ int main(int argc, char **argv, char **envp)qemu_add_opts (&qemu_realtime_opts);qemu_add_opts (&qemu_msg_opts);qemu_add_opts (&qemu_name_opts); +qemu_add_opts (&qemu_kbddelay_opts);runstate_init ();
@@ -3408,6 +3424,30 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_k: keyboard_layout = optarg;break ; +case QEMU_OPTION_kbddelay: { +uint64_t duration_value; +const char *duration_string; + + opts =qemu_opts_parse (qemu_find_opts ("kbddelay" ), optarg,1 ); +if (!opts) { +exit (EXIT_FAILURE ); + } + + duration_string =qemu_opt_get (opts,"duration" ); +if (!duration_string) { +error_report ("invalid -kbddelay option, missing 'duration' option" ); +exit (EXIT_FAILURE ); + } + +if (*duration_string) { + duration_value =qemu_opt_get_number (opts,"duration" ,20 ); + }else { + duration_value =20 ; + } + +qemu_input_event_set_keyboard_delay (duration_value); +break ; + }case QEMU_OPTION_localtime: rtc_utc =0 ;break ;
Quoted 11 lines · Dave Mielke
[quoted lines by Peter Maydell on 2014/05/25 at 01:04 +0100]
Quoted 2 lines
Why is this a problem only for the curses UI frontend, and not for any of the other UIs which might send key events?
One reason is that most UIs send key events as they receive them from the keyboard, one at a time, whereas the curses UI gets a single key event from curses and then sends all of the scancodes which it takes to represent that key. In other words, a single key event from curses could result in as many as 10 actual key events needing to be passed along - both the press and release for the actual key plus up to four modifiers (shift, control, alt, altgr).
Tried to make the curses ui a bit more clever? You could try caching the modifier state, then send only the changes. That gets the number of events down to 6 max (4 to update modifier state, 2 for the actual key).
Other question: has "git revert 2858ab09e6f708e381fc1a1cc87e747a690c4884" any effect?
cheers,
Gerd
[quoted lines by Gerd Hoffmann on 2014/05/26 at 15:38 +0200]
Quoted 3 lines
Tried to make the curses ui a bit more clever? You could try caching the modifier state, then send only the changes. That gets the number of events down to 6 max (4 to update modifier state, 2 for the actual key).
Yes, except that, in my case, the problem already occurs on simple typing of lowercase letters, i.e. just two events.
Also, that approach could introduce new problems due to modifeir keys appearing to be stuck.
Quoted 2 lines
Other question: has "git revert
2858ab09e6f708e381fc1a1cc87e747a690c4884" any effect?
That gives me:
could not revert 2858ab0... ps2: set ps/2 output buffer size as the same as kernel
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
Re: [Qemu-trivial] [Qemu-devel] patch: add -kbddelay option
In reply to Dave Mielke[quoted lines by Dave Mielke on 2014/05/26 at 08:59 -0400]
I'm sorry for quoting myself, but I'm doing it for context since I have a question:
Quoted 5 lines
This patch, attached as qemu-kbddelay-1.patch, is a rework of the former curses UI patch so that the delay applies to key events in general. A new option, -kbddelay [duration=]msecs, controls it. As before, the default is 0, meaning no delay, in which case the timer and queue aren't used thus retaining the original behaviour.
I've currently coded it so that there's a new option - -kbddelay. So, we have the following two options:
(old) -k <language>
(new) -kbddelay [duration=]<msecs>
My question is if this is the best way to do it, or if the two options should be merged. For example:
-k [language=]<language>,delay=<msecs>
What do you think?
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
Quoted 8 lines · Dave Mielke
[quoted lines by Gerd Hoffmann on 2014/05/26 at 15:38 +0200]
Quoted 3 lines
Tried to make the curses ui a bit more clever? You could try caching the modifier state, then send only the changes. That gets the number of events down to 6 max (4 to update modifier state, 2 for the actual key).
Yes, except that, in my case, the problem already occurs on simple typing of lowercase letters, i.e. just two events.
What exactly is the problem?
Quoted 2 lines
Also, that approach could introduce new problems due to modifeir keys appearing to be stuck.
Indeed.
Quoted 6 lines
Quoted 2 lines
Other question: has "git revert
2858ab09e6f708e381fc1a1cc87e747a690c4884" any effect?That gives me:
could not revert 2858ab0... ps2: set ps/2 output buffer size as the same as kernel
Given that only two keys already problematic this probably wouldn't change things anyway.
cheers,
Gerd
Re: [Qemu-trivial] [Qemu-devel] patch: add -kbddelay option
In reply to Dave MielkeQuoted 17 lines · Dave Mielke
[quoted lines by Dave Mielke on 2014/05/26 at 08:59 -0400]
I'm sorry for quoting myself, but I'm doing it for context since I have a question:
Quoted 5 lines
This patch, attached as qemu-kbddelay-1.patch, is a rework of the former curses UI patch so that the delay applies to key events in general. A new option, -kbddelay [duration=]msecs, controls it. As before, the default is 0, meaning no delay, in which case the timer and queue aren't used thus retaining the original behaviour.
I've currently coded it so that there's a new option - -kbddelay. So, we have the following two options:
(old) -k <language>
(new) -kbddelay [duration=]<msecs>
Quoted 6 lines
My question is if this is the best way to do it, or if the two options should be merged. For example:
-k [language=]<language>,delay=<msecs>What do you think?
*If* the feature is deemed useful: better extend -k. We generally prefer extensible options based on QemuOpts to proliferating ad hoc single-purpose options.
[quoted lines by Gerd Hoffmann on 2014/05/27 at 07:44 +0200]
Quoted 1 line
What exactly is the problem?
At the user level, the keyboard appears to be dead. An inspection of the udnerlying code reveals that the application itsllf is querying the MS-DOS keyboard input buffer in a bad way. Those apps can't be fixed, though, because the bad code is in a library which is statically linked into every app using it, which means lots of apps, many of which, as is always the case, may not even have source code anymore.
Another thing to consider is that this, really, is a general problem. Most keyboard input code, especially in older days, would've nly ever been tested at typing speed. It should be expected, therefore, that there might be problems in some of it when input events arrive faster - in this case, "infinitely" fater. The solution I'm proposing, therefore, tackles it in a general way, and does nothing more than allow the user to request that, regardless of what the UI needs to do underneath, the keyboard events still arrive at the speed of a typist.
Did you see my other question abot either adding -kbddelay [duration=]msecs or merging it into -k (-k [language=]language[,delay=msecs]? Which would be the better approach?
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/
Quoted 7 lines · Dave Mielke
[quoted lines by Gerd Hoffmann on 2014/05/27 at 07:44 +0200]
Quoted 1 line
What exactly is the problem?
At the user level, the keyboard appears to be dead. An inspection of the udnerlying code reveals that the application itsllf is querying the MS-DOS keyboard input buffer in a bad way.
Which means exactly? They are not prepared to find data for more than one key event in the buffer?
Quoted 4 lines
Those apps can't be fixed, though, because
the bad code is in a library which is statically linked into every app using it, which means lots of apps, many of which, as is always the case, may not even have source code anymore.
Sure.
Quoted 8 lines
Another thing to consider is that this, really, is a general problem. Most keyboard input code, especially in older days, would've nly ever been tested at typing speed. It should be expected, therefore, that there might be problems in some of it when input events arrive faster - in this case, "infinitely" fater. The solution I'm proposing, therefore, tackles it in a general way, and does nothing more than allow the user to request that, regardless of what the UI needs to do underneath, the keyboard events still arrive at the speed of a typist.
I don't like the idea to do it in the UI code. I don't think the problem is as generic as you think it is. HID keyboards (usb, bluetooth) report keys in a completely different way, and probably your problem is specific to the ps/2 keyboard.
I'd try to do it in the ps/2 code, and try to do it without a timer.
Idea: Split the ps/2 keyboard queue into two. One will be guest-visible. The existing ps2 queue will do the job. The other, new queue will not be visible to the guest. Simliar to the queue you've added to the ui code. Put not more than one key event (1-3 scancodes) into the guest visible queue. Wait for the guest read the status register (signaling "no more data") once. Then go refill the guest-visible queue from the invisible queue. With some luck this makes things work without a delay.
If not we are not so lucky we have to fire a timer for queue refill after signaling "no more data" to the guest. Even in case we need a timer this is better than doing it in the ui code as we can arm the timer when we know the guest has actually seen the key event. So the guest being busy with something else and not polling the kbd for a time span longer than the delay will not break things, so we can use a pretty short delay.
cheers,
Gerd
Quoted 7 lines · Dave Mielke
[quoted lines by Michael Tokarev on 2014/05/25 at 16:41 +0400]
Quoted 1 line
And provided this hasn't been a problem for so many years,
Perhaps it hasn't been observed before because the curses UI may not have that many users. I myself must use it as, being blind, it's much easier for me to work in text mode than in graphics mode.
You were too modest to link your own webpage, but I'll do it for us all, because it'll help our understanding:
http://mielke.cc/brltty/index.html
http://mielke.cc/resume.html#exp-2000-PRESENT
Thanks
Laszlo
PS: stunned and amazed
[quoted lines by Gerd Hoffmann on 2014/05/27 at 11:09 +0200]
Quoted 2 lines
Which means exactly? They are not prepared to find data for more than one key event in the buffer?
Not exactly. The bad code is an attempt to do a nonblocking keyboard read in MS-DOS. It goes like this:
1) Peek the DOS keyboard buffer start and end pointers. If the buffer is empty then return "no input".
2) If no key is pressed then return "no input".
3) Use the blocking MS-DOS interface to wait for the next key and return it.
So, as you can see, there's a serious problem. Let's say that a key press and release go in together. That give us the following situation:
1) Peek the DOS input buffer. It isn't empty so proceed to the next step.
2) No key is pressed so return "no input".
I really do think, therefore, that the only way to deal with this is to slow down the input to typing speed.
Signature · 3 lines
Dave Mielke | 2213 Fox Crescent | The Bible is the very Word of God. Phone: 1-613-726-0014 | Ottawa, Ontario | http://Mielke.cc/bible/ EMail: [email protected] | Canada K2A 1H7 | http://FamilyRadio.com/