/* CacheFiles statistics
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public Licence
 * as published by the Free Software Foundation; either version
 * 2 of the Licence, or (at your option) any later version.
 */

#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "internal.h"

atomic_t cachefiles_lookup_histogram[HZ];
atomic_t cachefiles_mkdir_histogram[HZ];
atomic_t cachefiles_create_histogram[HZ];

/*
 * display the latency histogram
 */
static int cachefiles_histogram_show(struct seq_file *m, void *v)
{
	unsigned long index;
	unsigned x, y, z, t;

	switch ((unsigned long) v) {
	case 1:
		seq_puts(m, "JIFS  SECS  LOOKUPS   MKDIRS    CREATES\n");
		return 0;
	case 2:
		seq_puts(m, "===== ===== ========= ========= =========\n");
		return 0;
	default:
		index = (unsigned long) v - 3;
		x = atomic_read(&cachefiles_lookup_histogram[index]);
		y = atomic_read(&cachefiles_mkdir_histogram[index]);
		z = atomic_read(&cachefiles_create_histogram[index]);
		if (x == 0 && y == 0 && z == 0)
			return 0;

		t = (index * 1000) / HZ;

		seq_printf(m, "%4lu  0.%03u %9u %9u %9u\n", index, t, x, y, z);
		return 0;
	}
}

/*
 * set up the iterator to start reading from the first line
 */
static void *cachefiles_histogram_start(struct seq_file *m, loff_t *_pos)
{
	if ((unsigned long long)*_pos >= HZ + 2)
		return NULL;
	if (*_pos == 0)
		*_pos = 1;
	return (void *)(unsigned long) *_pos;
}

/*
 * move to the next line
 */
static void *cachefiles_histogram_next(struct seq_file *m, void *v, loff_t *pos)
{
	(*pos)++;
	return (unsigned long long)*pos > HZ + 2 ?
		NULL : (void *)(unsigned long) *pos;
}

/*
 * clean up after reading
 */
static void cachefiles_histogram_stop(struct seq_file *m, void *v)
{
}

static const struct seq_operations cachefiles_histogram_ops = {
	.start		= cachefiles_histogram_start,
	.stop		= cachefiles_histogram_stop,
	.next		= cachefiles_histogram_next,
	.show		= cachefiles_histogram_show,
};

/*
 * open "/proc/fs/cachefiles/XXX" which provide statistics summaries
 */
static int cachefiles_histogram_open(struct inode *inode, struct file *file)
{
	return seq_open(file, &cachefiles_histogram_ops);
}

static const struct file_operations cachefiles_histogram_fops = {
	.open		= cachefiles_histogram_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= seq_release,
};

/*
 * initialise the /proc/fs/cachefiles/ directory
 */
int __init cachefiles_proc_init(void)
{
	_enter("");

	if (!proc_mkdir("fs/cachefiles", NULL))
		goto error_dir;

	if (!proc_create("fs/cachefiles/histogram", S_IFREG | 0444, NULL,
			 &cachefiles_histogram_fops))
		goto error_histogram;

	_leave(" = 0");
	return 0;

error_histogram:
	remove_proc_entry("fs/cachefiles", NULL);
error_dir:
	_leave(" = -ENOMEM");
	return -ENOMEM;
}

/*
 * clean up the /proc/fs/cachefiles/ directory
 */
void cachefiles_proc_cleanup(void)
{
	remove_proc_entry("fs/cachefiles/histogram", NULL);
	remove_proc_entry("fs/cachefiles", NULL);
}
dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>testing</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>selftests</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/vm?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>vm</a>/<a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/vm/mlock-random-test.c?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>mlock-random-test.c</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>Linus Torvalds &lt;torvalds@linux-foundation.org&gt;</td><td class='right'>2017-01-27 12:29:30 -0800</td></tr>
<tr><th>committer</th><td>Linus Torvalds &lt;torvalds@linux-foundation.org&gt;</td><td class='right'>2017-01-27 12:29:30 -0800</td></tr>
<tr><th>commit</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/vm/mlock-random-test.c?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>dd3b9f25c867cb2507a45e436d6ede8eb08e7b05</a> (<a href='/cgit.cgi/linux/net-next.git/patch/tools/testing/selftests/vm/mlock-random-test.c?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/tree/?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>1ec6c08cd75610083d117a2c8d5eb0829e65f33e</a> /<a href='/cgit.cgi/linux/net-next.git/tree/tools/testing/selftests/vm/mlock-random-test.c?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>tools/testing/selftests/vm/mlock-random-test.c</a></td></tr>
<tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/vm/mlock-random-test.c?id=69978aa0f21f43529e11f924504dadb6ce2f229a'>69978aa0f21f43529e11f924504dadb6ce2f229a</a> (<a href='/cgit.cgi/linux/net-next.git/diff/tools/testing/selftests/vm/mlock-random-test.c?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05&amp;id2=69978aa0f21f43529e11f924504dadb6ce2f229a'>diff</a>)</td></tr><tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/tools/testing/selftests/vm/mlock-random-test.c?id=b4cfe3971f6eab542dd7ecc398bfa1aeec889934'>b4cfe3971f6eab542dd7ecc398bfa1aeec889934</a> (<a href='/cgit.cgi/linux/net-next.git/diff/tools/testing/selftests/vm/mlock-random-test.c?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05&amp;id2=b4cfe3971f6eab542dd7ecc398bfa1aeec889934'>diff</a>)</td></tr></table>
<div class='commit-subject'>Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma</div><div class='commit-msg'>Pull rdma fixes from Doug Ledford:
 "Second round of -rc fixes for 4.10.

  This -rc cycle has been slow for the rdma subsystem. I had already
  sent you the first batch before the Holiday break. After that, we kept
  only getting a few here or there. Up until this week, when I got a
  drop of 13 to one driver (qedr). So, here's the -rc patches I have. I
  currently have none held in reserve, so unless something new comes in,
  this is it until the next merge window opens.

  Summary:

   - series of iw_cxgb4 fixes to make it work with the drain cq API

   - one or two patches each to: srp, iser, cxgb3, vmw_pvrdma, umem,
     rxe, and ipoib

   - one big series (13 patches) for the new qedr driver"

* tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma: (27 commits)
  RDMA/cma: Fix unknown symbol when CONFIG_IPV6 is not enabled
  IB/rxe: Prevent from completer to operate on non valid QP
  IB/rxe: Fix rxe dev insertion to rxe_dev_list
  IB/umem: Release pid in error and ODP flow
  RDMA/qedr: Dispatch port active event from qedr_add
  RDMA/qedr: Fix and simplify memory leak in PD alloc
  RDMA/qedr: Fix RDMA CM loopback
  RDMA/qedr: Fix formatting
  RDMA/qedr: Mark three functions as static
  RDMA/qedr: Don't reset QP when queues aren't flushed
  RDMA/qedr: Don't spam dmesg if QP is in error state
  RDMA/qedr: Remove CQ spinlock from CM completion handlers
  RDMA/qedr: Return max inline data in QP query result
  RDMA/qedr: Return success when not changing QP state
  RDMA/qedr: Add uapi header qedr-abi.h
  RDMA/qedr: Fix MTU returned from QP query
  RDMA/core: Add the function ib_mtu_int_to_enum
  IB/vmw_pvrdma: Fix incorrect cleanup on pvrdma_pci_probe error path
  IB/vmw_pvrdma: Don't leak info from alloc_ucontext
  IB/cxgb3: fix misspelling in header guard
  ...
</div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?id=dd3b9f25c867cb2507a45e436d6ede8eb08e7b05'>Diffstat</a> (limited to 'tools/testing/selftests/vm/mlock-random-test.c')</div><table summary='diffstat' class='diffstat'>