Measuring the correctness of ndelay() function.

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Measuring the correctness of ndelay() function.

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

Kernel mdoule:

#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;
		start = ktime_get();
		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_DESCRIPTION("looping for 1000 times");

The output of dmesg:
[ 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.
# 2  
Not necessarily an answer but you could make ndelay very large and time it (possibly outside of the routine).
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
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...... Red Hat
Red Hat
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?...... Programming
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...... IP Networking
IP Networking
UNIX and Linux

Unix (trademarked as the UNIX certification mark) is a very mature family of multitasking, multiuser computer operating systems that evolved from the original AT&T Unix. Unix development starting in the 1970s by legendary Bell Labs programmers Ken Thompson, Dennis Ritchie, and others. Unix was first targeted for the Bell System and AT&T licensed Unix to outside parties. In the 1970s time period, this lead to a variety of for-profit as well as not-for-profit Unix variants.
In the early days, this included the University of California, Berkeley (BSD), Microsoft (Xenix), IBM (AIX), and Sun Microsystems (Solaris). In the early 1990s, AT&T sold their Unix rights to Novell. In 1995 Novell sold their Unix business to the Santa Cruz Operation (SCO). The UNIX trademark was passed to The Open Group, a "neutral" industry consortium. The Open Group promoted the use of the UNIX trademark for certified operating systems that comply with the Single UNIX Specification (SUS). In 2014 Apple's macOS became the Unix version with the largest global install base and macOS remains the largest Unix-user base today.
Linux is a family of open source Unix-like operating systems based on the Linux kernel. The Linux kernel is an operating system kernel first released by Linus Torvalds on 17 September 1991. Linux distributions include the Linux kernel, system software and libraries. Popular free open source Linux distributions include Debian, Fedora, and Ubuntu. Commercial Linux distributions include Red Hat Enterprise Linux and SUSE Linux Enterprise Server. Linux may be freely modified and redistributed. Anyone on the planet may create a Linux distribution for any purpose.
Please enjoy and help our forum community by "showing your work" and posting your code, even when your code is not working as expected. To help others help you, please wrap your code blocks, sample input, sample output, error messages, and other data in CODE tags and wrap your short commands and short data objects in ICODE tags. We were all beginners in the beginning. If you have any questions about how to register or how to post, please contact us in Live Chat. Thank you and enjoy this "forever free" technical support community for UNIX, Linux and computer information technology in general.