From 2d5d0e978c337b3342393de305cad54b3bd459bc Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 7 Feb 2019 16:26:26 +0000 Subject: [PATCH 1/4] scst_sysfs: Unbreak the 32-bit build git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7907 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_sysfs.c | 44 ++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 3542e05f1..6944b0995 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -4304,9 +4304,15 @@ void scst_tgt_dev_sysfs_del(struct scst_tgt_dev *tgt_dev) ** Sessions subdirectory implementation **/ +/* Calculate int_sqrt64((sumsq - sum * sum / count) / count) */ static u64 calc_stddev(u64 sumsq, u64 sum, u32 count) { - return int_sqrt64((sumsq - sum * sum / count) / count); + u64 d = sum * sum; + + do_div(d, count); + d = sumsq - d; + do_div(d, count); + return int_sqrt64(d); } static ssize_t scst_sess_latency_show(struct kobject *kobj, @@ -4324,6 +4330,8 @@ static ssize_t scst_sess_latency_show(struct kobject *kobj, uint64_t sum = 0, sumsq = 0; #endif unsigned count = 0, numst = 0; + u64 d_min_div_10, d_max_div_10, avg_div_10, stddev_div_10; + u32 d_min_mod_10, d_max_mod_10, avg_mod_10, stddev_mod_10; char state_name[32]; switch (attr->attr.name[0]) { @@ -4356,15 +4364,24 @@ static ssize_t scst_sess_latency_show(struct kobject *kobj, continue; scst_get_cmd_state_name(state_name, sizeof(state_name), k); - avg = d->sum / d->count; + avg = d->sum; + do_div(avg, d->count); stddev = calc_stddev(d->sumsq, d->sum, d->count); + d_min_div_10 = d->min; + d_min_mod_10 = do_div(d_min_div_10, 10); + d_max_div_10 = d->max; + d_max_mod_10 = do_div(d_max_div_10, 10); + avg_div_10 = avg; + avg_mod_10 = do_div(avg_div_10, 10); + stddev_div_10 = stddev; + stddev_mod_10 = do_div(stddev_div_10, 10); res += scnprintf(buf + res, PAGE_SIZE - res, - "%s %d %lld.%01lld %lld.%01lld %lld.%01lld %lld.%01lld us\n", + "%s %d %lld.%01d %lld.%01d %lld.%01d %lld.%01d us\n", state_name, d->count, - d->min / 10, d->min % 10, - d->max / 10, d->max % 10, - avg / 10, avg % 10, - stddev / 10, stddev % 10); + d_min_div_10, d_min_mod_10, + d_max_div_10, d_max_mod_10, + avg_div_10, avg_mod_10, + stddev_div_10, stddev_mod_10); #ifdef SCST_MEASURE_CLOCK_CYCLES min = d->minc * 10000 / (tsc_khz / 100); max = d->maxc * 10000 / (tsc_khz / 100); @@ -4399,12 +4416,17 @@ static ssize_t scst_sess_latency_show(struct kobject *kobj, count / numst, avg / 10, avg % 10, stddev / 10, stddev % 10); #else - avg = numst * sum / count; + avg = numst * sum; + do_div(avg, count); stddev = calc_stddev(sumsq, sum, count) * numst; + avg_div_10 = avg; + avg_mod_10 = do_div(avg_div_10, 10); + stddev_div_10 = stddev; + stddev_mod_10 = do_div(stddev_div_10, 10); res += scnprintf(buf + res, PAGE_SIZE - res, - "total %d - - %lld.%01lld %lld.%01lld us\n", - count / numst, avg / 10, avg % 10, stddev / 10, - stddev % 10); + "total %d - - %lld.%01d %lld.%01d us\n", + count / numst, avg_div_10, avg_mod_10, + stddev_div_10, stddev_mod_10); #endif } From 2d1a46182c4f53cf4867e6d1e15ea68bfeb8d78d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 8 Feb 2019 03:40:56 +0000 Subject: [PATCH 2/4] scst: Fix the TRACE_EXIT_HRES() macro git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7908 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst_debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scst/include/scst_debug.h b/scst/include/scst_debug.h index f1cf364f3..dabfe57a8 100644 --- a/scst/include/scst_debug.h +++ b/scst/include/scst_debug.h @@ -354,7 +354,7 @@ do { \ #define TRACE_EXIT_HRES(res) \ do { \ - unsigned long lres = (unsigned long)res; \ + unsigned long lres = (unsigned long)(res); \ \ if (trace_flag & TRACE_ENTRYEXIT) { \ if (trace_flag & TRACE_PID) { \ From 685c3dfee3c1b7933addcadf47af36e580901f03 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 8 Feb 2019 03:42:15 +0000 Subject: [PATCH 3/4] scst: Avoid using 64-bit divisions on 32-bit systems See also https://sourceforge.net/p/scst/tickets/17/. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7909 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index e55cc87f4..4952ca481 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -15841,7 +15841,7 @@ static void __scst_update_latency_stats(struct scst_cmd *cmd, cmd->state, delta); delta = 0; } - delta /= 100; + do_div(delta, 100); #ifdef SCST_MEASURE_CLOCK_CYCLES deltac = nowc - stat->last_update_tsc; if (deltac < 0 || deltac > tsc_khz * 1000) { @@ -15849,7 +15849,7 @@ static void __scst_update_latency_stats(struct scst_cmd *cmd, cmd->state, deltac); deltac = 0; } - deltac /= 100; + do_div(deltac, 100); #endif if (stat->count++ > 0) { if (delta < stat->min) From 9df67df1324d9feb7acdb69b96126066c918a33b Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 8 Feb 2019 03:43:35 +0000 Subject: [PATCH 4/4] iscsi-scst: Fix 32-bit compiler warnings git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7910 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/iser_rdma.c | 2 +- iscsi-scst/kernel/nthread.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iscsi-scst/kernel/isert-scst/iser_rdma.c b/iscsi-scst/kernel/isert-scst/iser_rdma.c index 3fb80102f..6180ce669 100644 --- a/iscsi-scst/kernel/isert-scst/iser_rdma.c +++ b/iscsi-scst/kernel/isert-scst/iser_rdma.c @@ -998,7 +998,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev) isert_dev->cq_desc = vmalloc(sizeof(*isert_dev->cq_desc) * isert_dev->num_cqs); if (unlikely(isert_dev->cq_desc == NULL)) { - PRINT_ERROR("Failed to allocate %ld bytes for iser cq_desc", + PRINT_ERROR("Failed to allocate %zd bytes for iser cq_desc", sizeof(*isert_dev->cq_desc) * isert_dev->num_cqs); err = -ENOMEM; goto fail_alloc_cq_desc; diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index 1692dcbeb..5f0cb8af0 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -581,7 +581,7 @@ restart: set_fs(oldfs); #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) - TRACE_DBG("nr_segs %zd, bytes_left %zd, res %d", + TRACE_DBG("nr_segs %ld, bytes_left %zd, res %d", msg->msg_iter.nr_segs, msg->msg_iter.count, res); #else TRACE_DBG("msg_iovlen %zd, read_size %d, res %d", msg->msg_iovlen,