Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client and wrapper: fix process priority mismatch #3988

Merged
merged 1 commit into from Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions client/app_start.cpp
Expand Up @@ -287,6 +287,9 @@ void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) {
FILE_REF& fref = avp->app_files[i];
aid.app_files.push_back(string(fref.file_name));
}
aid.no_priority_change = cc_config.no_priority_change;
aid.process_priority = cc_config.process_priority;
aid.process_priority_special = cc_config.process_priority_special;
}

// write the app init file.
Expand Down Expand Up @@ -509,22 +512,22 @@ static int get_priority(bool is_high_priority) {
int p = is_high_priority?cc_config.process_priority_special:cc_config.process_priority;
#ifdef _WIN32
switch (p) {
case 0: return IDLE_PRIORITY_CLASS;
case 1: return BELOW_NORMAL_PRIORITY_CLASS;
case 2: return NORMAL_PRIORITY_CLASS;
case 3: return ABOVE_NORMAL_PRIORITY_CLASS;
case 4: return HIGH_PRIORITY_CLASS;
case 5: return REALTIME_PRIORITY_CLASS;
case CONFIG_PRIORITY_LOWEST: return IDLE_PRIORITY_CLASS;
case CONFIG_PRIORITY_LOW: return BELOW_NORMAL_PRIORITY_CLASS;
case CONFIG_PRIORITY_NORMAL: return NORMAL_PRIORITY_CLASS;
case CONFIG_PRIORITY_HIGH: return ABOVE_NORMAL_PRIORITY_CLASS;
case CONFIG_PRIORITY_HIGHEST: return HIGH_PRIORITY_CLASS;
case CONFIG_PRIORITY_REALTIME: return REALTIME_PRIORITY_CLASS;
}
return is_high_priority ? BELOW_NORMAL_PRIORITY_CLASS : IDLE_PRIORITY_CLASS;
#else
switch (p) {
case 0: return PROCESS_IDLE_PRIORITY;
case 1: return PROCESS_MEDIUM_PRIORITY;
case 2: return PROCESS_NORMAL_PRIORITY;
case 3: return PROCESS_ABOVE_NORMAL_PRIORITY;
case 4: return PROCESS_HIGH_PRIORITY;
case 5: return PROCESS_REALTIME_PRIORITY;
case CONFIG_PRIORITY_LOWEST: return PROCESS_IDLE_PRIORITY;
case CONFIG_PRIORITY_LOW: return PROCESS_MEDIUM_PRIORITY;
case CONFIG_PRIORITY_NORMAL: return PROCESS_NORMAL_PRIORITY;
case CONFIG_PRIORITY_HIGH: return PROCESS_ABOVE_NORMAL_PRIORITY;
case CONFIG_PRIORITY_HIGHEST: return PROCESS_HIGH_PRIORITY;
case CONFIG_PRIORITY_REALTIME: return PROCESS_REALTIME_PRIORITY;
}
return is_high_priority ? PROCESS_MEDIUM_PRIORITY : PROCESS_IDLE_PRIORITY;
#endif
Expand Down
4 changes: 2 additions & 2 deletions lib/cc_config.cpp
Expand Up @@ -241,8 +241,8 @@ void CC_CONFIG::defaults() {
no_opencl = false;
no_priority_change = false;
os_random_only = false;
process_priority = -1;
process_priority_special = -1;
process_priority = CONFIG_PRIORITY_UNSPECIFIED;
process_priority_special = CONFIG_PRIORITY_UNSPECIFIED;
proxy_info.clear();
rec_half_life = 10*86400;
#ifdef ANDROID
Expand Down
2 changes: 1 addition & 1 deletion lib/cc_config.h
Expand Up @@ -186,7 +186,7 @@ struct CC_CONFIG {
bool no_opencl;
bool no_priority_change;
bool os_random_only;
int process_priority;
int process_priority; // values in common_defs.h
int process_priority_special;
PROXY_INFO proxy_info;
double rec_half_life;
Expand Down
13 changes: 13 additions & 0 deletions lib/common_defs.h
Expand Up @@ -79,6 +79,8 @@
#define NGRAPHICS_MSGS 7

// process priorities
// Unfortunately different areas of code use two different numbering schemes.
// The following is used in wrapper job.xml files
//
#define PROCESS_PRIORITY_UNSPECIFIED 0
#define PROCESS_PRIORITY_LOWEST 1
Expand All @@ -92,6 +94,17 @@
#define PROCESS_PRIORITY_HIGHEST 5
// win: HIGH; unix: -16

// The following is used in cc_config.xml,
// and passed to apps in the APP_INIT_DATA structure
//
#define CONFIG_PRIORITY_UNSPECIFIED -1
#define CONFIG_PRIORITY_LOWEST 0
#define CONFIG_PRIORITY_LOW 1
#define CONFIG_PRIORITY_NORMAL 2
#define CONFIG_PRIORITY_HIGH 3
#define CONFIG_PRIORITY_HIGHEST 4
#define CONFIG_PRIORITY_REALTIME 5

// priorities for client messages
//
#define MSG_INFO 1
Expand Down
10 changes: 5 additions & 5 deletions lib/proc_control.cpp
Expand Up @@ -287,11 +287,11 @@ int process_priority_value(int priority) {
return 0;
#else
switch (priority) {
case PROCESS_PRIORITY_LOWEST: return 19;
case PROCESS_PRIORITY_LOW: return 10;
case PROCESS_PRIORITY_NORMAL: return 0;
case PROCESS_PRIORITY_HIGH: return -10;
case PROCESS_PRIORITY_HIGHEST: return -16;
case PROCESS_PRIORITY_LOWEST: return PROCESS_IDLE_PRIORITY;
case PROCESS_PRIORITY_LOW: return PROCESS_MEDIUM_PRIORITY;
case PROCESS_PRIORITY_NORMAL: return PROCESS_NORMAL_PRIORITY;
case PROCESS_PRIORITY_HIGH: return PROCESS_ABOVE_NORMAL_PRIORITY;
case PROCESS_PRIORITY_HIGHEST: return PROCESS_HIGH_PRIORITY;
}
return 0;
#endif
Expand Down
5 changes: 4 additions & 1 deletion samples/wrapper/wrapper.cpp
Expand Up @@ -747,7 +747,10 @@ int TASK::run(int argct, char** argvt) {
priority_val = 0;
} else {
if (aid.process_priority > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also change this test to

if (aid.process_priority > CONFIG_PRIORITY_UNSPECIFIED) {

priority_val = process_priority_value(aid.process_priority);
// priority coming from the client is on scale where 0 is idle.
// for us, 1 is idle
//
priority_val = process_priority_value(aid.process_priority+1);
} else {
priority_val = process_priority_value(priority);
}
Expand Down