Fix: priority functionality not working properly (#232)
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import com.sheepit.client.Log;
|
import com.sheepit.client.Log;
|
||||||
@@ -31,11 +32,10 @@ import com.sheepit.client.hardware.cpu.CPU;
|
|||||||
|
|
||||||
public class FreeBSD extends OS {
|
public class FreeBSD extends OS {
|
||||||
private final String NICE_BINARY_PATH = "nice";
|
private final String NICE_BINARY_PATH = "nice";
|
||||||
private Boolean hasNiceBinary;
|
private final String ID_COMMAND_INVOCATION = "id -u";
|
||||||
|
|
||||||
public FreeBSD() {
|
public FreeBSD() {
|
||||||
super();
|
super();
|
||||||
this.hasNiceBinary = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
@@ -155,10 +155,7 @@ public class FreeBSD extends OS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> actual_command = command;
|
List<String> actual_command = command;
|
||||||
if (this.hasNiceBinary == null) {
|
if (checkNiceAvailability()) {
|
||||||
this.checkNiceAvailability();
|
|
||||||
}
|
|
||||||
if (this.hasNiceBinary.booleanValue()) {
|
|
||||||
// launch the process in lowest priority
|
// launch the process in lowest priority
|
||||||
if (env_overight != null) {
|
if (env_overight != null) {
|
||||||
actual_command.add(0, env_overight.get("PRIORITY"));
|
actual_command.add(0, env_overight.get("PRIORITY"));
|
||||||
@@ -183,17 +180,42 @@ public class FreeBSD extends OS {
|
|||||||
return builder.start();
|
return builder.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNiceAvailability() {
|
@Override public boolean getSupportHighPriority() {
|
||||||
|
try {
|
||||||
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
|
builder.command("bash", "-c", ID_COMMAND_INVOCATION);
|
||||||
|
builder.redirectErrorStream(true);
|
||||||
|
|
||||||
|
Process process = builder.start();
|
||||||
|
InputStream is = process.getInputStream();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
|
String userLevel = null;
|
||||||
|
if ((userLevel = reader.readLine()) != null) {
|
||||||
|
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
|
||||||
|
// to support changing the priority the nice tool must be accessible from the current user
|
||||||
|
return (userLevel.equals("0")) & checkNiceAvailability();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println(String.format("ERROR FreeBSD::getSupportHighPriority Unable to execute id command. IOException %s", e.getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean checkNiceAvailability() {
|
||||||
ProcessBuilder builder = new ProcessBuilder();
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
builder.command(NICE_BINARY_PATH);
|
builder.command(NICE_BINARY_PATH);
|
||||||
builder.redirectErrorStream(true);
|
builder.redirectErrorStream(true);
|
||||||
|
|
||||||
Process process = null;
|
Process process = null;
|
||||||
|
boolean hasNiceBinary = false;
|
||||||
try {
|
try {
|
||||||
process = builder.start();
|
process = builder.start();
|
||||||
this.hasNiceBinary = true;
|
hasNiceBinary = true;
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
this.hasNiceBinary = false;
|
|
||||||
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -201,5 +223,6 @@ public class FreeBSD extends OS {
|
|||||||
process.destroy();
|
process.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return hasNiceBinary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package com.sheepit.client.os;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -32,11 +33,10 @@ import com.sheepit.client.hardware.cpu.CPU;
|
|||||||
|
|
||||||
public class Linux extends OS {
|
public class Linux extends OS {
|
||||||
private final String NICE_BINARY_PATH = "nice";
|
private final String NICE_BINARY_PATH = "nice";
|
||||||
private Boolean hasNiceBinary;
|
private final String ID_COMMAND_INVOCATION = "id -u";
|
||||||
|
|
||||||
public Linux() {
|
public Linux() {
|
||||||
super();
|
super();
|
||||||
this.hasNiceBinary = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
@@ -155,7 +155,7 @@ public class Linux extends OS {
|
|||||||
// if Blender is already loading an OpenGL library, don't need to load Blender's default one (it will
|
// if Blender is already loading an OpenGL library, don't need to load Blender's default one (it will
|
||||||
// create system incompatibilities). If no OpenGL library is found, then load the one included in the binary
|
// create system incompatibilities). If no OpenGL library is found, then load the one included in the binary
|
||||||
// zip file
|
// zip file
|
||||||
if (isOpenGLAreadyInstalled(command.get(0)) == false) {
|
if (isOpenGLAlreadyInstalled(command.get(0)) == false) {
|
||||||
Boolean has_ld_library_path = new_env.containsKey("LD_LIBRARY_PATH");
|
Boolean has_ld_library_path = new_env.containsKey("LD_LIBRARY_PATH");
|
||||||
|
|
||||||
String lib_dir = (new File(command.get(0))).getParent() + File.separator + "lib";
|
String lib_dir = (new File(command.get(0))).getParent() + File.separator + "lib";
|
||||||
@@ -168,10 +168,7 @@ public class Linux extends OS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> actual_command = command;
|
List<String> actual_command = command;
|
||||||
if (this.hasNiceBinary == null) {
|
if (checkNiceAvailability()) {
|
||||||
this.checkNiceAvailability();
|
|
||||||
}
|
|
||||||
if (this.hasNiceBinary.booleanValue()) {
|
|
||||||
// launch the process in lowest priority
|
// launch the process in lowest priority
|
||||||
if (env_overight != null) {
|
if (env_overight != null) {
|
||||||
actual_command.add(0, env_overight.get("PRIORITY"));
|
actual_command.add(0, env_overight.get("PRIORITY"));
|
||||||
@@ -197,28 +194,41 @@ public class Linux extends OS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean getSupportHighPriority() {
|
@Override public boolean getSupportHighPriority() {
|
||||||
// only the root user can create process with high (negative nice) value
|
try {
|
||||||
String logname = System.getenv("LOGNAME");
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
String user = System.getenv("USER");
|
builder.command("bash", "-c", ID_COMMAND_INVOCATION);
|
||||||
|
builder.redirectErrorStream(true);
|
||||||
if ((logname != null && logname.equals("root")) || (user != null && user.equals("root"))) {
|
|
||||||
return true;
|
Process process = builder.start();
|
||||||
|
InputStream is = process.getInputStream();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
|
String userLevel = null;
|
||||||
|
if ((userLevel = reader.readLine()) != null) {
|
||||||
|
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
|
||||||
|
// to support changing the priority the nice tool must be accessible from the current user
|
||||||
|
return (userLevel.equals("0")) & checkNiceAvailability();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println(String.format("ERROR Linux::getSupportHighPriority Unable to execute id command. IOException %s", e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkNiceAvailability() {
|
@Override public boolean checkNiceAvailability() {
|
||||||
ProcessBuilder builder = new ProcessBuilder();
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
builder.command(NICE_BINARY_PATH);
|
builder.command(NICE_BINARY_PATH);
|
||||||
builder.redirectErrorStream(true);
|
builder.redirectErrorStream(true);
|
||||||
|
|
||||||
Process process = null;
|
Process process = null;
|
||||||
|
boolean hasNiceBinary = false;
|
||||||
try {
|
try {
|
||||||
process = builder.start();
|
process = builder.start();
|
||||||
this.hasNiceBinary = true;
|
hasNiceBinary = true;
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
this.hasNiceBinary = false;
|
|
||||||
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -226,9 +236,10 @@ public class Linux extends OS {
|
|||||||
process.destroy();
|
process.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return hasNiceBinary;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isOpenGLAreadyInstalled(String pathToRendEXE) {
|
protected boolean isOpenGLAlreadyInstalled(String pathToRendEXE) {
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||||
processBuilder.command("bash", "-c", "ldd '" + pathToRendEXE + "'"); // support for paths with an space
|
processBuilder.command("bash", "-c", "ldd '" + pathToRendEXE + "'"); // support for paths with an space
|
||||||
processBuilder.redirectErrorStream(true);
|
processBuilder.redirectErrorStream(true);
|
||||||
@@ -255,7 +266,7 @@ public class Linux extends OS {
|
|||||||
|
|
||||||
int exitCode = process.waitFor();
|
int exitCode = process.waitFor();
|
||||||
if (exitCode != 0) {
|
if (exitCode != 0) {
|
||||||
System.err.println(String.format("ERROR Linux::isOpenGLAreadyInstalled Unable to execute ldd command. Exit code %d", exitCode));
|
System.err.println(String.format("ERROR Linux::isOpenGLAlreadyInstalled Unable to execute ldd command. Exit code %d", exitCode));
|
||||||
System.err.println(String.format("Screen output from ldd execution: %s", screenOutput.toString()));
|
System.err.println(String.format("Screen output from ldd execution: %s", screenOutput.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package com.sheepit.client.os;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -30,11 +31,10 @@ import com.sheepit.client.hardware.cpu.CPU;
|
|||||||
|
|
||||||
public class Mac extends OS {
|
public class Mac extends OS {
|
||||||
private final String NICE_BINARY_PATH = "nice";
|
private final String NICE_BINARY_PATH = "nice";
|
||||||
private Boolean hasNiceBinary;
|
private final String ID_COMMAND_INVOCATION = "id -u";
|
||||||
|
|
||||||
public Mac() {
|
public Mac() {
|
||||||
super();
|
super();
|
||||||
this.hasNiceBinary = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
@@ -143,10 +143,7 @@ public class Mac extends OS {
|
|||||||
|
|
||||||
@Override public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
@Override public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||||
List<String> actual_command = command;
|
List<String> actual_command = command;
|
||||||
if (this.hasNiceBinary == null) {
|
if (checkNiceAvailability()) {
|
||||||
this.checkNiceAvailability();
|
|
||||||
}
|
|
||||||
if (this.hasNiceBinary.booleanValue()) {
|
|
||||||
// launch the process in lowest priority
|
// launch the process in lowest priority
|
||||||
if (env != null) {
|
if (env != null) {
|
||||||
actual_command.add(0, env.get("PRIORITY"));
|
actual_command.add(0, env.get("PRIORITY"));
|
||||||
@@ -172,17 +169,42 @@ public class Mac extends OS {
|
|||||||
return "/usr/local/cuda/lib/libcuda.dylib";
|
return "/usr/local/cuda/lib/libcuda.dylib";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkNiceAvailability() {
|
@Override public boolean getSupportHighPriority() {
|
||||||
|
try {
|
||||||
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
|
builder.command("bash", "-c", ID_COMMAND_INVOCATION);
|
||||||
|
builder.redirectErrorStream(true);
|
||||||
|
|
||||||
|
Process process = builder.start();
|
||||||
|
InputStream is = process.getInputStream();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
|
String userLevel = null;
|
||||||
|
if ((userLevel = reader.readLine()) != null) {
|
||||||
|
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
|
||||||
|
// to support changing the priority the nice tool must be accessible from the current user
|
||||||
|
return (userLevel.equals("0")) & checkNiceAvailability();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println(String.format("ERROR Mac::getSupportHighPriority Unable to execute id command. IOException %s", e.getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean checkNiceAvailability() {
|
||||||
ProcessBuilder builder = new ProcessBuilder();
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
builder.command(NICE_BINARY_PATH);
|
builder.command(NICE_BINARY_PATH);
|
||||||
builder.redirectErrorStream(true);
|
builder.redirectErrorStream(true);
|
||||||
|
|
||||||
Process process = null;
|
Process process = null;
|
||||||
|
boolean hasNiceBinary = false;
|
||||||
try {
|
try {
|
||||||
process = builder.start();
|
process = builder.start();
|
||||||
this.hasNiceBinary = true;
|
hasNiceBinary = true;
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
this.hasNiceBinary = false;
|
|
||||||
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -190,5 +212,6 @@ public class Mac extends OS {
|
|||||||
process.destroy();
|
process.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return hasNiceBinary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ public abstract class OS {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSupportHighPriority() {
|
public abstract boolean getSupportHighPriority();
|
||||||
return true;
|
|
||||||
}
|
public abstract boolean checkNiceAvailability();
|
||||||
|
|
||||||
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||||
ProcessBuilder builder = new ProcessBuilder(command);
|
ProcessBuilder builder = new ProcessBuilder(command);
|
||||||
|
|||||||
@@ -218,4 +218,13 @@ public class Windows extends OS {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean getSupportHighPriority() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean checkNiceAvailability() {
|
||||||
|
// In windows, nice is not required and therefore we return always true to show the slider in the Settings GUI
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -406,6 +406,10 @@ public class Settings implements Activity {
|
|||||||
priority.setValue(config.getPriority());
|
priority.setValue(config.getPriority());
|
||||||
JLabel priorityLabel = new JLabel(high_priority_support ? "Priority (High <-> Low):" : "Priority (Normal <-> Low):");
|
JLabel priorityLabel = new JLabel(high_priority_support ? "Priority (High <-> Low):" : "Priority (Normal <-> Low):");
|
||||||
|
|
||||||
|
boolean showPrioritySlider = os.checkNiceAvailability();
|
||||||
|
priority.setVisible(showPrioritySlider);
|
||||||
|
priorityLabel.setVisible(showPrioritySlider);
|
||||||
|
|
||||||
compute_devices_constraints.weightx = 1.0 / gpus.size();
|
compute_devices_constraints.weightx = 1.0 / gpus.size();
|
||||||
compute_devices_constraints.gridx = 0;
|
compute_devices_constraints.gridx = 0;
|
||||||
compute_devices_constraints.gridy++;
|
compute_devices_constraints.gridy++;
|
||||||
|
|||||||
Reference in New Issue
Block a user