From: Marcin Slusarz <hidden> Date: 2008-10-25 19:58:54
Add support for persistent console history, surviving
console switches. It allocates new scrollback buffer only when
user switches console for the first time.
Signed-off-by: Marcin Slusarz <redacted>
Cc: Antonino Daplas <adaplas@gmail.com>
Cc: Krzysztof Helt <redacted>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-fbdev-devel@lists.sourceforge.net
---
drivers/video/console/Kconfig | 11 ++++++
drivers/video/console/vgacon.c | 75 +++++++++++++++++++++++++++++++++++++--
2 files changed, 82 insertions(+), 4 deletions(-)
@@ -187,15 +189,76 @@ static void vgacon_scrollback_init(int pitch)}}+#ifdef CONFIG_VGACON_REMEMBER_SCROLLBACK+staticstructvgacon_scrollback_info{+void*data;+intcnt;+inttail;+intcur;+introws;+intsize;+}vgacon_scrollbacks[MAX_NR_CONSOLES];+staticintvgacon_last_vc_num;++staticvoidvgacon_switch_scrollback(structvc_data*c)+{+intnum=c->vc_num;+structvgacon_scrollback_info*old_scrollback=+&vgacon_scrollbacks[vgacon_last_vc_num];+structvgacon_scrollback_info*new_scrollback=+&vgacon_scrollbacks[num];++old_scrollback->cnt=vgacon_scrollback_cnt;+old_scrollback->tail=vgacon_scrollback_tail;+old_scrollback->cur=vgacon_scrollback_cur;+old_scrollback->rows=vgacon_scrollback_rows;+old_scrollback->size=vgacon_scrollback_size;++if(!new_scrollback->data){+introws=SCROLLBACK_SIZE/c->vc_size_row;++new_scrollback->data=kmalloc(SCROLLBACK_SIZE,GFP_KERNEL);+new_scrollback->cnt=0;+new_scrollback->tail=0;+new_scrollback->cur=0;+new_scrollback->rows=rows-1;+new_scrollback->size=rows*c->vc_size_row;++if(!new_scrollback->data){+printk(KERN_WARNING"VGAcon: failed to allocate memory for scrollback of console %d, using scrollback of console %d.\n",+num,vgacon_last_vc_num);+new_scrollback->data=old_scrollback->data;+old_scrollback->data=NULL;+}+}++vgacon_scrollback=new_scrollback->data;+vgacon_scrollback_cnt=new_scrollback->cnt;+vgacon_scrollback_tail=new_scrollback->tail;+vgacon_scrollback_cur=new_scrollback->cur;+vgacon_scrollback_rows=new_scrollback->rows;+vgacon_scrollback_size=new_scrollback->size;++vgacon_last_vc_num=num;+}+#else+staticinlinevoidvgacon_switch_scrollback(structvc_data*c)+{+vgacon_scrollback_init(c->vc_size_row);+}+#endif/**Calledonlyduinginitsocallofalloc_bootmenisok.*Marked__init_refoktosilencemodpost.*/staticvoid__init_refokvgacon_scrollback_startup(void){-vgacon_scrollback=alloc_bootmem(CONFIG_VGACON_SOFT_SCROLLBACK_SIZE-*1024);+vgacon_scrollback=alloc_bootmem(SCROLLBACK_SIZE);vgacon_scrollback_init(vga_video_num_columns*2);+#ifdef CONFIG_VGACON_REMEMBER_SCROLLBACK+vgacon_scrollbacks[0].data=vgacon_scrollback;+vgacon_last_vc_num=0;+#endif}staticvoidvgacon_scrollback_update(structvc_data*c,intt,intcount)
@@ -317,6 +380,10 @@ static int vgacon_scrolldelta(struct vc_data *c, int lines)#define vgacon_scrollback_init(...) do { } while (0)#define vgacon_scrollback_update(...) do { } while (0)+staticinlinevoidvgacon_switch_scrollback(structvc_data*c)+{+}+staticvoidvgacon_restore_screen(structvc_data*c){if(c->vc_origin!=c->vc_visible_origin)
@@ -823,7 +890,7 @@ static int vgacon_switch(struct vc_data *c)vgacon_doresize(c,c->vc_cols,c->vc_rows);}-vgacon_scrollback_init(c->vc_size_row);+vgacon_switch_scrollback(c);return0;/* Redrawing not needed */}
From: Andrew Morton <akpm@linux-foundation.org> Date: 2008-10-25 20:47:15
On Sat, 25 Oct 2008 21:58:19 +0200 Marcin Slusarz [off-list ref] wrote:
quoted hunk
Add support for persistent console history, surviving
console switches. It allocates new scrollback buffer only when
user switches console for the first time.
Signed-off-by: Marcin Slusarz <redacted>
Cc: Antonino Daplas <adaplas@gmail.com>
Cc: Krzysztof Helt <redacted>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-fbdev-devel@lists.sourceforge.net
---
drivers/video/console/Kconfig | 11 ++++++
drivers/video/console/vgacon.c | 75 +++++++++++++++++++++++++++++++++++++--
2 files changed, 82 insertions(+), 4 deletions(-)
I'd question the value in adding the config option. Why not make the
feature unconditionally present?
+#define SCROLLBACK_SIZE (CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024)
+
...
+#ifdef CONFIG_VGACON_REMEMBER_SCROLLBACK
+static struct vgacon_scrollback_info {
+ void *data;
+ int cnt;
+ int tail;
+ int cur;
+ int rows;
+ int size;
+} vgacon_scrollbacks[MAX_NR_CONSOLES];
Perhaps you were concerned about memory consumption?
If so, it would be much much better to make this feature switchable at
runtime (module parameter/boot option or a /proc or /sys knob).
+static int vgacon_last_vc_num;
We have lots of global state here with no apparent locking protecting
it. Possibly there's some higher-level lock which provides
seralisation? If so, the addition of a comment explaining all
this would be good.
From: Marcin Slusarz <hidden> Date: 2008-10-25 22:43:40
On Sat, Oct 25, 2008 at 01:46:15PM -0700, Andrew Morton wrote:
On Sat, 25 Oct 2008 21:58:19 +0200 Marcin Slusarz [off-list ref] wrote:
quoted
Add support for persistent console history, surviving
console switches. It allocates new scrollback buffer only when
user switches console for the first time.
Signed-off-by: Marcin Slusarz <redacted>
Cc: Antonino Daplas <adaplas@gmail.com>
Cc: Krzysztof Helt <redacted>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-fbdev-devel@lists.sourceforge.net
---
drivers/video/console/Kconfig | 11 ++++++
drivers/video/console/vgacon.c | 75 +++++++++++++++++++++++++++++++++++++--
2 files changed, 82 insertions(+), 4 deletions(-)
I'd question the value in adding the config option. Why not make the
feature unconditionally present?
quoted
+#define SCROLLBACK_SIZE (CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024)
+
...
+#ifdef CONFIG_VGACON_REMEMBER_SCROLLBACK
+static struct vgacon_scrollback_info {
+ void *data;
+ int cnt;
+ int tail;
+ int cur;
+ int rows;
+ int size;
+} vgacon_scrollbacks[MAX_NR_CONSOLES];
Perhaps you were concerned about memory consumption?
Yes. I could imagine scenario where this memory would be considered "wasted".
If so, it would be much much better to make this feature switchable at
runtime (module parameter/boot option or a /proc or /sys knob).
/sys knob seems to be the most flexible option.
/sys/class/vtconsole/vtconX/persistent_history? 0/1
quoted
+static int vgacon_last_vc_num;
We have lots of global state here with no apparent locking protecting
it. Possibly there's some higher-level lock which provides
seralisation? If so, the addition of a comment explaining all
this would be good.
I checked it and this code is called under console_sem.
vgacon_switch_scrollback <- vgacon_switch <- con_switch <- redraw_screen <- switch_screen <- complete_change_console <-
1) vt_ioctl (calls acquire_console_sem before complete_change_console)
2) change_console <- console_callback (calls acquire_console_sem before change_console)
Thanks for a review!
PS: why DECLARE_MUTEX _defines_ _semaphore_? there are only 8 uses of this
macro so it's not a big problem to rename it to e.g. DEFINE_SEMAPHORE (I can
provide a patch)
Marcin
From: Andrew Morton <akpm@linux-foundation.org> Date: 2008-10-25 23:15:37
On Sun, 26 Oct 2008 00:43:01 +0200 Marcin Slusarz [off-list ref] wrote:
PS: why DECLARE_MUTEX _defines_ _semaphore_?
The kernel gets definition-vs-declaration confused in several places.
there are only 8 uses of this
macro so it's not a big problem to rename it to e.g. DEFINE_SEMAPHORE (I can
provide a patch)
I'd say that s/declare/define/ at such a late stage in the semaphore's
lifetime would be of dubious value. But getting "MUTEX" out of that
macro's name would be a very good thing - it's a bad overlap with struct
mutex. Send patch :)