* [PATCH] docs: block: update ioprio.txt
@ 2012-06-19 8:51 Zheng Liu
2012-06-19 10:19 ` Karel Zak
[not found] ` <CAG27Bk2tXprRfMfYOVdWtwSbjw5Rw9Kxs6Wns+Gm65m3hoJawg@mail.gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Zheng Liu @ 2012-06-19 8:51 UTC (permalink / raw)
To: linux-doc, linux-kernel, util-linux
Cc: Jens Axboe, Rob Landley, Bernhard Voelker, Zheng Liu
From: Zheng Liu <wenqing.lz@taobao.com>
The ionice.c in ioprio.txt document needed updating for the latest util-linux
version.
CC: Jens Axboe <axboe@kernel.dk>
CC: Rob Landley <rob@landley.net>
CC: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
---
Documentation/block/ioprio.txt | 174 +++++++++++++++++++++++++---------------
1 files changed, 109 insertions(+), 65 deletions(-)
diff --git a/Documentation/block/ioprio.txt b/Documentation/block/ioprio.txt
index 8ed8c59..4aa59d6 100644
--- a/Documentation/block/ioprio.txt
+++ b/Documentation/block/ioprio.txt
@@ -64,36 +64,19 @@ will change pid 100 to run at the realtime scheduling class, at priority 2.
#include <errno.h>
#include <getopt.h>
#include <unistd.h>
-#include <sys/ptrace.h>
-#include <asm/unistd.h>
-
-extern int sys_ioprio_set(int, int, int);
-extern int sys_ioprio_get(int, int);
-
-#if defined(__i386__)
-#define __NR_ioprio_set 289
-#define __NR_ioprio_get 290
-#elif defined(__ppc__)
-#define __NR_ioprio_set 273
-#define __NR_ioprio_get 274
-#elif defined(__x86_64__)
-#define __NR_ioprio_set 251
-#define __NR_ioprio_get 252
-#elif defined(__ia64__)
-#define __NR_ioprio_set 1274
-#define __NR_ioprio_get 1275
-#else
-#error "Unsupported arch"
-#endif
+#include <sys/syscall.h>
+#include <ctype.h>
+
+static int tolerant;
static inline int ioprio_set(int which, int who, int ioprio)
{
- return syscall(__NR_ioprio_set, which, who, ioprio);
+ return syscall(SYS_ioprio_set, which, who, ioprio);
}
static inline int ioprio_get(int which, int who)
{
- return syscall(__NR_ioprio_get, which, who);
+ return syscall(SYS_ioprio_get, which, who);
}
enum {
@@ -109,72 +92,133 @@ enum {
IOPRIO_WHO_USER,
};
-#define IOPRIO_CLASS_SHIFT 13
+#define IOPRIO_CLASS_SHIFT (13)
+#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
-const char *to_prio[] = { "none", "realtime", "best-effort", "idle", };
+#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
+#define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
+#define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
-int main(int argc, char *argv[])
-{
- int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE;
- int c, pid = 0;
+const char *to_prio[] = {
+ [IOPRIO_CLASS_NONE] = "none",
+ [IOPRIO_CLASS_RT] = "realtime",
+ [IOPRIO_CLASS_BE] = "best-effort",
+ [IOPRIO_CLASS_IDLE] = "idle"
+};
- while ((c = getopt(argc, argv, "+n:c:p:")) != EOF) {
+int main(int argc, char **argv)
+{
+ int data = 4, set = 0, ioclass = IOPRIO_CLASS_BE, c;
+ pid_t pid = 0;
+
+ static const struct option longopts[] = {
+ { "classdata", required_argument, NULL, 'n' },
+ { "class", required_argument, NULL, 'c' },
+ { "help", no_argument, NULL, 'h' },
+ { "ignore", no_argument, NULL, 't' },
+ { "pid", required_argument, NULL, 'p' },
+ { "version", no_argument, NULL, 'V' },
+ { NULL, 0, NULL, 0 }
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+ atexit(close_stdout);
+
+ while ((c = getopt_long(argc, argv, "+n:c:p:tVh", longopts, NULL)) != EOF)
switch (c) {
case 'n':
- ioprio = strtol(optarg, NULL, 10);
- set = 1;
+ data = strtos32_or_err(optarg, _("invalid class data argument"));
+ set |= 1;
break;
case 'c':
- ioprio_class = strtol(optarg, NULL, 10);
- set = 1;
+ if (isdigit(*optarg))
+ ioclass = strtos32_or_err(optarg,
+ _("invalid class argument"));
+ else {
+ ioclass = parse_ioclass(optarg);
+ if (ioclass < 0)
+ errx(EXIT_FAILURE,
+ _("unknown scheduling class: '%s'"),
+ optarg);
+ }
+ set |= 2;
break;
case 'p':
- pid = strtol(optarg, NULL, 10);
+ pid = strtos32_or_err(optarg, _("invalid PID argument"));
break;
+ case 't':
+ tolerant = 1;
+ break;
+ case 'V':
+ printf(_("%s from %s\n"),
+ program_invocation_short_name, PACKAGE_STRING);
+ return EXIT_SUCCESS;
+ case 'h':
+ usage(stdout);
+ default:
+ usage(stderr);
}
- }
- switch (ioprio_class) {
+ switch (ioclass) {
case IOPRIO_CLASS_NONE:
- ioprio_class = IOPRIO_CLASS_BE;
+ if ((set & 1) && !tolerant)
+ warnx(_("ignoring given class data for none class"));
+ data = 0;
break;
case IOPRIO_CLASS_RT:
case IOPRIO_CLASS_BE:
break;
case IOPRIO_CLASS_IDLE:
- ioprio = 7;
+ if ((set & 1) && !tolerant)
+ warnx(_("ignoring given class data for idle class"));
+ data = 7;
break;
default:
- printf("bad prio class %d\n", ioprio_class);
- return 1;
+ if (!tolerant)
+ warnx(_("unknown prio class %d"), ioclass);
+ break;
}
- if (!set) {
- if (!pid && argv[optind])
- pid = strtol(argv[optind], NULL, 10);
-
- ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
-
- printf("pid=%d, %d\n", pid, ioprio);
-
- if (ioprio == -1)
- perror("ioprio_get");
- else {
- ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
- ioprio = ioprio & 0xff;
- printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
+ if (!set && !pid && optind == argc)
+ /*
+ * ionice without options, print the current ioprio
+ */
+ ioprio_print(0);
+
+ else if (!set && pid) {
+ /*
+ * ionice -p PID [PID ...]
+ */
+ ioprio_print(pid);
+
+ for(; argv[optind]; ++optind) {
+ pid = strtos32_or_err(argv[optind], _("invalid PID argument"));
+ ioprio_print(pid);
}
- } else {
- if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
- perror("ioprio_set");
- return 1;
+ } else if (set && pid) {
+ /*
+ * ionice -c CLASS -p PID [PID ...]
+ */
+ ioprio_setpid(pid, ioclass, data);
+
+ for(; argv[optind]; ++optind) {
+ pid = strtos32_or_err(argv[optind], _("invalid PID argument"));
+ ioprio_setpid(pid, ioclass, data);
}
-
- if (argv[optind])
- execvp(argv[optind], &argv[optind]);
- }
-
- return 0;
+ } else if (argv[optind]) {
+ /*
+ * ionice [-c CLASS] COMMAND
+ */
+ ioprio_setpid(0, ioclass, data);
+ execvp(argv[optind], &argv[optind]);
+ err(EXIT_FAILURE, _("executing %s failed"), argv[optind]);
+ } else
+ usage(stderr);
+
+
+ return EXIT_SUCCESS;
}
---> snip ionice.c tool <---
--
1.7.4.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] docs: block: update ioprio.txt
2012-06-19 8:51 [PATCH] docs: block: update ioprio.txt Zheng Liu
@ 2012-06-19 10:19 ` Karel Zak
[not found] ` <CAG27Bk2tXprRfMfYOVdWtwSbjw5Rw9Kxs6Wns+Gm65m3hoJawg@mail.gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: Karel Zak @ 2012-06-19 10:19 UTC (permalink / raw)
To: Zheng Liu
Cc: linux-doc, linux-kernel, util-linux, Jens Axboe, Rob Landley,
Bernhard Voelker, Zheng Liu
On Tue, Jun 19, 2012 at 04:51:37PM +0800, Zheng Liu wrote:
> From: Zheng Liu <wenqing.lz@taobao.com>
>
> The ionice.c in ioprio.txt document needed updating for the latest util-linux
> version.
>
> CC: Jens Axboe <axboe@kernel.dk>
> CC: Rob Landley <rob@landley.net>
> CC: Bernhard Voelker <mail@bernhard-voelker.de>
> Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
> ---
> Documentation/block/ioprio.txt | 174 +++++++++++++++++++++++++---------------
> 1 files changed, 109 insertions(+), 65 deletions(-)
BTW, does it make sense to maintain duplicate, untested and unused
code in kernel docs if we already have regular ionice(1) implementation
in util-linux?
Would be better to add URL to *maintained* code?
http://git.kernel.org/?p=utils/util-linux/util-linux.git;a=blob_plain;f=schedutils/ionice.c;hb=HEAD
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] docs: block: update ioprio.txt
[not found] ` <CAG27Bk2tXprRfMfYOVdWtwSbjw5Rw9Kxs6Wns+Gm65m3hoJawg@mail.gmail.com>
@ 2012-06-19 10:27 ` Zheng Liu
2012-06-21 4:50 ` Rob Landley
0 siblings, 1 reply; 6+ messages in thread
From: Zheng Liu @ 2012-06-19 10:27 UTC (permalink / raw)
To: Sami Kerola
Cc: Sami Kerola, Jens Axboe, Rob Landley, Bernhard Voelker, Zheng Liu,
linux-doc, linux-kernel, util-linux
Hi Sami,
[You forgot to CC'd other developers and mailing list]
On Tue, Jun 19, 2012 at 10:54:41AM +0200, Sami Kerola wrote:
> Hi Zheng,
>
> Wouldn't a patch such as below be better?
Looks good to me. But, IMHO, if reader cannot access Internet, my patch
maybe is better for them. The original writer is not me. So I don't
understand the original idea that puts ionice source code in here. I
think that Jens can do the final decision.
Hi Jens,
What's your opintion about Sami's and my patch?
Regards,
Zheng
>
> From 800d7d46f8c1945d9c2e43912376c9b7d00a15ba Mon Sep 17 00:00:00 2001
> From: Sami Kerola <kerolasa@iki.fi>
> Date: Tue, 19 Jun 2012 10:52:06 +0200
> Subject: [PATCH] docs: block: update ioprio.txt
>
> Inform the ionice.c in ioprio.txt document is moved to util-linux
> package.
>
> CC: Jens Axboe <axboe@kernel.dk>
> CC: Rob Landley <rob@landley.net>
> CC: Bernhard Voelker <mail@bernhard-voelker.de>
> CC: Zheng Liu <wenqing.lz@taobao.com>
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> Documentation/block/ioprio.txt | 126 ++--------------------------------------
> 1 file changed, 5 insertions(+), 121 deletions(-)
>
> diff --git a/Documentation/block/ioprio.txt b/Documentation/block/ioprio.txt
> index 8ed8c59..9ccd3f0 100644
> --- a/Documentation/block/ioprio.txt
> +++ b/Documentation/block/ioprio.txt
> @@ -57,127 +57,11 @@ For a running process, you can give the pid instead:
>
> will change pid 100 to run at the realtime scheduling class, at priority 2.
>
> ----> snip ionice.c tool <---
> -
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <errno.h>
> -#include <getopt.h>
> -#include <unistd.h>
> -#include <sys/ptrace.h>
> -#include <asm/unistd.h>
> -
> -extern int sys_ioprio_set(int, int, int);
> -extern int sys_ioprio_get(int, int);
> -
> -#if defined(__i386__)
> -#define __NR_ioprio_set 289
> -#define __NR_ioprio_get 290
> -#elif defined(__ppc__)
> -#define __NR_ioprio_set 273
> -#define __NR_ioprio_get 274
> -#elif defined(__x86_64__)
> -#define __NR_ioprio_set 251
> -#define __NR_ioprio_get 252
> -#elif defined(__ia64__)
> -#define __NR_ioprio_set 1274
> -#define __NR_ioprio_get 1275
> -#else
> -#error "Unsupported arch"
> -#endif
> -
> -static inline int ioprio_set(int which, int who, int ioprio)
> -{
> - return syscall(__NR_ioprio_set, which, who, ioprio);
> -}
> -
> -static inline int ioprio_get(int which, int who)
> -{
> - return syscall(__NR_ioprio_get, which, who);
> -}
> -
> -enum {
> - IOPRIO_CLASS_NONE,
> - IOPRIO_CLASS_RT,
> - IOPRIO_CLASS_BE,
> - IOPRIO_CLASS_IDLE,
> -};
> -
> -enum {
> - IOPRIO_WHO_PROCESS = 1,
> - IOPRIO_WHO_PGRP,
> - IOPRIO_WHO_USER,
> -};
> -
> -#define IOPRIO_CLASS_SHIFT 13
> -
> -const char *to_prio[] = { "none", "realtime", "best-effort", "idle", };
> -
> -int main(int argc, char *argv[])
> -{
> - int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE;
> - int c, pid = 0;
> -
> - while ((c = getopt(argc, argv, "+n:c:p:")) != EOF) {
> - switch (c) {
> - case 'n':
> - ioprio = strtol(optarg, NULL, 10);
> - set = 1;
> - break;
> - case 'c':
> - ioprio_class = strtol(optarg, NULL, 10);
> - set = 1;
> - break;
> - case 'p':
> - pid = strtol(optarg, NULL, 10);
> - break;
> - }
> - }
> -
> - switch (ioprio_class) {
> - case IOPRIO_CLASS_NONE:
> - ioprio_class = IOPRIO_CLASS_BE;
> - break;
> - case IOPRIO_CLASS_RT:
> - case IOPRIO_CLASS_BE:
> - break;
> - case IOPRIO_CLASS_IDLE:
> - ioprio = 7;
> - break;
> - default:
> - printf("bad prio class %d\n", ioprio_class);
> - return 1;
> - }
> -
> - if (!set) {
> - if (!pid && argv[optind])
> - pid = strtol(argv[optind], NULL, 10);
> -
> - ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
> -
> - printf("pid=%d, %d\n", pid, ioprio);
> -
> - if (ioprio == -1)
> - perror("ioprio_get");
> - else {
> - ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
> - ioprio = ioprio & 0xff;
> - printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
> - }
> - } else {
> - if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class <<
> IOPRIO_CLASS_SHIFT) == -1) {
> - perror("ioprio_set");
> - return 1;
> - }
> -
> - if (argv[optind])
> - execvp(argv[optind], &argv[optind]);
> - }
> -
> - return 0;
> -}
> -
> ----> snip ionice.c tool <---
> +Tool source code
> +----------------
>
> +Moved to util-linux package schedutils/ionice.c
> +
> +http://git.kernel.org/?p=utils/util-linux/util-linux.git;a=blob;f=schedutils/ionice.c
>
> March 11 2005, Jens Axboe <jens.axboe@oracle.com>
> --
> 1.7.9.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] docs: block: update ioprio.txt
2012-06-19 10:27 ` Zheng Liu
@ 2012-06-21 4:50 ` Rob Landley
2012-06-21 6:50 ` Sami Kerola
2012-06-21 10:19 ` gnehzuil.lzheng
0 siblings, 2 replies; 6+ messages in thread
From: Rob Landley @ 2012-06-21 4:50 UTC (permalink / raw)
To: Sami Kerola, Sami Kerola, Jens Axboe, Bernhard Voelker, Zheng Liu,
linux-doc, linux-kernel, util-linux
On 06/19/2012 05:27 AM, Zheng Liu wrote:
> Hi Sami,
>
> [You forgot to CC'd other developers and mailing list]
>
> On Tue, Jun 19, 2012 at 10:54:41AM +0200, Sami Kerola wrote:
>> Hi Zheng,
>>
>> Wouldn't a patch such as below be better?
>
> Looks good to me. But, IMHO, if reader cannot access Internet, my patch
> maybe is better for them. The original writer is not me. So I don't
> understand the original idea that puts ionice source code in here. I
> think that Jens can do the final decision.
>
> Hi Jens,
>
> What's your opintion about Sami's and my patch?
I note that it's nice to have a reference implementation for nontrivial
things. Also, util-linux isn't the end-all and be-all of linux
userspace: busybox has an ionice, and I plan to add an ionice
implementation to toybox as well.
So fixing reference code is good. That said, this isn't a "fix", this is
a rewrite adding all sorts of unnecessary complexity
(internationalization? strtos32_or_error() instead of strtol()?) that
makes it much _less_ effective as reference code.
Rob
--
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation. Pick one.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] docs: block: update ioprio.txt
2012-06-21 4:50 ` Rob Landley
@ 2012-06-21 6:50 ` Sami Kerola
2012-06-21 10:19 ` gnehzuil.lzheng
1 sibling, 0 replies; 6+ messages in thread
From: Sami Kerola @ 2012-06-21 6:50 UTC (permalink / raw)
To: Rob Landley
Cc: Jens Axboe, Bernhard Voelker, Zheng Liu, linux-doc, linux-kernel,
util-linux
On Thu, Jun 21, 2012 at 6:50 AM, Rob Landley <rob@landley.net> wrote:
> On 06/19/2012 05:27 AM, Zheng Liu wrote:
>> Hi Sami,
>>
>> [You forgot to CC'd other developers and mailing list]
Some times I do that intentionally. Oh, well now when my opinion is public...
>> On Tue, Jun 19, 2012 at 10:54:41AM +0200, Sami Kerola wrote:
>>> Hi Zheng,
>>>
>>> Wouldn't a patch such as below be better?
>>
>> Looks good to me. But, IMHO, if reader cannot access Internet, my patch
>> maybe is better for them. The original writer is not me. So I don't
>> understand the original idea that puts ionice source code in here. I
>> think that Jens can do the final decision.
>>
>> Hi Jens,
>>
>> What's your opintion about Sami's and my patch?
>
> I note that it's nice to have a reference implementation for nontrivial
> things. Also, util-linux isn't the end-all and be-all of linux
> userspace: busybox has an ionice, and I plan to add an ionice
> implementation to toybox as well.
>
> So fixing reference code is good. That said, this isn't a "fix", this is
> a rewrite adding all sorts of unnecessary complexity
> (internationalization? strtos32_or_error() instead of strtol()?) that
> makes it much _less_ effective as reference code.
That makes sense. How about having simple example in linux
Documentation/ and note with reference link to util-linux
implementation. The note could tell something like 'version various
distributions package comes from util-linux, please see [git link]'.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] docs: block: update ioprio.txt
2012-06-21 4:50 ` Rob Landley
2012-06-21 6:50 ` Sami Kerola
@ 2012-06-21 10:19 ` gnehzuil.lzheng
1 sibling, 0 replies; 6+ messages in thread
From: gnehzuil.lzheng @ 2012-06-21 10:19 UTC (permalink / raw)
To: Rob Landley
Cc: Sami Kerola, Sami Kerola, Jens Axboe, Bernhard Voelker, Zheng Liu,
linux-doc, linux-kernel, util-linux
On 06/21/2012 12:50 PM, Rob Landley wrote:
> On 06/19/2012 05:27 AM, Zheng Liu wrote:
>> Hi Sami,
>>
>> [You forgot to CC'd other developers and mailing list]
>>
>> On Tue, Jun 19, 2012 at 10:54:41AM +0200, Sami Kerola wrote:
>>> Hi Zheng,
>>>
>>> Wouldn't a patch such as below be better?
>>
>> Looks good to me. But, IMHO, if reader cannot access Internet, my patch
>> maybe is better for them. The original writer is not me. So I don't
>> understand the original idea that puts ionice source code in here. I
>> think that Jens can do the final decision.
>>
>> Hi Jens,
>>
>> What's your opintion about Sami's and my patch?
>
> I note that it's nice to have a reference implementation for nontrivial
> things. Also, util-linux isn't the end-all and be-all of linux
> userspace: busybox has an ionice, and I plan to add an ionice
> implementation to toybox as well.
>
> So fixing reference code is good. That said, this isn't a "fix", this is
> a rewrite adding all sorts of unnecessary complexity
> (internationalization? strtos32_or_error() instead of strtol()?) that
> makes it much _less_ effective as reference code.
OK. I will repost a second version later.
Regards,
Zheng
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-06-21 10:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-19 8:51 [PATCH] docs: block: update ioprio.txt Zheng Liu
2012-06-19 10:19 ` Karel Zak
[not found] ` <CAG27Bk2tXprRfMfYOVdWtwSbjw5Rw9Kxs6Wns+Gm65m3hoJawg@mail.gmail.com>
2012-06-19 10:27 ` Zheng Liu
2012-06-21 4:50 ` Rob Landley
2012-06-21 6:50 ` Sami Kerola
2012-06-21 10:19 ` gnehzuil.lzheng
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).