Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e2efe32 authored by Mohammed Mirza Mandayappurath Manzoor's avatar Mohammed Mirza Mandayappurath Manzoor Committed by Gerrit - the friendly Code Review server
Browse files

msm: kgsl: Add a sysfs node to control performance counter reads



Currently performance counters are global and can be read by anyone. Change
the behaviour to disable reading global counters as default and add a sysfs
node to enable/disable reads.

Change-Id: Ic3785acd9bd7425c2a844ed103d7b870d9f80adf
Signed-off-by: default avatarMohammed Mirza Mandayappurath Manzoor <quic_mmandaya@quicinc.com>
Signed-off-by: default avatarHarshitha Sai Neelati <quic_hsaineel@quicinc.com>
parent 5a26bbcc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 */
#include <linux/delay.h>
#include <linux/input.h>
@@ -1578,6 +1579,8 @@ static int adreno_probe(struct platform_device *pdev)
	adreno_debugfs_init(adreno_dev);
	adreno_profile_init(adreno_dev);

	adreno_dev->perfcounter = false;

	adreno_sysfs_init(adreno_dev);

	kgsl_pwrscale_init(&pdev->dev, CONFIG_QCOM_ADRENO_DEFAULT_GOVERNOR);
+6 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 */
#ifndef __ADRENO_H
#define __ADRENO_H
@@ -556,6 +557,11 @@ struct adreno_device {
	bool gpuhtw_llc_slice_enable;
	unsigned int zap_loaded;
	unsigned int soc_hw_rev;
	/*
	 * @perfcounter: Flag to clear perfcounters across contexts and
	 * controls perfcounter ioctl read
	 */
	bool perfcounter;
};

/**
+9 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 */

#include "adreno.h"
@@ -164,6 +165,14 @@ static long adreno_ioctl_perfcounter_read_compat(
	struct kgsl_perfcounter_read_compat *read32 = data;
	struct kgsl_perfcounter_read read;

	/*
	 * When performance counter zapping is enabled, the counters are cleared
	 * across context switches. Reading the counters when they are zapped is
	 * not permitted.
	 */
	if (!adreno_dev->perfcounter)
		return -EPERM;

	read.reads = (struct kgsl_perfcounter_read_group __user *)
		(uintptr_t)read32->reads;
	read.count = read32->count;
+9 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 */

#include <linux/slab.h>
@@ -133,6 +134,14 @@ static long adreno_ioctl_perfcounter_read(struct kgsl_device_private *dev_priv,
	struct adreno_device *adreno_dev = ADRENO_DEVICE(dev_priv->device);
	struct kgsl_perfcounter_read *read = data;

	/*
	 * When performance counter zapping is enabled, the counters are cleared
	 * across context switches. Reading the counters when they are zapped is
	 * not permitted.
	 */
	if (!adreno_dev->perfcounter)
		return -EPERM;

	return (long) adreno_perfcounter_read_group(adreno_dev, read->reads,
		read->count);
}
+36 −1
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 */

#include <linux/sysfs.h>
@@ -323,6 +324,31 @@ static int _acd_store(struct adreno_device *adreno_dev, unsigned int val)
	return gmu_core_acd_set(device, val);
}

static unsigned int _perfcounter_show(struct adreno_device *adreno_dev)
{
	return adreno_dev->perfcounter;
}

static int _perfcounter_store(struct adreno_device *adreno_dev,
		unsigned int val)
{
	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);

	if (adreno_dev->perfcounter == val)
		return 0;

	mutex_lock(&device->mutex);

	/* Power down the GPU before changing the state */
	kgsl_pwrctrl_change_state(device, KGSL_STATE_SUSPEND);
	adreno_dev->perfcounter = val;
	kgsl_pwrctrl_change_state(device, KGSL_STATE_SLUMBER);

	mutex_unlock(&device->mutex);

	return 0;
}

static ssize_t _sysfs_store_u32(struct device *dev,
		struct device_attribute *attr,
		const char *buf, size_t count)
@@ -416,6 +442,7 @@ static ADRENO_SYSFS_BOOL(throttling);
static ADRENO_SYSFS_BOOL(ifpc);
static ADRENO_SYSFS_RO_U32(ifpc_count);
static ADRENO_SYSFS_BOOL(acd);
static ADRENO_SYSFS_BOOL(perfcounter);


static const struct attribute *_attr_list[] = {
@@ -439,6 +466,7 @@ static const struct attribute *_attr_list[] = {
	&adreno_attr_ifpc_count.attr.attr,
	&adreno_attr_preempt_count.attr.attr,
	&adreno_attr_acd.attr.attr,
	&adreno_attr_perfcounter.attr.attr,
	NULL,
};

@@ -465,7 +493,14 @@ void adreno_sysfs_close(struct adreno_device *adreno_dev)
int adreno_sysfs_init(struct adreno_device *adreno_dev)
{
	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
	int ret;

	return sysfs_create_files(&device->dev->kobj, _attr_list);
	ret = sysfs_create_files(&device->dev->kobj, _attr_list);

	/* Notify userspace */
	if (!ret)
		kobject_uevent(&device->dev->kobj, KOBJ_ADD);

	return ret;
}