Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5765873pxu; Wed, 23 Dec 2020 05:06:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNrcRhFFrseuTADhUOgxCF3UomiSxY4Be6q9pAoIEIa8speQMK3jKwbehILW3YnTkAMk/5 X-Received: by 2002:a17:906:b217:: with SMTP id p23mr19642123ejz.461.1608728809018; Wed, 23 Dec 2020 05:06:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608728809; cv=none; d=google.com; s=arc-20160816; b=FFxhX+Dpk2e6v6LY2peeGoLVjyZ+bQaF3qgeAwWVmCSj/P38FBZVcaHwj+NXruIDiU tJohyHW4aLiTH9IjkGjU/Xx0/S7EW4EvrBe7n2c/cp9gRcQiwHwJClaHMB1hcIz6+uXZ jNZ8oiXH9WShfC0EyHs1V9AkGY5Nb8q7MUfY++1HNAEOF9PmkBJOY1APxC5JfHc26wp7 mTU2BLEY7mpz/bMcxEntUex0uLxm9cCKr3I8bBw9xNyw69sM0gFvP09i7cCvbtF9bFQV hgvEyn7+D57DpafVHbSOhABAPnC01gyFvrEYkd4Ao1xa2h2RlbL9HxhyH7RtQ7ISn0nh Cqyw== 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=GQEGh0m+NTPmtbyUDuII+8SX9h69uvlF5qdnN2tVzs0=; b=t6wJBbf8ldVyTN4dzEj9GMHO69V0sehopr0mQh6f0YAmJ7Ou9LHvYjt8szhLo9I8LX bY+H/Qa1qCMHMcKFKsS9WzGPMdzfTkQbcgp1ZLQtLSr3muM+cBQezzRti4qrEfsRR9FZ xA5aKMeyr20bzFkTTPAW5JlwPOiykrYEVSO3Qmt6oKyhbxM6clk3G1Dg5Dn/gAIfjYcM n7W2y61JVgD7mKeikhckqjs8cvo11zXmqeG+5kWRSgENEYbHM3SaLeva+/QtPiNGL4cw bPH7ZryLDA4iK6p8jbSTw4iqrIQo+tMc5OKWM0zJQTTlRC9WYqNEUFn2aZp1JXcy+sBJ v09g== 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 b24si11455425eju.531.2020.12.23.05.06.25; Wed, 23 Dec 2020 05:06:49 -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 S1728606AbgLWNFV (ORCPT + 99 others); Wed, 23 Dec 2020 08:05:21 -0500 Received: from mga02.intel.com ([134.134.136.20]:55057 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727422AbgLWNFU (ORCPT ); Wed, 23 Dec 2020 08:05:20 -0500 IronPort-SDR: QX7vq5yAMhe3GKOKPk8wCxU3ylFrtx6lQ2MLGsRg3jsKLjD16DCgSQ/3DKy6dZYfREiZdzX9+8 uXI6iZ/9AvrA== X-IronPort-AV: E=McAfee;i="6000,8403,9843"; a="163068594" X-IronPort-AV: E=Sophos;i="5.78,441,1599548400"; d="scan'208";a="163068594" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2020 05:03:35 -0800 IronPort-SDR: H7TatNds+gnfhlfHoJrf3aQcGUi1WkFiA5k9kGKxThXz8jdn/gHkLzxNG84RO/3/Covv3N9M+R lex2wrshsx1A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,441,1599548400"; d="scan'208";a="393087790" Received: from nntpdsd52-183.inn.intel.com ([10.125.52.183]) by fmsmga002.fm.intel.com with ESMTP; 23 Dec 2020 05:03:32 -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 v2 4/6] perf stat: Helper functions for IIO stacks list in iiostat mode Date: Wed, 23 Dec 2020 16:03:18 +0300 Message-Id: <20201223130320.3930-5-alexander.antonov@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20201223130320.3930-1-alexander.antonov@linux.intel.com> References: <20201223130320.3930-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 IIO stacks list. These helpers will be used in the follow-up patch. Signed-off-by: Alexander Antonov --- tools/perf/arch/x86/util/iiostat.c | 125 +++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 tools/perf/arch/x86/util/iiostat.c diff --git a/tools/perf/arch/x86/util/iiostat.c b/tools/perf/arch/x86/util/iiostat.c new file mode 100644 index 000000000000..98b9707b4827 --- /dev/null +++ b/tools/perf/arch/x86/util/iiostat.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * perf iiostat + * + * 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/iiostat.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