Author: Sam McCall Date: 2022-05-17T20:17:07+02:00 New Revision: 127a1492d72902e2b2cd8905c1198743761f52fb
URL: https://github.com/llvm/llvm-project/commit/127a1492d72902e2b2cd8905c1198743761f52fb DIFF: https://github.com/llvm/llvm-project/commit/127a1492d72902e2b2cd8905c1198743761f52fb.diff LOG: [clangd] Add command-line flag to set background indexing thread priority. This is a followup to D124715, which changed the default, and it anticipates future patches raising the priority of Low (which is currently equal to Background on Windows & Linux). The main point is to allow users to restore the old behavior, which e.g. allows efficiency cores to remain idle. I did consider making this a config setting, this is a more complicated change: - needs to touch queue priorities as well as thread priorities - we don't know the priority until evaluating the config inside the task - users would want the ability to prioritize background indexing tasks relative to each other without necessarily affecting thread priority, so using one option for both may be confusing I don't really have a use case, so I prefer the simpler thing. Differential Revision: https://reviews.llvm.org/D125673 Added: Modified: clang-tools-extra/clangd/ClangdServer.h clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/Background.h clang-tools-extra/clangd/tool/ClangdMain.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h index d1854c5f903ef..6d999722805ed 100644 --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -110,6 +110,7 @@ class ClangdServer { /// If true, ClangdServer automatically indexes files in the current project /// on background threads. The index is stored in the project root. bool BackgroundIndex = false; + llvm::ThreadPriority BackgroundIndexPriority = llvm::ThreadPriority::Low; /// If set, use this index to augment code completion results. SymbolIndex *StaticIndex = nullptr; diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp index 71860a3a4bcd2..b5349468eb24f 100644 --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -92,6 +92,7 @@ BackgroundIndex::BackgroundIndex( const ThreadsafeFS &TFS, const GlobalCompilationDatabase &CDB, BackgroundIndexStorage::Factory IndexStorageFactory, Options Opts) : SwapIndex(std::make_unique<MemIndex>()), TFS(TFS), CDB(CDB), + IndexingPriority(Opts.IndexingPriority), ContextProvider(std::move(Opts.ContextProvider)), IndexedSymbols(IndexContents::All), Rebuilder(this, &IndexedSymbols, Opts.ThreadPoolSize), @@ -165,6 +166,7 @@ BackgroundQueue::Task BackgroundIndex::indexFileTask(std::string Path) { elog("Indexing {0} failed: {1}", Path, std::move(Error)); }); T.QueuePri = IndexFile; + T.ThreadPri = IndexingPriority; T.Tag = std::move(Tag); T.Key = Key; return T; diff --git a/clang-tools-extra/clangd/index/Background.h b/clang-tools-extra/clangd/index/Background.h index 97f9095ed2c23..688c09814cd25 100644 --- a/clang-tools-extra/clangd/index/Background.h +++ b/clang-tools-extra/clangd/index/Background.h @@ -136,6 +136,8 @@ class BackgroundIndex : public SwapIndex { // Arbitrary value to ensure some concurrency in tests. // In production an explicit value is specified. size_t ThreadPoolSize = 4; + // Thread priority when indexing files. + llvm::ThreadPriority IndexingPriority = llvm::ThreadPriority::Low; // Callback that provides notifications as indexing makes progress. std::function<void(BackgroundQueue::Stats)> OnProgress = nullptr; // Function called to obtain the Context to use while indexing the specified @@ -194,6 +196,7 @@ class BackgroundIndex : public SwapIndex { // configuration const ThreadsafeFS &TFS; const GlobalCompilationDatabase &CDB; + llvm::ThreadPriority IndexingPriority; std::function<Context(PathRef)> ContextProvider; llvm::Error index(tooling::CompileCommand); diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index d86b5dab51e99..76cfaf7a35dfe 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -169,6 +169,21 @@ opt<bool> EnableBackgroundIndex{ init(true), }; +opt<llvm::ThreadPriority> BackgroundIndexPriority{ + "background-index-priority", + cat(Features), + desc("Thread priority for building the background index. " + "The effect of this flag is OS-specific."), + values(clEnumValN(llvm::ThreadPriority::Background, "background", + "Minimum priority, runs on idle CPUs. " + "May leave 'performance' cores unused."), + clEnumValN(llvm::ThreadPriority::Low, "low", + "Reduced priority compared to interactive work."), + clEnumValN(llvm::ThreadPriority::Default, "normal", + "Same priority as other clangd work.")), + init(llvm::ThreadPriority::Low), +}; + opt<bool> EnableClangTidy{ "clang-tidy", cat(Features), @@ -876,6 +891,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var } #endif Opts.BackgroundIndex = EnableBackgroundIndex; + Opts.BackgroundIndexPriority = BackgroundIndexPriority; Opts.ReferencesLimit = ReferencesLimit; auto PAI = createProjectAwareIndex(loadExternalIndex, Sync); if (StaticIdx) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits