From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 11 14:39:28 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CA45416A4D5 for ; Thu, 11 Dec 2003 14:39:28 -0800 (PST) Received: from mailout04.sul.t-online.com (mailout04.sul.t-online.com [194.25.134.18]) by mx1.FreeBSD.org (Postfix) with ESMTP id 71E0643E39 for ; Thu, 11 Dec 2003 14:22:25 -0800 (PST) (envelope-from D.Rock@t-online.de) Received: from fwd08.aul.t-online.de by mailout04.sul.t-online.com with smtp id 1AUZCS-0000ET-03; Thu, 11 Dec 2003 23:22:24 +0100 Received: from dialin.t-online.de (VrmbV0ZQgelrBpAX5vk79IVAgTrefgL94O-WT6pSu1AFp8yX2bJn8M@[217.234.80.131]) by fwd08.sul.t-online.com with esmtp id 1AUZCJ-0oTIZ60; Thu, 11 Dec 2003 23:22:15 +0100 Received: from t-online.de (doom [172.23.7.254])hBBMM68f094987 for ; Thu, 11 Dec 2003 23:22:06 +0100 (CET) Message-ID: <3FD8EE0E.7030608@t-online.de> Date: Thu, 11 Dec 2003 23:22:06 +0100 From: D.Rock@t-online.de (Daniel Rock) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-AT; rv:1.5) Gecko/20031007 X-Accept-Language: de-at, de, en-us, en MIME-Version: 1.0 To: hackers@freebsd.org Content-Type: multipart/mixed; boundary="------------080204010200040101060603" X-Spam-Status: No, hits=0.0 required=3.5 tests=none autolearn=no version=2.60 X-Spam-Checker-Version: SpamAssassin 2.60 (1.212-2003-09-23-exp) on server X-Seen: false X-ID: VrmbV0ZQgelrBpAX5vk79IVAgTrefgL94O-WT6pSu1AFp8yX2bJn8M Subject: Slow User-PPP X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Dec 2003 22:39:29 -0000 This is a multi-part message in MIME format. --------------080204010200040101060603 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi, I noticed for some time now a relatively high CPU usage of the user level ppp even on slow links. On my ADSL line (768/128) ppp consumes up to 20% CPU time (AMD K6-2 300MHz). I trussed the process and noticed, that it calls getprotobynumber() for each packet it receives. In most cases, the result from this call isn't used at all - only with debugging enabled or on errors. getprotobynumber() scans /etc/protocols - or even more expensive functions if NSS is involved. Below is a patch which reduces the getprotobynumber() calls, so they only get called if there is log output at all. With this patch, the CPU usage dropped from 20% to under 3% (on my full blown ADSL link) Daniel --------------080204010200040101060603 Content-Type: text/plain; name="ppp.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ppp.diff" Index: usr.sbin/ppp/ip.c =================================================================== RCS file: /export/cvs/src/usr.sbin/ppp/ip.c,v retrieving revision 1.100 diff -u -r1.100 ip.c --- usr.sbin/ppp/ip.c 26 Mar 2003 02:27:32 -0000 1.100 +++ usr.sbin/ppp/ip.c 11 Dec 2003 22:20:27 -0000 @@ -161,6 +161,18 @@ } } +char *toprototxt(int cproto) +{ + static char prototxt[16]; + struct protoent *pe; + + if ((pe = getprotobynumber(cproto)) == NULL) + snprintf(prototxt, sizeof prototxt, "%d", cproto); + else + snprintf(prototxt, sizeof prototxt, "%s", pe->p_name); + return prototxt; +} + /* * Check a packet against the given filter * Returns 0 to accept the packet, non-zero to drop the packet. @@ -187,8 +199,7 @@ int match; /* true if condition matched */ int mindata; /* minimum data size or zero */ const struct filterent *fp = filter->rule; - char dbuff[100], dstip[16], prototxt[16]; - struct protoent *pe; + char dbuff[100], dstip[16]; struct ncpaddr srcaddr, dstaddr; const char *payload; /* IP payload */ int datalen; /* IP datagram length */ @@ -239,10 +250,6 @@ cproto = pip->ip_p; } - if ((pe = getprotobynumber(cproto)) == NULL) - snprintf(prototxt, sizeof prototxt, "%d", cproto); - else - snprintf(prototxt, sizeof prototxt, "%s", pe->p_name); gotinfo = estab = syn = finrst = didname = 0; sport = dport = 0; @@ -356,7 +363,7 @@ if (datalen < mindata) { log_Printf(LogFILTER, " error: proto %s must be at least" - " %d octets\n", prototxt, mindata); + " %d octets\n", toprototxt(cproto), mindata); return 1; } @@ -367,7 +374,8 @@ ", estab = %d, syn = %d, finrst = %d", estab, syn, finrst); } - log_Printf(LogDEBUG, " Filter: proto = %s, %s\n", prototxt, dbuff); + log_Printf(LogDEBUG, " Filter: proto = %s, %s\n", + toprototxt(cproto), dbuff); } gotinfo = 1; } @@ -424,7 +432,8 @@ if (log_IsKept(LogFILTER)) { snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr)); log_Printf(LogFILTER, "%sbound rule = %d accept %s " - "src = %s:%d dst = %s:%d\n", filter->name, n, prototxt, + "src = %s:%d dst = %s:%d\n", filter->name, n, + toprototxt(cproto), ncpaddr_ntoa(&srcaddr), sport, dstip, dport); } } @@ -434,7 +443,7 @@ snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr)); log_Printf(LogFILTER, "%sbound rule = %d deny %s src = %s/%d dst = %s/%d\n", - filter->name, n, prototxt, + filter->name, n, toprototxt(cproto), ncpaddr_ntoa(&srcaddr), sport, dstip, dport); } return 1; @@ -450,7 +459,7 @@ snprintf(dstip, sizeof dstip, "%s", ncpaddr_ntoa(&dstaddr)); log_Printf(LogFILTER, "%sbound rule = implicit deny %s src = %s/%d dst = %s/%d\n", - filter->name, prototxt, ncpaddr_ntoa(&srcaddr), sport, + filter->name, toprototxt(cproto), ncpaddr_ntoa(&srcaddr), sport, dstip, dport); } --------------080204010200040101060603--