public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Re: [patch] nice.2: wfix
       [not found] <53fb2366-517c-9f76-982f-ac2d16d3476c@1a-insec.net>
@ 2022-12-11 17:33 ` Alejandro Colomar
  2022-12-14 15:28   ` Jakub Wilk
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2022-12-11 17:33 UTC (permalink / raw)
  To: GNU C Library; +Cc: linux-man, i+linux, Alejandro Colomar


[-- Attachment #1.1: Type: text/plain, Size: 1206 bytes --]

Hi glibc developers,

On 11/2/22 02:50, i+linux@1a-insec.net wrote:
> nice(2) in glibc uses `setpriority(PRIO_PROCESS, x)`. I think "thread" means 
> pthread more, so "process" is the better word here.
> 
> The patch is below:
> 
> 
>  From 835c33dbc72abec02d49a5ac6b1b16e4d39a599b Mon Sep 17 00:00:00 2001
> From: Locria Cyber <74560659+locriacyber@users.noreply.github.com>
> Date: Tue, 1 Nov 2022 06:10:16 +0000
> Subject: [PATCH] nice.2 tfix
> Signed-off-by: Locria Cyber <i+linux@1a.insec.net>

I never used this syscall.  Could any of you please review this patch?

Cheers,

Alex

> 
> ---
>   man2/nice.2 | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man2/nice.2 b/man2/nice.2
> index f4e2406..2ecd743 100644
> --- a/man2/nice.2
> +++ b/man2/nice.2
> @@ -36,7 +36,7 @@ Feature Test Macro Requirements for glibc (see
>   .BR nice ()
>   adds
>   .I inc
> -to the nice value for the calling thread.
> +to the nice value for the calling process.
>   (A higher nice value means a lower priority.)
>   .PP
>   The range of the nice value is +19 (low priority) to \-20 (high priority).

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] nice.2: wfix
  2022-12-11 17:33 ` [patch] nice.2: wfix Alejandro Colomar
@ 2022-12-14 15:28   ` Jakub Wilk
  2022-12-14 17:38     ` Alejandro Colomar
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Wilk @ 2022-12-14 15:28 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: libc-alpha, linux-man, i+linux

[-- Attachment #1: Type: text/plain, Size: 929 bytes --]

* Alejandro Colomar <alx.manpages@gmail.com>, 2022-12-11 18:33:
>>-to the nice value for the calling thread.
>>+to the nice value for the calling process.

nice() affecting the whole process, not just the calling thread, is what 
POSIX requires, and what glibc documents, but it's not actually how it 
works on Linux at the moment[*].

This is documented in the setpriority(2) man page:

"According to POSIX, the nice value is a per-process setting. However, 
under the current Linux/NPTL implementation of POSIX threads, the nice 
value is a per-thread attribute: different threads in the same process 
can have different nice values. Portable applications should avoid 
relying on the Linux behavior, which may be made standards conformant in 
the future."

It would be prudent to document this bug in the nice(2) man page too.


[*] I've tested this with Linux 6.0 + glibc 2.36.
See the attached test program.

-- 
Jakub Wilk

[-- Attachment #2: test-nice.c --]
[-- Type: text/x-csrc, Size: 563 bytes --]

#define _GNU_SOURCE

#include <inttypes.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static void print_nice()
{
    printf("[%jd] nice = %d\n", (intmax_t) gettid(), nice(0));
}

static void* thread(void *arg)
{
    print_nice();
    nice(17);
    print_nice();
    return NULL;
}

int main(int argc, char **argv)
{
    pthread_t pt;
    print_nice();
    int rc = pthread_create(&pt, NULL, thread, NULL);
    if (rc < 0)
        abort();
    rc = pthread_join(pt, NULL);
    if (rc < 0)
        abort();
    print_nice();
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] nice.2: wfix
  2022-12-14 15:28   ` Jakub Wilk
@ 2022-12-14 17:38     ` Alejandro Colomar
  2022-12-14 17:39       ` Alejandro Colomar
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2022-12-14 17:38 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: libc-alpha, linux-man, i+linux


[-- Attachment #1.1: Type: text/plain, Size: 1196 bytes --]

Hi Jakub!

On 12/14/22 16:28, Jakub Wilk wrote:
> * Alejandro Colomar <alx.manpages@gmail.com>, 2022-12-11 18:33:
>>> -to the nice value for the calling thread.
>>> +to the nice value for the calling process.
> 
> nice() affecting the whole process, not just the calling thread, is what POSIX 
> requires, and what glibc documents, but it's not actually how it works on Linux 
> at the moment[*].
> 
> This is documented in the setpriority(2) man page:
> 
> "According to POSIX, the nice value is a per-process setting. However, under the 
> current Linux/NPTL implementation of POSIX threads, the nice value is a 
> per-thread attribute: different threads in the same process can have different 
> nice values. Portable applications should avoid relying on the Linux behavior, 
> which may be made standards conformant in the future."
> 
> It would be prudent to document this bug in the nice(2) man page too.
> 
> 
> [*] I've tested this with Linux 6.0 + glibc 2.36.
> See the attached test program.

I think that patch would be a great example for the page.  Would you mind 
sending it as a patch?

Thanks,

Alex

> 

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] nice.2: wfix
  2022-12-14 17:38     ` Alejandro Colomar
@ 2022-12-14 17:39       ` Alejandro Colomar
  0 siblings, 0 replies; 4+ messages in thread
From: Alejandro Colomar @ 2022-12-14 17:39 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: libc-alpha, linux-man, i+linux


[-- Attachment #1.1: Type: text/plain, Size: 1309 bytes --]



On 12/14/22 18:38, Alejandro Colomar wrote:
> Hi Jakub!
> 
> On 12/14/22 16:28, Jakub Wilk wrote:
>> * Alejandro Colomar <alx.manpages@gmail.com>, 2022-12-11 18:33:
>>>> -to the nice value for the calling thread.
>>>> +to the nice value for the calling process.
>>
>> nice() affecting the whole process, not just the calling thread, is what POSIX 
>> requires, and what glibc documents, but it's not actually how it works on 
>> Linux at the moment[*].
>>
>> This is documented in the setpriority(2) man page:
>>
>> "According to POSIX, the nice value is a per-process setting. However, under 
>> the current Linux/NPTL implementation of POSIX threads, the nice value is a 
>> per-thread attribute: different threads in the same process can have different 
>> nice values. Portable applications should avoid relying on the Linux behavior, 
>> which may be made standards conformant in the future."
>>
>> It would be prudent to document this bug in the nice(2) man page too.
>>
>>
>> [*] I've tested this with Linux 6.0 + glibc 2.36.
>> See the attached test program.
> 
> I think that patch would be a great example for the page.  Would you mind 

s/patch/program/

> sending it as a patch?
> 
> Thanks,
> 
> Alex
> 
>>
> 

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-14 17:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <53fb2366-517c-9f76-982f-ac2d16d3476c@1a-insec.net>
2022-12-11 17:33 ` [patch] nice.2: wfix Alejandro Colomar
2022-12-14 15:28   ` Jakub Wilk
2022-12-14 17:38     ` Alejandro Colomar
2022-12-14 17:39       ` Alejandro Colomar

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 read-only IMAP folder(s) and NNTP newsgroup(s).