Skip site navigation (1)Skip section navigation (2)
Date:       Wed, 16 Aug 2000 15:23:23 +1000
From:      Peter Jeremy <peter.jeremy@alcatel.com.au>
To:        rhyason@cpsc.ucalgary.ca
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Collecting waiting statistics (simulation question)
Message-ID:  <00Aug16.152328est.115246@border.alcanet.com.au>

next in thread | raw e-mail | index | archive | help
On Mon, 14 Aug 2000, Jeff Rhyason wrote:
> Aah.  This isn't quite what I lust for:  Is it possible to get a *log* of
> allocation requests rather than aggregate sums or averages?  The reason is
> so I can calculate the distribution of the data. For example: the kind of
> information I would like to have from kern_malloc for each invocation is:
> 	- time of the allocation
> 	- size
> 	- time spent in asleep 
> 	- return value
> The same thing can be done with kern_free and from there the time the
> memory was used can be calculated.

Chunk suggested using something based on the existing kernel syslog
buffer and socket.  That strikes me as involving a fair amount of
work.

Many years ago, I was collecting statistics on interrupt jitter and
wrote a simple ring buffer that was intended to be very cheap for the
kernel to write to (though it will lose data if it overflows).  The
userland side just maps kvm and polls the data (this worked for me
since I have data being written at a known rate - and I don't think
I got the bugs out of the device driver interface).  This approach
might not be the cleanest, but it is quite quick to get going.

Pruning out the general-purpose bits of the code, you could use
something like the following:

struct kern_malloc_stats {
	struct timespec	kms_time;	/* allocation time */
	unsigned long	kms_size;	/* allocation size */
	struct malloc_type *kms_type;	/* optional */
	unsigned long	kms_delay;	/* nsec or usec in asleep() */
	void *		kms_return;
};

#define	KMS_ENTRIES	(1 << n)	/* pick <n> to suit */

struct kern_malloc_stats_buffer {
	unsigned int	rb_magic;	/* magic number for validation */
#define	RB_MAGIC	0xdeadbeef
	unsigned int	rb_write;	/* write index */
	struct kern_malloc_stats rb_buf[KMS_ENTRIES];
};

volatile struct kern_malloc_stats_buffer	kms_buf;

/* write a struct kern_malloc_stats into the buffer */
#define	kms_push(data)	do { \
		kms_buf.rb_buf[kms_buf.rb_write++] = (data); \
		kms_buf.rb_write &= KMS_ENTRIES - 1; \
	} while (0)

In userland, I just mmap'd kms_buf and polled it regularly (using
a local read pointer and kms_buf.rb_write to identify the active
areas) via an interval timer.

Peter


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?00Aug16.152328est.115246>