* [PATCH] sysrq: use only one slot for loglevels in key table
@ 2020-07-22 9:26 Yue Hu
2020-07-22 10:49 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Yue Hu @ 2020-07-22 9:26 UTC (permalink / raw)
To: gregkh, jslaby; +Cc: linux-kernel, huyue2, zbestahu
From: Yue Hu <huyue2@yulong.com>
Currently, sysrq_key_table[] has 10 slots for same interface to change
console loglevel. No specific purpose to do that. Let's use only one slot
to save memory space. Also, update the key2index calculation. And remove
needless code in help message print path to make the logic simpler.
Signed-off-by: Yue Hu <huyue2@yulong.com>
---
drivers/tty/sysrq.c | 27 +++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 7c95afa9..3f12910 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -442,17 +442,8 @@ static void sysrq_handle_unrt(int key)
/* Key Operations table and lock */
static DEFINE_SPINLOCK(sysrq_key_table_lock);
-static const struct sysrq_key_op *sysrq_key_table[36] = {
- &sysrq_loglevel_op, /* 0 */
- &sysrq_loglevel_op, /* 1 */
- &sysrq_loglevel_op, /* 2 */
- &sysrq_loglevel_op, /* 3 */
- &sysrq_loglevel_op, /* 4 */
- &sysrq_loglevel_op, /* 5 */
- &sysrq_loglevel_op, /* 6 */
- &sysrq_loglevel_op, /* 7 */
- &sysrq_loglevel_op, /* 8 */
- &sysrq_loglevel_op, /* 9 */
+static const struct sysrq_key_op *sysrq_key_table[27] = {
+ &sysrq_loglevel_op, /* 0 - 9 */
/*
* a: Don't use for system provided sysrqs, it is handled specially on
@@ -507,9 +498,9 @@ static int sysrq_key_table_key2index(int key)
int retval;
if ((key >= '0') && (key <= '9'))
- retval = key - '0';
+ retval = 0;
else if ((key >= 'a') && (key <= 'z'))
- retval = key + 10 - 'a';
+ retval = key + 1 - 'a';
else
retval = -1;
return retval;
@@ -577,16 +568,8 @@ void __handle_sysrq(int key, bool check_mask)
pr_info("HELP : ");
/* Only print the help msg once per handler */
for (i = 0; i < ARRAY_SIZE(sysrq_key_table); i++) {
- if (sysrq_key_table[i]) {
- int j;
-
- for (j = 0; sysrq_key_table[i] !=
- sysrq_key_table[j]; j++)
- ;
- if (j != i)
- continue;
+ if (sysrq_key_table[i])
pr_cont("%s ", sysrq_key_table[i]->help_msg);
- }
}
pr_cont("\n");
console_loglevel = orig_log_level;
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sysrq: use only one slot for loglevels in key table
2020-07-22 9:26 [PATCH] sysrq: use only one slot for loglevels in key table Yue Hu
@ 2020-07-22 10:49 ` Greg KH
2020-07-23 3:01 ` Yue Hu
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2020-07-22 10:49 UTC (permalink / raw)
To: Yue Hu; +Cc: jslaby, linux-kernel, huyue2, zbestahu
On Wed, Jul 22, 2020 at 05:26:09PM +0800, Yue Hu wrote:
> From: Yue Hu <huyue2@yulong.com>
>
> Currently, sysrq_key_table[] has 10 slots for same interface to change
> console loglevel. No specific purpose to do that. Let's use only one slot
> to save memory space. Also, update the key2index calculation. And remove
> needless code in help message print path to make the logic simpler.
That sounds like a lot of different things being all done at once. Can
you break this up into individual patches, each only doing one type of
thing at a time.
And if you are saving memory, please show how much you really are
saving.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sysrq: use only one slot for loglevels in key table
2020-07-22 10:49 ` Greg KH
@ 2020-07-23 3:01 ` Yue Hu
0 siblings, 0 replies; 3+ messages in thread
From: Yue Hu @ 2020-07-23 3:01 UTC (permalink / raw)
To: Greg KH; +Cc: jslaby, linux-kernel, huyue2, zbestahu
On Wed, 22 Jul 2020 12:49:52 +0200
Greg KH <gregkh@linuxfoundation.org> wrote:
> On Wed, Jul 22, 2020 at 05:26:09PM +0800, Yue Hu wrote:
> > From: Yue Hu <huyue2@yulong.com>
> >
> > Currently, sysrq_key_table[] has 10 slots for same interface to change
> > console loglevel. No specific purpose to do that. Let's use only one slot
> > to save memory space. Also, update the key2index calculation. And remove
> > needless code in help message print path to make the logic simpler.
>
> That sounds like a lot of different things being all done at once. Can
> you break this up into individual patches, each only doing one type of
> thing at a time.
Should be not. The different command key(0 - 9) share same operation which is just
setting loglevel. And the code will find the operation via key2index calculation.
So one index/slot is enough to represent it. rt?
>
> And if you are saving memory, please show how much you really are
> saving.
The key table is consuming global memory, decrease the array size should be more
better. It will save 9 slots space. The memory saving is 72 bytes via
sizeof(sysrq_key_table) tested under arm64.
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-23 3:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 9:26 [PATCH] sysrq: use only one slot for loglevels in key table Yue Hu
2020-07-22 10:49 ` Greg KH
2020-07-23 3:01 ` Yue Hu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®