2 * elvtune.c - I/O elevator tuner
4 * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * This file may be redistributed under the terms of the GNU General
20 * Public License, version 2.
26 #include <sys/ioctl.h>
31 /* this has to match with the kernel structure */
32 /* current version for ac19 and 2.2.16 */
33 typedef struct blkelv_ioctl_arg_s
{
37 int max_bomb_segments
;
40 #define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t))
41 #define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t))
45 fprintf(stderr
, "elvtune (%s)\n", util_linux_version
);
46 fprintf(stderr
, _("usage:\n"));
47 fprintf(stderr
, "\telvtune [-r r_lat] [-w w_lat] [-b b_lat]"
48 " /dev/blkdev1 [/dev/blkdev2...]\n");
49 fprintf(stderr
, "\telvtune -h\n");
50 fprintf(stderr
, "\telvtune -v\n");
55 fprintf(stderr
, "elvtune (%s)\n", util_linux_version
);
59 main(int argc
, char * argv
[]) {
60 int read_value
= 0xbeefbeef, write_value
= 0xbeefbeef, bomb_value
= 0xbeefbeef;
61 int read_set
, write_set
, bomb_set
, set
;
64 blkelv_ioctl_arg_t elevator
;
66 read_set
= write_set
= bomb_set
= set
= 0;
71 opt
= getopt(argc
, argv
, "r:w:b:hv");
76 read_value
= atoi(optarg
);
80 write_value
= atoi(optarg
);
84 bomb_value
= atoi(optarg
);
96 fprintf(stderr
, "parse error\n");
102 fprintf(stderr
, "missing blockdevice, use -h for help\n"), exit(1);
104 while (optind
< argc
) {
105 devname
= argv
[optind
++];
107 fd
= open(devname
, O_RDONLY
|O_NONBLOCK
);
113 if (ioctl(fd
, BLKELVGET
, &elevator
) < 0) {
120 elevator
.read_latency
= read_value
;
122 elevator
.write_latency
= write_value
;
124 elevator
.max_bomb_segments
= bomb_value
;
126 if (ioctl(fd
, BLKELVSET
, &elevator
) < 0) {
130 if (ioctl(fd
, BLKELVGET
, &elevator
) < 0) {
131 perror("ioctl reget");
136 printf("\n%s elevator ID\t\t%d\n", devname
, elevator
.queue_ID
);
137 printf("\tread_latency:\t\t%d\n", elevator
.read_latency
);
138 printf("\twrite_latency:\t\t%d\n", elevator
.write_latency
);
139 printf("\tmax_bomb_segments:\t%d\n\n", elevator
.max_bomb_segments
);