From 1439c045a5980d4b47875d2684ce906726227638 Mon Sep 17 00:00:00 2001 From: ngie Date: Fri, 13 Jan 2017 08:24:41 +0000 Subject: MFC r266773,r280680,r311710: r266773 (by jhb): Fix a couple of size_t != int warnings. r280680 (by kevlo): Print size_t's with %zu rather than "%zd. r311710: Style fixes - Delete trailing whitespace - Use nitems(mib) instead of hardcoding the mib length --- usr.bin/top/machine.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 6978060..f247d95 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -363,7 +363,7 @@ machine_init(struct statics *statics, char do_unames) size = sizeof(long) * maxcpu * CPUSTATES; times = malloc(size); if (times == NULL) - err(1, "malloc %zd bytes", size); + err(1, "malloc %zu bytes", size); if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1) err(1, "sysctlbyname kern.cp_times"); pcpu_cp_time = calloc(1, size); @@ -396,7 +396,7 @@ format_header(char *uname_field) { static char Header[128]; const char *prehead; - + if (ps.jail) jidlength = TOP_JID_LEN + 1; /* +1 for extra left space. */ else @@ -536,7 +536,7 @@ get_system_info(struct system_info *si) arc_stats[5] = arc_stat >> 10; si->arc = arc_stats; } - + /* set arrays and strings */ if (pcpu_stats) { si->cpustates = pcpu_cpu_states; @@ -562,7 +562,7 @@ get_system_info(struct system_info *si) mib[0] = CTL_KERN; mib[1] = KERN_BOOTTIME; size = sizeof(boottime); - if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && + if (sysctl(mib, nitems(mib), &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) { si->boottime = boottime; } else { @@ -917,7 +917,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags) argbuflen = cmdlen * 4; argbuf = (char *)malloc(argbuflen + 1); if (argbuf == NULL) { - warn("malloc(%d)", argbuflen + 1); + warn("malloc(%zu)", argbuflen + 1); free(cmdbuf); return NULL; } @@ -970,7 +970,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags) } } - if (ps.jail == 0) + if (ps.jail == 0) jid_buf[0] = '\0'; else snprintf(jid_buf, sizeof(jid_buf), "%*d", @@ -1026,7 +1026,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags) thr_buf[0] = '\0'; else snprintf(thr_buf, sizeof(thr_buf), "%*d ", - sizeof(thr_buf) - 2, pp->ki_numthreads); + (int)(sizeof(thr_buf) - 2), pp->ki_numthreads); snprintf(fmt, sizeof(fmt), proc_fmt, pp->ki_pid, -- cgit v1.1 From ae4583b77792c59260255ede908154bde007d7de Mon Sep 17 00:00:00 2001 From: smh Date: Mon, 16 Jan 2017 09:12:40 +0000 Subject: MFC r311769: Fix rstat: symbol not in namelist from netstat Sponsored by: Multiplay --- usr.bin/netstat/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 8ef9783..79adc9b 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -535,6 +535,9 @@ main(int argc, char *argv[]) if (xflag && Tflag) errx(1, "-x and -T are incompatible, pick one."); + /* Load all necessary kvm symbols */ + kresolve_list(nl); + if (Bflag) { if (!live) usage(); @@ -603,9 +606,6 @@ main(int argc, char *argv[]) exit(0); } - /* Load all necessary kvm symbols */ - kresolve_list(nl); - if (tp) { printproto(tp, tp->pr_name); exit(0); -- cgit v1.1 From dfceffa9f892c919b173a788b5c8ac30805375bc Mon Sep 17 00:00:00 2001 From: delphij Date: Wed, 18 Jan 2017 08:20:36 +0000 Subject: MFC r311275: Restructure libz. --- usr.bin/minigzip/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr.bin') diff --git a/usr.bin/minigzip/Makefile b/usr.bin/minigzip/Makefile index b2cfc46..37f642e 100644 --- a/usr.bin/minigzip/Makefile +++ b/usr.bin/minigzip/Makefile @@ -1,6 +1,6 @@ # $FreeBSD$ -SRCDIR= ${.CURDIR}/../../lib/libz/test +SRCDIR= ${.CURDIR}/../../contrib/zlib/test .PATH: ${SRCDIR} PROG= minigzip -- cgit v1.1 From 42e9324682a0972e7d339d70498fb0c80fa98b1d Mon Sep 17 00:00:00 2001 From: pfg Date: Wed, 18 Jan 2017 15:23:40 +0000 Subject: MFC r311947, r311981: rpcgen(1): Avoid unused variable warning on generated code. Avoid "unused variable 'i'" warnings in generated .c files by only emitting the "int i;" for non-opaque arrays. Opaque arrays use xdr_opaque() rather than iterating over the array. Obtained from: OpenBSD (CVS rev 1.28) rpcgen(1): Check getrlimit() return for generated code. Obtained from: NetBSD (CVS rev 1.27, 1.28) --- usr.bin/rpcgen/rpc_cout.c | 3 ++- usr.bin/rpcgen/rpc_svcout.c | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/rpcgen/rpc_cout.c b/usr.bin/rpcgen/rpc_cout.c index 4c36ce6..45f0d90 100644 --- a/usr.bin/rpcgen/rpc_cout.c +++ b/usr.bin/rpcgen/rpc_cout.c @@ -551,7 +551,8 @@ emit_struct(definition *def) } for (dl = def->def.st.decls; dl != NULL; dl = dl->next) - if (dl->decl.rel == REL_VECTOR){ + if (dl->decl.rel == REL_VECTOR && + strcmp(dl->decl.type, "opaque") != 0){ f_print(fout, "\tint i;\n"); break; } diff --git a/usr.bin/rpcgen/rpc_svcout.c b/usr.bin/rpcgen/rpc_svcout.c index 4b951a3..e868c01 100644 --- a/usr.bin/rpcgen/rpc_svcout.c +++ b/usr.bin/rpcgen/rpc_svcout.c @@ -728,7 +728,8 @@ write_timeout_func(void) if (tirpcflag) { f_print(fout, "\t\t\tstruct rlimit rl;\n\n"); f_print(fout, "\t\t\trl.rlim_max = 0;\n"); - f_print(fout, "\t\t\tgetrlimit(RLIMIT_NOFILE, &rl);\n"); + f_print(fout, "\t\t\tif (getrlimit(RLIMIT_NOFILE, &rl) == -1)\n"); + f_print(fout, "\t\t\t\treturn;\n"); f_print(fout, "\t\t\tif ((size = rl.rlim_max) == 0) {\n"); if (mtflag) @@ -902,7 +903,11 @@ write_rpc_svc_fg(const char *infile, const char *sp) /* get number of file descriptors */ if (tirpcflag) { f_print(fout, "%srl.rlim_max = 0;\n", sp); - f_print(fout, "%sgetrlimit(RLIMIT_NOFILE, &rl);\n", sp); + f_print(fout, "%sif (getrlimit(RLIMIT_NOFILE, &rl) == -1) {\n", + sp); + f_print(fout, "%s\tperror(\"getrlimit\");\n", sp); + f_print(fout, "%s\texit(1);\n", sp); + f_print(fout, "%s}\n", sp); f_print(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp); f_print(fout, "%s\texit(1);\n", sp); } else { -- cgit v1.1 From cce5ebe6044dbb57219042e8ebe92b059dac6dfc Mon Sep 17 00:00:00 2001 From: mav Date: Thu, 26 Jan 2017 21:00:49 +0000 Subject: MFC r311804: Rewrite CTL statistics in more simple and scalable way. Instead of collecting statistics for each combination of ports and logical units, that consumed ~45KB per LU with present number of ports, collect separate statistics for every port and every logical unit separately, that consume only 176 bytes per each single LU/port. This reduces struct ctl_lun size down to just 6KB. Also new IOCTL API/ABI does not hardcode number of LUs/ports, and should allow handling of very large quantities. Old API is still enabled in stable branches for compatibility reasons. --- usr.bin/ctlstat/ctlstat.8 | 7 +- usr.bin/ctlstat/ctlstat.c | 444 ++++++++++++++++++++++------------------------ 2 files changed, 214 insertions(+), 237 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/ctlstat/ctlstat.8 b/usr.bin/ctlstat/ctlstat.8 index 77eb790..038b8ca 100644 --- a/usr.bin/ctlstat/ctlstat.8 +++ b/usr.bin/ctlstat/ctlstat.8 @@ -34,7 +34,7 @@ .\" $Id: //depot/users/kenm/FreeBSD-test2/usr.bin/ctlstat/ctlstat.8#2 $ .\" $FreeBSD$ .\" -.Dd September 21, 2015 +.Dd January 9, 2017 .Dt CTLSTAT 8 .Os .Sh NAME @@ -118,5 +118,6 @@ every 10 seconds. .Xr ctld 8 , .Xr iostat 8 .Sh AUTHORS -.An Ken Merry Aq ken@FreeBSD.org -.An Will Andrews Aq will@FreeBSD.org +.An Ken Merry Aq Mt ken@FreeBSD.org +.An Will Andrews Aq Mt will@FreeBSD.org +.An Alexander Motin Aq Mt mav@FreeBSD.org diff --git a/usr.bin/ctlstat/ctlstat.c b/usr.bin/ctlstat/ctlstat.c index 3587586..d55e004 100644 --- a/usr.bin/ctlstat/ctlstat.c +++ b/usr.bin/ctlstat/ctlstat.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2004, 2008, 2009 Silicon Graphics International Corp. + * Copyright (c) 2017 Alexander Motin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -66,17 +67,17 @@ __FBSDID("$FreeBSD$"); #include /* - * The default amount of space we allocate for LUN storage space. We - * dynamically allocate more if needed. + * The default amount of space we allocate for stats storage space. + * We dynamically allocate more if needed. */ -#define CTL_STAT_NUM_LUNS 30 +#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_LUN_BITS 1024L +#define CTL_STAT_BITS 1024L static const char *ctlstat_opts = "Cc:Ddhjl:n:p:tw:"; static const char *ctlstat_usage = "Usage: ctlstat [-CDdjht] [-l lunnum]" @@ -101,31 +102,32 @@ typedef enum { #define CTLSTAT_FLAG_FIRST_RUN (1 << 2) #define CTLSTAT_FLAG_TOTALS (1 << 3) #define CTLSTAT_FLAG_DMA_TIME (1 << 4) -#define CTLSTAT_FLAG_LUN_TIME_VALID (1 << 5) -#define CTLSTAT_FLAG_LUN_MASK (1 << 6) -#define CTLSTAT_FLAG_PORT_MASK (1 << 7) +#define CTLSTAT_FLAG_TIME_VALID (1 << 5) +#define CTLSTAT_FLAG_MASK (1 << 6) +#define CTLSTAT_FLAG_LUNS (1 << 7) +#define CTLSTAT_FLAG_PORTS (1 << 8) #define F_CPU(ctx) ((ctx)->flags & CTLSTAT_FLAG_CPU) #define F_HDR(ctx) ((ctx)->flags & CTLSTAT_FLAG_HEADER) #define F_FIRST(ctx) ((ctx)->flags & CTLSTAT_FLAG_FIRST_RUN) #define F_TOTALS(ctx) ((ctx)->flags & CTLSTAT_FLAG_TOTALS) #define F_DMA(ctx) ((ctx)->flags & CTLSTAT_FLAG_DMA_TIME) -#define F_LUNVAL(ctx) ((ctx)->flags & CTLSTAT_FLAG_LUN_TIME_VALID) -#define F_LUNMASK(ctx) ((ctx)->flags & CTLSTAT_FLAG_LUN_MASK) -#define F_PORTMASK(ctx) ((ctx)->flags & CTLSTAT_FLAG_PORT_MASK) +#define F_TIMEVAL(ctx) ((ctx)->flags & CTLSTAT_FLAG_TIME_VALID) +#define F_MASK(ctx) ((ctx)->flags & CTLSTAT_FLAG_MASK) +#define F_LUNS(ctx) ((ctx)->flags & CTLSTAT_FLAG_LUNS) +#define F_PORTS(ctx) ((ctx)->flags & CTLSTAT_FLAG_PORTS) struct ctlstat_context { ctlstat_mode_types mode; int flags; - struct ctl_lun_io_stats *cur_lun_stats, *prev_lun_stats, - *tmp_lun_stats; - struct ctl_lun_io_stats cur_total_stats[3], prev_total_stats[3]; + struct ctl_io_stats *cur_stats, *prev_stats; + struct ctl_io_stats cur_total_stats[3], prev_total_stats[3]; struct timespec cur_time, prev_time; 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(lun_mask, CTL_STAT_LUN_BITS); - bitstr_t bit_decl(port_mask, CTL_MAX_PORTS); - int num_luns; + bitstr_t bit_decl(item_mask, CTL_STAT_BITS); + int cur_items, prev_items; + int cur_alloc, prev_alloc; int numdevs; int header_interval; }; @@ -135,12 +137,11 @@ struct ctlstat_context { #endif static void usage(int error); -static int getstats(int fd, int *num_luns, struct ctl_lun_io_stats **xlun_stats, - struct timespec *cur_time, int *lun_time_valid); +static int getstats(int fd, int *alloc_items, int *num_items, + struct ctl_io_stats **xstats, struct timespec *cur_time, int *time_valid); static int getcpu(struct ctl_cpu_stats *cpu_stats); -static void compute_stats(struct ctlstat_context *ctx, - struct ctl_lun_io_stats *cur_stats, - struct ctl_lun_io_stats *prev_stats, +static void compute_stats(struct ctl_io_stats *cur_stats, + struct ctl_io_stats *prev_stats, long double etime, long double *mbsec, long double *kb_per_transfer, long double *transfers_per_second, @@ -155,64 +156,55 @@ usage(int error) } static int -getstats(int fd, int *num_luns, struct ctl_lun_io_stats **xlun_stats, +getstats(int fd, int *alloc_items, int *num_items, struct ctl_io_stats **stats, struct timespec *cur_time, int *flags) { - struct ctl_lun_io_stats *lun_stats; - struct ctl_stats stats; - int more_space_count; + struct ctl_get_io_stats get_stats; + int more_space_count = 0; - more_space_count = 0; - - if (*num_luns == 0) - *num_luns = CTL_STAT_NUM_LUNS; - - lun_stats = *xlun_stats; + if (*alloc_items == 0) + *alloc_items = CTL_STAT_NUM_ITEMS; retry: + if (*stats == NULL) + *stats = malloc(sizeof(**stats) * *alloc_items); - if (lun_stats == NULL) { - lun_stats = (struct ctl_lun_io_stats *)malloc( - sizeof(*lun_stats) * *num_luns); - } - - memset(&stats, 0, sizeof(stats)); - stats.alloc_len = *num_luns * sizeof(*lun_stats); - memset(lun_stats, 0, stats.alloc_len); - stats.lun_stats = lun_stats; + memset(&get_stats, 0, sizeof(get_stats)); + get_stats.alloc_len = *alloc_items * sizeof(**stats); + memset(*stats, 0, get_stats.alloc_len); + get_stats.stats = *stats; - if (ioctl(fd, CTL_GETSTATS, &stats) == -1) - err(1, "error returned from CTL_GETSTATS ioctl"); + if (ioctl(fd, (*flags & CTLSTAT_FLAG_PORTS) ? CTL_GET_PORT_STATS : + CTL_GET_LUN_STATS, &get_stats) == -1) + err(1, "CTL_GET_*_STATS ioctl returned error"); - switch (stats.status) { + switch (get_stats.status) { case CTL_SS_OK: break; case CTL_SS_ERROR: - err(1, "CTL_SS_ERROR returned from CTL_GETSTATS ioctl"); + err(1, "CTL_GET_*_STATS ioctl returned CTL_SS_ERROR"); break; case CTL_SS_NEED_MORE_SPACE: - if (more_space_count > 0) { - errx(1, "CTL_GETSTATS returned NEED_MORE_SPACE again"); - } - *num_luns = stats.num_luns; - free(lun_stats); - lun_stats = NULL; + if (more_space_count >= 2) + errx(1, "CTL_GET_*_STATS returned NEED_MORE_SPACE again"); + *alloc_items = get_stats.num_items * 5 / 4; + free(*stats); + *stats = NULL; more_space_count++; goto retry; break; /* NOTREACHED */ default: - errx(1, "unknown status %d returned from CTL_GETSTATS ioctl", - stats.status); + errx(1, "CTL_GET_*_STATS ioctl returned unknown status %d", + get_stats.status); break; } - *xlun_stats = lun_stats; - *num_luns = stats.num_luns; - cur_time->tv_sec = stats.timestamp.tv_sec; - cur_time->tv_nsec = stats.timestamp.tv_nsec; - if (stats.flags & CTL_STATS_FLAG_TIME_VALID) - *flags |= CTLSTAT_FLAG_LUN_TIME_VALID; + *num_items = get_stats.fill_len / sizeof(**stats); + cur_time->tv_sec = get_stats.timestamp.tv_sec; + cur_time->tv_nsec = get_stats.timestamp.tv_nsec; + if (get_stats.flags & CTL_STATS_FLAG_TIME_VALID) + *flags |= CTLSTAT_FLAG_TIME_VALID; else - *flags &= ~CTLSTAT_FLAG_LUN_TIME_VALID; + *flags &= ~CTLSTAT_FLAG_TIME_VALID; return (0); } @@ -240,14 +232,13 @@ getcpu(struct ctl_cpu_stats *cpu_stats) } static void -compute_stats(struct ctlstat_context *ctx, struct ctl_lun_io_stats *cur_stats, - struct ctl_lun_io_stats *prev_stats, long double etime, +compute_stats(struct ctl_io_stats *cur_stats, + struct ctl_io_stats *prev_stats, long double etime, long double *mbsec, long double *kb_per_transfer, long double *transfers_per_second, long double *ms_per_transfer, long double *ms_per_dma, long double *dmas_per_second) { uint64_t total_bytes = 0, total_operations = 0, total_dmas = 0; - uint32_t port; struct bintime total_time_bt, total_dma_bt; struct timespec total_time_ts, total_dma_ts; int i; @@ -256,31 +247,18 @@ compute_stats(struct ctlstat_context *ctx, struct ctl_lun_io_stats *cur_stats, bzero(&total_dma_bt, sizeof(total_dma_bt)); bzero(&total_time_ts, sizeof(total_time_ts)); bzero(&total_dma_ts, sizeof(total_dma_ts)); - for (port = 0; port < CTL_MAX_PORTS; port++) { - if (F_PORTMASK(ctx) && - bit_test(ctx->port_mask, port) == 0) - continue; - for (i = 0; i < CTL_STATS_NUM_TYPES; i++) { - total_bytes += cur_stats->ports[port].bytes[i]; - total_operations += - cur_stats->ports[port].operations[i]; - total_dmas += cur_stats->ports[port].num_dmas[i]; - bintime_add(&total_time_bt, - &cur_stats->ports[port].time[i]); - bintime_add(&total_dma_bt, - &cur_stats->ports[port].dma_time[i]); - if (prev_stats != NULL) { - total_bytes -= - prev_stats->ports[port].bytes[i]; - total_operations -= - prev_stats->ports[port].operations[i]; - total_dmas -= - prev_stats->ports[port].num_dmas[i]; - bintime_sub(&total_time_bt, - &prev_stats->ports[port].time[i]); - bintime_sub(&total_dma_bt, - &prev_stats->ports[port].dma_time[i]); - } + for (i = 0; i < CTL_STATS_NUM_TYPES; i++) { + total_bytes += cur_stats->bytes[i]; + total_operations += cur_stats->operations[i]; + total_dmas += cur_stats->dmas[i]; + bintime_add(&total_time_bt, &cur_stats->time[i]); + bintime_add(&total_dma_bt, &cur_stats->dma_time[i]); + if (prev_stats != NULL) { + total_bytes -= prev_stats->bytes[i]; + total_operations -= prev_stats->operations[i]; + total_dmas -= prev_stats->dmas[i]; + bintime_sub(&total_time_bt, &prev_stats->time[i]); + bintime_sub(&total_dma_bt, &prev_stats->dma_time[i]); } } @@ -340,35 +318,25 @@ compute_stats(struct ctlstat_context *ctx, struct ctl_lun_io_stats *cur_stats, static const char *iotypes[] = {"NO IO", "READ", "WRITE"}; static void -ctlstat_dump(struct ctlstat_context *ctx) { - int iotype, lun, port; - struct ctl_lun_io_stats *stats = ctx->cur_lun_stats; +ctlstat_dump(struct ctlstat_context *ctx) +{ + int iotype, i; + struct ctl_io_stats *stats = ctx->cur_stats; - for (lun = 0; lun < ctx->num_luns;lun++) { - if (F_LUNMASK(ctx) && bit_test(ctx->lun_mask, lun) == 0) + for (i = 0; i < ctx->cur_items;i++) { + if (F_MASK(ctx) && bit_test(ctx->item_mask, i) == 0) continue; - printf("lun %d\n", lun); - for (port = 0; port < CTL_MAX_PORTS; port++) { - if (F_PORTMASK(ctx) && - bit_test(ctx->port_mask, port) == 0) - continue; - printf(" port %d\n", - stats[lun].ports[port].targ_port); - for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; - iotype++) { - printf(" io type %d (%s)\n", iotype, - iotypes[iotype]); - printf(" bytes %ju\n", (uintmax_t) - stats[lun].ports[port].bytes[iotype]); - printf(" operations %ju\n", (uintmax_t) - stats[lun].ports[port].operations[iotype]); - PRINT_BINTIME(" io time", - stats[lun].ports[port].time[iotype]); - printf(" num dmas %ju\n", (uintmax_t) - stats[lun].ports[port].num_dmas[iotype]); - PRINT_BINTIME(" dma time", - stats[lun].ports[port].dma_time[iotype]); - } + printf("%s %d\n", F_PORTS(ctx) ? "port" : "lun", stats[i].item); + for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; iotype++) { + printf(" io type %d (%s)\n", iotype, iotypes[iotype]); + printf(" bytes %ju\n", (uintmax_t) + stats[i].bytes[iotype]); + printf(" operations %ju\n", (uintmax_t) + stats[i].operations[iotype]); + printf(" dmas %ju\n", (uintmax_t) + stats[i].dmas[iotype]); + PRINT_BINTIME(" io time", stats[i].time[iotype]); + PRINT_BINTIME(" dma time", stats[i].dma_time[iotype]); } } } @@ -378,63 +346,49 @@ ctlstat_dump(struct ctlstat_context *ctx) { (uintmax_t)(((bt).frac >> 32) * 1000000 >> 32)) static void ctlstat_json(struct ctlstat_context *ctx) { - int iotype, lun, port; - struct ctl_lun_io_stats *stats = ctx->cur_lun_stats; + int iotype, i; + struct ctl_io_stats *stats = ctx->cur_stats; - printf("{\"luns\":["); - for (lun = 0; lun < ctx->num_luns; lun++) { - if (F_LUNMASK(ctx) && bit_test(ctx->lun_mask, lun) == 0) + printf("{\"%s\":[", F_PORTS(ctx) ? "ports" : "luns"); + for (i = 0; i < ctx->cur_items; i++) { + if (F_MASK(ctx) && bit_test(ctx->item_mask, i) == 0) continue; - printf("{\"ports\":["); - for (port = 0; port < CTL_MAX_PORTS;port++) { - if (F_PORTMASK(ctx) && - bit_test(ctx->port_mask, port) == 0) - continue; - printf("{\"num\":%d,\"io\":[", - stats[lun].ports[port].targ_port); - for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; - iotype++) { - printf("{\"type\":\"%s\",", iotypes[iotype]); - printf("\"bytes\":%ju,", (uintmax_t)stats[ - lun].ports[port].bytes[iotype]); - printf("\"operations\":%ju,", (uintmax_t)stats[ - lun].ports[port].operations[iotype]); - JSON_BINTIME("io time", - stats[lun].ports[port].time[iotype]); - JSON_BINTIME("dma time", - stats[lun].ports[port].dma_time[iotype]); - printf("\"num dmas\":%ju}", (uintmax_t) - stats[lun].ports[port].num_dmas[iotype]); - if (iotype < (CTL_STATS_NUM_TYPES - 1)) - printf(","); /* continue io array */ - } - printf("]}"); /* close port */ - if (port < (CTL_MAX_PORTS - 1)) - printf(","); /* continue port array */ + printf("{\"num\":%d,\"io\":[", + stats[i].item); + for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; iotype++) { + printf("{\"type\":\"%s\",", iotypes[iotype]); + printf("\"bytes\":%ju,", (uintmax_t)stats[ + i].bytes[iotype]); + printf("\"operations\":%ju,", (uintmax_t)stats[ + i].operations[iotype]); + printf("\"dmas\":%ju}", (uintmax_t) + stats[i].dmas[iotype]); + JSON_BINTIME("io time", stats[i].time[iotype]); + JSON_BINTIME("dma time", stats[i].dma_time[iotype]); + if (iotype < (CTL_STATS_NUM_TYPES - 1)) + printf(","); /* continue io array */ } - printf("]}"); /* close lun */ - if (lun < (ctx->num_luns - 1)) + printf("]}"); + if (i < (ctx->cur_items - 1)) printf(","); /* continue lun array */ } - printf("]}"); /* close luns and toplevel */ + printf("]}"); } static void ctlstat_standard(struct ctlstat_context *ctx) { long double etime; uint64_t delta_jiffies, delta_idle; - uint32_t port; long double cpu_percentage; - int i; - int j; + int i, j; cpu_percentage = 0; if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0)) errx(1, "error returned from getcpu()"); - etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec + - (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; + etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec + + (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; if (F_CPU(ctx)) { ctx->prev_total_jiffies = ctx->cur_total_jiffies; @@ -465,29 +419,28 @@ ctlstat_standard(struct ctlstat_context *ctx) { if (F_TOTALS(ctx)) { fprintf(stdout, "%s Read %s" " Write %s Total\n", - (F_LUNVAL(ctx) != 0) ? " " : "", - (F_LUNVAL(ctx) != 0) ? " " : "", - (F_LUNVAL(ctx) != 0) ? " " : ""); + (F_TIMEVAL(ctx) != 0) ? " " : "", + (F_TIMEVAL(ctx) != 0) ? " " : "", + (F_TIMEVAL(ctx) != 0) ? " " : ""); hdr_devs = 3; } else { - for (i = 0; i < min(CTL_STAT_LUN_BITS, - ctx->num_luns); i++) { - int lun; + for (i = 0; i < min(CTL_STAT_BITS, + ctx->cur_items); i++) { + int item; /* * Obviously this won't work with * LUN numbers greater than a signed * integer. */ - lun = (int)ctx->cur_lun_stats[i - ].lun_number; + item = (int)ctx->cur_stats[i].item; - if (F_LUNMASK(ctx) && - bit_test(ctx->lun_mask, lun) == 0) + if (F_MASK(ctx) && + bit_test(ctx->item_mask, item) == 0) continue; fprintf(stdout, "%15.6s%d %s", - "lun", lun, - (F_LUNVAL(ctx) != 0) ? " " : ""); + F_PORTS(ctx) ? "port" : "lun", item, + (F_TIMEVAL(ctx) != 0) ? " " : ""); hdr_devs++; } fprintf(stdout, "\n"); @@ -496,7 +449,7 @@ ctlstat_standard(struct ctlstat_context *ctx) { fprintf(stdout, " "); for (i = 0; i < hdr_devs; i++) fprintf(stdout, "%s KB/t %s MB/s", - (F_LUNVAL(ctx) != 0) ? " ms" : "", + (F_TIMEVAL(ctx) != 0) ? " ms" : "", (F_DMA(ctx) == 0) ? "tps" : "dps"); fprintf(stdout, "\n"); ctx->header_interval = 20; @@ -519,55 +472,48 @@ ctlstat_standard(struct ctlstat_context *ctx) { memset(&ctx->cur_total_stats, 0, sizeof(ctx->cur_total_stats)); /* Use macros to make the next loop more readable. */ -#define ADD_STATS_BYTES(st, p, i, j) \ - ctx->cur_total_stats[st].ports[p].bytes[j] += \ - ctx->cur_lun_stats[i].ports[p].bytes[j] -#define ADD_STATS_OPERATIONS(st, p, i, j) \ - ctx->cur_total_stats[st].ports[p].operations[j] += \ - ctx->cur_lun_stats[i].ports[p].operations[j] -#define ADD_STATS_NUM_DMAS(st, p, i, j) \ - ctx->cur_total_stats[st].ports[p].num_dmas[j] += \ - ctx->cur_lun_stats[i].ports[p].num_dmas[j] -#define ADD_STATS_TIME(st, p, i, j) \ - bintime_add(&ctx->cur_total_stats[st].ports[p].time[j], \ - &ctx->cur_lun_stats[i].ports[p].time[j]) -#define ADD_STATS_DMA_TIME(st, p, i, j) \ - bintime_add(&ctx->cur_total_stats[st].ports[p].dma_time[j], \ - &ctx->cur_lun_stats[i].ports[p].dma_time[j]) - - for (i = 0; i < ctx->num_luns; i++) { - if (F_LUNMASK(ctx) && bit_test(ctx->lun_mask, - (int)ctx->cur_lun_stats[i].lun_number) == 0) +#define ADD_STATS_BYTES(st, i, j) \ + ctx->cur_total_stats[st].bytes[j] += \ + ctx->cur_stats[i].bytes[j] +#define ADD_STATS_OPERATIONS(st, i, j) \ + ctx->cur_total_stats[st].operations[j] += \ + ctx->cur_stats[i].operations[j] +#define ADD_STATS_DMAS(st, i, j) \ + ctx->cur_total_stats[st].dmas[j] += \ + ctx->cur_stats[i].dmas[j] +#define ADD_STATS_TIME(st, i, j) \ + bintime_add(&ctx->cur_total_stats[st].time[j], \ + &ctx->cur_stats[i].time[j]) +#define ADD_STATS_DMA_TIME(st, i, j) \ + bintime_add(&ctx->cur_total_stats[st].dma_time[j], \ + &ctx->cur_stats[i].dma_time[j]) + + for (i = 0; i < ctx->cur_items; i++) { + if (F_MASK(ctx) && bit_test(ctx->item_mask, + (int)ctx->cur_stats[i].item) == 0) continue; - for (port = 0; port < CTL_MAX_PORTS; port++) { - if (F_PORTMASK(ctx) && - bit_test(ctx->port_mask, port) == 0) - continue; - for (j = 0; j < CTL_STATS_NUM_TYPES; j++) { - ADD_STATS_BYTES(2, port, i, j); - ADD_STATS_OPERATIONS(2, port, i, j); - ADD_STATS_NUM_DMAS(2, port, i, j); - ADD_STATS_TIME(2, port, i, j); - ADD_STATS_DMA_TIME(2, port, i, j); - } - ADD_STATS_BYTES(0, port, i, CTL_STATS_READ); - ADD_STATS_OPERATIONS(0, port, i, - CTL_STATS_READ); - ADD_STATS_NUM_DMAS(0, port, i, CTL_STATS_READ); - ADD_STATS_TIME(0, port, i, CTL_STATS_READ); - ADD_STATS_DMA_TIME(0, port, i, CTL_STATS_READ); - - ADD_STATS_BYTES(1, port, i, CTL_STATS_WRITE); - ADD_STATS_OPERATIONS(1, port, i, - CTL_STATS_WRITE); - ADD_STATS_NUM_DMAS(1, port, i, CTL_STATS_WRITE); - ADD_STATS_TIME(1, port, i, CTL_STATS_WRITE); - ADD_STATS_DMA_TIME(1, port, i, CTL_STATS_WRITE); + for (j = 0; j < CTL_STATS_NUM_TYPES; j++) { + ADD_STATS_BYTES(2, i, j); + ADD_STATS_OPERATIONS(2, i, j); + ADD_STATS_DMAS(2, i, j); + ADD_STATS_TIME(2, i, j); + ADD_STATS_DMA_TIME(2, i, j); } + ADD_STATS_BYTES(0, i, CTL_STATS_READ); + ADD_STATS_OPERATIONS(0, i, CTL_STATS_READ); + ADD_STATS_DMAS(0, i, CTL_STATS_READ); + ADD_STATS_TIME(0, i, CTL_STATS_READ); + ADD_STATS_DMA_TIME(0, i, CTL_STATS_READ); + + ADD_STATS_BYTES(1, i, CTL_STATS_WRITE); + ADD_STATS_OPERATIONS(1, i, CTL_STATS_WRITE); + ADD_STATS_DMAS(1, i, CTL_STATS_WRITE); + ADD_STATS_TIME(1, i, CTL_STATS_WRITE); + ADD_STATS_DMA_TIME(1, i, CTL_STATS_WRITE); } for (i = 0; i < 3; i++) { - compute_stats(ctx, &ctx->cur_total_stats[i], + compute_stats(&ctx->cur_total_stats[i], F_FIRST(ctx) ? NULL : &ctx->prev_total_stats[i], etime, &mbsec[i], &kb_per_transfer[i], &transfers_per_sec[i], @@ -576,7 +522,7 @@ ctlstat_standard(struct ctlstat_context *ctx) { if (F_DMA(ctx) != 0) fprintf(stdout, " %5.1Lf", ms_per_dma[i]); - else if (F_LUNVAL(ctx) != 0) + else if (F_TIMEVAL(ctx) != 0) fprintf(stdout, " %5.1Lf", ms_per_transfer[i]); fprintf(stdout, " %4.0Lf %5.0Lf %4.0Lf", @@ -585,25 +531,32 @@ ctlstat_standard(struct ctlstat_context *ctx) { dmas_per_sec[i], mbsec[i]); } } else { - for (i = 0; i < min(CTL_STAT_LUN_BITS, ctx->num_luns); i++) { + for (i = 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; long double ms_per_dma; long double dmas_per_sec; - if (F_LUNMASK(ctx) && bit_test(ctx->lun_mask, - (int)ctx->cur_lun_stats[i].lun_number) == 0) + if (F_MASK(ctx) && bit_test(ctx->item_mask, + (int)ctx->cur_stats[i].item) == 0) continue; - compute_stats(ctx, &ctx->cur_lun_stats[i], - F_FIRST(ctx) ? NULL : &ctx->prev_lun_stats[i], + for (j = 0; j < ctx->prev_items; j++) { + if (ctx->prev_stats[j].item == + ctx->cur_stats[i].item) + break; + } + if (j >= ctx->prev_items) + j = -1; + compute_stats(&ctx->cur_stats[i], + j >= 0 ? &ctx->prev_stats[j] : NULL, etime, &mbsec, &kb_per_transfer, &transfers_per_sec, &ms_per_transfer, &ms_per_dma, &dmas_per_sec); if (F_DMA(ctx)) fprintf(stdout, " %5.1Lf", ms_per_dma); - else if (F_LUNVAL(ctx) != 0) + else if (F_TIMEVAL(ctx) != 0) fprintf(stdout, " %5.1Lf", ms_per_transfer); fprintf(stdout, " %4.0Lf %5.0Lf %4.0Lf", @@ -620,6 +573,7 @@ main(int argc, char **argv) int count, waittime; int fd, retval; struct ctlstat_context ctx; + struct ctl_io_stats *tmp_stats; /* default values */ retval = 0; @@ -658,15 +612,16 @@ main(int argc, char **argv) int cur_lun; cur_lun = atoi(optarg); - if (cur_lun > CTL_STAT_LUN_BITS) + if (cur_lun > CTL_STAT_BITS) errx(1, "Invalid LUN number %d", cur_lun); - if (!F_LUNMASK(&ctx)) + if (!F_MASK(&ctx)) ctx.numdevs = 1; else ctx.numdevs++; - bit_set(ctx.lun_mask, cur_lun); - ctx.flags |= CTLSTAT_FLAG_LUN_MASK; + bit_set(ctx.item_mask, cur_lun); + ctx.flags |= CTLSTAT_FLAG_MASK; + ctx.flags |= CTLSTAT_FLAG_LUNS; break; } case 'n': @@ -676,11 +631,16 @@ main(int argc, char **argv) int cur_port; cur_port = atoi(optarg); - if (cur_port > CTL_MAX_PORTS) - errx(1, "Invalid LUN number %d", cur_port); + if (cur_port > CTL_STAT_BITS) + errx(1, "Invalid port number %d", cur_port); - bit_set(ctx.port_mask, cur_port); - ctx.flags |= CTLSTAT_FLAG_PORT_MASK; + if (!F_MASK(&ctx)) + ctx.numdevs = 1; + else + ctx.numdevs++; + bit_set(ctx.item_mask, cur_port); + ctx.flags |= CTLSTAT_FLAG_MASK; + ctx.flags |= CTLSTAT_FLAG_PORTS; break; } case 't': @@ -697,29 +657,45 @@ main(int argc, char **argv) } } - if (!F_TOTALS(&ctx) && !F_LUNMASK(&ctx)) { + if (F_LUNS(&ctx) && F_PORTS(&ctx)) + errx(1, "Options -p and -l are exclusive."); + + if (!F_LUNS(&ctx) && !F_PORTS(&ctx)) { + if (F_TOTALS(&ctx)) + ctx.flags |= CTLSTAT_FLAG_PORTS; + else + ctx.flags |= CTLSTAT_FLAG_LUNS; + } + + if (!F_TOTALS(&ctx) && !F_MASK(&ctx)) { /* * Note that this just selects the first N LUNs to display, * but at this point we have no knoweledge of which LUN * numbers actually exist. So we may select LUNs that * aren't there. */ - bit_nset(ctx.lun_mask, 0, min(ctx.numdevs - 1, - CTL_STAT_LUN_BITS - 1)); - ctx.flags |= CTLSTAT_FLAG_LUN_MASK; + bit_nset(ctx.item_mask, 0, min(ctx.numdevs - 1, + CTL_STAT_BITS - 1)); + ctx.flags |= CTLSTAT_FLAG_MASK; } if ((fd = open(CTL_DEFAULT_DEV, O_RDWR)) == -1) err(1, "cannot open %s", CTL_DEFAULT_DEV); for (;count != 0;) { - ctx.tmp_lun_stats = ctx.prev_lun_stats; - ctx.prev_lun_stats = ctx.cur_lun_stats; - ctx.cur_lun_stats = ctx.tmp_lun_stats; + tmp_stats = ctx.prev_stats; + ctx.prev_stats = ctx.cur_stats; + ctx.cur_stats = tmp_stats; + c = ctx.prev_alloc; + ctx.prev_alloc = ctx.cur_alloc; + ctx.cur_alloc = c; + c = ctx.prev_items; + ctx.prev_items = ctx.cur_items; + ctx.cur_items = c; ctx.prev_time = ctx.cur_time; ctx.prev_cpu = ctx.cur_cpu; - if (getstats(fd, &ctx.num_luns, &ctx.cur_lun_stats, - &ctx.cur_time, &ctx.flags) != 0) + if (getstats(fd, &ctx.cur_alloc, &ctx.cur_items, + &ctx.cur_stats, &ctx.cur_time, &ctx.flags) != 0) errx(1, "error returned from getstats()"); switch(ctx.mode) { -- cgit v1.1 From cc500d084d5d3d5930ac536c10c970c18bc78b52 Mon Sep 17 00:00:00 2001 From: asomers Date: Thu, 2 Feb 2017 19:50:28 +0000 Subject: MFC r311160, r311210, r311288, r311292, r311298, r311340 r311160: misc minor fixes in mpr(4) sys/dev/mpr/mpr_sas.c * Fix a potential null pointer dereference (CID 1305731) * Check for overrun of the ccb_scsiio.cdb_io.cdb_bytes buffer (CID 1211934) sys/dev/mpr/mpr_sas_lsi.c * Nullify a dangling pointer in mprsas_get_sata_identify * Fix a memory leak in mprsas_SSU_to_SATA_devices (CID 1211935) Reported by: Coverity (partially) CID: 1305731 1211934 1211935 Reviewed by: slm MFC after: 4 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D8880 r311210: Quell Coverity for diskinfo(8) * CID 1198994: Don't run the speed disk on a disk with no sectors * CID 1011442: Don't call close(2) if open(2) fails * CID 1011161: Use snprintf instead of sprintf * CID 1009825: Check the return value of lseek Reported by: Coverity CID: 1198994 1011442 1011161 1009825 MFC after: 4 weeks Sponsored by: Spectra Logic Corp r311288: Delete dead code in chat(8) It's always been dead, ever since first import in 1994. It's still dead in OpenBSD's version, too. Reported by: Coverity CID: 270586 MFC after: 4 weeks Sponsored by: Spectra Logic Corp r311292: Remove dead code in rpc_parse.c It's been dead ever since it was imported from TI-RPC in 1995. The dead code is still present in Illumos today, but was removed from NetBSD in 2006. Reported by: Coverity CID: 270097 Obtained from: NetBSD MFC after: 4 weeks Sponsored by: Spectra Logic Corp r311298: Remove dead code in dhclient(8) The offending code has been dead ever since the import from OpenBSD in r195805. OpenBSD later deleted that entire function. Reported by: Coverity CID: 500059 MFC after: 4 weeks Sponsored by: Spectra Logic Corp r311340: Misc Coverity fixes for tail(1) CID 1006402: Initialize stack variable CID 271580: Don't leak memory when ENOMEM. Reported by: Coverity CID: 271580 1006402 MFC after: 4 weeks Sponsored by: Spectra Logic Corp --- usr.bin/chat/chat.c | 9 +-------- usr.bin/rpcgen/rpc_parse.c | 10 ---------- usr.bin/tail/reverse.c | 9 ++++++++- 3 files changed, 9 insertions(+), 19 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/chat/chat.c b/usr.bin/chat/chat.c index fa2df10..c82a130 100644 --- a/usr.bin/chat/chat.c +++ b/usr.bin/chat/chat.c @@ -1173,7 +1173,7 @@ int get_string(char *string) { char temp[STR_LEN]; - int c, printed = 0; + int c; size_t len, minlen; char *s = temp, *end = s + STR_LEN; char *logged = temp; @@ -1306,13 +1306,6 @@ get_string(char *string) alarm(0); - if (verbose && printed) { - if (alarmed) - chat_logf(" -- read timed out"); - else - chat_logf(" -- read failed: %m"); - } - exit_code = 3; alarmed = 0; return (0); diff --git a/usr.bin/rpcgen/rpc_parse.c b/usr.bin/rpcgen/rpc_parse.c index f7f857a..9f88033 100644 --- a/usr.bin/rpcgen/rpc_parse.c +++ b/usr.bin/rpcgen/rpc_parse.c @@ -290,7 +290,6 @@ def_union(definition *defp) declaration dec; case_list *cases; case_list **tailp; - int flag; defp->def_kind = DEF_UNION; scan(TOK_IDENT, &tok); @@ -309,7 +308,6 @@ def_union(definition *defp) cases->case_name = tok.str; scan(TOK_COLON, &tok); /* now peek at next token */ - flag = 0; if (peekscan(TOK_CASE, &tok)){ do { scan2(TOK_IDENT, TOK_CHARCONST, &tok); @@ -322,14 +320,6 @@ def_union(definition *defp) scan(TOK_COLON, &tok); } while (peekscan(TOK_CASE, &tok)); } - else - if (flag) - { - - *tailp = cases; - tailp = &cases->next; - cases = XALLOC(case_list); - }; get_declaration(&dec, DEF_UNION); cases->case_decl = dec; diff --git a/usr.bin/tail/reverse.c b/usr.bin/tail/reverse.c index 511f88c..8726905 100644 --- a/usr.bin/tail/reverse.c +++ b/usr.bin/tail/reverse.c @@ -117,6 +117,7 @@ r_reg(FILE *fp, const char *fn, enum STYLE style, off_t off, struct stat *sbp) map.start = NULL; map.mapoff = map.maxoff = size; map.fd = fileno(fp); + map.maplen = 0; /* * Last char is special, ignore whether newline or not. Note that @@ -205,7 +206,13 @@ r_buf(FILE *fp, const char *fn) (tl->l = malloc(BSZ)) == NULL) { if (!mark) err(1, "malloc"); - tl = enomem ? tl->next : mark; + if (enomem) + tl = tl->next; + else { + if (tl) + free(tl); + tl = mark; + } enomem += tl->len; } else if (mark) { tl->next = mark; -- cgit v1.1 From 09eee9cc17136358d1adeb4bfaa934e7fdc78d70 Mon Sep 17 00:00:00 2001 From: delphij Date: Mon, 6 Feb 2017 05:24:17 +0000 Subject: MFC r312664: Always initialize 'c'. --- usr.bin/mail/send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr.bin') diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index 5be7405..ba72c2f 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -59,7 +59,7 @@ sendmessage(struct message *mp, FILE *obuf, struct ignoretab *doign, FILE *ibuf; char *cp, *cp2, line[LINESIZE]; int ishead, infld, ignoring, dostat, firstline; - int c, length, prefixlen; + int c = 0, length, prefixlen; /* * Compute the prefix string, without trailing whitespace -- cgit v1.1 From 3b74e89d5395f6ecc8990eed9fee691c4522b161 Mon Sep 17 00:00:00 2001 From: pfg Date: Mon, 6 Feb 2017 05:27:05 +0000 Subject: MFC r312667: sort - Don't live-loop threads. Worker threads now use a pthread_cond_t to wait for work instead of burning the cpu up. Obtained from: DragonflyBSD (07774aea0ccf64a48fcfad8899e3bf7c8f18277a) --- usr.bin/sort/radixsort.c | 52 ++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/sort/radixsort.c b/usr.bin/sort/radixsort.c index f6cf6ac..59d1571 100644 --- a/usr.bin/sort/radixsort.c +++ b/usr.bin/sort/radixsort.c @@ -83,12 +83,12 @@ static struct level_stack *g_ls; #if defined(SORT_THREADS) /* stack guarding mutex */ +static pthread_cond_t g_ls_cond; static pthread_mutex_t g_ls_mutex; /* counter: how many items are left */ static size_t sort_left; /* guarding mutex */ -static pthread_mutex_t sort_left_mutex; /* semaphore to count threads */ static sem_t mtsem; @@ -99,23 +99,25 @@ static sem_t mtsem; static inline void sort_left_dec(size_t n) { - - pthread_mutex_lock(&sort_left_mutex); + pthread_mutex_lock(&g_ls_mutex); sort_left -= n; - pthread_mutex_unlock(&sort_left_mutex); + if (sort_left == 0 && nthreads > 1) + pthread_cond_broadcast(&g_ls_cond); + pthread_mutex_unlock(&g_ls_mutex); } /* * Do we have something to sort ? + * + * This routine does not need to be locked. */ static inline bool have_sort_left(void) { bool ret; - pthread_mutex_lock(&sort_left_mutex); ret = (sort_left > 0); - pthread_mutex_unlock(&sort_left_mutex); + return (ret); } @@ -146,6 +148,11 @@ push_ls(struct sort_level* sl) #if defined(SORT_THREADS) if (nthreads > 1) + pthread_cond_signal(&g_ls_cond); +#endif + +#if defined(SORT_THREADS) + if (nthreads > 1) pthread_mutex_unlock(&g_ls_mutex); #endif } @@ -184,13 +191,19 @@ pop_ls_mt(void) pthread_mutex_lock(&g_ls_mutex); - if (g_ls) { - sl = g_ls->sl; - saved_ls = g_ls; - g_ls = g_ls->next; - } else { + for (;;) { + if (g_ls) { + sl = g_ls->sl; + saved_ls = g_ls; + g_ls = g_ls->next; + break; + } sl = NULL; saved_ls = NULL; + + if (have_sort_left() == 0) + break; + pthread_cond_wait(&g_ls_cond, &g_ls_mutex); } pthread_mutex_unlock(&g_ls_mutex); @@ -493,13 +506,8 @@ run_sort_cycle_mt(void) for (;;) { slc = pop_ls_mt(); - if (slc == NULL) { - if (have_sort_left()) { - pthread_yield(); - continue; - } + if (slc == NULL) break; - } run_sort_level_next(slc); } } @@ -510,9 +518,7 @@ run_sort_cycle_mt(void) static void* sort_thread(void* arg) { - run_sort_cycle_mt(); - sem_post(&mtsem); return (arg); @@ -608,8 +614,7 @@ run_top_sort_level(struct sort_level *sl) pthread_t pth; pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, - PTHREAD_DETACHED); + pthread_attr_setdetachstate(&attr, PTHREAD_DETACHED); for (;;) { int res = pthread_create(&pth, &attr, @@ -626,7 +631,7 @@ run_top_sort_level(struct sort_level *sl) pthread_attr_destroy(&attr); } - for(i = 0; i < nthreads; ++i) + for (i = 0; i < nthreads; ++i) sem_wait(&mtsem); } #endif /* defined(SORT_THREADS) */ @@ -649,7 +654,7 @@ run_sort(struct sort_list_item **base, size_t nmemb) pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_ADAPTIVE_NP); pthread_mutex_init(&g_ls_mutex, &mattr); - pthread_mutex_init(&sort_left_mutex, &mattr); + pthread_cond_init(&g_ls_cond, NULL); pthread_mutexattr_destroy(&mattr); @@ -677,7 +682,6 @@ run_sort(struct sort_list_item **base, size_t nmemb) if (nthreads > 1) { sem_destroy(&mtsem); pthread_mutex_destroy(&g_ls_mutex); - pthread_mutex_destroy(&sort_left_mutex); } nthreads = nthreads_save; #endif -- cgit v1.1 From fb74bd6a61f647b480386ee1bb23d218fab87190 Mon Sep 17 00:00:00 2001 From: delphij Date: Mon, 6 Feb 2017 05:34:47 +0000 Subject: MFC r312663: When creating record file, use umask 077 instead of the default. --- usr.bin/mail/send.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'usr.bin') diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index ba72c2f..a199323 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -566,8 +566,13 @@ savemail(char name[], FILE *fi) char buf[BUFSIZ]; int i; time_t now; + mode_t saved_umask; - if ((fo = Fopen(name, "a")) == NULL) { + saved_umask = umask(077); + fo = Fopen(name, "a"); + umask(saved_umask); + + if (fo == NULL) { warn("%s", name); return (-1); } -- cgit v1.1