From: Bart Van Assche <bvanassche@acm.org>
To: Douglas Gilbert <dgilbert@interlog.com>, linux-scsi@vger.kernel.org
Cc: martin.petersen@oracle.com, hare@suse.de
Subject: Re: [PATCH v3] scsi_debug: randomize command duration option
Date: Wed, 2 Oct 2019 11:00:15 -0700 [thread overview]
Message-ID: <c15cbefb-87d9-e624-184e-c65ef386b79e@acm.org> (raw)
In-Reply-To: <20191002032707.19918-1-dgilbert@interlog.com>
On 10/1/19 8:27 PM, Douglas Gilbert wrote:
> - kt = ns_to_ktime((u64)delta_jiff * (NSEC_PER_SEC / HZ));
> - } else
> - kt = ndelay;
> + u64 ns = jiffies_to_nsecs(delta_jiff);
> +
> + if (sdebug_random && ns < U32_MAX) {
> + ns = prandom_u32_max((u32)ns);
> + } else if (sdebug_random) {
> + ns >>= 12; /* scale to 4 usec precision */
> + if (ns < U32_MAX) /* over 4 hours max */
> + ns = prandom_u32_max((u32)ns);
> + ns <<= 12;
An explanation of how the scaling factor has been chosen is missing.
Is it user friendly to disable randomization silently if delta_jiff
exceeds a certain value? How about restricting delta_jiff to e.g. ten
times the SCSI timeout?
> + } else { /* ndelay has a 4.2 second max */
> + kt = sdebug_random ? prandom_u32_max((u32)ndelay) :
> + (u32)ndelay;
> + }
Are these (u32) casts necessary?
> +static ssize_t random_show(struct device_driver *ddp, char *buf)
> +{
> + return scnprintf(buf, PAGE_SIZE, "%d\n", (int)sdebug_random);
> +}
Is the (int) cast necessary?
> +static ssize_t random_store(struct device_driver *ddp, const char *buf,
> + size_t count)
> +{
> + int n;
> +
> + if (count > 0 && kstrtoint(buf, 10, &n) == 0 && n >= 0) {
> + sdebug_random = (n > 0);
> + return count;
> + }
> + return -EINVAL;
> +}
> +static DRIVER_ATTR_RW(random);
Is the "count > 0" check useful? I don't think that sysfs ever passes
count == 0 to store callback functions.
Thanks,
Bart.
prev parent reply other threads:[~2019-10-02 18:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-02 3:27 [PATCH v3] scsi_debug: randomize command duration option Douglas Gilbert
2019-10-02 18:00 ` Bart Van Assche [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c15cbefb-87d9-e624-184e-c65ef386b79e@acm.org \
--to=bvanassche@acm.org \
--cc=dgilbert@interlog.com \
--cc=hare@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox