lkml.org 
[lkml]   [1999]   [Jun]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: TTY_FLIPBUF_SIZE too low causing dataloss on too fast serial lines?
Hi!

> If I were to change things now, I would not make struct tty bigger than
> PAGE_SIZE; even now, it's best if you avoid trying to allocate objects
> bigger than a page if you can help it. Instead, I'd make the flip
> buffer allocated separately from the tty structure, and make it up to
> the device driver what a proper size for the flip buffer ought to be.
> That way we don't have to waste a lot of memory if a device *knows* that
> it's only doing low-speed transfers that don't need a lot of flip buffer
> space.

So I guess you'l like following patch:

Pavel
(Implements exactly what you just described. It seems a lot of cleaner
than what is in, now, so I'd like to see it rolled in. Is it ok to
mail it to you or should I mail it to Linus?)

--- clean/include/linux/tty.h Fri May 14 20:42:58 1999
+++ linux/include/linux/tty.h Sun May 30 21:08:44 1999
@@ -127,11 +127,8 @@

/*
* This is the flip buffer used for the tty driver. The buffer is
- * located in the tty structure, and is used as a high speed interface
- * between the tty driver and the tty line discipline.
+ * kmalloced, and is used as a high speed interface
*/
-#define TTY_FLIPBUF_SIZE 512
-
struct tty_flip_buffer {
struct tq_struct tqueue;
struct semaphore pty_sem;
@@ -139,9 +136,9 @@
unsigned char *flag_buf_ptr;
int count;
int buf_num;
- unsigned char char_buf[2*TTY_FLIPBUF_SIZE];
- char flag_buf[2*TTY_FLIPBUF_SIZE];
- unsigned char slop[4]; /* N.B. bug overwrites buffer by 1 */
+ int flipbuf_size;
+ unsigned char *char_buf;
+ char *flag_buf;
};
/*
* The pty uses char_buf and flag_buf as a contiguous buffer
--- clean/include/linux/tty_flip.h Wed Sep 10 04:41:41 1997
+++ linux/include/linux/tty_flip.h Sun May 30 21:08:21 1999
@@ -10,7 +10,7 @@
_INLINE_ void tty_insert_flip_char(struct tty_struct *tty,
unsigned char ch, char flag)
{
- if (tty->flip.count < TTY_FLIPBUF_SIZE) {
+ if (tty->flip.count < tty->flip.flipbuf_size) {
tty->flip.count++;
*tty->flip.flag_buf_ptr++ = flag;
*tty->flip.char_buf_ptr++ = ch;
--- clean/drivers/char/tty_io.c Fri May 14 20:42:29 1999
+++ linux/drivers/char/tty_io.c Sun May 30 21:06:48 1999
@@ -1956,14 +1956,31 @@
if (driver->flags & TTY_DRIVER_INSTALLED)
return 0;

+ if (!driver->flipbuf_size) {
+ driver->flipbuf_size = 512;
+ }
+ /* there was notice about buffer overrun in original code -- that's why I do +4 */
+ driver->char_buf = kmalloc(driver->flipbuf_size*2 +4, GFP_KERNEL);
+ if (!driver->char_buf)
+ return -ENOMEM;
+ driver->flag_buf = kmalloc(driver->flipbuf_size*2 +4, GFP_KERNEL);
+ if (!driver->flag_buf) {
+ kfree(driver->char_buf);
+ return -ENOMEM;
+ }
+
error = register_chrdev(driver->major, driver->name, &tty_fops);
- if (error < 0)
+ if (error < 0) {
+ kfree(driver->char_buf);
+ kfree(driver->flag_buf);
return error;
+ }
else if(driver->major == 0)
driver->major = error;

if (!driver->put_char)
driver->put_char = tty_default_put_char;
+

driver->prev = 0;
driver->next = tty_drivers;

--
I'm really pavel@ucw.cz. Look at http://195.113.31.123/~pavel. Pavel
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:52    [W:0.066 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site