Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp233387rdb; Thu, 8 Feb 2024 04:40:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3b/O5ZbGXOEI4o3FRq0ayXauArfJNs5M6dMMA4/a1f/AW0HNuBSeOb+xP+ibwSR1bys1x X-Received: by 2002:aa7:c991:0:b0:560:535:864c with SMTP id c17-20020aa7c991000000b005600535864cmr6522304edt.12.1707396011820; Thu, 08 Feb 2024 04:40:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707396011; cv=pass; d=google.com; s=arc-20160816; b=jW/W1GylBjn5aif7YqSdhrI7B93IXXTa8Pw6XQB4nAgduTpv09f7Ki+Puy6jrSZ7SH 76JGaNVfd40ssiNamcN7mYZWjUaW84Uap7WaZT7qABAD2ztmFYmg58X3jv3Gh6UCHZ0O QDXDLL2wEiiQwiGhG6ScQEzQD6cuHCQzjCpOIcVLYme1DKgK1aJirEpctiKNQT71OGye 3M75tnQ1BuK3M3Jg4ONkkRx1hJR3zxXHTX6hHQ9GF7rZ9kd1NENPwX4S0GXSGiRYT0ea g1WmRYSBRh4lVn61jS8MFhLM0/JWeErhSz69PPlOZCiMa8QFTrQnS0G1KPpRASjuP6/z 59eA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=ErTvTuo2SVgUWpYevswA9L+JQIgliYWmEL+tw0XLXMQ=; fh=zuxSu3Xs7gJghuEsnMcc65Wq4z6lSS8DzSTVZIBtETg=; b=nqIM4kjg+RxUL7p9u0Y/vHG15aJukUyBJOhXSgprpNBoHNhFEp0eCTC7OISqjeFqIy XPP8/KopFAQNwihcj3nJATQ46p2i4Vd/x7e235dfFYR/kY1l4vEUO0SIWcbVG7g++MEW wMBjALO9S/m+YkDpqfKV17RrZAockag+xj+VT0OMgZF3ftc7w22VIwLLbA3aX9KQdZkl ZON3A+H/eNwFyKy9/ee35FGxv9IJSiHgWtyAaxBDi4zzVmHLhCpoClBzqLIEv/3InQ8N tH/MmZpuCWlBZsNxKTRcK0/Zn4fvgi2TezBRj/M3Hp/oARBg9MpGqFEH+r+GXF75ZBYr g24Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-58069-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58069-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=2; AJvYcCXWnqEfLtl4r7fmb6GknhB8l1ZbkoWI7PWu+DW/g1GZii46EQAFXjbT3hwT85X3sl6iBIiO5xdKDVpUbqDB1/Cr/IstVrTh5Bp0040kJQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v13-20020aa7d64d000000b0055fbc52463bsi858873edr.601.2024.02.08.04.40.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:40:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58069-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-58069-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58069-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8F7781F22FF4 for ; Thu, 8 Feb 2024 12:40:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89F0676046; Thu, 8 Feb 2024 12:39:54 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9A3176028 for ; Thu, 8 Feb 2024 12:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707395994; cv=none; b=PJrvxSqjC2jbk5c8cJJK2IeOVPbcCSGsKVTofm4Ho1wWbVgXFpIkhzPj6jgDu+jBQEf+oYULTMVWLEvKmYti7s+OvCSGTFDasBwI3YCzwSJCqqirUpeK+1M4pSOcOe3HAu7cL7WFhA4sl+ChDPqOrpOvG0hFxquZyc5754H5Hqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707395994; c=relaxed/simple; bh=0hbCarOtP5u95JGe8C90Cgaf3YAyJNnkarhl9gvl9NE=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q4I90tOAHJ/GoEqgYfhcG8ct/O+y2Gb4xLhAz/rmMocPOY1ioWLWddzxwUYT3RLyCCMji14rZYakj4wK27yF5DWYlBjM1YiPR9rvUQieLN6f/LNISgRpbuHnCiJ8eHsk+VZKrAPFVAPYKzrxr4ecXqygsCda4V5zp6qib/3pYso= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TVxLL487Tz6K5pX; Thu, 8 Feb 2024 20:36:26 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 29D9E140D1A; Thu, 8 Feb 2024 20:39:48 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 8 Feb 2024 12:39:47 +0000 Date: Thu, 8 Feb 2024 12:39:46 +0000 From: Jonathan Cameron To: Yicong Yang CC: , , , , , , , , Subject: Re: [PATCH 6/7] drivers/perf: hisi_pcie: Merge find_related_event() and get_event_idx() Message-ID: <20240208123946.00006618@Huawei.com> In-Reply-To: <20240204074527.47110-7-yangyicong@huawei.com> References: <20240204074527.47110-1-yangyicong@huawei.com> <20240204074527.47110-7-yangyicong@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To lhrpeml500005.china.huawei.com (7.191.163.240) On Sun, 4 Feb 2024 15:45:26 +0800 Yicong Yang wrote: > From: Junhao He > > The function xxx_find_related_event() scan all working events to find > related events. During this process, we also can find the idle counters. > If not found related events, return the first idle counter to simplify > the code. > > Signed-off-by: Junhao He > Signed-off-by: Yicong Yang A suggestion inline to avoid the magic HISI_PCIE_MAX_COUNTER value being used outside of the function. > --- > drivers/perf/hisilicon/hisi_pcie_pmu.c | 55 ++++++++++---------------- > 1 file changed, 21 insertions(+), 34 deletions(-) > > diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c > index 1b45aeb82859..2edde66675e7 100644 > --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c > +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c > @@ -397,16 +397,24 @@ static u64 hisi_pcie_pmu_read_counter(struct perf_event *event) > return hisi_pcie_pmu_readq(pcie_pmu, event->hw.event_base, idx); > } > > -static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu, > - struct perf_event *event) > +/* > + * Check all work events, if a relevant event is found then we return it > + * first, otherwise return the first idle counter (need to reset). > + */ > +static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu, > + struct perf_event *event) > { > + int first_idle = HISI_PCIE_MAX_COUNTERS; int first_idle = -EAGAIN; > struct perf_event *sibling; > int idx; > > for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) { > sibling = pcie_pmu->hw_events[idx]; > - if (!sibling) > + if (!sibling) { > + if (first_idle == HISI_PCIE_MAX_COUNTERS) if (first_idle == -EAGAIN) > + first_idle = idx; > continue; > + } > > /* Related events must be used in group */ > if (hisi_pcie_pmu_cmp_event(sibling, event) && > @@ -414,19 +422,7 @@ static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu, > return idx; > } > > - return idx; > -} > - > -static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu) > -{ > - int idx; > - > - for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) { > - if (!pcie_pmu->hw_events[idx]) > - return idx; > - } > - > - return -EINVAL; > + return first_idle; Then this will return -EAGAIN; > } > > static void hisi_pcie_pmu_event_update(struct perf_event *event) > @@ -552,27 +548,18 @@ static int hisi_pcie_pmu_add(struct perf_event *event, int flags) > > hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE; > > - /* Check all working events to find a related event. */ > - idx = hisi_pcie_pmu_find_related_event(pcie_pmu, event); > - if (idx < 0) > - return idx; > - > - /* Current event shares an enabled counter with the related event */ > - if (idx < HISI_PCIE_MAX_COUNTERS) { > - hwc->idx = idx; > - goto start_count; > - } > - > - idx = hisi_pcie_pmu_get_event_idx(pcie_pmu); > - if (idx < 0) > - return idx; > + idx = hisi_pcie_pmu_get_event_idx(pcie_pmu, event); > + if (idx == HISI_PCIE_MAX_COUNTERS) > + return -EAGAIN; Perhaps simpler to handle first_idle == HISI_PCIE_MAX_COUNTERS as an error return in hisi_pcie_pmu_get_event_idx - see above. if (idx < 0) return idx; > > hwc->idx = idx; > - pcie_pmu->hw_events[idx] = event; > - /* Reset Counter to avoid previous statistic interference. */ > - hisi_pcie_pmu_reset_counter(pcie_pmu, idx); > > -start_count: > + /* No enabled counter found with related event, reset it */ > + if (!pcie_pmu->hw_events[idx]) { > + hisi_pcie_pmu_reset_counter(pcie_pmu, idx); > + pcie_pmu->hw_events[idx] = event; > + } > + > if (flags & PERF_EF_START) > hisi_pcie_pmu_start(event, PERF_EF_RELOAD); >