Skip to contentSkip to conversation

(Fwd) about timer in linux kernel.

DISCUSSION Ulrich Windl 1 participant 1 message May 21, 2001

lore
Share & tools
lore
#0 lore raw

Maybe one of the people having written the code want to explain...

Thanks, Ulrich
------- Forwarded message follows -------

From:           	"meng-ju" <[email protected]>
To:             	<[email protected]>
Subject:        	about timer in linux kernel.
Date sent:      	Fri, 18 May 2001 16:58:55 -0700

Hi! Mr. Ulrich Windl,

I want to know how timer works in kernel.
When we call add_timer(), it will call add_timer_internal to add it to its list.
Now I am confused how the system checks if it is expired or not?
In run_timer_list(),
Why it uses tv1.vec + tv1.index to find out the expiration point while in add_timer_internal(), the expiration timer minus timer_jiffies? I don't understand what roles jiffies, timer_jiffies and tv1.index play.
Thanks for your patient and answering.

static inline void run_timer_list(void)

{
         spin_lock_irq(&timerlist_lock);
         while ((long)(jiffies - timer_jiffies) >= 0) {
                 struct list_head *head, *curr;
                 if (!tv1.index) {
                         int n= 1;
                         do {
                                cascade_timers(tvecs[n]);
                         } while (tvecs[n]->index == 1 && ++n < NOOF_TVECS);
                 }
repeat:
                head = tv1.vec + tv1.index;
                curr = head->next;
                if (curr != head) {
                        struct timer_list *timer;
                        void (*fn)(unsigned long);
                        unsigned long data;

                        timer = list_entry(curr, struct timer_list, list);
                        fn = timer->function;
                        data= timer->data;

                        detach_timer(timer);
                        timer->list.next = timer->list.prev = NULL;
                        timer_enter(timer);
                        spin_unlock_irq(&timerlist_lock);
                        fn(data);
                        spin_lock_irq(&timerlist_lock);
                        timer_exit();
                        goto repeat;
                }
                ++timer_jiffies;
           tv1.index = (tv1.index + 1) & TVR_MASK;
        }

........

Meng-Ju

------- End of forwarded message -------