Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 01-05-2022, 10:43 PM   #1
LQ Newbie
Registered: Jan 2022
Posts: 1

Rep: Reputation: 0
Unhappy sleep/wake-up timeout issue

I have a unexpected issue that related in sleep/wake-up timeout for task, while device driver develop.
my code use kernel function 'wait_for_completion_interruptible_timeout' when there is a reason for task sleep, this function parameter need input 'want timeout in jiffies', so i have try that input any value like "msecs_to_jiffies(255 * 1000)" for sleep task 255seconds.
I expected this function 'wait_for_completion_interruptible_timeout' return zero when after almost exactly 255seconds. but I measured the actual time, it was additionally delayed maximum almost 11 seconds(final time 266 seconds) in my test case.
so result of have additional test, the additionally delayed time is different, but the result is the same.
additionally delayed time range was random in 1ms ~ 11seconds.
this issue occur in kernel function 'msleep(255 * 1000)' too... because schedule_timeout() used in 'wait_for_completion_interruptible_timeout' and msleep.

※A additionally delayed time occurs even if a different number is entered like 1ms or 1seconds..

I think it "additionally delayed time" was mean that wake-up task but time to task racing until active run in cpu. am i guessing right? or not am i doing something wrong?
If my thoughts are right, How do I get the correct time?

Below is the sample code I tested.

struct completion cmp;
static long g_jiffies = 0;

static int _open(struct inode *inode, struct file *file)
    g_jiffies = 0;
    return 0;

static ssize_t _read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos)
    long sch = 0;

    printk(KERN_NOTICE "start checking\n");
    g_jiffies = jiffies; 
    sch = wait_for_completion_interruptible_timeout(&cmp,  msecs_to_jiffies(255 * 1000));
    //msleep(255 * 1000)

    printk(KERN_NOTICE "delay time = %ld\n", jiffies_to_msecs(jiffies - g_jiffies));
    return 0;
result dmesg :
[목 1월 6 13:05:30 2022] start checking
[목 1월 6 13:09:52 2022] delay time = 261808
Old 01-05-2022, 11:23 PM   #2
Registered: May 2003
Location: Bangalore ,Karnataka, India, Asia, Earth, Solar system, milky way galaxy, black hole
Distribution: murugesan openssl
Posts: 181

Rep: Reputation: 29

Linux oriented OS(kernel side) used to take care of:
1. buffer cache
2. process switching
3. timer interrupts
4. signal interrupts between programs/threads at kernel level
5. time synchronization between process and threads.
6. disk space management due to buffer cache(handled during Linux startup allocation to disk/cache).
Based on test case results adjust related msleep timing t meet your requirement intermediate between 1ms ~ 11seconds.
Take testing for more days/a month.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
systemctl suspend - USB sleep / wake issue dgalt Linux - Hardware 0 02-15-2016 07:45 PM
Can I wake up a server in "standby" or "memory" mode using wake-on-lan? songweijia Linux - Server 2 03-03-2010 06:51 PM
wake on lan magic packet does not wake. albean Linux - Networking 1 06-30-2007 03:57 PM
Screen does not wake up after going to sleep at promp PSIPHON Linux - General 1 08-09-2005 08:30 PM
monitor in supsend/sleep mode... can't "wake" it up schbond Linux - Hardware 2 09-15-2003 12:03 AM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration