# Some kernel library function questions

**URL:** <https://community.unix.com/t/some-kernel-library-function-questions/223166>\
**Category:** Linux\
**Created:** [December 5, 2008, 12:59am UTC](https://community.unix.com/t/some-kernel-library-function-questions/223166 "2008-12-05T00:59:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamjayanth](https://community.unix.com/letter_avatar/iamjayanth/32/6_22734026db12803ebb3e059622ac3534.png) [@iamjayanth](https://community.unix.com/u/iamjayanth)\
**Post date:** [December 5, 2008, 12:59am UTC](https://community.unix.com/t/some-kernel-library-function-questions/223166/1 "2008-12-05T00:59:34Z")

</div>

Sir,

```
        I am trying to learn how to write a device driver for an input device. As a start I tried to understand the actual device driver code written for linux 2.6.9 kernel. It is always good to follow masters in programming . I understood some parts of the code . But I got stuck with some library functions and macros . Hope you masters can shed some light in to my doubts.  

```

1. What is time\_after() function ? It is used in the actual serial mouse driver for kernel 2.6.9. Below given is the line where it is used

if (time\_after(jiffies, my\_mouse-\>last + HZ/10))  
my\_mouse-\>count = 0;

I tried to get the logic behind the line but I failed to do so . I read that jiffies is a global variable that increase with every time tick starting from system log on. Can anybody help me to understand the logic behind this line.

1. There is a mouse connect function which is called whenever we connect a serial mouse to the serial port. The function takes two arguments, a pointer to struct serio and struct serio\_drv. This struct serio pointer is used throughout the connect function but we are not initializing it anywhere. So What I understand is that when we connect the serial mouse the input sub system automatically initializes this structure with the details of the mouse we connected so that the driver program can use these details to select the protocol and type of mouse. I just want a conformation from you that what I understand is right (I hope so) .

2. in serio.h headerfile there are some macros defined. like

---

<div class="post-metadata">

**Author:** ![otheus](https://community.unix.com/user_avatar/community.unix.com/otheus/32/505_2.png) [@otheus](https://community.unix.com/u/otheus)\
**Post date:** [December 5, 2008, 6:28am UTC](https://community.unix.com/t/some-kernel-library-function-questions/223166/2 "2008-12-05T06:28:06Z")

</div>

Note: my responses might not be accurate:

> [@iamjayanth](#):
>
> 1. What is time\_after() function ? It is used in the actual serial mouse driver for kernel 2.6.9. Below given is the line where it is used
> 
> if (time\_after(jiffies, my\_mouse-\>last + HZ/10))  
> my\_mouse-\>count = 0;

Jiffies, as you noted, is the global clock tick in Linux. So this says, if it's now later that the last state-change of the mouse (within one-tenth of HZ), reset the mouse's "count", whatever that is. You could user \> or \< than or whatever here, except for the fact that sometimes, the jiffies parameter will wrap around -- it can do this on 32-bit machines if running longer than, say, a [strike]year[/strike] day. This function supposedly handles that case. See this thread: ['jiffies rollover, uptime etc.' - MARC](http://marc.info/?l=linux-kernel&m=101406885521792)

> [@](#):
>
> 1. ... So What I understand is that when we connect the serial mouse the input sub system automatically initializes this structure

I don't know. Sorry.

> [@](#):
>
> 1. ... In the both definition the label UL is used which I believe(?) stands for unsigned long.

Correct.

> [@](#):
>
> What my doubt is that why ff (small letter) and FF(capital letter ) is used . What is the difference between these two .

None. Absolutely none.

All hex digits are the numbers 0 through 9 and A through F. In C, and in most programming languages, it doesn't matter if the letter if upper or lowercase.

---

<div class="post-metadata">

**Author:** ![iamjayanth](https://community.unix.com/letter_avatar/iamjayanth/32/6_22734026db12803ebb3e059622ac3534.png) [@iamjayanth](https://community.unix.com/u/iamjayanth)\
**Post date:** [December 5, 2008, 7:02am UTC](https://community.unix.com/t/some-kernel-library-function-questions/223166/3 "2008-12-05T07:02:42Z")

</div>

Thanks otheus...... You are brilliant....... Please help me little bit more.......  
So you are saying ff is same and FF......so  
0xFFUL is 0x000000FF  
and  
0xff000000 is 0xFF000000  
Am I correct? thanks again...

---

<div class="post-metadata">

**Author:** ![otheus](https://community.unix.com/user_avatar/community.unix.com/otheus/32/505_2.png) [@otheus](https://community.unix.com/u/otheus)\
**Post date:** [December 5, 2008, 7:41am UTC](https://community.unix.com/t/some-kernel-library-function-questions/223166/4 "2008-12-05T07:41:08Z")

</div>

Correct.
