Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1530617 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2016-11-26 08:10 +0100 |
| Last post | 2016-11-26 18:40 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v3 19/30] perf clang jit: Insignt BPF and JIT functions in a Module Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:10 +0100
Re: [PATCH v3 19/30] perf clang jit: Insignt BPF and JIT functions in a Module Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-11-26 18:40 +0100
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-11-26 08:10 +0100 |
| Subject | [PATCH v3 19/30] perf clang jit: Insignt BPF and JIT functions in a Module |
| Message-ID | <sHFhw-3nx-39@gated-at.bofh.it> |
Identify BPF functions, JIT functions and maps during init. Functions in
section starting with "perfhook:" are JIT functions. They will be JIT
compiled and hooked at perfhooks.
During init of PerfModule, mark JIT functions as AvailableExternallyLinkage.
LLVM skips functions with linkage like this so they won't be compiled
into BPF objects.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
tools/perf/util/c++/clang.cpp | 32 ++++++++++++++++++++++++++++++++
tools/perf/util/c++/clang.h | 7 +++++++
2 files changed, 39 insertions(+)
diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
index d31b0a5..98d05e2 100644
--- a/tools/perf/util/c++/clang.cpp
+++ b/tools/perf/util/c++/clang.cpp
@@ -115,15 +115,47 @@ getModuleFromSource(llvm::opt::ArgStringList CFlags, StringRef Path)
PerfModule::PerfModule(std::unique_ptr<llvm::Module>&& M) : Module(std::move(M))
{
+ for (llvm::Function& F : *Module) {
+ if (F.getLinkage() != llvm::GlobalValue::ExternalLinkage)
+ continue;
+
+ if (StringRef(F.getSection()).startswith("perfhook:"))
+ JITFunctions.insert(&F);
+ else
+ BPFFunctions.insert(&F);
+ }
+ for (auto V = Module->global_begin(); V != Module->global_end(); V++) {
+ llvm::GlobalVariable *GV = &*V;
+ if (StringRef(GV->getSection()) == llvm::StringRef("maps"))
+ Maps.insert(GV);
+ }
}
+void PerfModule::prepareBPF(void)
+{
+ for (llvm::Function *F : JITFunctions)
+ F->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
+ for (llvm::Function *F : BPFFunctions)
+ F->setLinkage(llvm::GlobalValue::ExternalLinkage);
+
+}
+
+void PerfModule::prepareJIT(void)
+{
+ for (llvm::Function *F : BPFFunctions)
+ F->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
+ for (llvm::Function *F : JITFunctions)
+ F->setLinkage(llvm::GlobalValue::ExternalLinkage);
+
+}
std::unique_ptr<llvm::SmallVectorImpl<char>>
PerfModule::toBPFObject(void)
{
using namespace llvm;
+ prepareBPF();
std::string TargetTriple("bpf-pc-linux");
std::string Error;
const Target* Target = TargetRegistry::lookupTarget(TargetTriple, Error);
diff --git a/tools/perf/util/c++/clang.h b/tools/perf/util/c++/clang.h
index cbb291b..1eb71a6 100644
--- a/tools/perf/util/c++/clang.h
+++ b/tools/perf/util/c++/clang.h
@@ -6,6 +6,7 @@
#include "llvm/IR/Module.h"
#include "llvm/Option/Option.h"
#include <memory>
+#include <set>
namespace perf {
@@ -14,6 +15,12 @@ using namespace llvm;
class PerfModule {
private:
std::unique_ptr<llvm::Module> Module;
+
+ std::set<llvm::GlobalVariable *> Maps;
+ std::set<llvm::Function *> BPFFunctions;
+ std::set<llvm::Function *> JITFunctions;
+ void prepareBPF(void);
+ void prepareJIT(void);
public:
inline llvm::Module *getModule(void)
{
--
2.10.1
[toc] | [next] | [standalone]
| From | Alexei Starovoitov <alexei.starovoitov@gmail.com> |
|---|---|
| Date | 2016-11-26 18:40 +0100 |
| Subject | Re: [PATCH v3 19/30] perf clang jit: Insignt BPF and JIT functions in a Module |
| Message-ID | <sHP7c-189-23@gated-at.bofh.it> |
| In reply to | #1530617 |
On Sat, Nov 26, 2016 at 07:03:43AM +0000, Wang Nan wrote:
> Identify BPF functions, JIT functions and maps during init. Functions in
> section starting with "perfhook:" are JIT functions. They will be JIT
> compiled and hooked at perfhooks.
>
> During init of PerfModule, mark JIT functions as AvailableExternallyLinkage.
> LLVM skips functions with linkage like this so they won't be compiled
> into BPF objects.
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
...
> +void PerfModule::prepareBPF(void)
> +{
> + for (llvm::Function *F : JITFunctions)
> + F->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
> + for (llvm::Function *F : BPFFunctions)
> + F->setLinkage(llvm::GlobalValue::ExternalLinkage);
> +
> +}
> +
> +void PerfModule::prepareJIT(void)
> +{
> + for (llvm::Function *F : BPFFunctions)
> + F->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
> + for (llvm::Function *F : JITFunctions)
> + F->setLinkage(llvm::GlobalValue::ExternalLinkage);
> +
> +}
Nice trick.
Please document it in the perf+llvm design doc.
Acked-by: Alexei Starovoitov <ast@kernel.org>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web