Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1072412imu; Thu, 13 Dec 2018 08:58:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/U8YTWwx7QcfW+kJ032Xa0UO1NCqt4KA547qR5xlRtIuULqIGz0aTGwmqDja1cryLDPolB3 X-Received: by 2002:a17:902:264:: with SMTP id 91mr24507725plc.108.1544720312976; Thu, 13 Dec 2018 08:58:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544720312; cv=none; d=google.com; s=arc-20160816; b=rr7khN/81obSzJ5KiDd5f6/tQFv2/78RuHH8t5pGWz3nGtBACeptV4o45J/aHpJff+ pOzXwdHwFBL4mvynG3tT95awMmpARUHF60KUC47+BghYrvArBfAtnilbN3gFD6F3QBy6 B2pbFJLTgSTaLtr/Oke4t9W8Yr9QdiqhH6xU+HYvC98lT2KA4+Zqalt3kDjk+vOPIiYw qRmxiaNu6i/Br7DwsMnfzkiMIykaXu/5GH4I8cvCX0YVW+sHJSVdBS2frhoqFYhbFmrL fHDK6djIruUCteCpGXWOl/uApfCzYeNTnjk+y5zBgnj7cXZeGRRABzaOmW+iyZInseOp tj3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=1DhVer8bRUHu3gU+sZEtA237NZplv8ZqrGNl0E1/i3c=; b=i2bM+MkaS1YTo7QzA1QPrTMkaHv8rrEnu2TT3WxpMTT+r1NW2IcgJIMBvcTh0QrAd6 dkDQRF0knvK4FowZozEp1ReexJ3kscBOnePR8aPzbkj8kduU5u8Km1Ip2YBfqChLexm9 nDEAxdVWHMNMFEKkJGiFQTvFKjjGDPlZ+0FcmF3YgcxeQZ0il4jeCYW4OnHLETHTSF6G caxrXkEKZGOdY9V+X4nczEr89MUHLzJTW3bisCLazfu43328wR1XSNten4fvRcBJNhtA OSh1sgvPBrp0eCKvQes8pu4rzhd1MK+OXXX4WR78XnpiIqd5Asyrskxsxv/7gIfAPx0A GNBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=Jq4RgcgA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m14si1823785pgd.326.2018.12.13.08.58.17; Thu, 13 Dec 2018 08:58:32 -0800 (PST) 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; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=Jq4RgcgA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729655AbeLMQ4p (ORCPT + 99 others); Thu, 13 Dec 2018 11:56:45 -0500 Received: from smtprelay2.synopsys.com ([198.182.60.111]:37722 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729645AbeLMQ4p (ORCPT ); Thu, 13 Dec 2018 11:56:45 -0500 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id E0EF310C17FD; Thu, 13 Dec 2018 08:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1544720204; bh=Aoa+yMFINIyNSLFAiNcrIQz8XLb2ZfPLflM2tFZRRY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jq4RgcgAqsDMzhs/uOeD5hRTouT6pAKH2t8WY7+AsLyW57SCnNp3pOiqSJxKiBieq TX82nY6+qU3pEzoG4A4F2CA/Fk0NVkKMtExFcjufAp623yEIvnQC/FrNbbfUboUpiH n0NsWx6YkZRieC33hEmdE65XUlNwg//8ff7doCO8lUsU2riRWvGn+u4wwd9O5NsKbe QnbBzZSpW1PD4aAlY2j6xVpWiGnll75/8yf298JUoF5XLC3TczhszfdXh/TqqUOY6y Ihq+mbUhkLD/VFfhIEf+jgOs//ZqoKVNO00qgL+vRgSEswRUEqSrO2zMRZ0a/Zy45N 2FEhAEAjpOe2Q== Received: from paltsev-e7480.internal.synopsys.com (paltsev-e7480.internal.synopsys.com [10.121.3.66]) by mailhost.synopsys.com (Postfix) with ESMTP id 0FE49307B; Thu, 13 Dec 2018 08:56:40 -0800 (PST) From: Eugeniy Paltsev To: linux-snps-arc@lists.infradead.org, Vineet Gupta Cc: linux-kernel@vger.kernel.org, Alexey Brodkin , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Eugeniy Paltsev Subject: [PATCH v2 3/4] ARC: perf: move HW events mapping to separate function Date: Thu, 13 Dec 2018 19:56:20 +0300 Message-Id: <20181213165621.20817-4-Eugeniy.Paltsev@synopsys.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20181213165621.20817-1-Eugeniy.Paltsev@synopsys.com> References: <20181213165621.20817-1-Eugeniy.Paltsev@synopsys.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move HW events mapping to separate function to make code more readable. Signed-off-by: Eugeniy Paltsev --- arch/arc/kernel/perf_event.c | 48 ++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c index d60aaaead421..248c7b61690a 100644 --- a/arch/arc/kernel/perf_event.c +++ b/arch/arc/kernel/perf_event.c @@ -530,11 +530,39 @@ static int arc_pmu_raw_alloc(struct device *dev) return 0; } +static inline bool event_in_hw_event_map(int i, char *name) +{ + if (!arc_pmu_ev_hw_map[i]) + return false; + + if (!strlen(arc_pmu_ev_hw_map[i])) + return false; + + if (strcmp(arc_pmu_ev_hw_map[i], name)) + return false; + + return true; +} + +static void arc_pmu_map_hw_event(int j, char *str) +{ + int i; + + /* See if HW condition has been mapped to a perf event_id */ + for (i = 0; i < ARRAY_SIZE(arc_pmu_ev_hw_map); i++) { + if (event_in_hw_event_map(i, str)) { + pr_debug("mapping perf event %2d to h/w event \'%8s\' (idx %d)\n", + i, str, j); + arc_pmu->ev_hw_idx[i] = j; + } + } +} + static int arc_pmu_device_probe(struct platform_device *pdev) { struct arc_reg_pct_build pct_bcr; struct arc_reg_cc_build cc_bcr; - int i, j, has_interrupts; + int i, has_interrupts; int counter_size; /* in bits */ union cc_name { @@ -582,23 +610,13 @@ static int arc_pmu_device_probe(struct platform_device *pdev) arc_pmu->ev_hw_idx[i] = -1; /* loop thru all available h/w condition indexes */ - for (j = 0; j < cc_bcr.c; j++) { - write_aux_reg(ARC_REG_CC_INDEX, j); + for (i = 0; i < cc_bcr.c; i++) { + write_aux_reg(ARC_REG_CC_INDEX, i); cc_name.indiv.word0 = read_aux_reg(ARC_REG_CC_NAME0); cc_name.indiv.word1 = read_aux_reg(ARC_REG_CC_NAME1); - /* See if it has been mapped to a perf event_id */ - for (i = 0; i < ARRAY_SIZE(arc_pmu_ev_hw_map); i++) { - if (arc_pmu_ev_hw_map[i] && - !strcmp(arc_pmu_ev_hw_map[i], cc_name.str) && - strlen(arc_pmu_ev_hw_map[i])) { - pr_debug("mapping perf event %2d to h/w event \'%8s\' (idx %d)\n", - i, cc_name.str, j); - arc_pmu->ev_hw_idx[i] = j; - } - } - - arc_pmu_add_raw_event_attr(j, cc_name.str); + arc_pmu_map_hw_event(i, cc_name.str); + arc_pmu_add_raw_event_attr(i, cc_name.str); } arc_pmu_events_attr_gr.attrs = arc_pmu->attrs; -- 2.14.5