From: willy@linux.intel.com (Matthew Wilcox)
Subject: Trivial interrupt coalescing program
Date: Wed, 26 Jun 2013 13:58:58 -0400 [thread overview]
Message-ID: <20130626175858.GD8211@linux.intel.com> (raw)
I'm playing around with interrupt coalescing settings at the moment, and
I wrote this little program to change them from userspace. Hopefully it's
also good documentation for how to use one of the ioctls :-)
/*
* nvme_irqcoal.c
* Copyright (c) 2013, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <linux/nvme.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
static const char *perrstr;
int err, fd;
struct nvme_admin_cmd cmd;
if ((argc != 2) && (argc != 4)) {
fprintf(stderr, "Usage: %s <device> [<threshold> <time>]\n",
argv[0]);
return 1;
}
perrstr = argv[1];
err = open(argv[1], O_RDWR);
if (err < 0)
goto perror;
fd = err;
memset(&cmd, 0, sizeof(cmd));
if (argc == 4) {
unsigned thresh = strtoul(argv[2], NULL, 10);
unsigned time = strtoul(argv[3], NULL, 10);
if ((thresh > 255) || (time > 255)) {
fprintf(stderr, "Threshold and time must both be "
"less than 255\n");
return 1;
}
cmd.opcode = nvme_admin_set_features;
cmd.cdw10 = 8;
cmd.cdw11 = thresh | (time << 8);
perrstr = "Set Features";
err = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
if (err != 0)
goto perror;
}
cmd.opcode = nvme_admin_get_features;
cmd.cdw10 = 8;
perrstr = "Get Features";
err = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
if (err != 0)
goto perror;
printf("Threshold set to %d, Time set to %d\n", cmd.result & 0xff,
cmd.result >> 8);
return 0;
perror:
if (err < 0)
perror(perrstr);
else
fprintf(stderr, "%s returned NVMe status code %x\n", perrstr,
err);
return 1;
}
reply other threads:[~2013-06-26 17:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20130626175858.GD8211@linux.intel.com \
--to=willy@linux.intel.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;
as well as URLs for NNTP newsgroup(s).