From owner-freebsd-hackers@FreeBSD.ORG Fri Sep 26 14:51:39 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2DD87BF4 for ; Fri, 26 Sep 2014 14:51:39 +0000 (UTC) Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by mx1.freebsd.org (Postfix) with ESMTP id 30889788 for ; Fri, 26 Sep 2014 14:51:37 +0000 (UTC) Received: by ajax-webmail-newmailweb.ustc.edu.cn (Coremail) ; Fri, 26 Sep 2014 22:51:36 +0800 (GMT+08:00) X-CM-HeaderCharset: UTF-8 X-Originating-IP: [58.211.218.74] Date: Fri, 26 Sep 2014 22:51:36 +0800 (GMT+08:00) From: btw@mail.ustc.edu.cn To: freebsd-hackers Subject: Questions with the in_cksumdata() function in sys/amd64/amd64/in_cksum.c X-Priority: 3 X-Mailer: Coremail Webmail Server Version XT3.0.4a build 20140813(28498.6655.6441) Copyright (c) 2002-2014 www.mailtech.cn ustc-xl X-SendMailWithSms: false Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 MIME-Version: 1.0 Message-ID: <3225c531.3abe.148b2721f15.Coremail.btw@mail.ustc.edu.cn> X-CM-TRANSID: LkAmygCXeYp4fSVUzYgGAA--.1169W X-CM-SenderInfo: xewzqzxdloh3xvwfhvlgxou0/1tbiAQUTAVQhl71ibgACsH X-Coremail-Antispam: 1Ur529EdanIXcx71UUUUU7IcSsGvfJ3iIAIbVAYjsxI4VWxJw CS07vEb4IE77IF4wCS07vE1I0E4x80FVAKz4kxMIAIbVAFxVCaYxvI4VCIwcAKzIAtYxBI daVFxhVjvjDU= X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Sep 2014 14:51:39 -0000 Hi All, I'm reading the in_cksumdata() function in sys/amd64/amd64/in_cksum.c, and I have some questions with the following comment and code: static u_int64_t in_cksumdata(const void *buf, int len) { ...... /* * access prefilling to start load of next cache line. * then add current cache line * save result of prefilling for loop iteration. */ prefilled = lw[0]; while ((len -= 32) >= 4) { u_int64_t prefilling = lw[8]; sum += prefilled + lw[1] + lw[2] + lw[3] + lw[4] + lw[5] + lw[6] + lw[7]; lw += 8; prefilled = prefilling; } ...... } It said that it adds the current cache line, and it adds 32 bytes actually, while on amd64 platform, the size of each cache line is 64 bytes. So I think the correct code should be something like this: static u_int64_t in_cksumdata(const void *buf, int len) { ...... /* * access prefilling to start load of next cache line. * then add current cache line * save result of prefilling for loop iteration. */ prefilled = lw[0]; while ((len -= 64) >= 4) { u_int64_t prefilling = lw[16]; sum += prefilled + lw[1] + lw[2] + lw[3] + lw[4] + lw[5] + lw[6] + lw[7] + lw[8] + lw[9] + lw[10] + lw[11] + lw[12] + lw[13] + lw[14] + lw[15]; lw += 16; prefilled = prefilling; } ...... } The full patch is: diff --git a/in_cksum.c b/in_cksum.c index 2ae3a0c..4f141f8 100644 --- a/in_cksum.c +++ b/in_cksum.c @@ -140,19 +140,23 @@ in_cksumdata(const void *buf, int len) * save result of prefilling for loop iteration. */ prefilled = lw[0]; - while ((len -= 32) >= 4) { - u_int64_t prefilling = lw[8]; + while ((len -= 64) >= 4) { + u_int64_t prefilling = lw[16]; sum += prefilled + lw[1] + lw[2] + lw[3] - + lw[4] + lw[5] + lw[6] + lw[7]; - lw += 8; + + lw[4] + lw[5] + lw[6] + lw[7] + + lw[8] + lw[9] + lw[10] + lw[11] + + lw[12] + lw[13] + lw[14] + lw[15]; + lw += 16; prefilled = prefilling; } if (len >= 0) { sum += prefilled + lw[1] + lw[2] + lw[3] - + lw[4] + lw[5] + lw[6] + lw[7]; - lw += 8; + + lw[4] + lw[5] + lw[6] + lw[7] + + lw[8] + lw[9] + lw[10] + lw[11] + + lw[12] + lw[13] + lw[14] + lw[15]; + lw += 16; } else { - len += 32; + len += 64; } while ((len -= 16) >= 0) { sum += (u_int64_t) lw[0] + lw[1] + lw[2] + lw[3]; Sorry about the confusion if I did something wrong. - twb