From patchwork Wed Oct 14 12:41:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54943 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 4BD1423012 for ; Wed, 14 Oct 2015 12:49:17 +0000 (UTC) Received: by lbwr8 with SMTP id r8sf25404430lbw.0 for ; Wed, 14 Oct 2015 05:49:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=js7nh34lOsMo+RCInF/1i7du/FyddnBBZ/XOYSb8SV0=; b=GAQCZpBaXnhNUeJUbA1+2SlLUwshxg53V56Ro41y10SxukvgR53YNRKlRzPujV7e+U UGxXKfqymAQrcVbCAN3iRdqAcjtE50pcUvMagWLEovKuq/ZF9ETpxZ6HlIlW3lB45ElT 5scFC2xWakM6B1Pz9ZNhu2npY1HSU1JLe+yEd+5HapWi7dOOl85j64vWWPesefn8hjRc aRRejsqfN0oaV1H8hp9ciBcBUrOwnefQhBuwxcBmsyDfRxcFaMPGuQ+JnB+9fdyj/GPJ Upmf22yCRpZspkFV47wl3cgGRFoceJfDLbjeRHNH7symniYw9nA0L7fTr2WOdPHRByia e19A== X-Gm-Message-State: ALoCoQmcrYDuPvOu3LTN+NEtZ28JBqPn8Ea1kAuNBmU/42KpWh3Resk9MvafsNLy2Vur2/OlvL8l X-Received: by 10.180.210.212 with SMTP id mw20mr5494231wic.3.1444826956282; Wed, 14 Oct 2015 05:49:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.87.8 with SMTP id l8ls36276lfb.92.gmail; Wed, 14 Oct 2015 05:49:16 -0700 (PDT) X-Received: by 10.112.146.104 with SMTP id tb8mr1520060lbb.35.1444826956102; Wed, 14 Oct 2015 05:49:16 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id p3si5447409lfb.105.2015.10.14.05.49.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 05:49:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbcao8 with SMTP id ao8so45335252lbc.3 for ; Wed, 14 Oct 2015 05:49:15 -0700 (PDT) X-Received: by 10.112.159.136 with SMTP id xc8mr1226233lbb.76.1444826955881; Wed, 14 Oct 2015 05:49:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2712772lbq; Wed, 14 Oct 2015 05:49:14 -0700 (PDT) X-Received: by 10.69.1.5 with SMTP id bc5mr3545858pbd.151.1444826949384; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qw9si13041049pbc.223.2015.10.14.05.49.08; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753745AbbJNMtG (ORCPT + 30 others); Wed, 14 Oct 2015 08:49:06 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:27779 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753559AbbJNMmw (ORCPT ); Wed, 14 Oct 2015 08:42:52 -0400 Received: from 172.24.1.49 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BOX06061; Wed, 14 Oct 2015 20:42:43 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Wed, 14 Oct 2015 20:42:36 +0800 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [PATCH 27/31] perf tools: Pass available CPU number to clang compiler Date: Wed, 14 Oct 2015 12:41:38 +0000 Message-ID: <1444826502-49291-28-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> References: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.561E4DC3.01F4, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: f850d57609698cc779277d604a17daec Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch introduces a new macro "__NR_CPUS__" to perf's embedded clang compiler, which represent the available CPU counters in this system. BPF program can use this macro to create a map with same number of system CPUs. For exmaple: struct bpf_map_def SEC("maps") pmu_map = { .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, .key_size = sizeof(int), .value_size = sizeof(u32), .max_entries = __NR_CPUS__, }; Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/n/ebpf-y603iy62s8w4br4t2gxfois4@git.kernel.org --- tools/perf/util/llvm-utils.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c index 4f6a478..80eecef 100644 --- a/tools/perf/util/llvm-utils.c +++ b/tools/perf/util/llvm-utils.c @@ -11,10 +11,11 @@ #include "cache.h" #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ - "$CLANG_EXEC -D__KERNEL__ $CLANG_OPTIONS " \ - "$KERNEL_INC_OPTIONS -Wno-unused-value " \ - "-Wno-pointer-sign -working-directory " \ - "$WORKING_DIR -c \"$CLANG_SOURCE\" -target bpf -O2 -o -" + "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ + "$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \ + "-Wno-unused-value -Wno-pointer-sign " \ + "-working-directory $WORKING_DIR " \ + "-c \"$CLANG_SOURCE\" -target bpf -O2 -o -" struct llvm_param llvm_param = { .clang_path = "clang", @@ -326,8 +327,8 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts) int llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz) { - int err; - char clang_path[PATH_MAX]; + int err, nr_cpus_avail; + char clang_path[PATH_MAX], nr_cpus_avail_str[64]; const char *clang_opt = llvm_param.clang_opt; const char *template = llvm_param.clang_bpf_cmd_template; char *kbuild_dir = NULL, *kbuild_include_opts = NULL; @@ -354,6 +355,17 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, */ get_kbuild_opts(&kbuild_dir, &kbuild_include_opts); + nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF); + if (nr_cpus_avail <= 0) { + pr_err( +"WARNING:\tunable to get available CPUs in this system: %s\n" +" \tUse 128 instead.\n", strerror(errno)); + nr_cpus_avail = 128; + } + snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d", + nr_cpus_avail); + + force_set_env("NR_CPUS", nr_cpus_avail_str); force_set_env("CLANG_EXEC", clang_path); force_set_env("CLANG_OPTIONS", clang_opt); force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);