From c9a0c7c15615ce7108df7d379d30185e0785d657 Mon Sep 17 00:00:00 2001 From: Jan Pedersen Date: Mon, 19 Jan 2026 12:16:53 +0100 Subject: [PATCH] support niceness for local bulids --- client/main.cpp | 11 ++++++++++- daemon/main.cpp | 1 + services/comm.cpp | 6 ++++++ services/comm.h | 8 +++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/client/main.cpp b/client/main.cpp index ae381712..4032e92e 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -121,6 +121,15 @@ static void icerun_show_usage() "\n"); } +static int get_niceness() +{ + errno = 0; + int niceness = getpriority( PRIO_PROCESS, getpid()); + if( niceness == -1 && errno != 0 ) + niceness = 0; + return niceness; +} + volatile bool local = false; static void dcc_client_signalled(int whichsig) @@ -591,7 +600,7 @@ int main(int argc, char **argv) Msg *startme = nullptr; /* Inform the daemon that we like to start a job. */ - if (local_daemon->send_msg(JobLocalBeginMsg(0, get_absfilename(job.outputFile()),fulljob))) { + if (local_daemon->send_msg(JobLocalBeginMsg(0, get_absfilename(job.outputFile()),fulljob,get_niceness()))) { /* Now wait until the daemon gives us the start signal. 40 minutes should be enough for all normal compile or link jobs, but with expensive jobs (which fulljobs may likely be, e.g. LTO linking) use an even larger timeout. */ diff --git a/daemon/main.cpp b/daemon/main.cpp index 2b9082f3..655e01f6 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -1872,6 +1872,7 @@ bool Daemon::handle_local_job(Client *client, Msg *msg) { JobLocalBeginMsg* m = dynamic_cast(msg); client->status = Client::LINKJOB; + client->niceness = m->niceness; client->outfile = m->outfile; client->fulljob = m->fulljob; return true; diff --git a/services/comm.cpp b/services/comm.cpp index c43732d5..445d8b1d 100644 --- a/services/comm.cpp +++ b/services/comm.cpp @@ -2286,6 +2286,9 @@ void JobLocalBeginMsg::fill_from_channel(MsgChannel *c) *c >> full; fulljob = full; } + if (IS_PROTOCOL_VERSION(45, c)) { + *c >> niceness; + } } void JobLocalBeginMsg::send_to_channel(MsgChannel *c) const @@ -2297,6 +2300,9 @@ void JobLocalBeginMsg::send_to_channel(MsgChannel *c) const if (IS_PROTOCOL_VERSION(44, c)) { *c << (uint32_t) fulljob; } + if (IS_PROTOCOL_VERSION(45, c)) { + *c << niceness; + } } void JobLocalDoneMsg::fill_from_channel(MsgChannel *c) diff --git a/services/comm.h b/services/comm.h index 0727251d..9e7d265f 100644 --- a/services/comm.h +++ b/services/comm.h @@ -36,7 +36,7 @@ #include "job.h" // if you increase the PROTOCOL_VERSION, add a macro below and use that -#define PROTOCOL_VERSION 44 +#define PROTOCOL_VERSION 45 // if you increase the MIN_PROTOCOL_VERSION, comment out macros below and clean up the code #define MIN_PROTOCOL_VERSION 21 @@ -740,12 +740,13 @@ class JobDoneMsg : public Msg class JobLocalBeginMsg : public Msg { public: - JobLocalBeginMsg(int job_id = 0, const std::string &file = "", bool full = false) + JobLocalBeginMsg(int job_id = 0, const std::string &file = "", bool full = false, uint32_t _niceness = 0) : Msg(Msg::JOB_LOCAL_BEGIN) , outfile(file) , stime(time(0)) , id(job_id) - , fulljob(full) {} + , fulljob(full) + , niceness(_niceness) {} virtual void fill_from_channel(MsgChannel *c); virtual void send_to_channel(MsgChannel *c) const; @@ -754,6 +755,7 @@ class JobLocalBeginMsg : public Msg uint32_t stime; uint32_t id; bool fulljob; + uint32_t niceness; // nice priority (0-20) }; class JobLocalDoneMsg : public Msg