Skip to Content
Linux Device Drivers
book

Linux Device Drivers

by Alessandro Rubini
February 1998
Intermediate to advanced
439 pages
13h 46m
English
O'Reilly Media, Inc.
Content preview from Linux Device Drivers

Chapter 6. Flow of Time

At this point, we know how to write a full-featured char module. We’ll deal with kernel resources available to the driver in the next few chapters. I’ll start by showing how timing issues are addressed from kernel code. This involves, in ascending order of complexity:

  • Knowing the current time

  • Delaying operation for a specified amount of time

  • Scheduling asynchronous functions to happen after a specified time lapse

Time Intervals in the Kernel

The first point we need to cover is the timer interrupt, which is the mechanism the kernel uses to keep track of time intervals. The timer interrupt is set to a default frequency of HZ, which is an architecture-dependent value defined in <linux/param.h>. Through at least version 2.0 and 2.1.43, Linux defines HZ to be 1024 for the Alpha and 100 for all other platforms.

When the timer interrupt occurs, the jiffies value is incremented. jiffies is thus the number of clock ticks since the operating system was booted; it is declared in <linux/sched.h> as unsigned long volatile, and it will overflow in one and a third years of continuous operation. If you’re planning on more than one and a third years of uptime, you’d better buy yourself an Alpha, which won’t overflow for half a billion years--it has 64-bit longs. I can’t tell you exactly what happens when jiffies overflows, and I haven’t got time to wait to find out.

If you change the value of HZ and try to recompile the kernel, you won’t notice any difference when ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Linux Device Drivers Development

Linux Device Drivers Development

John Madieu
Linux Device Drivers, Second Edition

Linux Device Drivers, Second Edition

Jonathan Corbet, Alessandro Rubini

Publisher Resources

ISBN: 1565922921Catalog PageErrata