Re: [RFC PATCH v2 5/5] drm, cgroup: Add peak GEM buffer allocation limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 09.05.19 um 23:04 schrieb Kenny Ho:
This new drmcgrp resource limits the largest GEM buffer that can be
allocated in a cgroup.

Change-Id: I0830d56775568e1cf215b56cc892d5e7945e9f25
Signed-off-by: Kenny Ho <Kenny.Ho@xxxxxxx>
---
  include/linux/cgroup_drm.h |  2 ++
  kernel/cgroup/drm.c        | 59 ++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+)

diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h
index fe14ba7bb1cf..57c07a148975 100644
--- a/include/linux/cgroup_drm.h
+++ b/include/linux/cgroup_drm.h
@@ -16,8 +16,10 @@
  struct drmcgrp_device_resource {
  	/* for per device stats */
  	s64			bo_stats_total_allocated;
+	size_t			bo_stats_peak_allocated;
s64 bo_limits_total_allocated;
+	size_t			bo_limits_peak_allocated;

Why s64 for the total limit and size_t for the peak allocation?

Christian.

  };
struct drmcgrp {
diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c
index bc3abff09113..5c7e1b8059ce 100644
--- a/kernel/cgroup/drm.c
+++ b/kernel/cgroup/drm.c
@@ -17,6 +17,7 @@ struct drmcgrp_device {
  	struct mutex		mutex;
s64 bo_limits_total_allocated_default;
+	size_t			bo_limits_peak_allocated_default;
  };
#define DRMCG_CTF_PRIV_SIZE 3
@@ -24,6 +25,7 @@ struct drmcgrp_device {
enum drmcgrp_res_type {
  	DRMCGRP_TYPE_BO_TOTAL,
+	DRMCGRP_TYPE_BO_PEAK,
  };
enum drmcgrp_file_type {
@@ -72,6 +74,9 @@ static inline int init_drmcgrp_single(struct drmcgrp *drmcgrp, int i)
  	if (known_drmcgrp_devs[i] != NULL) {
  		ddr->bo_limits_total_allocated =
  		  known_drmcgrp_devs[i]->bo_limits_total_allocated_default;
+
+		ddr->bo_limits_peak_allocated =
+		  known_drmcgrp_devs[i]->bo_limits_peak_allocated_default;
  	}
return 0;
@@ -131,6 +136,9 @@ static inline void drmcgrp_print_stats(struct drmcgrp_device_resource *ddr,
  	case DRMCGRP_TYPE_BO_TOTAL:
  		seq_printf(sf, "%lld\n", ddr->bo_stats_total_allocated);
  		break;
+	case DRMCGRP_TYPE_BO_PEAK:
+		seq_printf(sf, "%zu\n", ddr->bo_stats_peak_allocated);
+		break;
  	default:
  		seq_puts(sf, "\n");
  		break;
@@ -149,6 +157,9 @@ static inline void drmcgrp_print_limits(struct drmcgrp_device_resource *ddr,
  	case DRMCGRP_TYPE_BO_TOTAL:
  		seq_printf(sf, "%lld\n", ddr->bo_limits_total_allocated);
  		break;
+	case DRMCGRP_TYPE_BO_PEAK:
+		seq_printf(sf, "%zu\n", ddr->bo_limits_peak_allocated);
+		break;
  	default:
  		seq_puts(sf, "\n");
  		break;
@@ -167,6 +178,9 @@ static inline void drmcgrp_print_default(struct drmcgrp_device *ddev,
  	case DRMCGRP_TYPE_BO_TOTAL:
  		seq_printf(sf, "%lld\n", ddev->bo_limits_total_allocated_default);
  		break;
+	case DRMCGRP_TYPE_BO_PEAK:
+		seq_printf(sf, "%zu\n", ddev->bo_limits_peak_allocated_default);
+		break;
  	default:
  		seq_puts(sf, "\n");
  		break;
@@ -182,6 +196,11 @@ static inline void drmcgrp_print_help(int cardNum, struct seq_file *sf,
  		"Total amount of buffer allocation in bytes for card%d\n",
  		cardNum);
  		break;
+	case DRMCGRP_TYPE_BO_PEAK:
+		seq_printf(sf,
+		"Largest buffer allocation in bytes for card%d\n",
+		cardNum);
+		break;
  	default:
  		seq_puts(sf, "\n");
  		break;
@@ -254,6 +273,10 @@ ssize_t drmcgrp_bo_limit_write(struct kernfs_open_file *of, char *buf,
                                  if (val < 0) continue;
  				ddr->bo_limits_total_allocated = val;
  				break;
+			case DRMCGRP_TYPE_BO_PEAK:
+                                if (val < 0) continue;
+				ddr->bo_limits_peak_allocated = val;
+				break;
  			default:
  				break;
  			}
@@ -300,6 +323,33 @@ struct cftype files[] = {
  		.private = (DRMCGRP_TYPE_BO_TOTAL << DRMCG_CTF_PRIV_SIZE) |
  			DRMCGRP_FTYPE_MAX,
  	},
+	{
+		.name = "buffer.peak.stats",
+		.seq_show = drmcgrp_bo_show,
+		.private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) |
+			DRMCGRP_FTYPE_STATS,
+	},
+	{
+		.name = "buffer.peak.default",
+		.seq_show = drmcgrp_bo_show,
+		.flags = CFTYPE_ONLY_ON_ROOT,
+		.private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) |
+			DRMCGRP_FTYPE_DEFAULT,
+	},
+	{
+		.name = "buffer.peak.help",
+		.seq_show = drmcgrp_bo_show,
+		.flags = CFTYPE_ONLY_ON_ROOT,
+		.private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) |
+			DRMCGRP_FTYPE_HELP,
+	},
+	{
+		.name = "buffer.peak.max",
+		.write = drmcgrp_bo_limit_write,
+		.seq_show = drmcgrp_bo_show,
+		.private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) |
+			DRMCGRP_FTYPE_MAX,
+	},
  	{ }	/* terminate */
  };
@@ -323,6 +373,7 @@ int drmcgrp_register_device(struct drm_device *dev) ddev->dev = dev;
  	ddev->bo_limits_total_allocated_default = S64_MAX;
+	ddev->bo_limits_peak_allocated_default = SIZE_MAX;
mutex_init(&ddev->mutex); @@ -393,6 +444,11 @@ bool drmcgrp_bo_can_allocate(struct task_struct *task, struct drm_device *dev,
  			result = false;
  			break;
  		}
+
+		if (d->bo_limits_peak_allocated < size) {
+			result = false;
+			break;
+		}
  	}
  	mutex_unlock(&known_drmcgrp_devs[devIdx]->mutex);
@@ -414,6 +470,9 @@ void drmcgrp_chg_bo_alloc(struct drmcgrp *drmcgrp, struct drm_device *dev,
  		ddr = drmcgrp->dev_resources[devIdx];
ddr->bo_stats_total_allocated += (s64)size;
+
+		if (ddr->bo_stats_peak_allocated < (size_t)size)
+			ddr->bo_stats_peak_allocated = (size_t)size;
  	}
  	mutex_unlock(&known_drmcgrp_devs[devIdx]->mutex);
  }

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux