mirror of
https://github.com/MaskRay/ccls.git
synced 2025-06-07 08:44:55 +00:00
use SCHED_BATCH scheduling priority for indexing threads
This commit is contained in:
parent
cef0203484
commit
c3fe0f4000
@ -255,6 +255,7 @@ void *indexer(void *arg_) {
|
|||||||
delete arg;
|
delete arg;
|
||||||
std::string name = "indexer" + std::to_string(idx);
|
std::string name = "indexer" + std::to_string(idx);
|
||||||
set_thread_name(name.c_str());
|
set_thread_name(name.c_str());
|
||||||
|
setBatchPriority();
|
||||||
pipeline::indexer_Main(h->manager, h->vfs, h->project, h->wfiles);
|
pipeline::indexer_Main(h->manager, h->vfs, h->project, h->wfiles);
|
||||||
pipeline::threadLeave();
|
pipeline::threadLeave();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -17,4 +17,6 @@ void freeUnusedMemory();
|
|||||||
void traceMe();
|
void traceMe();
|
||||||
|
|
||||||
void spawnThread(void *(*fn)(void *), void *arg);
|
void spawnThread(void *(*fn)(void *), void *arg);
|
||||||
|
|
||||||
|
void setBatchPriority();
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
#include "platform.hh"
|
#include "platform.hh"
|
||||||
|
|
||||||
|
#include "log.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -17,6 +18,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <sched.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -75,6 +77,26 @@ void spawnThread(void *(*fn)(void *), void *arg) {
|
|||||||
pthread_create(&thd, &attr, fn, arg);
|
pthread_create(&thd, &attr, fn, arg);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setBatchPriority() {
|
||||||
|
#ifdef SCHED_BATCH
|
||||||
|
pid_t this_thread_id = gettid();
|
||||||
|
|
||||||
|
// get a sched_param with the existing thread sched_priority
|
||||||
|
errno = 0;
|
||||||
|
struct sched_param p;
|
||||||
|
p.sched_priority = getpriority(PRIO_PROCESS, this_thread_id);
|
||||||
|
if (p.sched_priority == -1 && errno != 0) {
|
||||||
|
LOG_S(ERROR) << "failed to getpriority(): " << strerror(errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// retain the existing sched_priority, but use SCHED_BATCH policy
|
||||||
|
if (sched_setscheduler(this_thread_id, SCHED_BATCH, &p) == -1) {
|
||||||
|
LOG_S(ERROR) << "failed to sched_setscheduler(): " << strerror(errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,6 +48,8 @@ void traceMe() {}
|
|||||||
void spawnThread(void *(*fn)(void *), void *arg) {
|
void spawnThread(void *(*fn)(void *), void *arg) {
|
||||||
std::thread(fn, arg).detach();
|
std::thread(fn, arg).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setBatchPriority() {}
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user