Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4093405pxb; Tue, 26 Jan 2021 12:12:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwr6Ue96/XMm3c/X1r9lrabNnVdOWJrcpTK0Fr500no1XcvXoszvDdQqtGEgidbxjfp3C2i X-Received: by 2002:a50:e0c1:: with SMTP id j1mr5754578edl.253.1611691920008; Tue, 26 Jan 2021 12:12:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611691920; cv=none; d=google.com; s=arc-20160816; b=iivK3crVrccjtl4VnnJwGioZK2LSxmxCMHE1zQCk5K78vKIATSEDcdQPYtIgQc/+DL kONxJJScQMBx339HReDiEII3h7/JCE14RQreb7Sb0jxyZFdYrpTW9E5FzZFnh/bAtH6w Pbudlx9OV+MA0ZK3woLc0oXqXqNXvI33H1srvwp3QFiPjolimA8ZSWuk4If7gZ87WtAO B79tZsYZ9MMl7hwdZAgJii+blQXZ2PUdO+/EgaSN2y+Cw0aBB1RrlMoDMAGmV0/kVAYr IwD8WDlODkIhQtwVL68kYDN2MRyfcUkjsfYkm3YmsOkrxOvOOGUqs7Ob1/Rr4KUL0K2c X9eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=EGHeTnkluGx85vTn09S+7Ug77lRzli3BY5TbwIS3ebQ=; b=t9CSGkBVSeJ38RFYNT4xMRQz8MowUDpH2+thIeZmJTMKrPeQIPXTzKc3uJiumCXr3s eoQL/pDMIyAaf/eACb5p/tODxyx4ha7MyZ4Ock/7ngFG1Dqvi7CC5NJ4knMEik6eoj01 5dzaSbbyHedsolWEJvskSTY6puKGknij3OXZa+W7GBPpg1KSBq/gbbwkymfBD6p7bstQ 1yKDrv3O7aP7FVU1nCOHJEi+fcnZm8+gtuVDAf9g0w7DJpv6pBrHTHsQkVm1+lch33iu mwbucBKMOEYA8rovsCNjGOf0eM16B1Ru+mVNdqe9M0phszC4oJmraJHvfuEgfiGDMB7K LC0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zm16si7492313ejb.35.2021.01.26.12.11.34; Tue, 26 Jan 2021 12:11:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393113AbhAZRpX (ORCPT + 99 others); Tue, 26 Jan 2021 12:45:23 -0500 Received: from mga05.intel.com ([192.55.52.43]:6423 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389659AbhAZIKJ (ORCPT ); Tue, 26 Jan 2021 03:10:09 -0500 IronPort-SDR: eoDhxz2Mc321mRnTBAK2iZcL3DOnGrkHAxM+sWrB+c0bdZAvgHPP8XKdnjeedLiu64sX1wbYrD T1mTT4uSnabw== X-IronPort-AV: E=McAfee;i="6000,8403,9875"; a="264688809" X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="264688809" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2021 00:06:33 -0800 IronPort-SDR: Ls4TMIdyeImP0viNg2nwhJz5Flw+DJnoYqN9idZ2iERjMCBTrTXbL+bfIsePSaYNngx032p6nj BCf5PMmSLbRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="572855841" Received: from nntpdsd52-183.inn.intel.com ([10.125.52.183]) by orsmga005.jf.intel.com with ESMTP; 26 Jan 2021 00:06:30 -0800 From: Alexander Antonov To: acme@kernel.org Cc: linux-kernel@vger.kernel.org, jolsa@redhat.com, ak@linux.intel.com, alexander.shishkin@linux.intel.com, mark.rutland@arm.com, namhyung@kernel.org, irogers@google.com, mingo@redhat.com, peterz@infradead.org, alexander.antonov@linux.intel.com Subject: [PATCH v3 3/5] perf stat: Helper functions for PCIe root ports list in iostat mode Date: Tue, 26 Jan 2021 11:06:17 +0300 Message-Id: <20210126080619.30275-4-alexander.antonov@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210126080619.30275-1-alexander.antonov@linux.intel.com> References: <20210126080619.30275-1-alexander.antonov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce helper functions to control PCIe root ports list. These helpers will be used in the follow-up patch. Signed-off-by: Alexander Antonov --- tools/perf/arch/x86/util/iostat.c | 127 ++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tools/perf/arch/x86/util/iostat.c diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c new file mode 100644 index 000000000000..3ef727f9da63 --- /dev/null +++ b/tools/perf/arch/x86/util/iostat.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * perf iostat + * + * Copyright (C) 2020, Intel Corporation + * + * Authors: Alexander Antonov + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "util/cpumap.h" +#include "util/debug.h" +#include "util/iostat.h" +#include "util/counts.h" +#include "path.h" + +struct iio_root_port { + u32 domain; + u8 bus; + u8 die; + u8 pmu_idx; + int idx; +}; + +struct iio_root_ports_list { + struct iio_root_port **rps; + int nr_entries; +}; + +static void iio_root_port_show(FILE *output, + const struct iio_root_port * const rp) +{ + if (output && rp) + fprintf(output, "S%d-uncore_iio_%d<%04x:%02x>\n", + rp->die, rp->pmu_idx, rp->domain, rp->bus); +} + +static struct iio_root_port *iio_root_port_new(u32 domain, u8 bus, + u8 die, u8 pmu_idx) +{ + struct iio_root_port *p = calloc(1, sizeof(*p)); + + if (p) { + p->domain = domain; + p->bus = bus; + p->die = die; + p->pmu_idx = pmu_idx; + } + return p; +} + +static struct iio_root_ports_list *iio_root_ports_list_new(void) +{ + struct iio_root_ports_list *list = calloc(1, sizeof(*list)); + + if (list) { + list->rps = calloc(1, sizeof(struct iio_root_port *)); + if (!list->rps) { + free(list); + list = NULL; + } + } + + return list; +} + +static void iio_root_ports_list_free(struct iio_root_ports_list *list) +{ + int idx; + + if (list) { + for (idx = 0; idx < list->nr_entries; idx++) + free(list->rps[idx]); + free(list->rps); + free(list); + } +} + +static struct iio_root_port *iio_root_port_find_by_notation( + const struct iio_root_ports_list * const list, u32 domain, u8 bus) +{ + int idx; + struct iio_root_port *rp; + + if (list) { + for (idx = 0; idx < list->nr_entries; idx++) { + rp = list->rps[idx]; + if (rp && rp->domain == domain && rp->bus == bus) + return rp; + } + } + return NULL; +} + +static int iio_root_ports_list_insert(struct iio_root_ports_list *list, + struct iio_root_port * const rp) +{ + struct iio_root_port **tmp_buf; + + if (list && rp) { + rp->idx = list->nr_entries++; + /* One more for NULL.*/ + tmp_buf = realloc(list->rps, + (list->nr_entries + 1) * sizeof(*list->rps)); + if (!tmp_buf) { + pr_err("Failed to realloc memory\n"); + return -ENOMEM; + } + tmp_buf[rp->idx] = rp; + tmp_buf[list->nr_entries] = NULL; + list->rps = tmp_buf; + } + return 0; +} -- 2.19.1