From owner-svn-src-all@freebsd.org Mon Dec 11 14:54:44 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0D24AE93FE2; Mon, 11 Dec 2017 14:54:44 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 C18FD68D5B; Mon, 11 Dec 2017 14:54:43 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBBEsgCM093987; Mon, 11 Dec 2017 14:54:42 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBBEsgGL093986; Mon, 11 Dec 2017 14:54:42 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201712111454.vBBEsgGL093986@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Mon, 11 Dec 2017 14:54:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326769 - head/usr.bin/ctlstat X-SVN-Group: head X-SVN-Commit-Author: bapt X-SVN-Commit-Paths: head/usr.bin/ctlstat X-SVN-Commit-Revision: 326769 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Dec 2017 14:54:44 -0000 Author: bapt Date: Mon Dec 11 14:54:42 2017 New Revision: 326769 URL: https://svnweb.freebsd.org/changeset/base/326769 Log: Remove hard coded number of lun definition The number of lun exposed is now exposed via sysctl by the kernel. Use that number in ctlstat instead of the hardcoded version Add a backward compatibility in case the sysctl(2) request fails. This also allows ctlstat -l 1118 to actually work when having more than 1024 luns. Reviewed by: avg, manu (both before the backward compatibility addition) Approved by: avg, manu (both before the backward compatibility addition) MFC after: 2 weeks Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D13446 Modified: head/usr.bin/ctlstat/ctlstat.c Modified: head/usr.bin/ctlstat/ctlstat.c ============================================================================== --- head/usr.bin/ctlstat/ctlstat.c Mon Dec 11 14:47:23 2017 (r326768) +++ head/usr.bin/ctlstat/ctlstat.c Mon Dec 11 14:54:42 2017 (r326769) @@ -74,12 +74,7 @@ __FBSDID("$FreeBSD$"); */ #define CTL_STAT_NUM_ITEMS 256 -/* - * The default number of LUN selection bits we allocate. This is large - * because we don't currently increase it if the user specifies a LUN - * number of 1024 or larger. - */ -#define CTL_STAT_BITS 1024L +static int ctl_stat_bits; static const char *ctlstat_opts = "Cc:Ddhjl:n:p:tw:"; static const char *ctlstat_usage = "Usage: ctlstat [-CDdjht] [-l lunnum]" @@ -127,7 +122,7 @@ struct ctlstat_context { struct ctl_cpu_stats cur_cpu, prev_cpu; uint64_t cur_total_jiffies, prev_total_jiffies; uint64_t cur_idle, prev_idle; - bitstr_t bit_decl(item_mask, CTL_STAT_BITS); + bitstr_t *item_mask; int cur_items, prev_items; int cur_alloc, prev_alloc; int numdevs; @@ -431,7 +426,7 @@ ctlstat_standard(struct ctlstat_context *ctx) { (F_TIMEVAL(ctx) != 0) ? " " : ""); n = 3; } else { - for (i = n = 0; i < min(CTL_STAT_BITS, + for (i = n = 0; i < min(ctl_stat_bits, ctx->cur_items); i++) { int item; @@ -539,7 +534,7 @@ ctlstat_standard(struct ctlstat_context *ctx) { dmas_per_sec[i], mbsec[i]); } } else { - for (i = n = 0; i < min(CTL_STAT_BITS, ctx->cur_items); i++) { + for (i = n = 0; i < min(ctl_stat_bits, ctx->cur_items); i++) { long double mbsec, kb_per_transfer; long double transfers_per_sec; long double ms_per_transfer; @@ -582,6 +577,7 @@ main(int argc, char **argv) int c; int count, waittime; int fd, retval; + size_t size; struct ctlstat_context ctx; struct ctl_io_stats *tmp_stats; @@ -596,6 +592,16 @@ main(int argc, char **argv) ctx.flags |= CTLSTAT_FLAG_FIRST_RUN; ctx.flags |= CTLSTAT_FLAG_HEADER; + size = sizeof(ctl_stat_bits); + if (sysctlbyname("kern.cam.ctl.max_luns", &ctl_stat_bits, &size, NULL, + 0) == -1) { + /* Backward compatibility for where the sysctl wasn't exposed */ + ctl_stat_bits = 1024; + } + ctx.item_mask = bit_alloc(ctl_stat_bits); + if (ctx.item_mask == NULL) + err(1, "bit_alloc() failed"); + while ((c = getopt(argc, argv, ctlstat_opts)) != -1) { switch (c) { case 'C': @@ -622,7 +628,7 @@ main(int argc, char **argv) int cur_lun; cur_lun = atoi(optarg); - if (cur_lun > CTL_STAT_BITS) + if (cur_lun > ctl_stat_bits) errx(1, "Invalid LUN number %d", cur_lun); if (!F_MASK(&ctx)) @@ -641,7 +647,7 @@ main(int argc, char **argv) int cur_port; cur_port = atoi(optarg); - if (cur_port > CTL_STAT_BITS) + if (cur_port > ctl_stat_bits) errx(1, "Invalid port number %d", cur_port); if (!F_MASK(&ctx))