From: 常廉志 <changlianzhi@uniontech.com>
To: "dmitry.torokhov" <dmitry.torokhov@gmail.com>
Cc: "Greg KH" <gregkh@linuxfoundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
jirislaby <jirislaby@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
282827961 <282827961@qq.com>
Subject: Re: [PATCH v9] tty: Fix the keyboard led light display problem
Date: Tue, 2 Nov 2021 15:09:20 +0800 [thread overview]
Message-ID: <tencent_58FBAAE735B7BF622A690384@qq.com> (raw)
In-Reply-To: <YYC4QGKjY42lZXsE@google.com>
> >
> > Hi Dmitry, I don’t know if I fully understand what you mean, but I will
> > try to fully explain the intent of the current patch.
> > (1) What is the current bug phenomenon? I will describe with the Num
> > Lock indicator as the object here.
> >
> > Phenomenon 1: Suppose that Xorg is bound to tty1 in the desktop environment.
> > At this time, the Num light of the keyboard is on, and the keypad can input numbers
> > normally; assume that the state of the keyboard light saved by tty2 itself is the
> > opposite (the Num light is off, The keypad cannot enter numbers); at this time,
> > if we use the key combination "ctrl+alt+F2" to switch the system to tty2, we will find
> > that the Num light is still on, but the keypad cannot enter numbers.
> >
> > Phenomenon 2: Assuming that you are currently in the tty2 environment, the Num
> > light of the keyboard is on, and the keypad can input numbers normally; assume that
> > the Num state saved by Xorg is the same as that of tty2 (the Num light is on, and the
> > keypad can input numbers normally); At this point, if we use the key combination
> > "ctrl+alt+F1" to switch the system to tty1 (that is, to switch to the desktop environment)
> > , we will find that the Num light will not light up, but the small keyboard can input numbers .
> >
> > (2) Why do these two phenomena occur?
> > The variable static unsigned int ledstate is defined in keyboard.c. ledstate should be used to
> > tell VT the current state of the keyboard light, because after each VT sets the state of the
> > keyboard light, it will synchronize the latest keyboard light state to ledstate( (Implemented
> > in the kbd_bh() function).
> >
> > Then the problem comes. The scope of ledstate is only in VT, and it cannot include all the
> > scenes where the keyboard light is set. And, in the desktop environment, "kb->kbdmode ==
> > VC_OFF" of tty1, at this time, through the NumLock button, only Xorg's own state can be
> > changed, and the led state stored by tty1 cannot be changed (implemented in the kbd_keycode()
> > function), This results in that the kb->ledflagstate stored by tty1 itself and the ledstate in the tty
> > environment are always 0 at this time.
> >
> > When we switch tty, the VT code compares the current tty's kb->ledflagstate and ledstate values.
> > If they are inconsistent, change the state of the keyboard light (implemented in the kbd_bh() function).
> >
> > In phenomenon 1, in the desktop environment, although the actual state saved by xorg is 1, the state
> > of ledstate of tty is always 0. In the environment of tty2, the state of kb->ledflagstate of tty2 is also 0.
> > At this point, in the kbd_bh() function, comparing these two values is equal, there is no need to set the
> > led light state to the keyboard. So after switching to tty2, the Num light is still on, but the small
> > keyboard cannot input numbers.
> >
> > In phenomenon 2, in the tty2 environment, the state of ledstate is set to 1, but the kb->ledflagstate of
> > tty1 is 0. At this time, the two values are not equal in the kbd_bh() function, so set the led The light
> > status to the keyboard. Xorg did not redistribute the configuration during this process is also one of
> > the reasons. And even if Xorg re-issues the configuration at this time, it will cause confusion and only
> > one can be set.
> >
> > (3) How to solve it?
> > To solve the problem of phenomenon 1, we must first enable ledstate to correctly reflect the current
> > state of the keyboard light. Therefore, the solution to all versions of patch is to synchronize the
> > latest led state of the input device to ledstate.
> You assume that input's device NumLock LED reflects the state of
> terminal. That does not have to be the case.
> Now how to solve this... On VT switch redraw_screen() calls
> vt_set_leds_compute_shiftstate(). Can we do something like:
> /*
> * On VT switch pretend our led state is opposite of target
> * state to ensure we refresh all leds.
> */
> spin_lock_irqsave(&led_lock, flags);
> leds = getleds();
> leds |= (unsigned int)kbd->lockstate << 8;
> ledstate = ~leds;
> spin_unlock_irqrestore(&led_lock, flags);
>
> set_leds();
>
> ?
Hi Dmitry:
/*
* The following piece of code exists in the kbd_bh() function
*/
spin_lock_irqsave(&led_lock, flags);
leds = getleds();
leds |= (unsigned int)kbd->lockstate << 8;
ledstate = ~leds;
spin_unlock_irqrestore(&led_lock, flags);
Moreover, the process of calling the set_leds() function is
the process of calling the kbd_bh function:
static void set_leds(void)
{
tasklet_schedule(&keyboard_tasklet);
}
static DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh);
I don't really understand what you mean here, but one thing
can be confirmed, my patch just synchronizes the current input
device's led state to ledstate. Moreover, after VT's
kb->ledflagstate is set to the input device, it will also
be synchronized to ledstate (the original logic of the kbd_bh()
function), which does not destroy the original internal logic of
VT. In addition, I have tested it, whether it is switching
between the desktop environment (tty1) and tty2~6, or switching
between tty2~6, the indicator status of the keyboard light is
correct, and it is normal in the multi-keyboard state. .
Of course, I need to add the Xorg repair patch I mentioned
earlier.
Thanks.
--
lianzhi chang
next prev parent reply other threads:[~2021-11-02 7:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-01 12:35 Re:[PATCH v9] tty: Fix the keyboard led light display problem 常廉志
2021-11-01 12:48 ` [PATCH " Greg KH
2021-11-01 16:35 ` dmitry.torokhov
2021-11-02 3:16 ` 常廉志
2021-11-02 4:02 ` dmitry.torokhov
2021-11-02 7:09 ` 常廉志 [this message]
2021-11-02 23:51 ` dmitry.torokhov
-- strict thread matches above, loose matches on Subject: below --
2021-10-27 5:35 lianzhi chang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_58FBAAE735B7BF622A690384@qq.com \
--to=changlianzhi@uniontech.com \
--cc=282827961@qq.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).