Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752814AbcKZR3t (ORCPT ); Sat, 26 Nov 2016 12:29:49 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36252 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752240AbcKZR3l (ORCPT ); Sat, 26 Nov 2016 12:29:41 -0500 Date: Sat, 26 Nov 2016 09:29:36 -0800 From: Alexei Starovoitov To: Wang Nan Cc: acme@redhat.com, ast@fb.com, lizefan@huawei.com, hekuang@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, joe@ovn.org, Jiri Olsa Subject: Re: [PATCH v3 20/30] perf clang jit: add PerfModule::doJIT to JIT perfhook functions Message-ID: <20161126172934.GG83987@ast-mbp.thefacebook.com> References: <20161126070354.141764-1-wangnan0@huawei.com> <20161126070354.141764-21-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161126070354.141764-21-wangnan0@huawei.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1834 Lines: 52 On Sat, Nov 26, 2016 at 07:03:44AM +0000, Wang Nan wrote: > PerfModule::doJIT JIT compile perfhook functions and saves result into > a map. Add a test case for it. > > At this stage perfhook functions can do no useful things because they > can't invoke external functions and can't return value. Following > commits are going to make improvment. > > Don't hook functions right after jitted because bpf_object is unavailable > during jitting but it should be the context of jitted functions. > > Signed-off-by: Wang Nan ... > + for (Function *F : JITFunctions) { > + JITSymbol sym = CompileLayer.findSymbol(F->getName().str(), true); > + > + /* > + * Type of F->getSection() is moving from > + * const char * to StringRef. > + * Convert it to std::string so we don't need > + * consider this API change. > + */ > + std::string sec(F->getSection()); > + std::string hook(&sec.c_str()[sizeof("perfhook:") - 1]); > + perf_hook_func_t func = (perf_hook_func_t)(intptr_t)sym.getAddress(); > + > + if (JITResult[hook]) > + llvm::errs() << "Warning: multiple functions on hook " > + << hook << ", only one is used\n"; > + JITResult[hook] = func; > + } > + return 0; > +} > + > class ClangOptions { > llvm::SmallString FileName; > llvm::SmallString<64> KVerDef; > @@ -292,6 +359,10 @@ void perf_clang__init(void) > LLVMInitializeBPFTarget(); > LLVMInitializeBPFTargetMC(); > LLVMInitializeBPFAsmPrinter(); > + > + llvm::InitializeNativeTarget(); > + llvm::InitializeNativeTargetAsmPrinter(); > + llvm::InitializeNativeTargetAsmParser(); Looks great. I bet a lot of people reading perf code won't be able to understand what you're doing here. Could you please add a design doc on how perf<->clang/llvm interaction is done. Acked-by: Alexei Starovoitov