Commit Graph

72 Commits

Author SHA1 Message Date
Qais Yousef ee3f4a3dfc Move sched_attr struct and syscall definitions into header file
So that we can re-use them in other files.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
2021-01-30 17:13:17 +00:00
Karel Zak 865f5f469c chrt: don't restrict --reset-on-fork, add more info to man page
The flag works (= kernel accepts it) for all scheduling policies
and sched_getattr() returns the flag for all policies.

There is no reason for userspace to be more smart than kernel or hide
the flag when it prints sched_getattr()/sched_getscheduler() results.

 # chrt -v --reset-on-fork --batch 0 /bin/true
 pid 1315019's new scheduling policy: SCHED_BATCH|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --fifo 1 /bin/true
 pid 1315055's new scheduling policy: SCHED_FIFO|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --deadline --sched-period 10000 0 /bin/true
 pid 1315182's new scheduling policy: SCHED_DEADLINE|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --idle 0 /bin/true
 pid 1315247's new scheduling policy: SCHED_IDLE|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --rr 1 /bin/true
 pid 1315275's new scheduling policy: SCHED_RR|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --other 0 /bin/true
 pid 1315311's new scheduling policy: SCHED_OTHER|SCHED_RESET_ON_FORK

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-01 11:51:12 +02:00
Karel Zak 240634f80c chrt: use SCHED_FLAG_RESET_ON_FORK for sched_setattr()
Reviewed by many people, used for years (but probably nobody uses
SCHED_DEADLINE with reset-on-fork), but we all missed:

- sched_setscheduler() uses SCHED_RESET_ON_FORK (0x40000000)
- sched_setattr() uses SCHED_FLAG_RESET_ON_FORK (0x01)

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1883013
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-01 10:40:27 +02:00
jonnyh64 fcc3078754 chrt: Use sched_setscheduler system call directly
musl libc does not support the sched_setscheduler library function
because the underlying Linux system call does not confirm to Posix;
this patch makes chrt use the system call directly

[kzak@redhat.com:
    - note that musl libc implements sched_setscheduler()
      but returns -ENOSYS all time...
    - add ifdefs to the patch
    - make sure we include syscall.h]

References: http://git.musl-libc.org/cgit/musl/commit/src/sched/sched_setscheduler.c?id=1e21e78bf7a5c24c217446d8760be7b7188711c2
Addresses: https://github.com/karelzak/util-linux/issues/943
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-30 10:45:32 +01:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak 685f544918 chrt: fix compiler warning [-Wmaybe-uninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-20 10:43:32 +01:00
Karel Zak 61b6222269 schedutils: use errexec()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:40:59 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 5118d1be2a misc: never use usage(ERROR)
We are using better/shorter error messages and somtimes
also errtryhelp().

Here we fix all cases where the usage function took
an int argument for exit_code.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Andreas Henriksson c7adc2f204 chrt: default to SCHED_RR policy
This fixes a regression introduced in:

commit 7a4ea5664e
"chrt: add control struct"

Previously (and as documented in the manpage) the default policy
was SCHED_RR. Now it's implicitly SCHED_OTHER (0) as the value
is not initialized explicitly anymore.

Test-command: chrt 90 echo hello

Reported-by: Patrick Pelissier <patrick.pelissier@gmail.com>
Addresses: http://bugs.debian.org/846572
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2016-12-05 13:07:50 +01:00
Ruediger Meier fded05ac81 chrt: fix HAVE_SCHED_SETATTR fallback case
Broken since 6f27e449. We could not enter the fallback
if HAVE_SCHED_SETATTR is not defined.

Two gcc warnings made this issue visible:
  schedutils/chrt.c:247:1: warning: label 'fallback' defined but not used [-Wunused-label]
  schedutils/chrt.c:266:9: warning: 'policy' may be used uninitialized in this function [-Wuninitialized]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 11:03:21 +02:00
Karel Zak 88b60f0bde chrt: follow nice setting, prefer sched_setscheduler()
* do not reset 'nice' setting by sched_setattr(), if 'nice' setting
  is not zero then chrt ends with EPERM for non-root users:

  $ renice -n 5 -p $$; chrt -v -b 0 date
  12475 (process ID) old priority 0, new priority 5
  chrt: failed to set pid 0's policy: Operation not permitted

* it seems more elegant to always use old sched_setscheduler() API for
  non-deadline policies; in this case we do not need getpriority()
  to keep 'nice' unchanged.

Addresses: https://github.com/karelzak/util-linux/issues/359
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-03 11:02:35 +02:00
Karel Zak 6f27e449a9 chrt: add fallback to be usable on kernels without sched_{get,set}attr
We have fallback for compilation with/without proper glibc and kernel
headers, but it's not enough, because people can switch between
kernels with and without the syscalls. (For example RT kernels for
RHEL/CentOS).

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1353340
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-11 15:33:46 +02:00
Karel Zak 078720a76f tests: add chrt test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-11 10:25:13 +02:00
Sami Kerola 2e31d1c3a5 chrt: validate priority before trying to use it
Earlier message:

$ chrt -i 1 ls
chrt: failed to set pid 0's policy: Invalid argument

basically told 'something failed', while the new one tries to be more
helpful.

$ chrt -i 1 ls
chrt: unsupported priority value for the policy: 1: see --max for valid range

Addresses: https://bugs.debian.org/791707
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-13 12:29:16 +02:00
Sami Kerola b3a5067148 chrt: make --sched-* short options to require an argument
These options are expecting an argument, and the long options struct already
required them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-04 10:26:03 +02:00
Ruediger Meier a03eac5294 chrt: restore removed ifdef SCHED_RESET_ON_FORK
They got lost in acde3a05.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-24 12:46:20 +01:00
Ruediger Meier 59e4a3827b chrt: fix case SCHED_RR
Looks like the logic was mistakenly changed in acde3a05.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-24 12:46:20 +01:00
Karel Zak acde3a05a9 chrt: use sched_getattr() 2016-01-20 15:32:30 +01:00
Karel Zak 1a7e63950b chrt: add support for SCHED_DEADLINE
This patch introduces

	-d, --deadline
	-T, --sched-runtime
	-D, --sched-deadline
	-P, --sched-period

command line options. The functionality is available only for Linux with
sched_setattr() [kernel >=3.14]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-20 14:04:32 +01:00
Karel Zak 15167589fb chrt: use sched_setattr() if available
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-20 12:44:27 +01:00
Karel Zak a6fec53788 chrt: make usage more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-19 14:52:51 +01:00
Karel Zak 4820a7373a chrt: set function refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-19 14:46:30 +01:00
Karel Zak a30cf65076 chrt: output function refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-19 14:38:18 +01:00
Karel Zak 7a4ea5664e chrt: add control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-19 14:24:53 +01:00
Benno Schulenberg 9acbe2aa47 chrt: slice up the usage text and normalize its layout
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-06-15 15:06:36 +02:00
Benno Schulenberg 4e4bc0c801 chrt: make the usage synopsis clearer
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-06-15 15:06:35 +02:00
Karel Zak 3fabc3637c chrt: fix --help inconsistency
Reported-by: Martin Steigerwald <ms@teamix.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-09 11:16:45 +02:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola a587cc5520 textual: use manual tail usage() macro
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:24 +02:00
Sami Kerola f627750083 textual: use version printing macro everywhere
Only mount, umount, and blkid remains not using the macro because they
are print also library references.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:23 +02:00
Benno Schulenberg a7560c0655 textual: make the license of chrt and taskset slightly more explicit
This makes it match the license of the man pages.
While there, also tweak some other comment lines.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-08-20 10:47:09 +02:00
Benno Schulenberg 4ce393f4d8 textual: fix several typos and angular brackets in messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:11:14 +02:00
Sami Kerola fdf8fb1cc0 chrt: make command syntax easier to understand in usage()
And mention in manual that the default is referring to the internal
default of this command, not the Linux system default.  Manual page
example also tries to be a little more complete how to use the command.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-05 13:56:17 +02:00
Sami Kerola 07ff972eb6 translation: unify exec error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:17 +01:00
Benno Schulenberg 8c219bf463 textual: gettextize several overlooked messages
Also improve the clarity of some of them.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:29 +01:00
Yuri Chornoivan bbac757b1e textual: fix typos in messages 2012-09-04 17:26:31 +02:00
Karel Zak 630ed89d5a schedutils: cleanup strtoxx_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 17:45:05 +02:00
Sami Kerola ed8ec2a65d schedutils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:51:32 +02:00
Sami Kerola 7cebf0bb4f docs: corrections to FSF license files, and postal address
The COPYING and Documentation/licenses/COPYING* files are being
replaced by files from GNU web site.

http://www.gnu.org/licenses/gpl-2.0.txt
http://www.gnu.org/licenses/lgpl-2.1.txt

Postal addresses to FSF in other files are updated to match with the
address in license files.

Reference: http://lists.gnu.org/archive/html/freefont-announce/2005-04/msg00001.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-24 14:13:35 +01:00
Karel Zak 337b8eade0 chrt: add comment to keep static analysers happy 2012-01-31 21:16:28 +01:00
Karel Zak c150589fce chrt: silently ignore -R if unsupported
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-02 14:29:03 +02:00
Sami Kerola 8a44fb011d chrt: add strings to use NLS
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-21 17:32:28 +02:00
Sami Kerola 110d680af8 chrt: coding style fix
Make horizontal list vertical and few other enhancements to
readability.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-07-21 15:53:44 +02:00
Sami Kerola 90b7d261b9 chrt: data type compiler warning fixed
chrt.c:158:16: warning: comparison of integers of different
	signs: 'int' and 'unsigned long' [-Wsign-compare]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-07-21 15:52:25 +02:00
Davidlohr Bueso 1b9b57ace5 chrt: clarify use of -a option
With this option we can operate on all the thread group of a process not just
for changes, but also when obtaining information via sched_getscheduler().

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2011-05-17 16:29:59 +02:00
Karel Zak 503cbbe1d4 chrt: allow to use --all-tasks when retrieve info
master thread:
 $ chrt --pid $(pidof firefox)

all threads:
 $ chrt --all-tasks --pid $(pidof firefox)

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-05 14:23:38 +02:00
Davidlohr Bueso 78904e7647 chrt: make threads aware
Currently this program works only with the master thread. Add a '-t'
option to propagate changes to the entire group of threads.

Example:

root@offworld:~/projects/util-linux/schedutils# ls /proc/2111/task/
2111  2112  2119  2121  2138  2139  2159  2160
root@offworld:~/projects/util-linux/schedutils# ./chrt -p 2111
pid 2111's current scheduling policy: SCHED_RR
pid 2111's current scheduling priority: 3
root@offworld:~/projects/util-linux/schedutils# ./chrt -t -p 2 2111
root@offworld:~/projects/util-linux/schedutils# ./chrt -p 2112
pid 2112's current scheduling policy: SCHED_RR
pid 2112's current scheduling priority: 2
root@offworld:~/projects/util-linux/schedutils# ./chrt -p 2111
pid 2111's current scheduling policy: SCHED_RR
pid 2111's current scheduling priority: 2

[kzak@redhat.com: - rename -t/--thread to -a/--all-tasks]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-05 14:02:34 +02:00