Skip to contentSkip to conversation

s390: statistics infrastructure.

PATCH In review Martin Schwidefsky 3 participants 3 messages Oct 28, 2005 – Oct 31, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/14 s390: statistics infrastructure.

From: Martin Peschke <[email protected]>

[patch 1/14] s390: statistics infrastructure.

Add the statistics facility. This features offers a simple way to gather statistical data and to display them via the debugfs. An example how this is used:

	struct statistic_interface *stat_if;
	struct statistic *stat;

	statistic_interface_create(&stat_if, "whatever");
	statistic_create(&stat, stat_if, "stat-name", "unit");
	statistic_define_value(stat, range_min, range_max, def_mode);
	...
	statistic_inc(stat, value);	/* repeat.. */
	...
	statistic_interface_remove(&stat_if);

---

 arch/s390/kernel/Makefile    |    3 
 arch/s390/kernel/sgrb.c      |  303 +++++
 arch/s390/kernel/statistic.c | 2236 +++++++++++++++++++++++++++++++++++++++++++
 include/asm-s390/sgrb.h      |   94 +
 include/asm-s390/statistic.h |  334 ++++++
 include/linux/list.h         |   12 
 include/linux/parser.h       |    2 
 lib/parser.c                 |   60 +
 8 files changed, 3043 insertions(+), 1 deletion(-)
arch/s390/kernel/Makefile +2 -1
diff -urpN linux-2.6/arch/s390/kernel/Makefile linux-2.6-patched/arch/s390/kernel/Makefile
@@ -6,7 +6,8 @@ EXTRA_AFLAGS	:= -traditional
 
 obj-y	:=  bitmap.o traps.o time.o process.o \
             setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \
-            semaphore.o s390_ext.o debug.o profile.o irq.o reipl_diag.o
+            semaphore.o s390_ext.o debug.o profile.o irq.o sgrb.o \
+            statistic.o reipl_diag.o
 
 extra-$(CONFIG_ARCH_S390_31)	+= head.o 
 extra-$(CONFIG_ARCH_S390X)	+= head64.o 
arch/s390/kernel/sgrb.c +303 -0

303 lines not on this page · raw message

arch/s390/kernel/statistic.c +2236 -0

2,236 lines not on this page · raw message

include/asm-s390/sgrb.h +94 -0

94 lines not on this page · raw message

include/asm-s390/statistic.h +334 -0

334 lines not on this page · raw message

include/linux/list.h +12 -0
diff -urpN linux-2.6/include/linux/list.h linux-2.6-patched/include/linux/list.h
@@ -406,6 +406,18 @@ static inline void list_splice_init(stru
 	     pos = list_entry(pos->member.next, typeof(*pos), member))
 
 /**
+ * list_for_each_entry_continue_reverse -       iterate backwards over list
+ *                      of given type continuing before existing point
+ * @pos:        the type * to use as a loop counter.
+ * @head:       the head for your list.
+ * @member:     the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_continue_reverse(pos, head, member)                 \
+        for (pos = list_entry(pos->member.prev, typeof(*pos), member);  \
+             prefetch(pos->member.prev), &pos->member != (head);        \
+             pos = list_entry(pos->member.prev, typeof(*pos), member))
+
+/**
  * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  * @pos:	the type * to use as a loop counter.
  * @n:		another type * to use as temporary storage
include/linux/parser.h +2 -0
diff -urpN linux-2.6/include/linux/parser.h linux-2.6-patched/include/linux/parser.h
@@ -31,3 +31,5 @@ int match_octal(substring_t *, int *resu
 int match_hex(substring_t *, int *result);
 void match_strcpy(char *, substring_t *);
 char *match_strdup(substring_t *);
+int match_u64(substring_t *, u64 *result, int);
+int match_s64(substring_t *, s64 *result, int);
lib/parser.c +60 -0

1 line not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 8 lines · Martin Schwidefsky

From: Martin Peschke <[email protected]>

[patch 1/14] s390: statistics infrastructure.

Add the statistics facility. This features offers a simple way to gather statistical data and to display them via the debugfs. An example how this is used:

Quoted 10 lines
	struct statistic_interface *stat_if;
	struct statistic *stat;

	statistic_interface_create(&stat_if, "whatever");
	statistic_create(&stat, stat_if, "stat-name", "unit");
	statistic_define_value(stat, range_min, range_max, def_mode);
	...
	statistic_inc(stat, value);	/* repeat.. */
	...
	statistic_interface_remove(&stat_if);

This certainly doesn't belong into arch code. Please move to common code and send over to lkml for detailed review.

#2 lore raw
In reply to Martin Schwidefsky
Quoted 9 lines · Martin Schwidefsky

From: Martin Peschke <[email protected]>

[patch 1/14] s390: statistics infrastructure.

Add the statistics facility. This features offers a simple way to gather statistical data and to display them via the debugfs. An example how this is used:

Quoted 11 lines
	struct statistic_interface *stat_if;
	struct statistic *stat;

	statistic_interface_create(&stat_if, "whatever");
	statistic_create(&stat, stat_if, "stat-name", "unit");
	statistic_define_value(stat, range_min, range_max, def_mode);
	...
	statistic_inc(stat, value);	/* repeat.. */
	...
	statistic_interface_remove(&stat_if);

I agree with Christoph on this: please present it as a Kconfigurable generic option and flesh out the changelog a bit. If the documentation in the source file isn't sufficient, consider a Documentation/ file too, please.

arch/s390/kernel/sgrb.c line 33

Quoted 2 lines
arch/s390/kernel/sgrb.c +2 -0
+static struct sgrb_seg *
+sgrb_seg_alloc(struct list_head *lh, int size, unsigned int gfp)

Use gfp_t throughout.

Quoted 1 line

+EXPORT_SYMBOL(sgrb_seg_find);

Can we use EXPORT_SYMBOL_GPL throughout?

arch/s390/kernel/sgrb.c line 79

Quoted 7 lines
arch/s390/kernel/sgrb.c +7 -0
+
+/**
+ * sgrb_seg_release_all - releases scatter-gather buffer
+ * @lh: list_head that holds list of scattered buffer parts
+ */
+void
+sgrb_seg_release_all(struct list_head *lh)

Coding style nit: please do

void sgrb_seg_release_all(struct list_head *lh)

as per the rest of the core kernel.

(If we end up deciding to keep all this in arch/s390 then I guess we can live with s390 peculiarities though)

arch/s390/kernel/sgrb.c line 95

Quoted 5 lines
arch/s390/kernel/sgrb.c +5 -0
+static inline int
+sgrb_ptr_identical(
+	struct sgrb_ptr *a,
+	struct sgrb_ptr *b)
+{

Here too.

Quoted 25 lines
arch/s390/kernel/sgrb.c +25 -0
+
+/**
+ * sgrb_alloc - prepare a new ringbuffer for use
+ *
+ * @rb: a ringbuffer struct provided by the exploiter
+ * @entry_size: size of entries in ringbuffer
+ * @entry_num: total number of entries in ringbuffer
+ * @seg_size: size of individual, scatter-gathered segments used to build up
+ *            ringbuffer
+ * @gfp: kmalloc flags
+ *
+ * Returns 0 on success.
+ * Returns -ENOMEM if some memory allocation failed.
+ **/
+int
+sgrb_alloc(
+	struct sgrb *rb,
+	int entry_size, int entry_num, int seg_size, int gfp)
+{
+	int i;
+	struct sgrb_seg *seg;
+	int entries_per_seg = (seg_size / entry_size);
+	int seg_num = entry_num / entries_per_seg;
+	int residual = (entry_num % entries_per_seg) * entry_size;
+

arch/s390/kernel/sgrb.c line 156

Quoted 10 lines
arch/s390/kernel/sgrb.c +10 -0
+	rb->entry_size = entry_size;
+	INIT_LIST_HEAD(&rb->seg_lh);
+	for (i = 0; i < seg_num; i++)
+		if (!sgrb_seg_alloc(&rb->seg_lh, seg_size, gfp))
+			return -ENOMEM;
+	if (residual)
+		if (!sgrb_seg_alloc(&rb->seg_lh, residual, gfp))
+			return -ENOMEM;
+	list_for_each_entry(seg, &rb->seg_lh, list)
+		break;

eh? Something's gone rather wrong here.

Quoted 13 lines
arch/s390/kernel/sgrb.c +12 -0
+	rb->first.seg = seg;
+	rb->last.seg = seg;
+	sgrb_init(rb);
+	return 0;
+}
+EXPORT_SYMBOL(sgrb_alloc);
+
...
+static void
+sgrb_next_entry(
+	struct sgrb *rb,
+	struct sgrb_ptr *pos,
+	struct sgrb_ptr *next)

arch/s390/kernel/sgrb.c line 191

Quoted 10 lines
arch/s390/kernel/sgrb.c +10 -0
+{
+	sgrb_ptr_copy(next, pos);
+	next->offset += rb->entry_size;
+	if ((next->offset + rb->entry_size) - 1 > next->seg->size) {
+		if (rb->seg_lh.prev == &next->seg->list) {
+			next->seg = NULL;
+			next->seg = list_prepare_entry(next->seg, &rb->seg_lh, list);
+		}
+		list_for_each_entry_continue(next->seg, &rb->seg_lh, list)
+			break;

You did it again. I guess it's deliberate. Isn't there a simpler way?

Quoted 3 lines

+/**
+ * sgrb_produce_nooverwrite - put an entry into the ringbuffer
+ * if there is room whithout the need to overwrite the oldest

spello

Quoted 17 lines
arch/s390/kernel/sgrb.c +17 -0
+/**
+ * sgrb_consume_delete - get an entry from the ringbuffer and
+ *     delete the entry from the ringbuffer so that it can't
+ *     be consumed twice, and in order to free up its slot for
+ *     another entry
+ *
+ * @rb: the ringbuffer to use
+ *
+ * Returns address of the entry read, if there is an entry available.
+ * Returns NULL otherwise.
+ **/
+void *
+sgrb_consume_delete(struct sgrb *rb)
+{
+	struct sgrb_ptr prev;
+
+	if (!sgrb_ptr_valid(&rb->first))

arch/s390/kernel/sgrb.c line 271

Quoted 10 lines
arch/s390/kernel/sgrb.c +10 -0
+		return NULL;
+	sgrb_ptr_copy(&prev, &rb->first);
+	if (sgrb_ptr_identical(&rb->last, &rb->first))
+		sgrb_init(rb);
+	else
+		sgrb_next_entry(rb, &rb->first, &rb->first);
+	rb->entries--;
+	return sgrb_entry(&prev);
+}
+EXPORT_SYMBOL(sgrb_consume_delete);

I guess all of these functions require caller-provided locking, and that's documented somewhere?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+extern void tod_to_timeval(__u64, struct timespec *);

Please don't put extern decls in .c files - put them in a header file.

Quoted 6 lines
arch/s390/kernel/statistic.c +6 -0
+static inline void
+statistic_nsec_to_timespec(u64 nsec, struct timespec *xtime)
+{
+	unsigned long long sec;
+
+        sec = nsec;

arch/s390/kernel/statistic.c line 253

Quoted 10 lines
arch/s390/kernel/statistic.c +10 -0
+        do_div(sec, 1000000000);
+        xtime->tv_sec = sec;
+        xtime->tv_nsec = nsec - sec * 1000000000;
+}
+
+static inline u64
+statistic_timespec_to_nsec(struct timespec *xtime)
+{
+	return (xtime->tv_sec * 1000000000 + xtime->tv_nsec);
+}

Maybe these should be put in jiffies.h.

Quoted 44 lines
arch/s390/kernel/statistic.c +44 -0
+/**
+ * statistic_create - create a statistic and attach it to a given interface
+ * @stat_ptr: reference to struct statistic pointer
+ * @interface_ptr: reference to struct statistic_interface pointer
+ * @name: name of statistic to be created and as seen in "data" and
+ *        "definition" files
+ *
+ * Create a statistic, which - after being defined and enabled - is ready
+ * to capture and compute data provided by the exploiter. A line in the
+ * interface's "definition" file will hold specifics about the named statistic.
+ *
+ * On success, 0 is returned, the struct statistic pointer
+ * provided by the caller points to a newly alloacted struct,
+ * and the statistic is defined as type "value" by default.
+ *
+ * If the struct statistic pointer provided by the caller
+ * is not NULL (used), this routine fails, the struct statistic
+ * pointer is not changed, and -EINVAL is returned.
+ *
+ * If some required memory could not be allocated this routine fails,
+ * the struct statistic pointer is not changed, and -ENOMEM is returned.
+ **/
+int
+statistic_create(
+	struct statistic **stat_ptr,
+	struct statistic_interface *interface,
+	const char *name,
+	const char *units)
+{
+	struct statistic *stat;
+
+	if (*stat_ptr || !interface)
+		return -EINVAL;
+
+	stat = kmalloc(sizeof(struct statistic), GFP_KERNEL);
+	if (!stat)
+		return -ENOMEM;
+	memset(stat, 0, sizeof(struct statistic));
+
+	stat->interface = interface;
+	strlcpy(stat->name, name, sizeof(stat->name));
+	strlcpy(stat->units, units, sizeof(stat->units));
+	statistic_define_value(stat, STATISTIC_RANGE_MIN, STATISTIC_RANGE_MAX,
+				STATISTIC_DEF_MODE_INC);

arch/s390/kernel/statistic.c line 482

Quoted 10 lines
arch/s390/kernel/statistic.c +10 -0
+	statistic_stop_nolock(stat);
+	stat->started = stat->stopped;
+	stat->stat_ptr = stat_ptr;
+
+	list_add_tail(&stat->list, &interface->statistic_lh);
+
+	*stat_ptr = stat;
+
+	return 0;
+}

A lot of this looks pretty generic as well.

It's a lot of code, and it'll be some work to make it generic.

Can you help us decide whether there's actually any point in making it generic? What problems was it designed to solve, and what additional problems might it all be useful for?

Thanks.