Skip to content

Commit 6d8ed84

Browse files
committed
[AutoBump] Merge with 50b1534 (Jun 27)
2 parents 7d62407 + 50b1534 commit 6d8ed84

File tree

1,230 files changed

+105843
-47723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,230 files changed

+105843
-47723
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ clang/test/AST/Interp/ @tbaederr
6464
/mlir/Dialect/*/Transforms/Bufferize.cpp @matthias-springer
6565

6666
# Linalg Dialect in MLIR.
67-
/mlir/include/mlir/Dialect/Linalg/* @dcaballe @nicolasvasilache @rengolin
68-
/mlir/lib/Dialect/Linalg/* @dcaballe @nicolasvasilache @rengolin
67+
/mlir/include/mlir/Dialect/Linalg @dcaballe @nicolasvasilache @rengolin
68+
/mlir/lib/Dialect/Linalg @dcaballe @nicolasvasilache @rengolin
6969
/mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp @MaheshRavishankar @nicolasvasilache
7070
/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp @MaheshRavishankar @nicolasvasilache
7171
/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @MaheshRavishankar @nicolasvasilache
@@ -85,8 +85,8 @@ clang/test/AST/Interp/ @tbaederr
8585
/mlir/**/*VectorToSCF* @banach-space @dcaballe @matthias-springer @nicolasvasilache
8686
/mlir/**/*VectorToLLVM* @banach-space @dcaballe @nicolasvasilache
8787
/mlir/**/*X86Vector* @aartbik @dcaballe @nicolasvasilache
88-
/mlir/include/mlir/Dialect/Vector/* @dcaballe @nicolasvasilache
89-
/mlir/lib/Dialect/Vector/* @dcaballe @nicolasvasilache
88+
/mlir/include/mlir/Dialect/Vector @dcaballe @nicolasvasilache
89+
/mlir/lib/Dialect/Vector @dcaballe @nicolasvasilache
9090
/mlir/lib/Dialect/Vector/Transforms/* @hanhanW @nicolasvasilache
9191
/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp @MaheshRavishankar @nicolasvasilache
9292
/mlir/**/*EmulateNarrowType* @dcaballe @hanhanW

bolt/docs/OptimizingLinux.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Optimizing Linux Kernel with BOLT
2+
3+
4+
## Introduction
5+
6+
Many Linux applications spend a significant amount of their execution time in the kernel. Thus, when we consider code optimization for system performance, it is essential to improve the CPU utilization not only in the user-space applications and libraries but also in the kernel. BOLT has demonstrated double-digit gains while being applied to user-space programs. This guide shows how to apply BOLT to the x86-64 Linux kernel and enhance your system's performance. In our experiments, BOLT boosted database TPS by 2 percent when applied to the kernel compiled with the highest level optimizations, including PGO and LTO. The database spent ~40% of the time in the kernel and was quite sensitive to kernel performance.
7+
8+
BOLT optimizes code layout based on a low-level execution profile collected with the Linux `perf` tool. The best quality profile should include branch history, such as Intel's last branch records (LBR). BOLT runs on a linked binary and reorders the code while combining frequently executed blocks of instructions in a manner best suited for the hardware. Other than branch instructions, most of the code is left unchanged. Additionally, BOLT updates all metadata associated with the modified code, including DWARF debug information and Linux ORC unwind information.
9+
10+
While BOLT optimizations are not specific to the Linux kernel, certain quirks distinguish the kernel from user-level applications.
11+
12+
BOLT has been successfully applied to and tested with several flavors of the x86-64 Linux kernel.
13+
14+
15+
## QuickStart Guide
16+
17+
BOLT operates on a statically-linked kernel executable, a.k.a. `vmlinux` binary. However, most Linux distributions use a `vmlinuz` compressed image for system booting. To use BOLT on the kernel, you must either repackage `vmlinuz` after BOLT optimizations or add steps for running BOLT into the kernel build and rebuild `vmlinuz`. Uncompressing `vmlinuz` and repackaging it with a new `vmlinux` binary falls beyond the scope of this guide, and at some point, we may add the capability to run BOLT directly on `vmlinuz`. Meanwhile, this guide focuses on steps for integrating BOLT into the kernel build process.
18+
19+
20+
### Building the Kernel
21+
22+
After downloading the kernel sources and configuration for your distribution, you should be able to build `vmlinuz` using the `make bzImage` command. Ideally, the kernel should binary match the kernel on the system you are about to optimize (the target system). The binary matching part is critical as BOLT performs profile matching and optimizations at the binary level. We recommend installing a freshly built kernel on the target system to avoid any discrepancies.
23+
24+
Note that the kernel build will produce several artifacts besides bzImage. The most important of them is the uncompressed `vmlinux` binary, which will be used in the next steps. Make sure to save this file.
25+
26+
Build and target systems should have a `perf` tool installed for collecting and processing profiles. If your build system differs from the target, make sure `perf` versions are compatible. The build system should also have the latest BOLT binary and tools (`llvm-bolt`, `perf2bolt`).
27+
28+
Once the target system boots with the freshly-built kernel, start your workload, such as a database benchmark. While the system is under load, collect the kernel profile using perf:
29+
30+
31+
```bash
32+
$ sudo perf record -a -e cycles -j any,k -F 5000 -- sleep 600
33+
```
34+
35+
36+
Convert `perf` profile into a format suitable for BOLT passing the `vmlinux` binary to `perf2bolt`:
37+
38+
39+
```bash
40+
$ sudo chwon $USER perf.data
41+
$ perf2bolt -p perf.data -o perf.fdata vmlinux
42+
```
43+
44+
45+
Under a high load, `perf.data` should be several gigabytes in size and you should expect the converted `perf.fdata` not to exceed 100 MB.
46+
47+
Two changes are required for the kernel build. The first one is optional but highly recommended. It introduces a BOLT-reserved space into `vmlinux` code section:
48+
49+
50+
```diff
51+
--- a/arch/x86/kernel/vmlinux.lds.S
52+
+++ b/arch/x86/kernel/vmlinux.lds.S
53+
@@ -139,6 +139,11 @@ SECTIONS
54+
STATIC_CALL_TEXT
55+
*(.gnu.warning)
56+
57+
+ /* Allocate space for BOLT */
58+
+ __bolt_reserved_start = .;
59+
+ . += 2048 * 1024;
60+
+ __bolt_reserved_end = .;
61+
+
62+
#ifdef CONFIG_RETPOLINE
63+
__indirect_thunk_start = .;
64+
*(.text.__x86.*)
65+
```
66+
67+
68+
The second patch adds a step that runs BOLT on `vmlinux` binary:
69+
70+
71+
```diff
72+
--- a/scripts/link-vmlinux.sh
73+
+++ b/scripts/link-vmlinux.sh
74+
@@ -340,5 +340,13 @@ if is_enabled CONFIG_KALLSYMS; then
75+
fi
76+
fi
77+
78+
+# Apply BOLT
79+
+BOLT=llvm-bolt
80+
+BOLT_PROFILE=perf.fdata
81+
+BOLT_OPTS="--dyno-stats --eliminate-unreachable=0 --reorder-blocks=ext-tsp --simplify-conditional-tail-calls=0 --skip-funcs=__entry_text_start,irq_entries_start --split-functions"
82+
+mv vmlinux vmlinux.pre-bolt
83+
+echo BOLTing vmlinux
84+
+${BOLT} vmlinux.pre-bolt -o vmlinux --data ${BOLT_PROFILE} ${BOLT_OPTS}
85+
+
86+
# For fixdep
87+
echo "vmlinux: $0" > .vmlinux.d
88+
```
89+
90+
91+
If you skipped the first step or are running BOLT on a pre-built `vmlinux` binary, drop the `--split-functions` option.
92+
93+
94+
## Performance Expectations
95+
96+
By improving the code layout, BOLT can boost the kernel's performance by up to 5% by reducing instruction cache misses and branch mispredictions. When measuring total system performance, you should scale this number accordingly based on the time your application spends in the kernel (excluding I/O time).
97+
98+
99+
## Profile Quality
100+
101+
The timing and duration of the profiling may have a significant effect on the performance of the BOLTed kernel. If you don't know your workload well, it's recommended that you profile for the whole duration of the benchmark run. As longer times will result in larger `perf.data` files, you can lower the profiling frequency by providing a smaller value of `-F` flag. E.g., to record the kernel profile for half an hour, use the following command:
102+
103+
104+
```bash
105+
$ sudo perf record -a -e cycles -j any,k -F 1000 -- sleep 1800
106+
```
107+
108+
109+
110+
## BOLT Disassembly
111+
112+
BOLT annotates the disassembly with control-flow information and attaches Linux-specific metadata to the code. To view annotated disassembly, run:
113+
114+
115+
```bash
116+
$ llvm-bolt vmlinux -o /dev/null --print-cfg
117+
```
118+
119+
120+
If you want to limit the disassembly to a set of functions, add `--print-only=<func1regex>,<func2regex>,...`, where a function name is specified using regular expressions.

clang-tools-extra/clang-doc/tool/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set(assets
2525
)
2626

2727
set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
28-
set(resource_dir "${CMAKE_BINARY_DIR}/share/clang")
28+
set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
2929
set(out_files)
3030

3131
function(copy_files_to_dst src_dir dst_dir file)
@@ -42,7 +42,7 @@ endfunction(copy_files_to_dst)
4242

4343
foreach(f ${assets})
4444
install(FILES ${asset_dir}/${f}
45-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
45+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang-doc"
4646
COMPONENT clang-doc)
4747
copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
4848
endforeach(f)

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Example usage for a project using a compile commands database:
188188
llvm::sys::path::native(ClangDocPath, NativeClangDocPath);
189189
llvm::SmallString<128> AssetsPath;
190190
AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
191-
llvm::sys::path::append(AssetsPath, "..", "share", "clang");
191+
llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
192192
llvm::SmallString<128> DefaultStylesheet;
193193
llvm::sys::path::native(AssetsPath, DefaultStylesheet);
194194
llvm::sys::path::append(DefaultStylesheet,

clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@
1818

1919
using namespace clang::ast_matchers;
2020

21+
namespace clang::tidy {
22+
23+
template <>
24+
struct OptionEnumMapping<misc::UseInternalLinkageCheck::FixModeKind> {
25+
static llvm::ArrayRef<
26+
std::pair<misc::UseInternalLinkageCheck::FixModeKind, StringRef>>
27+
getEnumMapping() {
28+
static constexpr std::pair<misc::UseInternalLinkageCheck::FixModeKind,
29+
StringRef>
30+
Mapping[] = {
31+
{misc::UseInternalLinkageCheck::FixModeKind::None, "None"},
32+
{misc::UseInternalLinkageCheck::FixModeKind::UseStatic,
33+
"UseStatic"},
34+
};
35+
return {Mapping};
36+
}
37+
};
38+
39+
} // namespace clang::tidy
40+
2141
namespace clang::tidy::misc {
2242

2343
namespace {
@@ -57,6 +77,16 @@ AST_POLYMORPHIC_MATCHER(isExternStorageClass,
5777

5878
} // namespace
5979

80+
UseInternalLinkageCheck::UseInternalLinkageCheck(StringRef Name,
81+
ClangTidyContext *Context)
82+
: ClangTidyCheck(Name, Context),
83+
HeaderFileExtensions(Context->getHeaderFileExtensions()),
84+
FixMode(Options.get("FixMode", FixModeKind::UseStatic)) {}
85+
86+
void UseInternalLinkageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
87+
Options.store(Opts, "FixMode", FixMode);
88+
}
89+
6090
void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) {
6191
auto Common =
6292
allOf(isFirstDecl(), isAllRedeclsInMainFile(HeaderFileExtensions),
@@ -82,11 +112,21 @@ static constexpr StringRef Message =
82112

83113
void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) {
84114
if (const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("fn")) {
85-
diag(FD->getLocation(), Message) << "function" << FD;
115+
DiagnosticBuilder DB = diag(FD->getLocation(), Message) << "function" << FD;
116+
SourceLocation FixLoc = FD->getTypeSpecStartLoc();
117+
if (FixLoc.isInvalid() || FixLoc.isMacroID())
118+
return;
119+
if (FixMode == FixModeKind::UseStatic)
120+
DB << FixItHint::CreateInsertion(FixLoc, "static ");
86121
return;
87122
}
88123
if (const auto *VD = Result.Nodes.getNodeAs<VarDecl>("var")) {
89-
diag(VD->getLocation(), Message) << "variable" << VD;
124+
DiagnosticBuilder DB = diag(VD->getLocation(), Message) << "variable" << VD;
125+
SourceLocation FixLoc = VD->getTypeSpecStartLoc();
126+
if (FixLoc.isInvalid() || FixLoc.isMacroID())
127+
return;
128+
if (FixMode == FixModeKind::UseStatic)
129+
DB << FixItHint::CreateInsertion(FixLoc, "static ");
90130
return;
91131
}
92132
llvm_unreachable("");

clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ namespace clang::tidy::misc {
2020
/// http://clang.llvm.org/extra/clang-tidy/checks/misc/use-internal-linkage.html
2121
class UseInternalLinkageCheck : public ClangTidyCheck {
2222
public:
23-
UseInternalLinkageCheck(StringRef Name, ClangTidyContext *Context)
24-
: ClangTidyCheck(Name, Context),
25-
HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
23+
UseInternalLinkageCheck(StringRef Name, ClangTidyContext *Context);
2624
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2725
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
26+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2827
std::optional<TraversalKind> getCheckTraversalKind() const override {
2928
return TK_IgnoreUnlessSpelledInSource;
3029
}
3130

31+
enum class FixModeKind {
32+
None,
33+
UseStatic,
34+
};
35+
3236
private:
3337
FileExtensionsSet HeaderFileExtensions;
38+
FixModeKind FixMode;
3439
};
3540

3641
} // namespace clang::tidy::misc

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ option is recognized.
325325
)"),
326326
cl::init(false), cl::cat(ClangTidyCategory));
327327

328+
static cl::opt<bool> AllowNoChecks("allow-no-checks", desc(R"(
329+
Allow empty enabled checks. This suppresses
330+
the "no checks enabled" error when disabling
331+
all of the checks.
332+
)"),
333+
cl::init(false),
334+
cl::cat(ClangTidyCategory));
335+
328336
namespace clang::tidy {
329337

330338
static void printStats(const ClangTidyStats &Stats) {
@@ -598,7 +606,7 @@ int clangTidyMain(int argc, const char **argv) {
598606
}
599607

600608
if (ListChecks) {
601-
if (EnabledChecks.empty()) {
609+
if (EnabledChecks.empty() && !AllowNoChecks) {
602610
llvm::errs() << "No checks enabled.\n";
603611
return 1;
604612
}
@@ -652,6 +660,10 @@ int clangTidyMain(int argc, const char **argv) {
652660
}
653661

654662
if (EnabledChecks.empty()) {
663+
if (AllowNoChecks) {
664+
llvm::outs() << "No checks enabled.\n";
665+
return 0;
666+
}
655667
llvm::errs() << "Error: no checks enabled.\n";
656668
llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
657669
return 1;

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ def main():
229229
default=[],
230230
help="Load the specified plugin in clang-tidy.",
231231
)
232+
parser.add_argument(
233+
"-allow-no-checks",
234+
action="store_true",
235+
help="Allow empty enabled checks.",
236+
)
232237

233238
clang_tidy_args = []
234239
argv = sys.argv[1:]
@@ -327,6 +332,8 @@ def main():
327332
common_clang_tidy_args.append("-p=%s" % args.build_path)
328333
if args.use_color:
329334
common_clang_tidy_args.append("--use-color")
335+
if args.allow_no_checks:
336+
common_clang_tidy_args.append("--allow-no-checks")
330337
for arg in args.extra_arg:
331338
common_clang_tidy_args.append("-extra-arg=%s" % arg)
332339
for arg in args.extra_arg_before:

0 commit comments

Comments
 (0)