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

Commit 72483f35 authored by Sudarshan Rajagopalan's avatar Sudarshan Rajagopalan
Browse files

dma-buf: Use monotonic clock for buffer time tracking



gettimeofday() uses CLOCK_REALTIME which gives the current real-world
time. This time is discontiguous from boot till the userspace sets
the "wall clock time". Depending on such discountigous timer for
tracking buffer alive time is not right. Instead, use ktime which
uses CLOCK_MONOTONIC which is guaranteed to increase monotonically
from zero when system boots.

Change-Id: I2889be4ac7bb0e2ffd8845af1a8c91759712c891
Signed-off-by: default avatarSudarshan Rajagopalan <sudaraja@codeaurora.org>
parent 4164fb8e
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -474,7 +474,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
	dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll;
	dmabuf->cb_excl.active = dmabuf->cb_shared.active = 0;
	dmabuf->name = bufname;
	getnstimeofday(&dmabuf->ctime);
	dmabuf->ktime = ktime_get();

	if (!resv) {
		resv = (struct reservation_object *)&dmabuf[1];
@@ -1326,24 +1326,21 @@ static int get_dma_info(const void *data, struct file *file, unsigned int n)
static void write_proc(struct seq_file *s, struct dma_proc *proc)
{
	struct dma_info *tmp;
	struct timespec curr_time;

	getnstimeofday(&curr_time);
	seq_printf(s, "\n%s (PID %ld) size: %ld\nDMA Buffers:\n",
		proc->name, proc->pid, proc->size);
	seq_printf(s, "%-8s\t%-8s\t%-8s\n",
		"Name", "Size (KB)", "Time Alive (sec)");

	list_for_each_entry(tmp, &proc->dma_bufs, head) {
		struct dma_buf *dmabuf;
		struct timespec mtime;
		__kernel_time_t elap_mtime;
		struct dma_buf *dmabuf = tmp->dmabuf;
		ktime_t elapmstime = ktime_ms_delta(ktime_get(), dmabuf->ktime);

		dmabuf = tmp->dmabuf;
		mtime = dmabuf->ctime;
		elap_mtime = curr_time.tv_sec - mtime.tv_sec;
		elapmstime = ktime_divns(elapmstime, MSEC_PER_SEC);
		seq_printf(s, "%-8s\t%-8ld\t%-8ld\n",
			dmabuf->name, dmabuf->size / SZ_1K, elap_mtime);
				dmabuf->name,
				dmabuf->size / SZ_1K,
				elapmstime);
	}
}

+2 −1
Original line number Diff line number Diff line
@@ -383,6 +383,7 @@ struct dma_buf_ops {
 * @vmap_ptr: the current vmap ptr if vmapping_counter > 0
 * @exp_name: name of the exporter; useful for debugging.
 * @name: unique name for the buffer
 * @ktime: time (in jiffies) at which the buffer was born
 * @owner: pointer to exporter module; used for refcounting when exporter is a
 *         kernel module.
 * @list_node: node for dma_buf accounting and debugging.
@@ -411,7 +412,7 @@ struct dma_buf {
	void *vmap_ptr;
	const char *exp_name;
	char *name;
	struct timespec ctime;
	ktime_t ktime;
	struct module *owner;
	struct list_head list_node;
	void *priv;