Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2338364pxb; Mon, 19 Apr 2021 03:27:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwu7B+d4rCw2FBzsL5eoU4MOrJTutsoZLAC0d/q5gXHwaUwoMkdNjGnzJO3VFx159LPWbpB X-Received: by 2002:a50:d4dd:: with SMTP id e29mr18754305edj.257.1618828063246; Mon, 19 Apr 2021 03:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618828063; cv=none; d=google.com; s=arc-20160816; b=U3FdN7Mdaf8W64wmJZY0UUsEQ8AHVTMhFf9jm1n/FBRcyfOb4noL2w8FA6DGfs/QX/ NtvDI48fPWWT51xh9AJao3Hl7UiCVXeYV/Q1hRcNBsQ9KfLxdo51/I1ZTfrbgwHsqku9 kcuzNY+PR0L41aM3Xh+sP8D21Bddnl/u26J3QxwbFgW7VldeA/zRWBUIDSnI3ai7oaYO 938Q7a6yGDlGv9sr+lA2xnkTeezVOxPGGSqjhLwVBlagYyr3lweBF3CP74XaZTzdnWi2 E+14sF54pzvVinBiHFpZScj3s24bUhB4l0yLVbl56HF4jg9ec7NehrPZIYA+FBvP/JG/ F+dw== 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=l8fYC0feE/wIcUXqI6Pdv4FlUUx/fy1vsjTtfSr2dAw=; b=kPJlcl/GxjQGKg0J/QbCCepk6e1VEDW74K4H/30DjSzTyJpVrdrK0/eTQRANlCwIhi eV+iuBxT2pnBVnoQI6WPvqxw8iwvAc9pgijRMOjWrf6IABAKEN17fP6FuwzkLuNg9zkN D3inKvFVT+DUPhTInf5VARslNnZjI1cEOwwbgjBbmGfvyvD8JWU+kpIj2614+l8nYyNC k74nrlk0CjX2j/zGNViww1gLaSDz7DJZBx64QMwqnDYDUbADxYv/2vkT+M9kgJWrVN/b X20ztaMe5J1xTruiA7/G2k8BBxa5Y9Dhsxgyx6+4e9OaWO9ly/vtf2eR3NSugeZ/mUne D2wA== 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 g16si12209641ejm.310.2021.04.19.03.27.20; Mon, 19 Apr 2021 03:27:43 -0700 (PDT) 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 S238028AbhDSJme (ORCPT + 99 others); Mon, 19 Apr 2021 05:42:34 -0400 Received: from mga12.intel.com ([192.55.52.136]:60390 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231904AbhDSJm1 (ORCPT ); Mon, 19 Apr 2021 05:42:27 -0400 IronPort-SDR: 2YC4LCTtThz0YflRoiUY8a6/B/WmYq3K6OgPUsFSUdO9/o2CLumvYNAAjgT9ROseT93+XFJ7u0 3Aj28LMpKWaQ== X-IronPort-AV: E=McAfee;i="6200,9189,9958"; a="174787674" X-IronPort-AV: E=Sophos;i="5.82,233,1613462400"; d="scan'208";a="174787674" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2021 02:41:58 -0700 IronPort-SDR: E1DomlE8udAJKtddbxmOe9Z/y9Jy4Rk6rqqr/7XyG2GL+BIIXXYm68gJ1Zn2ctUeq+q4fcwN5M DjuEqsQWqElQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,233,1613462400"; d="scan'208";a="452089684" Received: from nntpdsd52-165.inn.intel.com ([10.125.52.165]) by FMSMGA003.fm.intel.com with ESMTP; 19 Apr 2021 02:41:54 -0700 From: alexander.antonov@linux.intel.com 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, alexey.v.bayduraev@linux.intel.com Subject: [RESEND PATCH v5 2/4] perf stat: Helper functions for PCIe root ports list in iostat mode Date: Mon, 19 Apr 2021 12:41:45 +0300 Message-Id: <20210419094147.15909-3-alexander.antonov@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20210419094147.15909-1-alexander.antonov@linux.intel.com> References: <20210419094147.15909-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 From: Alexander Antonov Introduce helper functions to control PCIe root ports list. These helpers will be used in the follow-up patch. Acked-by: Namhyung Kim Signed-off-by: Alexander Antonov --- tools/perf/arch/x86/util/iostat.c | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 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..c4471f8efa5e --- /dev/null +++ b/tools/perf/arch/x86/util/iostat.c @@ -0,0 +1,110 @@ +// 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 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++; + tmp_buf = realloc(list->rps, + list->nr_entries * sizeof(*list->rps)); + if (!tmp_buf) { + pr_err("Failed to realloc memory\n"); + return -ENOMEM; + } + tmp_buf[rp->idx] = rp; + list->rps = tmp_buf; + } + return 0; +} -- 2.21.3