lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20111206114438.GA17186@localhost>
Date:	Tue, 6 Dec 2011 19:44:38 +0800
From:	Wu Fengguang <fengguang.wu@...el.com>
To:	Andi Kleen <andi@...stfloor.org>
Cc:	"greg@...ah.com" <greg@...ah.com>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
	Andi Kleen <ak@...ux.intel.com>
Subject: Re: [PATCH 2/3] DEBUGFS: Add per cpu counters

On Sat, Dec 03, 2011 at 02:43:26AM +0800, Andi Kleen wrote:
> From: Andi Kleen <ak@...ux.intel.com>
> 
> Add a simple way to export per cpu counters in debugfs.
> 
> This is done using a section, so that they can be declared using
> a simple macro with minimal typing.
> 
> OPEN: modules are not supported yet.
> 
> Signed-off-by: Andi Kleen <ak@...ux.intel.com>
> ---
>  fs/debugfs/Makefile               |    2 +-
>  fs/debugfs/counter.c              |   73 +++++++++++++++++++++++++++++++++++++
>  include/asm-generic/vmlinux.lds.h |    6 +++
>  include/linux/debugfs.h           |   27 ++++++++++++++
>  4 files changed, 107 insertions(+), 1 deletions(-)
>  create mode 100644 fs/debugfs/counter.c
> 
> diff --git a/fs/debugfs/Makefile b/fs/debugfs/Makefile
> index 840c456..21be8d3 100644
> --- a/fs/debugfs/Makefile
> +++ b/fs/debugfs/Makefile
> @@ -1,4 +1,4 @@
> -debugfs-objs	:= inode.o file.o
> +debugfs-objs	:= inode.o file.o counter.o
>  
>  obj-$(CONFIG_DEBUG_FS)	+= debugfs.o
>  
> diff --git a/fs/debugfs/counter.c b/fs/debugfs/counter.c
> new file mode 100644
> index 0000000..2372faf
> --- /dev/null
> +++ b/fs/debugfs/counter.c
> @@ -0,0 +1,73 @@
> +#include <linux/debugfs.h>
> +#include <linux/seq_file.h>
> +#include <linux/percpu.h>
> +#include <linux/kernel.h>
> +
> +/* OPEN: implement module support */

Yeah, I think the module support would benefit my case as well.

To support module users, init_counters() will be exported with the
__start___debugfs/__stop___debugfs hard coding removed. Then I'll be
call it from the readahead initilization code:

DEFINE_PER_CPU(unsigned long[RA_PATTERN_MAX][RA_ACCOUNT_MAX], ra_counter);
struct debugfs_counter ra_pcpu_counter[RA_PATTERN_MAX][RA_ACCOUNT_MAX];

// init ra_pcpu_counter in a loop
for each pattern
        init_counters(ra_pcpu_counter[pattern], ra_pcpu_counter[pattern+1]);

Does this usage sound reasonable?

> +extern struct debugfs_counter __start___debugfs[], __stop___debugfs[];
> +
> +static unsigned sum_counter(unsigned __percpu *counter)
> +{
> +	int cpu;
> +	unsigned sum = 0;
> +
> +	for_each_online_cpu (cpu)
> +		sum += per_cpu(*counter, cpu);
> +	return sum;
> +}
> +
> +static int
> +dump_counters(struct seq_file *m,
> +	      struct debugfs_counter *cnt, struct debugfs_counter *stop,
> +	      char *fn)
> +{
> +	int n = 0;
> +	for (; cnt < stop; cnt++)
> +		if (fn[0] == cnt->fn[0] && !strcmp(cnt->fn, fn))
> +			n += seq_printf(m, "%s: %u\n",
> +					cnt->name, sum_counter(cnt->ptr));
> +	return n;
> +}
> +
> +static int show_debugfs_counter(struct seq_file *m, void *arg)
> +{
> +	int n;
> +	n = dump_counters(m, __start___debugfs, __stop___debugfs, m->private);

That hard coded __start___debugfs/__stop___debugfs is OK for POC, and
will need to be improved to work with multiple users in kernel.

Thanks,
Fengguang
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ