Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp454352rwd; Sat, 27 May 2023 00:08:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+zJMd/3zpg/EcdQ1fQvDrq+ohR52tkmPw5PKV6ZD1fd5EHmx9DQVo3tqqeTTipi9j/ZPK X-Received: by 2002:a05:6a00:10cb:b0:644:c365:50d5 with SMTP id d11-20020a056a0010cb00b00644c36550d5mr6680337pfu.6.1685171335013; Sat, 27 May 2023 00:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685171334; cv=none; d=google.com; s=arc-20160816; b=Bb2PYuHyi5L9num3ktHX8q2wTEkKvLxAqHfgxugsE2k372x1Vki3nM2sSYVN3/WN3h PcioRiv0QNBeVa4VLZR7qUO9lYJtxpd2BLzmu9CN6c4b5K0D8wcqlScsY2WMTgeBcdwj eaiAPux3aPsv38UUvIUA8weWDNifOlnk0jHOVZgva9IyzRhDIbIk37HWO9fLpKIHMlXe qu6bN2j25o4F+SosiBRq8XXUC3f/EKiT3O3LF5UYB9L+E3ctE/MENQo/yEnDwZu/+NZO fpHVvagKwBS0sRlfqczCSBItTgNLvYz2IMQDbBC7MPUMxz1lPUhl876T6F/PfitUrEdI Ixqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=Qen4GVWa/7aIbQPBEtYhhBVhYqE76cxpfox6PcTbjwM=; b=RRfwcuEvNz7w9dWV2oxbZXrnzRvODVpgFTSTm7JSSk7wz9AysRiJWCRffJgAH6mMyw CGSniJxjJ4V86GWAQdQb7Ukm0N04osA/E+UUrw67pOKzW9fsLUKhUFJXMWXHJ2xkpZxa gJSfg5kc3FIaGWHwRuY4bRXPSVmsxyX7VQ5pXw296JJIsEjQygIu9tYh4Mdhysd+eqEu pqQ6fgJhmH3y0YHapRqi9/T6XW1LOP9wBY48WP58k8bK6kBDMuqOUB6Gi99N0m6L3Szp t7t+Khtl4zxE8omlZRsnFU06T04q7rHEFsmO1ex7i6+yjBtXzHdqkKDbKGqEY2+cRZjg Bs4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v128-20020a626186000000b0064f74cf9df3si3617643pfb.110.2023.05.27.00.08.39; Sat, 27 May 2023 00:08:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbjE0G0l convert rfc822-to-8bit (ORCPT + 99 others); Sat, 27 May 2023 02:26:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjE0G0g (ORCPT ); Sat, 27 May 2023 02:26:36 -0400 Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9F1116; Fri, 26 May 2023 23:26:34 -0700 (PDT) Received: by mail-ua1-f53.google.com with SMTP id a1e0cc1a2514c-786470fd7a3so443942241.3; Fri, 26 May 2023 23:26:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685168794; x=1687760794; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K1Vo/4/ITtOwqXGKuD1nMtQeDHz1HuSSJxIWcuEXzLo=; b=TbAdKBIgSrv3BNl1t5qhDNT8Y4YVzdBt7yOxDRkjk1eLHXJWSXRUoxnosuQM5G8zRI /lnKEnZ7hNYqj7tjLTT6tsW5LBdtnAP0sVBJ5VmvNT4F89rbqpFxRgJ01EgQZFUdnUMM vYS3AEUOTIPrIFAL1kTaLRQS0i6RymhjsAnXMkRHbYBatqhuJ10Xcdy+JlBH7ENbnEXx 23foDNEdnvqZn1KNLdGrsBLoG74B7WoJt95pv7PrVZotOtETDfbHoc6kkcTysmz7qxXh w45e/Tle3JAubrNN4EePjFFreWaurTYtoSwhzb1CrjWys5FhrgzobHFUUBIpz+byhms3 2b3w== X-Gm-Message-State: AC+VfDxJnS1OB4tusxKwSZMer55TA8+Ovr7unZ+VKaIPK3RF0SzQei3p lgMpRCpziUrn/iK44QlWlpTI3zrgZQenf+5qXSBduaED X-Received: by 2002:a1f:cac6:0:b0:45a:8582:126d with SMTP id a189-20020a1fcac6000000b0045a8582126dmr438138vkg.8.1685168793866; Fri, 26 May 2023 23:26:33 -0700 (PDT) MIME-Version: 1.0 References: <20230526095824.16336-1-Jonathan.Cameron@huawei.com> <20230526095824.16336-5-Jonathan.Cameron@huawei.com> In-Reply-To: <20230526095824.16336-5-Jonathan.Cameron@huawei.com> From: Namhyung Kim Date: Fri, 26 May 2023 23:26:22 -0700 Message-ID: Subject: Re: [PATCH v7 4/5] perf: CXL Performance Monitoring Unit driver To: Jonathan Cameron Cc: Liang Kan , linux-cxl@vger.kernel.org, peterz@infradead.org, mark.rutland@arm.com, will@kernel.org, dan.j.williams@intel.com, mingo@redhat.com, acme@kernel.org, linuxarm@huawei.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso , Dave Jiang , Stephane Eranian Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 26, 2023 at 3:00 AM Jonathan Cameron wrote: > > CXL rev 3.0 introduces a standard performance monitoring hardware > block to CXL. Instances are discovered using CXL Register Locator DVSEC > entries. Each CXL component may have multiple PMUs. > > This initial driver supports a subset of types of counter. > It supports counters that are either fixed or configurable, but requires > that they support the ability to freeze and write value whilst frozen. > > Development done with QEMU model which will be posted shortly. > > Example: > > $ perf stat -a -e cxl_pmu_mem0.0/h2d_req_snpcur/ -e cxl_pmu_mem0.0/h2d_req_snpdata/ -e cxl_pmu_mem0.0/clock_ticks/ sleep 1 > > Performance counter stats for 'system wide': > > 96,757,023,244,321 cxl_pmu_mem0.0/h2d_req_snpcur/ > 96,757,023,244,365 cxl_pmu_mem0.0/h2d_req_snpdata/ > 193,514,046,488,653 cxl_pmu_mem0.0/clock_ticks/ > > 1.090539600 seconds time elapsed > > Reviewed-by: Dave Jiang > Reviewed-by: Kan Liang > Signed-off-by: Jonathan Cameron > --- > v7: THanks to Namhyung and Stephane for reviews > - Set the cpu for an event only after validation checks. > - Added -a to make perf default of all CPUs explicit in command line. > - Fix wrong event names in example. > --- [SNIP] > +static void cxl_pmu_event_start(struct perf_event *event, int flags) > +{ > + struct cxl_pmu_info *info = pmu_to_cxl_pmu_info(event->pmu); > + struct hw_perf_event *hwc = &event->hw; > + void __iomem *base = info->base; > + u64 cfg; > + > + /* > + * All paths to here should either set these flags directly or > + * call cxl_pmu_event_stop() which will ensure the correct state. > + */ > + if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED))) > + return; > + > + WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE)); > + hwc->state = 0; > + > + /* > + * Currently only hdm filter control is implemnted, this code will Typo: implemented > + * want generalizing when more filters are added. > + */ > + if (info->filter_hdm) { > + if (cxl_pmu_config1_hdm_filter_en(event)) > + cfg = cxl_pmu_config2_get_hdm_decoder(event); > + else > + cfg = GENMASK(15, 0); /* No filtering if 0xFFFF_FFFF */ > + writeq(cfg, base + CXL_PMU_FILTER_CFG_REG(hwc->idx, 0)); > + } > + > + cfg = readq(base + CXL_PMU_COUNTER_CFG_REG(hwc->idx)); > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_INT_ON_OVRFLW, 1); > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_FREEZE_ON_OVRFLW, 1); > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_ENABLE, 1); > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_EDGE, > + cxl_pmu_config1_get_edge(event) ? 1 : 0); > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_INVERT, > + cxl_pmu_config1_get_invert(event) ? 1 : 0); > + > + /* Fixed purpose counters have next two fields RO */ > + if (test_bit(hwc->idx, info->conf_counter_bm)) { > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_EVENT_GRP_ID_IDX_MSK, > + hwc->event_base); > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_EVENTS_MSK, > + cxl_pmu_config_get_mask(event)); > + } > + cfg &= ~CXL_PMU_COUNTER_CFG_THRESHOLD_MSK; > + /* > + * For events that generate only 1 count per clock the CXL 3.0 spec > + * states the threshold shall be set to 1 but if set to 0 it will > + * count the raw value anwyay? Typo: anyway? > + * There is no definition of what events will count multiple per cycle > + * and hence to which non 1 values of threshold can apply. > + * (CXL 3.0 8.2.7.2.1 Counter Configuration - threshold field definition) > + */ > + cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_THRESHOLD_MSK, > + cxl_pmu_config1_get_threshold(event)); > + writeq(cfg, base + CXL_PMU_COUNTER_CFG_REG(hwc->idx)); > + > + local64_set(&hwc->prev_count, 0); > + writeq(0, base + CXL_PMU_COUNTER_REG(hwc->idx)); > + > + perf_event_update_userpage(event); > +} > + [SNIP] > + > +static int cxl_pmu_online_cpu(unsigned int cpu, struct hlist_node *node) > +{ > + struct cxl_pmu_info *info = hlist_entry_safe(node, struct cxl_pmu_info, node); > + > + if (info->on_cpu != -1) > + return 0; > + > + info->on_cpu = cpu; > + /* > + * CPU HP lock is held so we should be guaranteed that the CPU hasn't yet > + * gone away again. > + */ > + WARN_ON(irq_set_affinity(info->irq, cpumask_of(cpu))); > + > + return 0; > +} > + > +static int cxl_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) > +{ > + struct cxl_pmu_info *info = hlist_entry_safe(node, struct cxl_pmu_info, node); > + unsigned int target; > + > + if (info->on_cpu != cpu) > + return 0; > + > + info->on_cpu = -1; > + target = cpumask_any_but(cpu_online_mask, cpu); > + if (target >= nr_cpu_ids) { > + dev_err(info->pmu.dev, "Unable to find a suitable CPU\n"); > + return 0; > + } > + > + perf_pmu_migrate_context(&info->pmu, cpu, target); > + info->on_cpu = target; > + /* > + * CPU HP lock is held so we should be guaranteed that this CPU hasn't yet > + * gone away. > + */ > + WARN_ON(irq_set_affinity(info->irq, cpumask_of(target))); > + > + return 0; > +} IIUC a CXL PMU hardware (say cxl_pmu_mem0.0) is shared across all CPUs and it would return the same value when read from any CPU, right? Thanks, Namhyung > + > +static __init int cxl_pmu_init(void) > +{ > + int rc; > + > + rc = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, > + "AP_PERF_CXL_PMU_ONLINE", > + cxl_pmu_online_cpu, cxl_pmu_offline_cpu); > + if (rc < 0) > + return rc; > + cxl_pmu_cpuhp_state_num = rc; > + > + rc = cxl_driver_register(&cxl_pmu_driver); > + if (rc) > + cpuhp_remove_multi_state(cxl_pmu_cpuhp_state_num); > + > + return rc; > +} > + > +static __exit void cxl_pmu_exit(void) > +{ > + cxl_driver_unregister(&cxl_pmu_driver); > + cpuhp_remove_multi_state(cxl_pmu_cpuhp_state_num); > +} > + > +MODULE_LICENSE("GPL"); > +MODULE_IMPORT_NS(CXL); > +module_init(cxl_pmu_init); > +module_exit(cxl_pmu_exit); > +MODULE_ALIAS_CXL(CXL_DEVICE_PMU); > -- > 2.39.2 >