From owner-freebsd-hackers Mon Mar 19 12:31:11 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from moutvdom00.kundenserver.de (moutvdom00.kundenserver.de [195.20.224.149]) by hub.freebsd.org (Postfix) with ESMTP id 1EBEB37B71B for ; Mon, 19 Mar 2001 12:31:04 -0800 (PST) (envelope-from volker@thalreit.de) Received: from [195.20.224.220] (helo=mrvdom04.kundenserver.de) by moutvdom00.kundenserver.de with esmtp (Exim 2.12 #2) id 14f6Ix-0003sC-00; Mon, 19 Mar 2001 21:31:03 +0100 Received: from p3e9b810a.dip.t-dialin.net ([62.155.129.10] helo=ikarus.thalreit) by mrvdom04.kundenserver.de with esmtp (Exim 2.12 #2) id 14f6In-0001M5-00; Mon, 19 Mar 2001 21:30:54 +0100 Received: (from volker@localhost) by ikarus.thalreit (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) id f2JKUuE00907; Mon, 19 Mar 2001 21:30:56 +0100 Date: Mon, 19 Mar 2001 21:30:55 +0100 From: Volker Jahns To: hackers@freebsd.org Cc: Volker.Jahns@dpma.de Subject: Serial port open Message-ID: <20010319213055.A881@ikarus.thalreit> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I do have a small problem w/ serial IO. I have attached code to 1. open a serial line, 2. set terminal attributes, 3. close the serial port, 4. iterate thru 1.-3. a second time. /* serial test */ /* FreeBSD 3 second */ #include #include #include #include #include #include #include #define BENCHMARK 2 int main (int argc, char **argv) { int err, rfd, tset, i, j; struct termios tp, op; /* test loop to check how long it takes to open/close the port */ for ( j = 0; j < BENCHMARK; j++) { rfd = open("/dev/ttyd0", O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY); printf("open\t\t: errno %d\n", errno); if (rfd == -1) { perror("open: couldn't open /dev/ttyd0"); } else { fcntl(rfd, F_SETFL, 0); } /* get terminal attributes */ tcgetattr(rfd, &op); tcgetattr(rfd, &tp); /* set terminal attr */ cfsetispeed(&tp, 9600); cfsetospeed(&tp, 9600); tp.c_iflag = 0; tp.c_oflag = 0; tp.c_cflag = 0; tp.c_lflag = 0; for ( i = 0; i < NCCS; i++) { tp.c_cc[i] = 0; } tp.c_iflag &= (IXON | IXOFF | IXANY); tp.c_cflag |= PARENB; tp.c_cflag &= ~PARODD; tp.c_cflag |= CLOCAL; tp.c_cflag |= CREAD; tp.c_cflag |= CS8; tp.c_cflag |= CSTOPB; tp.c_cflag |= CSIZE; tp.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); tp.c_cc[VMIN]=0; tp.c_cc[VTIME]=1; /* set terminal attributes */ tcsetattr(rfd, TCSANOW, &tp); /* reset terminal attributes */ tcsetattr(rfd, TCSANOW, &op); close(rfd); /* 2nd service */ } } between the 1st call to close and the 2nd call to open the system spends some 3 (three !) seconds. volker@nemo testing > time ./io_fbsd-2 open : errno 0 open : errno 0 real 0m2.998s user 0m0.000s sys 0m0.004s I am running FreeBSD nemo.zvr.dpma.de 4.2-RELEASE FreeBSD 4.2-RELEASE #0: Thu Mar 15 12:58:51 CET 2001 but happens also w/ 4.1. What is actually wrong about the code? What is it I am missing? If this is the incorrect list to consider the problem, could you please redirect? for case anybody wants to know, here is the relevant output of kdump 21753 io_fbsd-2 985009390.419433 RET close 0 21753 io_fbsd-2 985009390.419451 CALL open(0x80488a0,0x8006,0xbfbff6a0) 21753 io_fbsd-2 985009390.419467 NAMI "/dev/ttyd0" 21753 io_fbsd-2 985009393.411359 RET open 3 21753 io_fbsd-2 985009393.411426 CALL write(0x1,0x804b000,0x10) It shows, that it takes approx 3 seconds between the call to open and the return of the call. This is actually is striped down version of code to read out data of a serially connected weatherstation. -- Volker Jahns, Thalreit/DE, +49 80 35 69 25, mailto:Volker.Jahns@thalreit.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message