From owner-svn-src-head@FreeBSD.ORG Mon Dec 22 20:42:40 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 52C3DF76; Mon, 22 Dec 2014 20:42:40 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 350CBF7B; Mon, 22 Dec 2014 20:42:40 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBMKgeUF049405; Mon, 22 Dec 2014 20:42:40 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBMKgbc5049395; Mon, 22 Dec 2014 20:42:37 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201412222042.sBMKgbc5049395@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 22 Dec 2014 20:42:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r276079 - head/lib/libstand X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Dec 2014 20:42:40 -0000 Author: ian Date: Mon Dec 22 20:42:36 2014 New Revision: 276079 URL: https://svnweb.freebsd.org/changeset/base/276079 Log: Add a divisor parameter to twiddle() so that callers can request that output only happen on every Nth call. Update the existing twiddle() calls done in various IO loops to roughly reflect the relative IO sizes. That is, tftp and nfs call twiddle() on every 1K block, ufs on every filesystem block, so the network calls now use a much larger divisor than disk IO calls. Also add a new twiddle_divisor() function that allows an application to set a global divisor that is applied on top of the per-call divisors. Nothing calls this yet, but loader(8) will be using it to further throttle the cursor for slow serial consoles. Modified: head/lib/libstand/cd9660.c head/lib/libstand/ext2fs.c head/lib/libstand/nandfs.c head/lib/libstand/nfs.c head/lib/libstand/read.c head/lib/libstand/stand.h head/lib/libstand/tftp.c head/lib/libstand/twiddle.c head/lib/libstand/ufs.c head/lib/libstand/write.c Modified: head/lib/libstand/cd9660.c ============================================================================== --- head/lib/libstand/cd9660.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/cd9660.c Mon Dec 22 20:42:36 2014 (r276079) @@ -281,7 +281,7 @@ cd9660_open(const char *path, struct ope buf = malloc(buf_size = ISO_DEFAULT_BLOCK_SIZE); vd = buf; for (bno = 16;; bno++) { - twiddle(); + twiddle(1); rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno), ISO_DEFAULT_BLOCK_SIZE, buf, &read); if (rc) @@ -314,7 +314,7 @@ cd9660_open(const char *path, struct ope while (off < dsize) { if ((off % ISO_DEFAULT_BLOCK_SIZE) == 0) { - twiddle(); + twiddle(1); rc = f->f_dev->dv_strategy (f->f_devdata, F_READ, cdb2devb(bno + boff), @@ -374,7 +374,7 @@ cd9660_open(const char *path, struct ope /* Check for Rock Ridge since we didn't in the loop above. */ bno = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length); - twiddle(); + twiddle(1); rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno), ISO_DEFAULT_BLOCK_SIZE, buf, &read); if (rc) @@ -431,7 +431,7 @@ buf_read_file(struct open_file *f, char if (fp->f_buf == (char *)0) fp->f_buf = malloc(ISO_DEFAULT_BLOCK_SIZE); - twiddle(); + twiddle(16); rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(blkno), ISO_DEFAULT_BLOCK_SIZE, fp->f_buf, &read); if (rc) Modified: head/lib/libstand/ext2fs.c ============================================================================== --- head/lib/libstand/ext2fs.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/ext2fs.c Mon Dec 22 20:42:36 2014 (r276079) @@ -353,7 +353,7 @@ ext2fs_open(const char *upath, struct op /* allocate space and read super block */ fs = (struct ext2fs *)malloc(sizeof(*fs)); fp->f_fs = fs; - twiddle(); + twiddle(1); error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, EXT2_SBLOCK, EXT2_SBSIZE, (char *)fs, &buf_size); if (error) @@ -395,7 +395,7 @@ ext2fs_open(const char *upath, struct op len = blkgrps * fs->fs_bsize; fp->f_bg = malloc(len); - twiddle(); + twiddle(1); error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, EXT2_SBLOCK + EXT2_SBSIZE / DEV_BSIZE, len, (char *)fp->f_bg, &buf_size); @@ -507,7 +507,7 @@ ext2fs_open(const char *upath, struct op if (error) goto out; - twiddle(); + twiddle(1); error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsb_to_db(fs, disk_block), fs->fs_bsize, buf, &buf_size); @@ -568,7 +568,7 @@ read_inode(ino_t inumber, struct open_fi * Read inode and save it. */ buf = malloc(fs->fs_bsize); - twiddle(); + twiddle(1); error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, ino_to_db(fs, fp->f_bg, inumber), fs->fs_bsize, buf, &rsize); if (error) @@ -665,7 +665,7 @@ block_map(struct open_file *f, daddr_t f if (fp->f_blk[level] == (char *)0) fp->f_blk[level] = malloc(fs->fs_bsize); - twiddle(); + twiddle(1); error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsb_to_db(fp->f_fs, ind_block_num), fs->fs_bsize, fp->f_blk[level], &fp->f_blksize[level]); @@ -723,7 +723,7 @@ buf_read_file(struct open_file *f, char bzero(fp->f_buf, block_size); fp->f_buf_size = block_size; } else { - twiddle(); + twiddle(4); error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsb_to_db(fs, disk_block), block_size, fp->f_buf, &fp->f_buf_size); Modified: head/lib/libstand/nandfs.c ============================================================================== --- head/lib/libstand/nandfs.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/nandfs.c Mon Dec 22 20:42:36 2014 (r276079) @@ -921,7 +921,7 @@ nandfs_bmap_lookup(struct nandfs *fs, st return (0); } - twiddle(); + twiddle(1); NANDFS_DEBUG("calling get_map with %jx\n", ind_block_num); map = nandfs_get_map(fs, node, ind_block_num, phys); if (map == NULL) Modified: head/lib/libstand/nfs.c ============================================================================== --- head/lib/libstand/nfs.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/nfs.c Mon Dec 22 20:42:36 2014 (r276079) @@ -662,7 +662,7 @@ nfs_read(struct open_file *f, void *buf, (int)fp->off); #endif while ((int)size > 0) { - twiddle(); + twiddle(16); cc = nfs_readdata(fp, fp->off, (void *)addr, size); /* XXX maybe should retry on certain errors */ if (cc == -1) { @@ -1311,7 +1311,7 @@ nfs_read(struct open_file *f, void *buf, (int)fp->off); #endif while ((int)size > 0) { - twiddle(); + twiddle(16); cc = nfs_readdata(fp, fp->off, (void *)addr, size); /* XXX maybe should retry on certain errors */ if (cc == -1) { Modified: head/lib/libstand/read.c ============================================================================== --- head/lib/libstand/read.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/read.c Mon Dec 22 20:42:36 2014 (r276079) @@ -77,7 +77,7 @@ read(int fd, void *dest, size_t bcount) return (-1); } if (f->f_flags & F_RAW) { - twiddle(); + twiddle(4); errno = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, btodb(f->f_offset), bcount, dest, &resid); if (errno) Modified: head/lib/libstand/stand.h ============================================================================== --- head/lib/libstand/stand.h Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/stand.h Mon Dec 22 20:42:36 2014 (r276079) @@ -242,7 +242,8 @@ extern int sprintf(char *buf, const char extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4); extern void vsprintf(char *buf, const char *cfmt, __va_list); -extern void twiddle(void); +extern void twiddle(u_int callerdiv); +extern void twiddle_divisor(u_int globaldiv); extern void ngets(char *, int); #define gets(x) ngets((x), 0) Modified: head/lib/libstand/tftp.c ============================================================================== --- head/lib/libstand/tftp.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/tftp.c Mon Dec 22 20:42:36 2014 (r276079) @@ -447,14 +447,12 @@ tftp_read(struct open_file *f, void *add size_t *resid /* out */) { struct tftp_handle *tftpfile; - static int tc = 0; tftpfile = (struct tftp_handle *) f->f_fsdata; while (size > 0) { int needblock, count; - if (!(tc++ % 16)) - twiddle(); + twiddle(32); needblock = tftpfile->off / tftpfile->tftp_blksize + 1; Modified: head/lib/libstand/twiddle.c ============================================================================== --- head/lib/libstand/twiddle.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/twiddle.c Mon Dec 22 20:42:36 2014 (r276079) @@ -42,11 +42,28 @@ __FBSDID("$FreeBSD$"); /* Extra functions from NetBSD standalone printf.c */ +static u_int globaldiv; + void -twiddle() +twiddle(u_int callerdiv) { - static int pos; + static u_int callercnt, globalcnt, pos; + + callercnt++; + if (callerdiv > 1 && (callercnt % callerdiv) != 0) + return; + + globalcnt++; + if (globaldiv > 1 && (globalcnt % globaldiv) != 0) + return; putchar("|/-\\"[pos++ & 3]); putchar('\b'); } + +void +twiddle_divisor(u_int gdiv) +{ + + globaldiv = gdiv; +} Modified: head/lib/libstand/ufs.c ============================================================================== --- head/lib/libstand/ufs.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/ufs.c Mon Dec 22 20:42:36 2014 (r276079) @@ -155,7 +155,7 @@ read_inode(inumber, f) * Read inode and save it. */ buf = malloc(fs->fs_bsize); - twiddle(); + twiddle(1); rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsbtodb(fs, ino_to_fsba(fs, inumber)), fs->fs_bsize, buf, &rsize); @@ -265,7 +265,7 @@ block_map(f, file_block, disk_block_p) if (fp->f_blk[level] == (char *)0) fp->f_blk[level] = malloc(fs->fs_bsize); - twiddle(); + twiddle(1); rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsbtodb(fp->f_fs, ind_block_num), fs->fs_bsize, @@ -346,7 +346,7 @@ buf_write_file(f, buf_p, size_p) if (fp->f_buf == (char *)0) fp->f_buf = malloc(fs->fs_bsize); - twiddle(); + twiddle(4); rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsbtodb(fs, disk_block), block_size, fp->f_buf, &fp->f_buf_size); @@ -365,7 +365,7 @@ buf_write_file(f, buf_p, size_p) * Write the block out to storage. */ - twiddle(); + twiddle(4); rc = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE, fsbtodb(fs, disk_block), block_size, fp->f_buf, &fp->f_buf_size); @@ -406,7 +406,7 @@ buf_read_file(f, buf_p, size_p) bzero(fp->f_buf, block_size); fp->f_buf_size = block_size; } else { - twiddle(); + twiddle(4); rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsbtodb(fs, disk_block), block_size, fp->f_buf, &fp->f_buf_size); @@ -515,7 +515,7 @@ ufs_open(upath, f) /* allocate space and read super block */ fs = malloc(SBLOCKSIZE); fp->f_fs = fs; - twiddle(); + twiddle(1); /* * Try reading the superblock in each of its possible locations. */ @@ -649,7 +649,7 @@ ufs_open(upath, f) if (rc) goto out; - twiddle(); + twiddle(1); rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, fsbtodb(fs, disk_block), fs->fs_bsize, buf, &buf_size); Modified: head/lib/libstand/write.c ============================================================================== --- head/lib/libstand/write.c Mon Dec 22 20:33:40 2014 (r276078) +++ head/lib/libstand/write.c Mon Dec 22 20:42:36 2014 (r276079) @@ -80,7 +80,7 @@ write(fd, dest, bcount) return (-1); } if (f->f_flags & F_RAW) { - twiddle(); + twiddle(4); errno = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE, btodb(f->f_offset), bcount, dest, &resid); if (errno)