home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / bsd / 2878 < prev    next >
Encoding:
Text File  |  1992-07-25  |  9.2 KB  |  283 lines

  1. Newsgroups: comp.unix.bsd
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!mips!mips!kpc!amdcad!BitBlocks.com!bvs
  3. From: bvs@BitBlocks.COM (Bakul Shah)
  4. Subject: New /sys/i386/i386/in_cksum.c
  5. Message-ID: <1992Jul25.231505.9325@BitBlocks.COM>
  6. Organization: Bit Blocks, Inc.
  7. Date: Sat, 25 Jul 1992 23:15:05 GMT
  8. Lines: 273
  9.  
  10. The enclosed in_cksum.c is about 5 times faster for 128 byte
  11. mbufs (and upto 10 times faster for large mbufs).  However, its
  12. effect on the overall throughput is rather small; which is not
  13. too surprising.  The best ttcp performance I get with the new
  14. in_cksum is about 264KB/s (SunOS3.5/Sun 3 -> 25Mhz i486 +
  15. WE8013EPC) & 242KB/s (pc->sun), up from 256KB/s & 238KB/s.
  16.  
  17. This in_cksum is derived from the CCI version of the same from
  18. the tahoe release.  All I had to do was replace the carry related
  19. macros with i386 specific ones (+ I made some cosmetic changes).
  20. Thanks to gcc I didn't have to guess which registers contained
  21. the checksum and the mbuf data ptr!  Use at your own risk.  If
  22. you do decide to use it, make sure you move the original in_cksum.c
  23. out of the way or else this shar won't overwrite it.
  24.  
  25. And now for some extra credit :-),  for those of you who don't
  26. have a quayle, here is a quick crash course on configuring and
  27. creating new kernels.
  28.  
  29. cd /sys/i386/conf    # this is is where config info is kept
  30. cp GENERICISA FOO    # GENERICISA is a confiuration script
  31.             # that describes a particular config.
  32.             # Most likely you are running a kernel
  33.             # that was built out of this script.
  34.             # Copy it to a new file so that you can
  35.             # create your own configuration.
  36. vi FOO            # Now remove devices you don't have,
  37.             # especially the network devices and
  38.             # make any other changes you wish;
  39.             # such as adding option MFS for a memory
  40.             # file system for /tmp etc.  You can also
  41.             # add psuedo-device ddb (the debugger).
  42.             # Change`ident' entry to FOO or what is your config
  43.             # file name and `cpu' to "i486" if you have a 486.
  44.             # You may also wish to look at some other
  45.             # all UPPERCASE files in the same dir.  You shouldn't
  46.             # change any other files unless you really know
  47.             # what you are doing.
  48. config FOO        # this will create /sys/compile/FOO dir
  49.             # and put a bunch of files in there including
  50.             # a Makefile.
  51. cd /sys/compile/FOO
  52. # If you are running the original you have some work to do
  53. #vi Makefile        # If you are running the original
  54.             # 0.1 release you will have to manually add
  55.             # vers.o at the end of the line that starts
  56.             # with SYSTEM_LD  (or you can just get the
  57.             # new Makefile.i386 patch from agate).
  58. #cp ../GENERICAISA/vers.c .    # since this file is missing
  59. #cc -c vers.c            # since the Makefile won't do it. 
  60. make            # this will make a new kernel
  61.  
  62. Now you can copy it to / but make sure you have fixit.fs or
  63. dist.fs floppy handy so that you can recover.
  64.  
  65. mv /386bsd /386bsd.alt    # save the old kernel
  66. cp 386bsd /386bsd
  67. fastboot        # that is it!  A few seconds later you should
  68.             # be running on your new kernel.
  69.  
  70. -- Bakul Shah <bvs@bitblocks.com>
  71.  
  72. #!/bin/sh
  73. # This is a shell archive (produced by shar 3.49)
  74. # To extract the files from this archive, save it to a file, remove
  75. # everything above the "!/bin/sh" line above, and type "sh file_name".
  76. #
  77. # made 07/25/1992 22:47 UTC by bvs@bitblocks.com
  78. # Source directory /kabul/src/sys.386bsd
  79. #
  80. # existing files will NOT be overwritten unless -c is specified
  81. #
  82. # This shar contains:
  83. # length  mode       name
  84. # ------ ---------- ------------------------------------------
  85. #   5048 -rw-rw-r-- i386/i386/in_cksum.c
  86. #
  87. # ============= i386/i386/in_cksum.c ==============
  88. if test ! -d 'i386'; then
  89.     echo 'x - creating directory i386'
  90.     mkdir 'i386'
  91. fi
  92. if test ! -d 'i386/i386'; then
  93.     echo 'x - creating directory i386/i386'
  94.     mkdir 'i386/i386'
  95. fi
  96. if test -f 'i386/i386/in_cksum.c' -a X"$1" != X"-c"; then
  97.     echo 'x - skipping i386/i386/in_cksum.c (File already exists)'
  98. else
  99. echo 'x - extracting i386/i386/in_cksum.c (Text)'
  100. sed 's/^X//' << 'SHAR_EOF' > 'i386/i386/in_cksum.c' &&
  101. /*-
  102. X * Copyright (c) 1990 The Regents of the University of California.
  103. X * All rights reserved.
  104. X *
  105. X * Redistribution and use in source and binary forms, with or without
  106. X * modification, are permitted provided that the following conditions
  107. X * are met:
  108. X * 1. Redistributions of source code must retain the above copyright
  109. X *    notice, this list of conditions and the following disclaimer.
  110. X * 2. Redistributions in binary form must reproduce the above copyright
  111. X *    notice, this list of conditions and the following disclaimer in the
  112. X *    documentation and/or other materials provided with the distribution.
  113. X * 3. All advertising materials mentioning features or use of this software
  114. X *    must display the following acknowledgement:
  115. X *    This product includes software developed by the University of
  116. X *    California, Berkeley and its contributors.
  117. X * 4. Neither the name of the University nor the names of its contributors
  118. X *    may be used to endorse or promote products derived from this software
  119. X *    without specific prior written permission.
  120. X *
  121. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  122. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  123. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  124. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  125. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  126. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  127. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  128. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  129. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  130. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  131. X * SUCH DAMAGE.
  132. X *
  133. X * from tahoe:    in_cksum.c    1.2    86/01/05
  134. X *    @(#)in_cksum.c    1.3 (Berkeley) 1/19/91
  135. X *
  136. X * 920724     i386 changes by Bakul Shah <bvs@bitblocks.com>
  137. X */
  138. X
  139. #include "param.h"
  140. #include "sys/mbuf.h"
  141. X
  142. /*
  143. X * Checksum routine for Internet Protocol family headers.
  144. X *
  145. X * This routine is very heavily used in the network
  146. X * code and should be modified for each CPU to be as fast as possible.
  147. X * 
  148. X * This implementation is 386 version.
  149. X */
  150. X
  151. #undef    ADDCARRY
  152. #define ADDCARRY(x)     if ((x) > 0xffff) (x) -= 0xffff
  153. #define REDUCE          {sum = (sum & 0xffff) + (sum >> 16); ADDCARRY(sum);}
  154. X
  155. /*
  156. X * Thanks to gcc we don't have to guess
  157. X * which registers contain sum & w.
  158. X */
  159. #define CLC     asm("clc")
  160. #define ADD(n)  asm("adcl " #n "(%2), %0": "=r"(sum): "0"(sum), "r"(w))
  161. #define MOP     asm("adcl $0, %0":         "=r"(sum): "0"(sum))
  162. X
  163. in_cksum(m, len)
  164. X    register struct mbuf *m;
  165. X    register int len;
  166. {
  167. X    register u_short *w;
  168. X    register unsigned sum = 0;
  169. X    register int mlen = 0;
  170. X    int byte_swapped = 0;
  171. X    union { char    c[2]; u_short    s; } su;
  172. X
  173. X    for (;m && len; m = m->m_next) {
  174. X        if (m->m_len == 0)
  175. X            continue;
  176. X        w = mtod(m, u_short *);
  177. X        if (mlen == -1) {
  178. X            /*
  179. X             * The first byte of this mbuf is the continuation
  180. X             * of a word spanning between this mbuf and the
  181. X             * last mbuf.
  182. X             */
  183. X
  184. X            /* su.c[0] is already saved when scanning previous 
  185. X             * mbuf.  sum was REDUCEd when we found mlen == -1
  186. X             */
  187. X            su.c[1] = *(u_char *)w;
  188. X            sum += su.s;
  189. X            w = (u_short *)((char *)w + 1);
  190. X            mlen = m->m_len - 1;
  191. X            len--;
  192. X        } else
  193. X            mlen = m->m_len;
  194. X        if (len < mlen)
  195. X            mlen = len;
  196. X        len -= mlen;
  197. X        /*
  198. X         * Force to long boundary so we do longword aligned
  199. X         * memory operations
  200. X         */
  201. X        if (3 & (int) w) {
  202. X            REDUCE;
  203. X            if ((1 & (int) w) && (mlen > 0)) {
  204. X                sum <<= 8;
  205. X                su.c[0] = *(char *)w;
  206. X                w = (u_short *)((char *)w + 1);
  207. X                mlen--;
  208. X                byte_swapped = 1;
  209. X            }
  210. X            if ((2 & (int) w) && (mlen >= 2)) {
  211. X                sum += *w++;
  212. X                mlen -= 2;
  213. X            }
  214. X        }
  215. X        /*
  216. X         * Do as much of the checksum as possible 32 bits at at time.
  217. X         * In fact, this loop is unrolled to make overhead from
  218. X         * branches &c small.
  219. X         */
  220. X        while ((mlen -= 32) >= 0) {
  221. X            /*
  222. X             * Clear the carry flag, add with carry 16 words
  223. X             * and fold-in last carry by adding a 0 with carry.
  224. X             */
  225. X            CLC;
  226. X            ADD(0);  ADD(4);  ADD(8);  ADD(12);
  227. X            ADD(16); ADD(20); ADD(24); ADD(28);
  228. X            MOP; w += 16;
  229. X        }
  230. X        mlen += 32;
  231. X        while ((mlen -= 8) >= 0) {
  232. X            CLC;
  233. X            ADD(0); ADD(4);
  234. X            MOP;
  235. X            w += 4;
  236. X        }
  237. X        mlen += 8;
  238. X        if (mlen == 0 && byte_swapped == 0)
  239. X            continue;       /* worth 1% maybe ?? */
  240. X        REDUCE;
  241. X        while ((mlen -= 2) >= 0) {
  242. X            sum += *w++;
  243. X        }
  244. X        if (byte_swapped) {
  245. X            sum <<= 8;
  246. X            byte_swapped = 0;
  247. X            if (mlen == -1) {
  248. X                su.c[1] = *(char *)w;
  249. X                sum += su.s;
  250. X                mlen = 0;
  251. X            } else
  252. X                mlen = -1;
  253. X        } else if (mlen == -1)
  254. X            /*
  255. X             * This mbuf has odd number of bytes.
  256. X             * There could be a word split betwen
  257. X             * this mbuf and the next mbuf.
  258. X             * Save the last byte (to prepend to next mbuf).
  259. X             */
  260. X            su.c[0] = *(char *)w;
  261. X    }
  262. X
  263. X    if (len)
  264. X        printf("cksum: out of data\n");
  265. X    if (mlen == -1) {
  266. X        /* The last mbuf has odd # of bytes. Follow the
  267. X           standard (the odd byte is shifted left by 8 bits) */
  268. X        su.c[1] = 0;
  269. X        sum += su.s;
  270. X    }
  271. X    REDUCE;
  272. X    return (~sum & 0xffff);
  273. }
  274. SHAR_EOF
  275. chmod 0664 i386/i386/in_cksum.c ||
  276. echo 'restore of i386/i386/in_cksum.c failed'
  277. Wc_c="`wc -c < 'i386/i386/in_cksum.c'`"
  278. test 5048 -eq "$Wc_c" ||
  279.     echo 'i386/i386/in_cksum.c: original size 5048, current size' "$Wc_c"
  280. fi
  281. exit 0
  282. shar: saving i386/i386/in_cksum.c (Text)
  283.