Ktime Use Example "original"

Source: Internet
Author: User

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/interrupt.h>


static void Time_get (ktime_t *start);

static void Time_get (ktime_t *start)
{
*start = Ktime_get ();
}

static int time_print (const char *name, ktime_t starttime)
{
ktime_t Rettime;
S64 Usecs64;
int usecs;
unsigned long my_s, my_us;

Rettime = Ktime_get ();
Usecs64 = Ktime_to_us (Ktime_sub (Rettime, starttime));
Usecs = Usecs64;

my_s = usecs/usec_per_msec;
My_us = usecs% Usec_per_msec;


if (Usecs = = 0)
Usecs = 1;

PRINTK ("Time:%ld.%0 3LD \ r \ n ", my_s, My_us);

return 0;
}

static int hello_init (void)
{
ktime_t My_time;

PRINTK (Kern_alert "Hello, World ver=%s\n", "1.0");

Time_get (&my_time);
Time_print (NULL, my_time);

Mdelay (100);

Time_print (NULL, my_time);

return 0;
}

static void Hello_exit (void)
{
PRINTK (Kern_alert "Goodbye, cruel world\n");
}

Module_init (Hello_init);
Module_exit (Hello_exit);

Module_license ("Dual BSD/GPL");

[80492.470000] Hello, World ver=1.0
[80492.480000] time:0.000
[80492.580000] time:102.299

Ktime Use Example "original"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.