Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 146765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:39:42+00:00 2026-05-11T08:39:42+00:00

I’ve read chapter 7 in the ‘Linux Device Drivers’ (which can be found here)

  • 0

I’ve read chapter 7 in the ‘Linux Device Drivers’ (which can be found here) that time can be measured in ‘jiffies’. The problem with the stock jiffies variable is that it wraps around quite frequently (especially if you have your CONFIG_HZ set to 1000).

In my kernel module I’m saving a jiffies value that is set to some time in the future and comparing it at a later time with the current ‘jiffies’ value. I’ve learned already that there are functions that take the 32bit jiffy wrap into consideration so to compare two values I’m using this:

if (time_after(jiffies, some_future_jiffies_value)) {    // we've already passed the saved value } 

Here comes my question: So now I want to set the ‘some_future_jiffies_value’ to ‘now + 10ms’. This can easily be accomplished by doing this:

some_future_jiffies_value = jiffies + msecs_to_jiffies(10); 

Is this correct? What happens if the current jiffies is near MAX_JIFFY_OFFSET and the resulting value of msecs_to_jiffies(10) puts some_future_jiffies_value past that offset? Does it wrap around automatically or should I add some code to check for this? Are there functions that save me from having to deal with this?

Update:

To avoid stuff with wraparound I’ve rewritten my sleep loop:

   // Sleep for the appropriate time    while (time_after(some_future_jiffies_value, jiffies))    {       set_current_state(TASK_INTERRUPTIBLE);       schedule_timeout(1);    } 

I assume this is more portable right?

Update 2:

Thank you very much ‘ctuffli’ for taking the time to come back to this question and providing some feedback on my comments as well. My kernel driver is working fine now and it is a lot less ugly compared to the situation before you provided me with all these tips. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:39:42+00:00Added an answer on May 11, 2026 at 8:39 am

    What you are implementing here is essentially msleep_interruptible() (linux/kernel/timer.c)

    /**  * msleep_interruptible - sleep waiting for signals  * @msecs: Time in milliseconds to sleep for  */ unsigned long msleep_interruptible(unsigned int msecs) 

    This function has the advantage that the specification is in milliseconds and hides the details of jiffies wrapping internally. Be sure to check the return values as this call returns the number of jiffies remaining. Zero means the call slept the specified number of milliseconds while a non-zero value indicates the call was interrupted this many jiffies early.

    With regard to wrapping, see section 6.2.1.2 for a description of jiffies and wrapping. Also, this post tries to describe wrapping in the abstract.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should look into the concept of weighted randomization as… May 11, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer Great question, actually. You have two options: Modify the "ATTRIBUTE"… May 11, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer I believe it's because you're including a semicolon after the… May 11, 2026 at 10:41 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.