[haiku-commits] Change in ...haiku[r1beta1]: libroot: add [gs]etpriority implementation

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 28 Jun 2019 20:26:29 +0000

From Calvin Hill <mr_j.c.h@xxxxxxxxxxx>:

Hello waddlesplash, Jérôme Duval,

I'd like you to do a code review. Please visit

    https://review.haiku-os.org/c/haiku/+/1538

to review the following change.


Change subject: libroot: add [gs]etpriority implementation
......................................................................

libroot: add [gs]etpriority implementation

Implemented against POSIX-1.2013.

The implementation POSIX requirement thats setpriority() shall affect the
priority of all system scope threads only extends to POSIX threads. This
is implemented by modifying the default attributes for newly spawned
pthreads.

It is not possible to modify the default pthread attributes for different
processes with the current implementation, as default pthread attributes
are implemented in user-space. As a result, PRIO_PROCESS for which and 0
for who is the only supported combination for setpriority().

While it is possible to move the default attributes to the kernel, it
is chosen not to so as to keep the pthread implementation user-space only.

POSIX requires that lowering the nice value (increasing priority) can be
done only by processes with appropriate privileges. However, as Haiku
currently doesn't harbor any restrictions in setting the thread priority,
this is not implemented.

It is possible to have small precision errors when converting from Unix-
style thread priority to Be-style. For example, the following program
outputs "17" instead of the expected "18":

        #include <stdio.h>
        #include <sys/resource.h>

        int
        main()
        {
                setpriority(PRIO_PROCESS, 0, 18);
                printf("%d\n", getpriority(PRIO_PROCESS, 0));
                return 0;
        }

The underlying reason is because when you setpriority() both 18 and 19
are converted to the Be-style "2". This problem should not happen with
priority levels lower than or equal to 20, when the Be notation is more
precise than the Unix-style.

Done as a part of GCI 2014. Fixes #2817.

Signed-off-by: Timothy Gu <timothygu99@xxxxxxxxx>
Co-authored-by: Leorize <leorize+oss@xxxxxxxxxxx>
Change-Id: Ie14f105b00fe8563d16b3562748e1c2e56c873a6
Reviewed-on: https://review.haiku-os.org/c/78
Reviewed-by: Jérôme Duval <jerome.duval@xxxxxxxxx>
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
---
M headers/posix/limits.h
M headers/posix/sys/resource.h
M headers/private/libroot/pthread_private.h
M src/system/libroot/posix/pthread/pthread.cpp
M src/system/libroot/posix/sys/Jamfile
A src/system/libroot/posix/sys/priority.c
6 files changed, 210 insertions(+), 5 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/38/1538/1
--
To view, visit https://review.haiku-os.org/c/haiku/+/1538
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: r1beta1
Gerrit-Change-Id: Ie14f105b00fe8563d16b3562748e1c2e56c873a6
Gerrit-Change-Number: 1538
Gerrit-PatchSet: 1
Gerrit-Owner: Calvin Hill <mr_j.c.h@xxxxxxxxxxx>
Gerrit-Reviewer: Jérôme Duval <jerome.duval@xxxxxxxxx>
Gerrit-Reviewer: waddlesplash <waddlesplash@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in ...haiku[r1beta1]: libroot: add [gs]etpriority implementation - Gerrit