public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/4] seq_file: Add seq_cpumask_list(), seq_nodemask_list()
@ 2008-10-12  9:29 Lai Jiangshan
  2008-10-16 19:58 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2008-10-12  9:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alexey Dobriyan, Paul Menage, Paul Jackson,
	Linux Kernel Mailing List


seq_cpumask_list(), seq_nodemask_list() are very like seq_cpumask(),
seq_nodemask(), but they print human readable string.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 11c85fe..eba2eab 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -465,6 +465,22 @@ int seq_bitmap(struct seq_file *m, unsigned long *bits, unsigned int nr_bits)
 }
 EXPORT_SYMBOL(seq_bitmap);
 
+int seq_bitmap_list(struct seq_file *m, unsigned long *bits,
+		unsigned int nr_bits)
+{
+	if (m->count < m->size) {
+		int len = bitmap_scnlistprintf(m->buf + m->count,
+				m->size - m->count, bits, nr_bits);
+		if (m->count + len < m->size) {
+			m->count += len;
+			return 0;
+		}
+	}
+	m->count = m->size;
+	return -1;
+}
+EXPORT_SYMBOL(seq_bitmap_list);
+
 static void *single_start(struct seq_file *p, loff_t *pos)
 {
 	return NULL + (*pos == 0);
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index a1783b2..dc50bcc 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -60,6 +60,19 @@ static inline int seq_nodemask(struct seq_file *m, nodemask_t *mask)
 	return seq_bitmap(m, mask->bits, MAX_NUMNODES);
 }
 
+int seq_bitmap_list(struct seq_file *m, unsigned long *bits,
+		unsigned int nr_bits);
+
+static inline int seq_cpumask_list(struct seq_file *m, cpumask_t *mask)
+{
+	return seq_bitmap_list(m, mask->bits, NR_CPUS);
+}
+
+static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
+{
+	return seq_bitmap_list(m, mask->bits, MAX_NUMNODES);
+}
+
 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
 int single_release(struct inode *, struct file *);
 void *__seq_open_private(struct file *, const struct seq_operations *, int);



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/4] seq_file: Add seq_cpumask_list(), seq_nodemask_list()
  2008-10-12  9:29 [PATCH 2/4] seq_file: Add seq_cpumask_list(), seq_nodemask_list() Lai Jiangshan
@ 2008-10-16 19:58 ` Andrew Morton
  2008-10-16 22:56   ` Mike Travis
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2008-10-16 19:58 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: adobriyan, menage, pj, linux-kernel

On Sun, 12 Oct 2008 17:29:25 +0800
Lai Jiangshan <laijs@cn.fujitsu.com> wrote:

> +static inline int seq_cpumask_list(struct seq_file *m, cpumask_t *mask)
> +{
> +	return seq_bitmap_list(m, mask->bits, NR_CPUS);
> +}

Is it possible to avoid using NR_CPUS?  In some situations it'd be much
more efficient to use the runtime-determined max possible cpu index.

But I don't immediately recall how to get at that number. 
num_possible_cpus() assumes that there are no holes in the CPU
identifier list.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/4] seq_file: Add seq_cpumask_list(), seq_nodemask_list()
  2008-10-16 19:58 ` Andrew Morton
@ 2008-10-16 22:56   ` Mike Travis
  2008-10-16 23:08     ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Travis @ 2008-10-16 22:56 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Lai Jiangshan, adobriyan, menage, pj, linux-kernel

Andrew Morton wrote:
> On Sun, 12 Oct 2008 17:29:25 +0800
> Lai Jiangshan <laijs@cn.fujitsu.com> wrote:
> 
>> +static inline int seq_cpumask_list(struct seq_file *m, cpumask_t *mask)
>> +{
>> +	return seq_bitmap_list(m, mask->bits, NR_CPUS);
>> +}
> 
> Is it possible to avoid using NR_CPUS?  In some situations it'd be much
> more efficient to use the runtime-determined max possible cpu index.
> 
> But I don't immediately recall how to get at that number. 
> num_possible_cpus() assumes that there are no holes in the CPU
> identifier list.
> 

nr_cpu_ids represents the max index +1 of the possible cpus.  (Usually the
same as num_possible_cpus() except a.) it doesn't need to do the cpus_weight()
op, and b.) *if* (a big if) the cpu indices are sparse, then they wouldn't
be the same values.)

Thanks,
Mike

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/4] seq_file: Add seq_cpumask_list(), seq_nodemask_list()
  2008-10-16 22:56   ` Mike Travis
@ 2008-10-16 23:08     ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2008-10-16 23:08 UTC (permalink / raw)
  To: Mike Travis; +Cc: laijs, adobriyan, menage, pj, linux-kernel

On Thu, 16 Oct 2008 15:56:30 -0700
Mike Travis <travis@sgi.com> wrote:

> Andrew Morton wrote:
> > On Sun, 12 Oct 2008 17:29:25 +0800
> > Lai Jiangshan <laijs@cn.fujitsu.com> wrote:
> > 
> >> +static inline int seq_cpumask_list(struct seq_file *m, cpumask_t *mask)
> >> +{
> >> +	return seq_bitmap_list(m, mask->bits, NR_CPUS);
> >> +}
> > 
> > Is it possible to avoid using NR_CPUS?  In some situations it'd be much
> > more efficient to use the runtime-determined max possible cpu index.
> > 
> > But I don't immediately recall how to get at that number. 
> > num_possible_cpus() assumes that there are no holes in the CPU
> > identifier list.
> > 
> 
> nr_cpu_ids represents the max index +1 of the possible cpus.  (Usually the
> same as num_possible_cpus() except a.) it doesn't need to do the cpus_weight()
> op, and b.) *if* (a big if) the cpu indices are sparse, then they wouldn't
> be the same values.)

OK, thanks.  I was foggily looking for max_possible_cpus(), to match
num_online_cpus(), num_possible_cpus(), num_present_cpus().  Silly me.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-10-16 23:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-12  9:29 [PATCH 2/4] seq_file: Add seq_cpumask_list(), seq_nodemask_list() Lai Jiangshan
2008-10-16 19:58 ` Andrew Morton
2008-10-16 22:56   ` Mike Travis
2008-10-16 23:08     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox