Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp365120lqb; Thu, 29 Feb 2024 03:27:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXPD3KeniTK8kG57oYK4sl5mmqDTAYOcxlI7tGYZ1bTnwRwVYxkDrB/7lm9WN3xJ8zwbTchnnAHJW35NgyUActTu2037GLRPC/9/wbV6A== X-Google-Smtp-Source: AGHT+IE1V7TrxSNuxAiPg9a6+UHxNO9JvCZW7fCpOe812P77E/Dur5fh6k6crtiAeYW0nMQwU4FP X-Received: by 2002:a05:6a21:1014:b0:1a0:e09d:8ecb with SMTP id nk20-20020a056a21101400b001a0e09d8ecbmr2375931pzb.6.1709206064231; Thu, 29 Feb 2024 03:27:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709206064; cv=pass; d=google.com; s=arc-20160816; b=mmu8XyBYpp6eg4+N05xYw9Ht99Lbg6jAuWxdJJT5O3cgGy3d1Hf3jVCsoZAks1dulc 2GeJudFhIJnVW/qRx8ga6KPh4sisBENJhyAkB+h5Onzd5+ItBOQWemV70pBe1Hy8p0kA yOawFvCia90tXiFBTORff/Q07OBtEwxrIrZozcDZM38+pMrN0LNoG6euiMzYo0H3TP4I HT33mh8WEQPxEg81IgJs6EPgn9LGYHRxy4pXoE7wCjAsvCGso8eQ9+FRA7WPS9pYbIZL iMZowEiHaEnvsqliRiJJxMuzlHO3tLccwDe1fU/smNZPE+CIBLzsnfdbEk6c1ZKkTgq1 zA1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:to:subject:cc; bh=5zH+1TICFWwOijAR7dcl5rdasEbMLiGTK9TudDVXlWQ=; fh=DmE6eH0OqVUuK3NqoiBLiT3jUWig2oM2NhDffaWrUXs=; b=RqOYxeW5v/Ca32ZaBv86306Ndktvf57fqbU5p2Q83FyL8yzRbGCy5l/8BB9/hdsP0t L+oc0FOPEZ4LxMcgh3tZxS/afF3HIdbjfgvUBQmXhKUT4kvlxEXs2mJNk4PgFPy3G0ly aP4F6ndI92PMmjx8lWrbv7vFMrrWgjUlqrUhnA3dZW8gDnsmLy/eW/0+JgxsDDMHYGE6 aru4Gp8RnVH5zsTURyvElhcVJr79VVKfbZSkexew/yoSl1zd0vL0BywQUx1DSLUqMvlb G76KavNJWfBbMxkBFY6J3gxuK4vKLfdNClJN3G86+6mSlK7ZZySWxTtm4rP4gQ1UAYn7 1yUw==; 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-86611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86611-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y8-20020a17090322c800b001dcad9d9e7dsi1178165plg.576.2024.02.29.03.27.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 03:27:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-86611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86611-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4F302B213DB for ; Thu, 29 Feb 2024 11:12:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E95AE7A73F; Thu, 29 Feb 2024 11:12:41 +0000 (UTC) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 CA38579DA7 for ; Thu, 29 Feb 2024 11:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709205161; cv=none; b=ATNN+G6ptChZkuIiONn+5/YKTZTf+KW8SI8D30CWHR+ThdyugQp7894YbLjPnStsO8FIj3Fjx6eLeqIgBsPQ9DaHOG1miLf0XiFcO8pbRK5lxybU/vY11N49Rr6OVy2go4IypEAzKwmmQBTYCNh0SidYh7SKpOQl0Q1wtk5vnNk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709205161; c=relaxed/simple; bh=cxeycH8tCuEZDYMhi2lhSLpSgbgDBpAwm99i4PAz+5I=; h=CC:Subject:To:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=rRIu/LCe/zMV7Be5AbJRY/yV8vVCbBncuZzJ3kn/ZZkePgIL3awM8fAit29gb236cSTEihhQJGNYENcK72cFIeF1bk51X11Y3G/gWlj9JNbZLqs/Dcaz18Am4RLxpDd+R8P0AcKW18K7Yj9/PN4uCGi18oTl/rYCSaMbscxcbDI= 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=45.249.212.35 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.19.163.44]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TlpR84Msgz1Q9Nn; Thu, 29 Feb 2024 19:10:12 +0800 (CST) Received: from canpemm500009.china.huawei.com (unknown [7.192.105.203]) by mail.maildlp.com (Postfix) with ESMTPS id D36581402CE; Thu, 29 Feb 2024 19:12:28 +0800 (CST) Received: from [10.67.121.177] (10.67.121.177) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 29 Feb 2024 19:12:28 +0800 CC: , , , , , , Subject: Re: [PATCH v2] drivers/perf: hisi: Enable HiSilicon Erratum 162700402 quirk for HIP09 To: Junhao He References: <20240227125231.53127-1-hejunhao3@huawei.com> From: Yicong Yang Message-ID: <4d628dcb-e54f-a6da-83aa-822957674819@huawei.com> Date: Thu, 29 Feb 2024 19:12:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240227125231.53127-1-hejunhao3@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500009.china.huawei.com (7.192.105.203) On 2024/2/27 20:52, Junhao He wrote: > HiSilicon UC PMU v2 suffers the erratum 162700402 that the PMU counter > cannot be set due to the lack of clock under power saving mode. This will > lead to error or inaccurate counts. The clock can be enabled by the PMU > global enabling control. > > This patch tries to fix this by set the UC PMU enable before set event > period to turn on the clock, and then restore the UC PMU configuration. > The counter register can hold its value without a clock. > > Signed-off-by: Junhao He > --- > > Changes since V1: > - Updated the comment regarding the quirk function. > - Extract write counter normal to a helper function. > Link: https://lore.kernel.org/all/20240207094245.34195-1-hejunhao3@huawei.com/ > This version looks clearer to me, Reviewed-by: Yicong Yang > drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 42 ++++++++++++++++++++- > 1 file changed, 41 insertions(+), 1 deletion(-) > > diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c > index 636fb79647c8..481dcc9e8fbf 100644 > --- a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c > +++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c > @@ -287,12 +287,52 @@ static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu, > return readq(uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx)); > } > > -static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu, > +static bool hisi_uc_pmu_get_glb_en_state(struct hisi_pmu *uc_pmu) > +{ > + u32 val; > + > + val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG); > + return !!FIELD_GET(HISI_UC_EVENT_GLB_EN, val); > +} > + > +static void hisi_uc_pmu_write_counter_normal(struct hisi_pmu *uc_pmu, > struct hw_perf_event *hwc, u64 val) > { > writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx)); > } > > +static void hisi_uc_pmu_write_counter_quirk_v2(struct hisi_pmu *uc_pmu, > + struct hw_perf_event *hwc, u64 val) > +{ > + hisi_uc_pmu_start_counters(uc_pmu); > + hisi_uc_pmu_write_counter_normal(uc_pmu, hwc, val); > + hisi_uc_pmu_stop_counters(uc_pmu); > +} > + > +static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu, > + struct hw_perf_event *hwc, u64 val) > +{ > + bool enable = hisi_uc_pmu_get_glb_en_state(uc_pmu); > + bool erratum = uc_pmu->identifier == HISI_PMU_V2; > + > + /* > + * HiSilicon UC PMU v2 suffers the erratum 162700402 that the > + * PMU counter cannot be set due to the lack of clock under power > + * saving mode. This will lead to error or inaccurate counts. > + * The clock can be enabled by the PMU global enabling control. > + * The irq handler and pmu_start() will call the function to set > + * period. If the function under irq context, the PMU has been > + * enabled therefore we set counter directly. Other situations > + * the PMU is disabled, we need to enable it to turn on the > + * counter clock to set period, and then restore PMU enable > + * status, the counter can hold its value without a clock. > + */ > + if (enable || !erratum) > + hisi_uc_pmu_write_counter_normal(uc_pmu, hwc, val); > + else > + hisi_uc_pmu_write_counter_quirk_v2(uc_pmu, hwc, val); > +} > + > static void hisi_uc_pmu_enable_counter_int(struct hisi_pmu *uc_pmu, > struct hw_perf_event *hwc) > { >