Sponsored Content
Operating Systems Linux Ubuntu Measuring the correctness of ndelay() function. Post 302969902 by BHASKAR JUPUDI on Tuesday 29th of March 2016 06:31:47 PM
Old 03-29-2016
Measuring the correctness of ndelay() function.

I wrote this kernel module to test the correctness of ndelay() function.

Kernel mdoule:

Code:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/time.h>
#include <linux/delay.h>
static int __init initialize(void)
{
	ktime_t start, end;
	s64 actual_time;
	int i;
	for(i=0;i<1000;i++)
	{
		start = ktime_get();
			ndelay(100);			
		end = ktime_get();
		actual_time = ktime_to_ns(ktime_sub(end, start));
		printk("%lld\n",(long long)actual_time);	
	}
	return 0;
}

static void __exit final(void)
{
     printk(KERN_INFO "Unload module\n");
}

module_init(initialize);
module_exit(final);

MODULE_AUTHOR("Bhaskar");
MODULE_DESCRIPTION("looping for 1000 times");
MODULE_LICENSE("GPL");



The output of dmesg:
Code:
[ 1028.135657] 379
[ 1028.135659] 383
[ 1028.135661] 370
[ 1028.135663] 372
[ 1028.135665] 332
[ 1028.135667] 348
[ 1028.135668] 318
[ 1028.135670] 365
[ 1028.135672] 350
[ 1028.135674] 327
[ 1028.135676] 359
[ 1028.135677] 358
[ 1028.135679] 320
[ 1028.135681] 393
[ 1028.135683] 359
[ 1028.135685] 357
[ 1028.135687] 361
[ 1028.135688] 325
[ 1028.135690] 360
[ 1028.135692] 302
[ 1028.135694] 353
[ 1028.135696] 375
[ 1028.135698] 342
[ 1028.135700] 377
[ 1028.135702] 382
[ 1028.135704] 390
[ 1028.135706] 322
[ 1028.135707] 361
[ 1028.135709] 392
[ 1028.135711] 387

Here my question is I'm trying to measure 100ns delay, but I'm getting output in 300's. One of the possible things that can happen is storing the value of ktime_get() into end module is taking some time. So can anyone please suggest me alternative or where I'm going wrong.
 

4 More Discussions You Might Find Interesting

1. Programming

Measuring System Call Time

Can anyone please help me in measuring the system call timings! How do I do it if I have to measure the timing of an operation, say getpid system call. What different functions can I use for that and what would be the difference using each of them? Thanx! (3 Replies)
Discussion started by: chacha
3 Replies

2. IP Networking

measuring traffic with iptables

i have a wireless network that is connected to internet over nat.there is ap that is connected to another ap in bridge mode, on ap is used for clients, and the other is connected to the machine that is doing masquerading. so i want to measure traffic of my clients and i thought about doing it with... (0 Replies)
Discussion started by: mdfk
0 Replies

3. Programming

Measuring memory used by a program?

I have a Java program. I want to measure the total memory used by the program, especially the peak memory. Is there a way to do it? I have tried utilities like time (which returns 0) and top (which is not very useful) as the program does not run for long. Can anyone suggest a way to do this?... (5 Replies)
Discussion started by: spathical
5 Replies

4. Red Hat

lightweight function for measuring time ( better than clock_getime )

HI I have a Red Hat Enterprise with Real Time kernel. Are you aware if there are C functions for this kernel or some code/library for this OS for measuring time more lightweight than clock_gettime and gettimeofday? THe hardware I have is NUMA. Reading forums I found gethrtime but it is... (1 Reply)
Discussion started by: manustone
1 Replies
_fini(9E)							Driver Entry Points							 _fini(9E)

NAME
_fini, _info, _init - loadable module configuration entry points SYNOPSIS
#include <sys/modctl.h> int _fini(void) int _info(struct modinfo *modinfop); int _init(void) INTERFACE LEVEL
Solaris DDI specific (Solaris DDI). These entry points are required. You must write them. PARAMETERS
_info() modinfop A pointer to an opaque modinfo structure. DESCRIPTION
_init() initializes a loadable module. It is called before any other routine in a loadable module. _init() returns the value returned by mod_install(9F). The module may optionally perform some other work before the mod_install(9F) call is performed. If the module has done some setup before the mod_install(9F) function is called, then it should be prepared to undo that setup if mod_install(9F) returns an error. _info() returns information about a loadable module. _info() returns the value returned by mod_info(9F). _fini() prepares a loadable module for unloading. It is called when the system wants to unload a module. If the module determines that it can be unloaded, then _fini() returns the value returned by mod_remove(9F). Upon successful return from _fini() no other routine in the module will be called before _init() is called. RETURN VALUES
_init() should return the appropriate error number if there is an error, otherwise it should return the return value from mod_install(9F). _info() should return the return value from mod_info(9F) _fini() should return the return value from mod_remove(9F). _fini() is permitted to return EBUSY prior to calling mod_remove(9F) if the driver should not be unloaded. Driver global resources, such as mutexes and calls to ddi_soft_state_fini(9F), should only be destroyed in _fini() after mod_remove() returns successfully. EXAMPLES
Example 1 Initializing and Freeing a Mutex The following example demonstrates how to initialize and free a mutex(9F). #include <sys/modctl.h> #include <sys/ddi.h> #include <sys/sunddi.h> static struct dev_ops drv_ops; /* * Module linkage information for the kernel. */ static struct modldrv modldrv = { &mod_driverops, /* Type of module. This one is a driver */ "Sample Driver", &drv_ops /* driver ops */ }; static struct modlinkage modlinkage = { MODREV_1, &modldrv, NULL }; /* * Global driver mutex */ static kmutex_t xx_global_mutex; int _init(void) { int i; /* * Initialize global mutex before mod_install'ing driver. * If mod_install() fails, must clean up mutex initialization */ mutex_init(&xx_global_mutex, NULL, MUTEX_DRIVER, (void *)NULL); if ((i = mod_install(&modlinkage)) != 0) { mutex_destroy(&xx_global_mutex); } return (i); } int _info(struct modinfo *modinfop) { return (mod_info(&modlinkage, modinfop)); } int _fini(void) { int i; /* * If mod_remove() is successful, we destroy our global mutex */ if ((i = mod_remove(&modlinkage)) == 0) { mutex_destroy(&xx_global_mutex); } return (i); } SEE ALSO
add_drv(1M), mod_info(9F), mod_install(9F), mod_remove(9F), mutex(9F), modldrv(9S), modlinkage(9S), modlstrmod(9S) Writing Device Drivers WARNINGS
Do not change the structures referred to by the modlinkage structure after the call to mod_install(), as the system may copy or change them. NOTES
Even though the identifiers _fini(), _info(), and _init() appear to be declared as globals, their scope is restricted by the kernel to the module that they are defined in. BUGS
On some implementations _info() may be called before _init(). SunOS 5.11 22 Jan 2002 _fini(9E)
All times are GMT -4. The time now is 02:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy