lkml.org 
[lkml]   [2011]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subject[PATCH v3 1/2] TTY: tty flip buffer optimisation.
Currently, free flip buffer (tty->buf.free) reserve memory for further used,
only if driver send to ldisc less 257 bytes in one time.
If driver send more, flip buffer reserve(kmalloc()) and then
free(kfree()) every chunk more 256 bytes every time.

For testing I use little program that write in loop, argv[1] bytes from one side pty and read on the other.
I get follow results:

ilya@serh:~/src/pty$ time ./bench_pty_buf 253
chunk = 253. loop = 3952569.
real 0m22.398s
user 0m0.604s
sys 0m19.545s

ilya@serh:~/src/pty$ time ./bench_pty_buf 255
chunk = 255. loop = 3921568.
real 0m20.437s
user 0m0.532s
sys 0m16.621s

ilya@serh:~/src/pty$ time ./bench_pty_buf 257
chunk = 257. loop = 3891050.
real 0m26.367s
user 0m0.552s
sys 0m28.010s

We can see that on 257 size chunk we loose ~20-30% performance.
The time's real was expected ~20-19 sek.

Program bench_pty_buf.c:
---
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>


#define WRITE_SIZE 1000000000

int main(int argc,char *argv[]) {
char pty_name[24];
int mfd, sfd, ptn, chunk, loop;
if(argc != 2)
goto error_exit;
if((chunk = atoi(argv[1])) <= 0)
goto error_exit;
loop = WRITE_SIZE/chunk;
printf("chunk = %d. loop = %d.\n",chunk, loop);
mfd = -1;
sfd = -1;
mfd = open("/dev/ptmx", O_RDWR);
if (mfd < 0) {
printf("Couldn't open /dev/ptmx %m");
goto error_exit;
}
if (ioctl(mfd, TIOCGPTN, &ptn) < 0) {
printf("Couldn't get pty number %m");
goto error_exit;
}
snprintf(pty_name, sizeof(pty_name), "/dev/pts/%d", ptn);
ptn = 0;
if (ioctl(mfd, TIOCSPTLCK, &ptn) < 0) {
printf("Couldn't unlock pty slave %s: %m", pty_name);
goto error_exit;
}
if ((sfd = open(pty_name, O_RDWR | O_NOCTTY)) < 0) {
printf("Couldn't open pty slave %s: %m", pty_name);
goto error_exit;
}
struct termios tios;
cfmakeraw(&tios);
if(tcsetattr(sfd, TCSAFLUSH, &tios) < 0) {
printf("Can't set raw mode pty slave %s.\n", pty_name);
goto error_exit;
}
char buf[] = { [0 ... 65535] = '1' };
int child;
int count;
int ret, fillcount;
/* Fill buffers without blocked "flip free = 65536" and "N_TTY_BUF_SIZE = 4096" */
for(count = 0; count < 270; count++) {
ret = write(sfd,buf,256);
if(ret < 0) {
printf("Couldn't fill pty master %s count = %d: %m", pty_name, count);
goto error_exit;
}
fillcount += ret;
}
if ( !(child=fork()) ) {
// Child
for(count = 0; count < loop*chunk + fillcount; count += ret) {
if((ret = read(mfd,buf,chunk)) < 0) {
printf("Read: Count = %d, chunk = %d, error = %m \n",count,chunk);
goto error_exit;
}
}
goto normal_exit;
}
// Parent
if (child < 0)
goto error_exit;
for(count = 0; count < loop*chunk; count += ret) {
if((ret = write(sfd, buf, chunk)) < 0) {
printf("Write: Count = %d, chunk = %d, error = %m \n",count,chunk);
goto error_exit;
}
}
int status;
waitpid(child,&status,0);
if(status)
goto error_exit;
normal_exit:
if (sfd >= 0) close(sfd);
if (mfd >= 0) close(mfd);
return 0;
error_exit:
if (sfd >= 0) close(sfd);
if (mfd >= 0) close(mfd);
return -1;
}




\
 
 \ /
  Last update: 2011-11-14 13:49    [W:0.024 / U:0.768 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site