From owner-freebsd-current@FreeBSD.ORG Fri Oct 22 14:22:30 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 828F21065670; Fri, 22 Oct 2010 14:22:30 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 525758FC0C; Fri, 22 Oct 2010 14:22:30 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id EE5E146B91; Fri, 22 Oct 2010 10:22:29 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id C07948A01D; Fri, 22 Oct 2010 10:22:27 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org Date: Fri, 22 Oct 2010 10:18:52 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100819; KDE/4.4.5; amd64; ; ) References: <20101022133702.GA22912@freebsd.org> In-Reply-To: <20101022133702.GA22912@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201010221018.52671.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Fri, 22 Oct 2010 10:22:28 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-1.9 required=4.2 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx Cc: Roman Divacky Subject: Re: [PATCH]: boot2 optimizations to shrink it X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Oct 2010 14:22:30 -0000 On Friday, October 22, 2010 9:37:02 am Roman Divacky wrote: > Hi, > > can you guys review this patch: > > http://lev.vlakno.cz/~rdivacky/boot2.safe.patch > > It shrinks boot2 by 52 bytes by: > > eliminating memcpy() calls > > buffer shrinking as we are only ever called with argument > < 256 for the %u modifier > > constifying write-only variable > > Rui Paulo tested this, is this patch ok? May I commit this? @@ -348,7 +348,7 @@ return; p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE); bootinfo.bi_symtab = VTOP(p); - memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms)); + *p = hdr.ex.a_syms; p += sizeof(hdr.ex.a_syms); if (hdr.ex.a_syms) { if (xfsread(ino, p, hdr.ex.a_syms)) @@ -385,7 +385,7 @@ if (xfsread(ino, &es, sizeof(es))) return; for (i = 0; i < 2; i++) { - memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size)); + *p = es[i].sh_size; p += sizeof(es[i].sh_size); fs_off = es[i].sh_offset; if (xfsread(ino, p, es[i].sh_size)) These are ok. @@ -567,7 +567,7 @@ printf(const char *fmt,...) { va_list ap; - char buf[10]; + char buf[4]; /* we are only passed values < 256 */ char *s; unsigned u; int c; This may not always be true in the future. I know I've printed out LBAs before for debugging issues with zfsboot. I'd really rather not make this change if at all possible. @@ -612,10 +612,10 @@ static int drvread(void *buf, unsigned lba, unsigned nblk) { - static unsigned c = 0x2d5c7c2f; + static const unsigned c = 0x2d5c7c2f; if (!OPT_CHECK(RBX_QUIET)) - printf("%c\b", c = c << 8 | c >> 24); + printf("%c\b", c << 8 | c >> 24); v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS; v86.addr = XREADORG; /* call to xread in boot1 */ v86.es = VTOPSEG(buf); This breaks the twiddle. With this change it will only ever print the second character in the twiddle set rather than rotating them. Perhaps you could use an rol instruction for this instead? Something like: if (!OPT_CHECK(RBX_QUIET)) { __asm ("rol %0,$8" : "=m" (&c)); printf("%c\b", c); } -- John Baldwin