mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8215962: Support ThreadPriorityPolicy mode 1 for non-root users on linux/bsd
Reviewed-by: dcubed, dholmes
This commit is contained in:
parent
839d71f4ca
commit
db1518dae2
3 changed files with 15 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -2256,7 +2256,8 @@ void os::naked_yield() {
|
|||
// not the entire user process, and user level threads are 1:1 mapped to kernel
|
||||
// threads. It has always been the case, but could change in the future. For
|
||||
// this reason, the code should not be used as default (ThreadPriorityPolicy=0).
|
||||
// It is only used when ThreadPriorityPolicy=1 and requires root privilege.
|
||||
// It is only used when ThreadPriorityPolicy=1 and may require system level permission
|
||||
// (e.g., root privilege or CAP_SYS_NICE capability).
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
int os::java_to_os_priority[CriticalPriority + 1] = {
|
||||
|
@ -2303,14 +2304,12 @@ int os::java_to_os_priority[CriticalPriority + 1] = {
|
|||
|
||||
static int prio_init() {
|
||||
if (ThreadPriorityPolicy == 1) {
|
||||
// Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1
|
||||
// if effective uid is not root. Perhaps, a more elegant way of doing
|
||||
// this is to test CAP_SYS_NICE capability, but that will require libcap.so
|
||||
if (geteuid() != 0) {
|
||||
if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) {
|
||||
warning("-XX:ThreadPriorityPolicy requires root privilege on Bsd");
|
||||
warning("-XX:ThreadPriorityPolicy=1 may require system level permission, " \
|
||||
"e.g., being the root user. If the necessary permission is not " \
|
||||
"possessed, changes to priority will be silently ignored.");
|
||||
}
|
||||
ThreadPriorityPolicy = 0;
|
||||
}
|
||||
}
|
||||
if (UseCriticalJavaThreadPriority) {
|
||||
|
@ -2327,6 +2326,7 @@ OSReturn os::set_native_priority(Thread* thread, int newpri) {
|
|||
return OS_OK;
|
||||
#elif defined(__FreeBSD__)
|
||||
int ret = pthread_setprio(thread->osthread()->pthread_id(), newpri);
|
||||
return (ret == 0) ? OS_OK : OS_ERR;
|
||||
#elif defined(__APPLE__) || defined(__NetBSD__)
|
||||
struct sched_param sp;
|
||||
int policy;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue