Skip to contentSkip to conversation

getpriority: Only getpriority translation the priority values

PATCH In review Theodore Dubois 4 participants 8 messages May 10, 2022 – May 18, 2022 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 getpriority: Only getpriority translation the priority values

The translation is needed to avoid returning a negative number from a successful syscall, and this requirement doesn't apply to setpriority. See the implementation of getpriority in kernel/sys.c.

---
 man2/getpriority.2 | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
getpriority.2 +4 -13
index 3e1be3e6c..24c1b7f11 100644
@@ -206,20 +206,11 @@ All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
 manner as Linux 2.6.12 and later.
 .\"
 .SS C library/kernel differences
-Within the kernel, nice values are actually represented
-using the range 40..1
-(since negative numbers are error codes) and these are the values
-employed by the
-.BR setpriority ()
-and
-.BR getpriority ()
-system calls.
-The glibc wrapper functions for these system calls handle the
-translations between the user-land and kernel representations
-of the nice value according to the formula
+The getpriority system call returns nice values translated to the range 40..1,
+since a negative return value would be interpreted as an error.
+The glibc wrapper function for getpriority translates the value back according to the formula
 .IR "unice\ =\ 20\ \-\ knice" .
-(Thus, the kernel's 40..1 range corresponds to the
-range \-20..19 as seen by user space.)
+(Thus, the 40..1 range returned by the kernel corresponds to the range \-20..19 as seen by user space.)
 .SH BUGS
 According to POSIX, the nice value is a per-process setting.
 However, under the current Linux/NPTL implementation of POSIX threads,
Signature · 1 line
2.36.0.512.ge40c2bad7a-goog
#1 lore raw
Quoted 3 lines · Theodore Dubois

The translation is needed to avoid returning a negative number from a successful syscall, and this requirement doesn't apply to setpriority. See the implementation of getpriority in kernel/sys.c.

Confirmed. See:

$ grepc -tf getpriority kernel/
./kernel/sys.c:274:
SYSCALL_DEFINE2(getpriority, int, which, int, who)
{
	...
			niceval = nice_to_rlimit(task_nice(p));
			if (niceval > retval)
				retval = niceval;
	...
	return retval;
}
$ grepc -tf setpriority kernel/
./kernel/sys.c:204:
SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
{
	...
	if (niceval < MIN_NICE)
		niceval = MIN_NICE;
	if (niceval > MAX_NICE)
		niceval = MAX_NICE;
	...
}
$ grepc -tm M.._NICE
./include/linux/sched/prio.h:5:
#define MAX_NICE	19

./include/linux/sched/prio.h:6:
#define MIN_NICE -20

$ grepc -tf nice_to_rlimit
./include/linux/sched/prio.h:32:
static inline long nice_to_rlimit(long nice)
{
	return (MAX_NICE - nice + 1);
}
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#2 lore raw
In reply to Theodore Dubois

Hi Theodore,

Quoted 5 lines · Theodore Dubois

The translation is needed to avoid returning a negative number from a successful syscall, and this requirement doesn't apply to setpriority. See the implementation of getpriority in kernel/sys.c.

Patch applied.

BTW, I had to manually edit the patch.
It's the second time I see this (I can't find the other one), your patch didn't apply for the following reason: the a/ and b/ prefixes in the file paths are missing. Did you use git-format-patch(1) to produce the patch? Can you reproduce this?

I CCd the git mailing list in case they know what's going on.

Thanks,

Alex

man2/getpriority.2

Quoted 5 lines
---
  man2/getpriority.2 | 17 ++++-------------
  1 file changed, 4 insertions(+), 13 deletions(-)
man2/getpriority.2 +0 -0

Should have been:

man2/getpriority.2 +0 -0

getpriority.2

Quoted 3 lines

index 3e1be3e6c..24c1b7f11 100644

getpriority.2 +0 -0

Should have been:

--- a/man2/getpriority.2
+++ b/man2/getpriority.2

Quoted 25 lines
getpriority.2 +4 -13
@@ -206,20 +206,11 @@ All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
  manner as Linux 2.6.12 and later.
  .\"
  .SS C library/kernel differences
-Within the kernel, nice values are actually represented
-using the range 40..1
-(since negative numbers are error codes) and these are the values
-employed by the
-.BR setpriority ()
-and
-.BR getpriority ()
-system calls.
-The glibc wrapper functions for these system calls handle the
-translations between the user-land and kernel representations
-of the nice value according to the formula
+The getpriority system call returns nice values translated to the range 40..1,
+since a negative return value would be interpreted as an error.
+The glibc wrapper function for getpriority translates the value back according to the formula
  .IR "unice\ =\ 20\ \-\ knice" .
-(Thus, the kernel's 40..1 range corresponds to the
-range \-20..19 as seen by user space.)
+(Thus, the 40..1 range returned by the kernel corresponds to the range \-20..19 as seen by user space.)
  .SH BUGS
  According to POSIX, the nice value is a per-process setting.
  However, under the current Linux/NPTL implementation of POSIX threads,
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#3 lore raw

[CC += nick]

Quoted 7 lines · Alejandro Colomar

Hi Theodore,

Quoted 4 lines · Theodore Dubois

The translation is needed to avoid returning a negative number from a successful syscall, and this requirement doesn't apply to setpriority. See the implementation of getpriority in kernel/sys.c.

Quoted 6 lines
Quoted 1 line

Patch applied.

BTW, I had to manually edit the patch.
It's the second time I see this (I can't find the other one), your patch

The other one:

<https://lore.kernel.org/linux-man/[email protected]/T/#u>

nick, I finally found it again!

Quoted 56 lines

didn't apply for the following reason: the a/ and b/ prefixes in the file paths are missing.  Did you use git-format-patch(1) to produce the patch?  Can you reproduce this?

I CCd the git mailing list in case they know what's going on.

Thanks,

Alex

man2/getpriority.2

Quoted 5 lines

---
  man2/getpriority.2 | 17 ++++-------------

  1 file changed, 4 insertions(+), 13 deletions(-)
man2/getpriority.2 +0 -0

Should have been:

man2/getpriority.2 +0 -0

getpriority.2

Quoted 4 lines

index 3e1be3e6c..24c1b7f11 100644

getpriority.2 +0 -0

Should have been:

man2/getpriority.2 +0 -0
Quoted 30 lines
getpriority.2 +0 -0
@@ -206,20 +206,11 @@ All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,

  manner as Linux 2.6.12 and later.
  .\"
  .SS C library/kernel differences

getpriority.2 +1 -11
-Within the kernel, nice values are actually represented
-using the range 40..1
-(since negative numbers are error codes) and these are the values
-employed by the
-.BR setpriority ()
-and
-.BR getpriority ()
-system calls.
-The glibc wrapper functions for these system calls handle the
-translations between the user-land and kernel representations
-of the nice value according to the formula
+The getpriority system call returns nice values translated to the 

range 40..1,

getpriority.2 +2 -0
+since a negative return value would be interpreted as an error.
+The glibc wrapper function for getpriority translates the value back 

according to the formula
  .IR "unice\ =\ 20\ \-\ knice" .

getpriority.2 +1 -2
-(Thus, the kernel's 40..1 range corresponds to the
-range \-20..19 as seen by user space.)
+(Thus, the 40..1 range returned by the kernel corresponds to the 

range \-20..19 as seen by user space.)
  .SH BUGS
  According to POSIX, the nice value is a per-process setting. However, under the current Linux/NPTL implementation of POSIX threads,

Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#4 lore raw
In reply to Alejandro Colomar
Quoted 8 lines · Alejandro Colomar

BTW, I had to manually edit the patch.
It's the second time I see this (I can't find the other one), your patch didn't apply for the following reason: the a/ and b/ prefixes in the file paths are missing. Did you use git-format-patch(1) to produce the patch? Can you reproduce this?

I CCd the git mailing list in case they know what's going on.

Sounds like git format-patch --no-prefix at play. Or more likely, that the diff.noprefix config is on. I don't think it can be cancelled out by a --no-no-prefix, unfortunately. If a script is involved in running git format-patch, maybe it's not too tedious to make it do

git -c diff.noprefix=no format-patch ...

to cancel the config. (If that config really does want to be on, that is.)

That said, something like

git am -p0 ...

should help on the receiving side, by way of skipping fewer path components when applying the patch.

Martin

#5 lore raw

Hi Martin,

Quoted 6 lines · Martin Ågren

That said, something like

   git am -p0 ...

should help on the receiving side, by way of skipping fewer path components when applying the patch.

That works for me.
Thanks!

Alex

Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#6 lore raw
In reply to Martin Ågren

Yep, I have diff.noprefix on.

~Theodore

Quoted 29 lines · Martin Ågren
Quoted 8 lines · Alejandro Colomar

BTW, I had to manually edit the patch.
It's the second time I see this (I can't find the other one), your patch didn't apply for the following reason: the a/ and b/ prefixes in the file paths are missing. Did you use git-format-patch(1) to produce the patch? Can you reproduce this?

I CCd the git mailing list in case they know what's going on.

Sounds like git format-patch --no-prefix at play. Or more likely, that the diff.noprefix config is on. I don't think it can be cancelled out by a --no-no-prefix, unfortunately. If a script is involved in running git format-patch, maybe it's not too tedious to make it do

git -c diff.noprefix=no format-patch ...

to cancel the config. (If that config really does want to be on, that is.)

That said, something like

git am -p0 ...

should help on the receiving side, by way of skipping fewer path components when applying the patch.

Martin

#7 lore raw

Perhaps we want {diff,log,format}.noprefix and friends?

Quoted 11 lines
Quoted 11 lines

git -c diff.noprefix=no format-patch ...

to cancel the config. (If that config really does want to be on, that is.)

That said, something like

git am -p0 ...

should help on the receiving side, by way of skipping fewer path components when applying the patch.

While it is very reasonable for end-users to make the output of their local "git diff" output to their taste by setting the diff.noprefix and other configuration options in the diff.* namespace, it is wrong to inflict such a personal preference on other project participants by sending such a no-prefix patch via "git format-patch", when the convention at the receiving project is to use "git am -p1" to accept them.

We would need to tweak the configuration system so that we can more easily introduce "format.noprefix" that overrides "diff.noprefix" only when the command being run is "git format-patch", perhaps?

As things stand, we could teach builtin/log.c::git_format_config() about "format.noprefix" and make "git format-patch" pay attention to that in addition to "diff.noprefix" fairly easily, but such an approach poorly scales. When a new configuration gets introduced in diff.c::git_diff_ui_config(), builtin/log.c::git_format_config() would also need to be updated.

I initially started writing this with "left over bits" mark, but it seems it is a bit larger in scope than that.

I also noticed that some format.* configuration variables are parsed in git_log_config(), not git_format_config(), so "git log" would end up honoring format.pretty and format.subjectprefix, etc., which look wrong but probably is way too late to "fix".