Timer Wheel

download Timer Wheel

of 13

Transcript of Timer Wheel

  • 8/3/2019 Timer Wheel

    1/13

    R e d e s i g n i n g t h e B S D C a l l o u t a n d

    T i m e r F a c i l i t i e s

    A d a m M . C o s t e l l o a n d G e o r g e V a r g h e s e

    w u c s - 9 5 - 2 3

    2 N o v 1 9 9 5

    D e p a r t m e n t o f C o m p u t e r S c i e n c e

    C a m p u s B o x 1 0 4 5

    W a s h i n g t o n U n i v e r s i t y

    O n e B r o o k i n g s D r i v e

    S t . L o u i s , M O 6 3 1 3 0 - 4 8 9 9

    A b s t r a c t

    W e d e s c r i b e a n e w i m p l e m e n t a t i o n o f t h e B S D c a l l o u t a n d t i m e r f a c i l i t i e s . C u r r e n t B S D

    k e r n e l s t a k e t i m e p r o p o r t i o n a l t o t h e n u m b e r o f o u t s t a n d i n g t i m e r s t o s e t o r c a n c e l t i m e r s .

    O u r i m p l e m e n t a t i o n t a k e s c o n s t a n t t i m e t o s t a r t , s t o p , a n d m a i n t a i n t i m e r s ; t h i s l e a d s t o

    a h i g h l y s c a l a b l e d e s i g n t h a t c a n s u p p o r t t h o u s a n d s o f o u t s t a n d i n g t i m e r s w i t h o u t m u c h

    o v e r h e a d . U n l i k e t h e e x i s t i n g i m p l e m e n t a t i o n , o u r r o u t i n e s a r e g u a r a n t e e d t o l o c k o u t

    i n t e r r u p t s o n l y f o r a s m a l l , b o u n d e d a m o u n t o f t i m e . W e a l s o e x t e n d t h e s e t i t i m e r ( )

    i n t e r f a c e t o a l l o w a p r o c e s s t o h a v e m u l t i p l e o u t s t a n d i n g t i m e r s , t h e r e b y r e d u c i n g t h e n e e d

    f o r u s e r s t o m a i n t a i n t h e i r o w n t i m e r p a c k a g e s . T h e c h a n g e s t o t h e B S D k e r n e l a r e s m a l l

    ( 5 4 8 l i n e s o f c o d e a d d e d , 8 0 r e m o v e d ) a n d a r e a v a i l a b l e o n t h e W o r l d W i d e W e b .

    T h i s w o r k s u p p o r t e d b y a g r a n t f r o m t h e N S F .

  • 8/3/2019 Timer Wheel

    2/13

    R e d e s i g n i n g t h e B S D C a l l o u t a n d T i m e r F a c i l i t i e s

    A d a m M . C o s t e l l o

    < a m c @ c s . w u s t l . e d u >

    h t t p : / / w w w . c s . w u s t l . e d u / ~ a m c /

    G e o r g e V a r g h e s e

    < v a r g h e s e @ c s . w u s t l . e d u >

    h t t p : / / w w w . c c r c . w u s t l . e d u / ~ v a r g h e s e /

    1 . I n t r o d u c t i o n

    T o s a t i s f y t h e n e e d s o f r e a l - t i m e a p p l i c a t i o n s a n d

    c o m m u n i c a t i o n p r o t o c o l s , o p e r a t i n g s y s t e m s p r o -

    v i d e t i m e r s . I n B S D

    1

    k e r n e l s , t i m e r s a r e p r o v i d e d

    b y t h e c a l l o u t f a c i l i t y , w h i c h a l l o w s a f u n c t i o n a n d

    a r g u m e n t t o b e r e g i s t e r e d t o b e c a l l e d a t a f u t u r e

    t i m e . A c l o c k i n t e r r u p t r o u t i n e p e r i o d i c a l l y c h e c k s

    t h e o u t s t a n d i n g c a l l o u t s , a n d c a l l s t h e f u n c t i o n s

    d u e t o b e c a l l e d .

    T h e r e a r e f o u r m e a s u r e s o f p e r f o r m a n c e o f t h e

    c a l l o u t f a c i l i t y :

    1 . T i m e t o s e t a c a l l o u t .

    2 . T i m e t o c a n c e l a c a l l o u t .

    3 . T i m e t o p r o c e s s a c l o c k t i c k .

    4 . T i m e t o p r o c e s s a n e x p i r e d c a l l o u t .

    A l s o o f i n t e r e s t i s t h e m a x i m u m a m o u n t o f t i m e

    t h a t i n t e r r u p t s c a n b e l o c k e d o u t d u r i n g t h e s e o p -

    e r a t i o n s . I f i n t e r r u p t s a r e l o c k e d o u t f o r t o o l o n g ,

    t i m e - c r i t i c a l I / O e v e n t s m a y b e m i s s e d b y t h e s y s -

    t e m .

    T h e e x i s t i n g i m p l e m e n t a t i o n t a k e s c o n s t a n t t i m e

    ( u s u a l l y ) t o p r o c e s s a c l o c k t i c k o r a n e x p i r e d c a l l -

    o u t , b u t t a k e s l i n e a r t i m e ( i n t h e n u m b e r o f o u t -

    s t a n d i n g c a l l o u t s ) t o s e t o r c a n c e l a c a l l o u t . I n -

    t e r r u p t s a r e l o c k e d o u t f o r t h e d u r a t i o n o f a s e t

    o r c a n c e l o p e r a t i o n , w h i c h c a n t a k e l i n e a r t i m e

    i n t h e n u m b e r o f o u t s t a n d i n g c a l l o u t s . O u r n e w

    i m p l e m e n t a t i o n a c h i e v e s w o r s t - c a s e c o n s t a n t t i m e

    f o r a l l o p e r a t i o n s e x c e p t p r o c e s s i n g a c l o c k t i c k ,

    f o r w h i c h i t a c h i e v e s a v e r a g e - c a s e c o n s t a n t t i m e .

    1

    T h r o u g h o u t t h i s p a p e r , \ B S D " r e f e r s t o 4 . 4 B S D - L i t e

    a n d i t s d e r i v a t i v e s , s u c h a s N e t B S D .

    I t a l s o n e v e r l o c k s o u t i n t e r r u p t s f o r m o r e t h a n a

    c o n s t a n t a m o u n t o f t i m e .

    W h y R e d e s i g n ? W h e n w e e x a m i n e d a t y p i c a l

    U N I X w o r k s t a t i o n k e r n e l , w e f o u n d o n l y 5 { 6 o u t -

    s t a n d i n g c a l l o u t s ( i n u s e b y R P C , N F S , a n d T C P ) .

    W i t h s u c h a s m a l l n u m b e r o f o u t s t a n d i n g c a l l o u t s ,

    t a k i n g l i n e a r t i m e t o s t a r t o r s t o p a c a l l o u t i s n o t

    v e r y o n e r o u s , a n d t h e B S D i m p l e m e n t a t i o n s e e m s

    a d e q u a t e . S o w h y b o t h e r w i t h a n e w i m p l e m e n t a -

    t i o n a n y w a y ?

    C l e a r l y , o u r n e w i m p l e m e n t a t i o n i s m o t i v a t e d b y

    e n v i r o n m e n t s w h i c h h a v e a l a r g e n u m b e r o f o u t -

    s t a n d i n g t i m e r s . N e t w o r k p r o t o c o l i m p l e m e n t a -

    t i o n s p r o v i d e t h e e a s i e s t e x a m p l e . T y p i c a l l y , f o r

    e v e r y p a c k e t s e n t b y a r e l i a b l e t r a n s p o r t p r o t o c o l

    s u c h a s T C P , a r e t r a n s m i s s i o n t i m e r i s s t a r t e d . I f

    a n a c k n o w l e d g e m e n t a r r i v e s p r o m p t l y , t h e t i m e r i s

    c a n c e l l e d ; w h e n t h e t i m e r e x p i r e s , t h e p a c k e t i s r e -

    t r a n s m i t t e d . S e v e r a l r e c e n t n e t w o r k i m p l e m e n t a -

    t i o n s C J R S 8 9 ] h a v e b e e n t u n e d t o s e n d p a c k e t s a t

    a r a t e o f 2 5 , 0 0 0 { 4 0 , 0 0 0 p a c k e t s p e r s e c o n d . T h e

    s i t u a t i o n i s e x a c e r b a t e d b e c a u s e m o s t t r a n s p o r t

    p r o t o c o l s u s e s l i d i n g w i n d o w p r o t o c o l s ( i n w h i c h

    a l a r g e n u m b e r o f p a c k e t s a r e a l l o w e d t o b e o u t -

    s t a n d i n g t o a l l o w p i p e l i n e d t h r o u g h p u t ) a n d b e -

    c a u s e s e r v e r s o f t e n m a i n t a i n s e v e r a l o u t s t a n d i n g

    c o n v e r s a t i o n s w i t h c l i e n t s . M o s t o t h e r n e t w o r k

    p r o t o c o l s a l s o u s e s e v e r a l t i m e r s f o r e r r o r r e c o v e r y

    a n d r a t e c o n t r o l .

    H o w t h e n c a n t h e B S D T C P i m p l e m e n t a t i o n

    g e t a w a y w i t h t w o c a l l o u t s ? T h i s i s p o s s i b l e b e -

    c a u s e t h e T C P i m p l e m e n t a t i o n m a i n t a i n s i t s o w n

    t i m e r s f o r a l l o u t s t a n d i n g p a c k e t s , a n d u s e s t w o

    k e r n e l c a l l o u t s a s c l o c k s t o r u n i t s o w n t i m e r s .

    1

  • 8/3/2019 Timer Wheel

    3/13

    2 C o s t e l l o a n d V a r g h e s e

    T C P m a i n t a i n s i t s p a c k e t t i m e r s i n t h e s i m p l e s t

    f a s h i o n : W h e n e v e r i t s s i n g l e k e r n e l t i m e r e x p i r e s ,

    i t t i c k s a w a y a t a l l i t s o u t s t a n d i n g p a c k e t t i m e r s .

    T h i s m e t h o d w o r k s r e a s o n a b l y w e l l i f t h e g r a n u -

    l a r i t y o f t i m e r s i s l o w .

    2

    H o w e v e r , i t i s d e s i r a b l e t o

    i m p r o v e t h e r e s o l u t i o n o f t h e r e t r a n s m i s s i o n t i m e r

    t o a l l o w s p e e d i e r r e c o v e r y .

    3

    W i t h a l a r g e n u m b e r

    o f n e r g r a n u l a r i t y t i m e r s , i t i s n e c e s s a r y t o h a v e

    m o r e e c i e n t t i m e r a l g o r i t h m s . R a t h e r t h a n h a v e

    e v e r y p r o t o c o l d u p l i c a t e t h e s e e c i e n t a l g o r i t h m s

    C J R S 8 9 , T N M L 9 3 ] , i t i s b e t t e r t o h a v e t h e k e r n e l

    d i r e c t l y p r o v i d e a n e c i e n t c a l l o u t f a c i l i t y .

    B e s i d e s n e t w o r k i n g a p p l i c a t i o n s , p r o c e s s c o n t r o l

    a n d o t h e r r e a l - t i m e a p p l i c a t i o n s w i l l a l s o b e n e -

    t f r o m l a r g e n u m b e r s o f n e g r a n u l a r i t y t i m e r s .

    A l s o , t h e n u m b e r o f u s e r s o n a s y s t e m m a y g r o w

    l a r g e e n o u g h t o l e a d t o a l a r g e n u m b e r o f o u t s t a n d -

    i n g t i m e r s . T h i s i s t h e r e a s o n c i t e d ( f o r r e d e s i g n -

    i n g t h e t i m e r f a c i l i t y ) b y t h e d e v e l o p e r s o f t h e I B M

    V M / X A S P 1 o p e r a t i n g s y s t e m D a v 8 9 ] .

    W i t h a l a r g e n u m b e r o f o u t s t a n d i n g c a l l o u t s , i t

    b e c o m e s i m p o r t a n t t o b o u n d t h e a m o u n t o f t i m e

    t h a t i n t e r r u p t s c a n b e l o c k e d o u t . F i n a l l y , r e g a r d -

    l e s s o f t h e n u m b e r o f c a l l o u t s , t h e c u r r e n t U N I X

    l i m i t o f o n e t i m e r p e r p r o c e s s s e e m s t o o r e s t r i c -

    t i v e . T h i s f o r c e s u s e r a p p l i c a t i o n s t h a t n e e d m u l -

    t i p l e t i m e r s e i t h e r t o f o r k a d d i t i o n a l p r o c e s s e s o r

    t o m a i n t a i n t h e i r o w n t i m e r s .

    T h e r e f o r e w e b e l i e v e t h a t w e c a n m a k e a c a s e

    f o r n e w c a l l o u t a n d t i m e r i m p l e m e n t a t i o n s t h a t a r e

    s c a l a b l e , r o b u s t , a n d e x i b l e . U n l i k e m a n y s c a l a b l e

    d e s i g n s , t h e r e i s n o p e r f o r m a n c e p e n a l t y w h e n t h e

    n u m b e r o f o u t s t a n d i n g c a l l o u t s i s s m a l l . A l s o , t h e

    i n c r e a s e i n t h e c o d e s i z e i s s m a l l ( 1 5 8 l i n e s f o r t h e

    n e w c a l l o u t f a c i l i t y , a n d 3 1 0 l i n e s f o r t h e e x t e n d e d

    i n t e r v a l t i m e r f a c i l i t y ) . T h u s , c o n s i d e r i n g t h e g e n -

    e r a l e n v i r o n m e n t s i n w h i c h U N I X k e r n e l s a r e a n d

    w i l l b e d e p l o y e d , t h e n e w i m p l e m e n t a t i o n a p p e a r s

    t o b e a w i s e a n d c h e a p p i e c e o f i n s u r a n c e .

    P r e v i o u s W o r k : V a r g h e s e a n d L a u c k V L 8 7 ]

    d e s c r i b e d a n u m b e r o f n e w s c h e m e s t o i m p l e -

    m e n t t i m e r s . T h e b a s i s o f o u r i m p l e m e n t a t i o n

    i s S c h e m e 6 i n V L 8 7 ] , w h i c h i s b a s e d o n a d a t a

    s t r u c t u r e c a l l e d a h a s h e d t i m i n g w h e e l . T h e w o r k

    2

    C u r r e n t l y T C P u s e s t w o v i r t u a l c l o c k s : o n e w i t h 2 0 0 m s

    t i c k s a n d o n e w i t h 5 0 0 m s t i c k s .

    3

    T h e l a r g e r t h e r e c o v e r y t i m e , t h e l a r g e r t h e a m o u n t o f

    d a t a t h a t c o u l d h a v e b e e n s e n t , e s p e c i a l l y a t h i g h s p e e d s .

    W h i l e p a c k e t l o s s d u e t o c o r r u p t i o n i s r a r e t o d a y , p a c k e t

    l o s s d u e t o c o n g e s t i o n i s s t i l l q u i t e c o m m o n .

    i n V L 8 7 ] i s m o s t l y t h e o r e t i c a l a n d d o e s n o t c o n -

    s i d e r s o m e o f t h e i s s u e s t h a t o c c u r i n a c t u a l o p -

    e r a t i n g s y s t e m s ; f o r e x a m p l e , i t a s s u m e s t h a t a l l

    t h e p e r t i c k b o o k k e e p i n g c a n b e d o n e a t t h e i n -

    t e r r u p t l e v e l , w h i c h i s c l e a r l y i n f e a s i b l e i n a r e a l

    s y s t e m . A f e w f a i r l y w e l l k n o w n n e t w o r k i n g i m p l e -

    m e n t a t i o n s ( e . g . , C J R S 8 9 , T N M L 9 3 ] ) h a v e u s e d

    t h e i d e a s i n V L 8 7 ] i n s p e c i a l i z e d t i m e r p a c k a g e s

    f o r t h e i r n e t w o r k i n g r o u t i n e s ( a s o p p o s e d t o a g e n -

    e r a l o p e r a t i n g s y s t e m f a c i l i t y ) . B r o w n B r o 8 8 ] e x -

    t e n d s h a s h e d t i m i n g w h e e l s t o w h a t h e c a l l s c a l e n -

    d a r q u e u e s ; t h e m a j o r d i e r e n c e i s t h a t c a l e n d a r

    q u e u e i m p l e m e n t a t i o n s a l s o p e r i o d i c a l l y r e s i z e t h e

    w h e e l i n o r d e r t o r e d u c e t h e o v e r h e a d

    4

    o f s t e p p i n g

    t h r o u g h e m p t y b u c k e t s . F o r t i m e r a p p l i c a t i o n s ,

    t h e c l o c k t i m e m u s t b e i n c r e m e n t e d o n e v e r y c l o c k

    t i c k a n y w a y ; t h u s a d d i n g a f e w i n s t r u c t i o n s t o s t e p

    t h r o u g h e m p t y b u c k e t s i s n o t s i g n i c a n t . D a v i s o n

    D a v 8 9 ] d e s c r i b e s a t i m e r i m p l e m e n t a t i o n f o r t h e

    I B M V M / X A S P 1 o p e r a t i n g s y s t e m b a s e d o n c a l -

    e n d a r q u e u e s . I n o u r s e t t i n g , t h e s m a l l i m p r o v e -

    m e n t i n p e r t i c k b o o k k e e p i n g ( f r o m r e s i z i n g t h e

    w h e e l p e r i o d i c a l l y ) d o e s n o t a p p e a r t o w a r r a n t t h e

    e x t r a c o m p l e x i t y o f r e s i z i n g .

    O r g a n i z a t i o n : T h e r e s t o f t h e p a p e r i s o r g a -

    n i z e d a s f o l l o w s . S e c t i o n 2 d e s c r i b e s t h e e x i s t i n g

    N e t B S D 1 . 0 k e r n e l i m p l e m e n t a t i o n o f t h e c a l l o u t

    f a c i l i t y . S e c t i o n 3 r e v i e w s a t i m i n g w h e e l a l g o r i t h m

    p r o p o s e d i n V L 8 7 ] . S e c t i o n 4 i l l u s t r a t e s h o w w e

    i m p l e m e n t e d t h i s a l g o r i t h m i n t h e N e t B S D 1 . 0 k e r -

    n e l a n d t h e i m p l e m e n t a t i o n i s s u e s t h a t w e e n c o u n -

    t e r e d . W e a l s o d e s c r i b e i n S e c t i o n 5 a n e x t e n s i o n

    t o t h e u s e r - l e v e l i n t e r v a l t i m e r f a c i l i t y t o a l l o w m u l -

    t i p l e o u t s t a n d i n g t i m e r s ; t h i s w a s e s s e n t i a l f o r t h e

    p e r f o r m a n c e t e s t s o f t h e n e w c a l l o u t f a c i l i t y , b u t

    w e b e l i e v e t h i s f e a t u r e i s u s e f u l i n i t s o w n r i g h t .

    S e c t i o n 6 p r e s e n t s p e r f o r m a n c e r e s u l t s . S e c t i o n 7

    d e s c r i b e s f u t u r e w o r k i n t h e a r e a s o f d y n a m i c s t o r -

    a g e a l l o c a t i o n a n d c l e a n i n g u p t h e i n t e r v a l t i m e r

    i n t e r f a c e . F i n a l l y , S e c t i o n 8 s t a t e s o u r c o n c l u s i o n s .

    2 . E x i s t i n g C a l l o u t

    I m p l e m e n t a t i o n

    I n t h e e x i s t i n g B S D i m p l e m e n t a t i o n , e a c h c a l l o u t

    i s r e p r e s e n t e d b y a c a l l o u t s t r u c t u r e c o n t a i n i n g

    4

    T h e i m p r o v e m e n t i s n o t w o r s t - c a s e , b u t i s d e m o n -

    s t r a t e d e m p i r i c a l l y f o r c e r t a i n b e n c h m a r k s .

  • 8/3/2019 Timer Wheel

    4/13

    R e d e s i g n i n g t h e B S D C a l l o u t a n d T i m e r F a c i l i t i e s 3

    a p o i n t e r t o t h e f u n c t i o n t o b e c a l l e d ( c f u n c ) a

    p o i n t e r t o t h e f u n c t i o n ' s a r g u m e n t ( c a r g ) , a n d

    a t i m e ( c t i m e ) e x p r e s s e d i n u n i t s o f c l o c k t i c k s .

    O u t s t a n d i n g c a l l o u t s a r e k e p t i n a l i n k e d l i s t ,

    s o r t e d b y t h e i r e x p i r a t i o n t i m e s . T h e c t i m e m e m -

    b e r o f e a c h c a l l o u t s t r u c t u r e i s d i e r e n t i a l , n o t

    a b s o l u t e | t h e r s t c a l l o u t i n t h e l i s t s t o r e s t h e

    n u m b e r o f t i c k s f r o m n o w u n t i l e x p i r a t i o n , a n d

    e a c h s u b s e q u e n t c a l l o u t i n t h e l i s t s t o r e s t h e n u m -

    b e r o f t i c k s b e t w e e n i t s o w n e x p i r a t i o n a n d t h e

    e x p i r a t i o n o f i t s p r e d e c e s s o r .

    F i g u r e 1 : T h e c a l l t o d o d a t a s t r u c t u r e .

    T h i s d a t a s t r u c t u r e ( c a l l e d c a l l t o d o , s e e

    F i g u r e 1 ) d i c t a t e s t h e p e r f o r m a n c e . B e c a u s e t h e

    t i m e s a r e d i e r e n t i a l , t h e c l o c k i n t e r r u p t r o u t i n e

    h a r d c l o c k ( ) n e e d s o n l y t o d e c r e m e n t t h e t i m e o f

    t h e r s t c a l l o u t i n t h e l i s t a n d c h e c k w h e t h e r i t b e -

    c o m e s z e r o , w h i c h t a k e s c o n s t a n t t i m e . I f t h e r s t

    c a l l o u t h a s e x p i r e d , a s o f t w a r e c l o c k i n t e r r u p t i s

    g e n e r a t e d . I t s h a n d l e r , s o f t c l o c k ( ) , r e p e a t e d l y

    c h e c k s t h e c a l l o u t a t t h e h e a d o f t h e l i s t , a n d i f i t

    i s e x p i r e d ( c t i m e m e m b e r e q u a l t o z e r o ) , r e m o v e s

    i t a n d c a l l s i t s f u n c t i o n . I n t e r r u p t s a r e l o c k e d o u t

    w h i l e t h e c a l l t o d o l i s t i s b e i n g m a n i p u l a t e d , b u t

    n o t w h i l e t h e f u n c t i o n i s e x e c u t i n g .

    C a l l o u t s a r e s e t a n d c a n c e l e d u s i n g t i m e o u t ( )

    a n d u n t i m e o u t ( ) , r e s p e c t i v e l y . t i m e o u t ( f u n c ,

    a r g , t i m e ) r e g i s t e r s f u n c ( a r g ) t o b e c a l l e d a t

    t h e s p e c i e d t i m e . u n t i m e o u t ( f u n c , a r g ) c a n -

    c e l s t h e c a l l o u t w i t h m a t c h i n g f u n c t i o n a n d a r g u -

    m e n t . B e c a u s e t h e c a l l t o d o l i s t m u s t b e s e a r c h e d

    l i n e a r l y , b o t h o p e r a t i o n s t a k e t i m e p r o p o r t i o n a l t o

    t h e n u m b e r o f o u t s t a n d i n g c a l l o u t s . I n t e r r u p t s a r e

    l o c k e d o u t f o r t h e d u r a t i o n o f t h e s e a r c h .

    T h e r e i s o n e c o m p l i c a t i o n : B e c a u s e t h e p r o c e s s -

    i n g o f e x p i r e d c a l l o u t s b y s o f t c l o c k ( ) , w h i c h c a n

    b e i n t e r r u p t e d b y h a r d c l o c k ( ) , m i g h t t a k e l o n g e r

    t h a n o n e c l o c k t i c k , c a l l o u t s m i g h t b e c o m e o v e r -

    d u e . T h i s i s r e p r e s e n t e d i n t h e c a l l t o d o l i s t b y

    c a l l o u t s a t t h e s t a r t o f t h e l i s t w i t h n e g a t i v e c t i m e

    m e m b e r s . A c t i m e m e m b e r o f ? t i n d i c a t e s t h a t

    t h e c a l l o u t i s o v e r d u e b y t t i c k s . h a r d c l o c k ( )

    m u s t d e c r e m e n t a l l n o n - p o s i t i v e c t i m e m e m b e r s

    a t t h e b e g i n n i n g o f t h e l i s t , a s w e l l a s t h e r s t p o s -

    i t i v e c t i m e m e m b e r i n t h e l i s t . T h e r e f o r e , t h e

    p r o c e s s i n g o f a c l o c k t i c k d o e s n o t n e c e s s a r i l y t a k e

    c o n s t a n t t i m e ( i f t h e r e a r e a n u m b e r o f e x p i r e d

    t i m e r s a t t h e h e a d o f t h e l i s t t h a t s o f t c l o c k ( )

    h a s n o t y e t p r o c e s s e d ) .

    3 . R e p l a c e m e n t C a l l o u t

    A l g o r i t h m

    T h e a l g o r i t h m u s e d b y t h e e x i s t i n g i m p l e m e n t a t i o n

    i s v e r y s i m i l a r t o S c h e m e 2 o f V L 8 7 ] . T h e n e w

    i m p l e m e n t a t i o n i s b a s e d o n S c h e m e 6 o f V L 8 7 ] .

    F i g u r e 2 : T h e c a l l w h e e l d a t a s t r u c t u r e .

    I n s t e a d o f a s i n g l e s o r t e d l i s t o f c a l l o u t s t r u c -

    t u r e s , w e u s e a c i r c u l a r a r r a y o f u n s o r t e d l i s t s .

    T h e a r r a y , c a l l e d c a l l w h e e l ( s e e F i g u r e 2 ) ,

    c o n t a i n s c a l l w h e e l s i z e e n t r i e s . A l l c a l l o u t s

    s c h e d u l e d t o e x p i r e a t t i m e t a p p e a r i n t h e

    l i s t c a l l w h e e l t % c a l l w h e e l s i z e ] , a n d t h e i r

    c t i m e m e m b e r s a r e s e t t o t / c a l l w h e e l s i z e

    c a l l w h e e l s i z e s h o u l d b e c h o s e n t o b e c o m p a r a b l e

    t o t h e m a x i m u m p o s s i b l e n u m b e r o f o u t s t a n d i n g

    c a l l o u t s t r u c t u r e s .

  • 8/3/2019 Timer Wheel

    5/13

    4 C o s t e l l o a n d V a r g h e s e

    O n e a c h c l o c k t i c k , t h e a p p r o p r i a t e l i s t m u s t b e

    t r a v e r s e d c o m p l e t e l y , t h e c t i m e m e m b e r o f e a c h

    c a l l o u t i n t h e l i s t d e c r e m e n t e d , a n d t h e e x p i r e d

    c a l l o u t s h a n d l e d a n d r e m o v e d . I n t h e w o r s t c a s e ,

    a l l o u t s t a n d i n g c a l l o u t s c o u l d b e i n t h e s a m e l i s t ,

    b u t s i n c e t h e n u m b e r o f l i s t s i s c o m p a r a b l e t o t h e

    m a x i m u m n u m b e r o f o u t s t a n d i n g c a l l o u t s , a n d t h e

    l i s t s a r e p r o c e s s e d i n a r o u n d - r o b i n f a s h i o n , t h e a v -

    e r a g e l i s t l e n g t h i s a s m a l l c o n s t a n t . T h u s , i t t a k e s

    a v e r a g e - c a s e c o n s t a n t t i m e t o p r o c e s s a c l o c k t i c k .

    T o h a n d l e a n e x p i r e d t i m e r s t i l l r e q u i r e s n o t h i n g

    m o r e t h a n r e m o v i n g t h e c a l l o u t f r o m a l i s t , w h i c h

    t a k e s w o r s t - c a s e c o n s t a n t t i m e , a n d t h e n c a l l i n g i t s

    f u n c t i o n .

    S e t t i n g a c a l l o u t r e q u i r e s d e t e r m i n i n g t h e a p p r o -

    p r i a t e l i s t a n d i n s e r t i n g a t t h e h e a d , w h i c h t a k e s

    w o r s t - c a s e c o n s t a n t t i m e . F o r c a n c e l i n g a c a l l o u t ,

    t h e o r i g i n a l S c h e m e 6 a l g o r i t h m a s s u m e s t h a t i t

    w i l l b e g i v e n a h a n d l e t o t h e c a l l o u t ( i . e . a n i d e n -

    t i e r w h i c h l o c a t e s t h e c a l l o u t i m m e d i a t e l y ) , i n

    w h i c h c a s e i t n e e d s o n l y t o d e l e t e t h e c a l l o u t f r o m

    t h e l i s t , t a k i n g w o r s t - c a s e c o n s t a n t t i m e . B u t t h e

    e x i s t i n g t i m e o u t ( ) i n t e r f a c e d o e s n o t u s e h a n d l e s ,

    s o t h i s b e c o m e s a p r o b l e m i n t h e i m p l e m e n t a t i o n .

    S e c t i o n 4 w i l l d e s c r i b e h o w t h i s p r o b l e m h a s b e e n

    o v e r c o m e i n t w o d i e r e n t w a y s . T h e o r i g i n a l a l -

    g o r i t h m a l s o a s s u m e s t h a t e a c h t i m e r r o u t i n e ( e s -

    p e c i a l l y t h e e q u i v a l e n t o f h a r d c l o c k ( ) ) r u n s t o

    c o m p l e t i o n , a n d d o e s n o t w o r r y a b o u t t h e d e t a i l s o f

    m u t u a l e x c l u s i o n a n d l o c k i n g o u t i n t e r r u p t s . T h e s e

    p r o b l e m s a r e a l s o a d d r e s s e d i n S e c t i o n 4 .

    4 . R e p l a c e m e n t C a l l o u t

    I m p l e m e n t a t i o n

    c a l l w h e e l s i z e i s c o n s t r a i n e d t o b e a p o w e r o f 2 ,

    e q u a l t o 2

    c a l l w h e e l b i t s

    . T h i s s i m p l i e s t h e d i -

    v i s i o n a n d r e m a i n d e r o p e r a t i o n s t o b i t s h i f t i n g a n d

    m a s k i n g . T h e l i s t s i n c a l l w h e e l a r e d o u b l y - l i n k e d

    ( r e q u i r i n g a n a d d i t i o n a l m e m b e r i n t h e c a l l o u t

    s t r u c t u r e s ) , a l l o w i n g t h e r e m o v a l o f a c a l l o u t

    s t r u c t u r e g i v e n o n l y a p o i n t e r t o i t .

    T h e o l d h a r d c l o c k ( ) h a d t o m a n i p u l a t e t h e

    c a l l t o d o s t r u c t u r e , b u t t h e n e w h a r d c l o c k ( )

    h a s n o t h i n g t o d o b u t i n c r e m e n t t h e g l o b a l

    t i c k s v a r i a b l e

    5

    ( w h i c h t h e o l d h a r d c l o c k ( )

    5

    A c t u a l l y , h a r d c l o c k ( ) a l s o d o e s o t h e r t h i n g s e n t i r e l y

    u n r e l a t e d t o t h e c a l l o u t f a c i l i t y .

    d i d a n y w a y ) , w h i c h r e p r e s e n t s t h e c u r r e n t

    t i m e . s o f t c l o c k ( ) h a s i t s o w n s t a t i c v a r i -

    a b l e , s o f t t i c k s s o f t c l o c k ( ) r e p e a t e d l y c h e c k s

    w h e t h e r s o f t t i c k s e q u a l s t i c k s , a n d i f n o t , i n -

    c r e m e n t s s o f t t i c k s a n d c h e c k s a l l t h e c a l l o u t s

    i n c a l l w h e e l s o f t t i c k s & c a l l w h e e l m a s k ] , e x -

    p i r i n g t h e o n e s w i t h c t i m e m e m b e r s e q u a l t o z e r o ,

    d e c r e m e n t i n g t h e c t i m e m e m b e r s o f t h e o t h e r s .

    A s a n o p t i m i z a t i o n , a f t e r h a r d c l o c k ( ) i n c r e m e n t s

    t i c k s , i t c h e c k s t o s e e i f s o f t t i c k s e q u a l s t i c k s

    - 1 a n d c a l l w h e e l t i c k s & c a l l w h e e l m a s k ] i s

    e m p t y . I f n o t , a s o f t w a r e i n t e r r u p t i s g e n e r -

    a t e d t o c a u s e s o f t c l o c k ( ) t o r u n . O t h e r w i s e ,

    h a r d c l o c k ( ) i n c r e m e n t s s o f t t i c k s i t s e l f r a t h e r

    t h a n i n c u r t h e o v e r h e a d o f a s o f t w a r e i n t e r r u p t ,

    s i n c e t h a t i s a l l s o f t c l o c k ( ) w o u l d h a v e d o n e .

    F i g u r e s 3 , 4 , a n d 5 s h o w t h e n e w c o d e f o r

    h a r d c l o c k ( ) a n d s o f t c l o c k ( )

    I f i t w e r e n o t f o r t h e l a c k o f h a n d l e s i n t h e e x i s t -

    i n g t i m e o u t ( ) / u n t i m e o u t ( ) i n t e r f a c e , t h e i m p l e -

    m e n t a t i o n o f t h o s e f u n c t i o n s w o u l d b e s t r a i g h t f o r -

    w a r d , a n d t h e r e w o u l d b e n o t h i n g t o s a y a b o u t

    t h e m h e r e . T h e r e a r e t w o p o s s i b l e s o l u t i o n s t o

    t h e p r o b l e m . W e c o u l d t r y t o n d a w a y , g i v e n

    a f u n c t i o n p o i n t e r a n d a r g u m e n t p o i n t e r , t o p r o -

    d u c e a p o i n t e r t o t h e m a t c h i n g c a l l o u t i n c o n -

    s t a n t t i m e . A h a s h t a b l e i s t h e o b v i o u s m e c h -

    a n i s m . T h e d i s a d v a n t a g e i s t h a t a h a s h t a -

    b l e c a n n o t g u a r a n t e e c o n s t a n t t i m e i n t h e w o r s t

    c a s e ; i t c a n o n l y p r o v i d e c o n s t a n t t i m e i n t h e

    e x p e c t e d c a s e . T h e o t h e r s o l u t i o n w o u l d b e

    t o p r o v i d e n e w i n t e r f a c e f u n c t i o n s c a l l e d , s a y ,

    s e t c a l l o u t ( ) a n d u n s e t c a l l o u t ( ) , w h i c h w o r k

    v e r y m u c h l i k e t i m e o u t ( ) a n d u n t i m e o u t ( ) , e x -

    c e p t t h a t s e t c a l l o u t ( ) r e t u r n s a h a n d l e , a n d

    u n s e t c a l l o u t ( ) t a k e s a h a n d l e a s i t s o n l y a r g u -

    m e n t . T h e d i s a d v a n t a g e h e r e i s t h a t e x i s t i n g c o d e

    e l s e w h e r e i n t h e k e r n e l a l r e a d y u s e s t h e e x i s t i n g

    i n t e r f a c e . I n t h e n e w i m p l e m e n t a t i o n , b o t h s o l u -

    t i o n s a r e u s e d . B o t h i n t e r f a c e s a r e a v a i l a b l e f o r

    a d d i n g a n d r e m o v i n g c a l l o u t s t o a n d f r o m a s i n g l e

    c a l l w h e e l . A h a s h t a b l e i s u s e d o n l y b y t h e o l d

    i n t e r f a c e .

    A t r s t , w e u s e d a c l o s e d - c h a i n i n g h a s h t a b l e . I f

    u n t i m e o u t ( f u n c , a r g ) w e r e c a l l e d , a n d n o o u t -

    s t a n d i n g c a l l o u t m a t c h e d t h e s p e c i e d f u n c t i o n

    a n d a r g u m e n t , t h e e n t i r e h a s h t a b l e w o u l d h a v e

    t o b e s e a r c h e d . W e d i d n o t e x p e c t u n t i m e o u t ( )

    e v e r t o b e c a l l e d t h i s w a y , b u t i t t u r n s o u t t h a t

  • 8/3/2019 Timer Wheel

    6/13

    R e d e s i g n i n g t h e B S D C a l l o u t a n d T i m e r F a c i l i t i e s 5

    s t r u c t c a l l o u t {

    s t r u c t c a l l o u t * c _ n e x t ; / * n e x t c a l l o u t i n q u e u e * /

    s t r u c t c a l l o u t * * c _ b a c k ; / * p o i n t e r b a c k t o t h e p t r * /

    / * p o i n t i n g a t t h i s s t r u c t * /

    s t r u c t c a l l o u t * h a s h _ n e x t ; / * n e x t a n d b a c k p o i n t e r s * /

    s t r u c t c a l l o u t * * h a s h _ b a c k ; / * f o r t h e c a l l h a s h a r r a y * /

    / * h a s h _ b a c k i s N U L L i f f t h i s c a l l o u t i s n o t i n t h e h a s h t a b l e . * /

    s t r u c t c a l l o u t _ h a n d l e {

    u n s i g n e d l o n g l o , h i ;

    } h a n d l e ; / * h a n d l e f o r t h i s c a l l o u t * /

    / * T h e l o w e s t c a l l o u t b i t s o f h a n d l e . h i a r e t h e * /

    / * i n d e x i n t o t h e c a l l o u t a r r a y o f t h i s c a l l o u t . * /

    v o i d * c _ a r g ; / * f u n c t i o n a r g u m e n t * /

    v o i d ( * c _ f u n c ) _ _ P ( ( v o i d * ) ) ; / * f u n c t i o n t o c a l l * /

    i n t c _ t i m e ; / * t i c k s t o t h e e v e n t > > c a l l w h e e l b i t s * /

    } ;

    i n t t i c k s ; / * C u r r e n t t i m e , i n t i c k s . * /

    s t a t i c i n t s o f t t i c k s ; / * L i k e t i c k s , b u t f o r s o f t c l o c k ( ) . * /

    s t a t i c s t r u c t c a l l o u t * n e x t s o f t c h e c k ; / * N e x t c a l l o u t t o b e c h e c k e d . * /

    F i g u r e 3 : D e c l a r a t i o n s u s e d b y h a r d c l o c k ( ) a n d s o f t c l o c k ( )

    v o i d h a r d c l o c k ( f r a m e )

    r e g i s t e r s t r u c t c l o c k f r a m e * f r a m e ;

    {

    / * T h e r e a l h a r d c l o c k ( ) a l s o d o e s o t h e r , n o n - c a l l o u t - r e l a t e d t h i n g s . * /

    t i c k s + + ;

    i f ( c a l l w h e e l t i c k s & c a l l w h e e l m a s k ] ) { / * T h i s c o n d i t i o n c h a n g e d . * /

    i f ( C L K F _ B A S E P R I ( f r a m e ) ) {

    / * S a v e t h e o v e r h e a d o f a s o f t w a r e i n t e r r u p t ; * /

    / * i t w i l l h a p p e n a s s o o n a s w e r e t u r n , s o d o i t n o w . * /

    ( v o i d ) s p l s o f t c l o c k ( ) ;

    s o f t c l o c k ( ) ;

    } e l s e

    s e t s o f t c l o c k ( ) ;

    }

    e l s e i f ( s o f t t i c k s + 1 = = t i c k s ) + + s o f t t i c k s ; / * T h i s l i n e i s n e w . * /

    }

    F i g u r e 4 : T h e n e w h a r d c l o c k ( ) f u n c t i o n . F r o m t h e o l d f u n c t i o n , s e v e r a l l i n e s d e a l i n g w i t h c a l l t o d o

    h a v e b e e n r e m o v e d , o n e l i n e h a s b e e n c h a n g e d , a n d o n e l i n e h a s b e e n a d d e d .

  • 8/3/2019 Timer Wheel

    7/13

    6 C o s t e l l o a n d V a r g h e s e

    v o i d s o f t c l o c k ( )

    {

    r e g i s t e r s t r u c t c a l l o u t * c ;

    r e g i s t e r i n t s t e p s ; / * N u m b e r o f s t e p s t a k e n s i n c e * /

    / * w e l a s t a l l o w e d i n t e r r u p t s . * /

    r e g i s t e r i n t s ;

    s = s p l h i g h ( ) ;

    s t e p s = 0 ;

    w h i l e ( s o f t t i c k s ! = t i c k s ) {

    i f ( + + s t e p s > = M A X _ S O F T C L O C K _ S T E P S ) {

    n e x t s o f t c h e c k = N U L L ;

    s p l x ( s ) ; / * G i v e h a r d c l o c k ( ) a c h a n c e . * /

    ( v o i d ) s p l h i g h ( ) ;

    s t e p s = 0 ;

    }

    c = c a l l w h e e l + + s o f t t i c k s & c a l l w h e e l m a s k ] ;

    w h i l e ( c ) {

    i f ( c - > c _ t i m e > 0 ) {

    - - c - > c _ t i m e ;

    c = c - > c _ n e x t ;

    i f ( + + s t e p s > = M A X _ S O F T C L O C K _ S T E P S ) {

    n e x t s o f t c h e c k = c ;

    s p l x ( s ) ; / * G i v e h a r d c l o c k ( ) a c h a n c e . * /

    ( v o i d ) s p l h i g h ( ) ;

    c = n e x t s o f t c h e c k ;

    s t e p s = 0 ;

    }

    }

    e l s e {

    i f ( n e x t s o f t c h e c k = * c - > c _ b a c k = c - > c _ n e x t )

    n e x t s o f t c h e c k - > c _ b a c k = c - > c _ b a c k ;

    i f ( c - > h a s h _ b a c k ) c a l l h a s h _ r e m o v e ( c ) ;

    e l s e i f ( + + c - > h a n d l e . l o = = 0 ) c - > h a n d l e . h i + = c a l l o u t s i z e ;

    s p l x ( s ) ;

    c - > c _ f u n c ( c - > c _ a r g ) ;

    ( v o i d ) s p l h i g h ( ) ;

    s t e p s = 0 ;

    c - > c _ n e x t = c a l l f r e e ;

    c a l l f r e e = c ;

    c = n e x t s o f t c h e c k ;

    }

    }

    }

    n e x t s o f t c h e c k = N U L L ;

    s p l x ( s ) ;

    }

    F i g u r e 5 : T h e n e w s o f t c l o c k ( ) f u n c t i o n . I t i s e n t i r e l y d i e r e n t f r o m t h e o l d o n e .

  • 8/3/2019 Timer Wheel

    8/13

    R e d e s i g n i n g t h e B S D C a l l o u t a n d T i m e r F a c i l i t i e s 7

    s u c h c a l l s a r e q u i t e c o m m o n . I n t h e o l d i m p l e m e n -

    t a t i o n , t h e c o s t o f c a n c e l i n g a n o n - e x i s t e n t c a l l o u t

    w a s a b o u t t h e s a m e a s c a n c e l i n g a n e x i s t e n t c a l l -

    o u t ( b o t h r e q u i r e a l i n e a r s e a r c h o f t h e c a l l t o d o

    s t r u c t u r e ) . W e w a n t e d b o t h s o r t s o f c a l l s t o h a v e

    e q u a l c o s t s i n t h e n e w i m p l e m e n t a t i o n a s w e l l , s o

    w e s w i t c h e d t o a n o p e n - c h a i n i n g h a s h t a b l e , i n

    w h i c h o n l y o n e b u c k e t n e e d s t o b e s e a r c h e d i n

    a n y c a s e . T h i s r e q u i r e d t h e a d d i t i o n o f t w o m o r e

    m e m b e r s t o t h e c a l l o u t s t r u c t u r e , s o t h a t e a c h

    c a l l o u t , w h i c h m i g h t a l r e a d y b e l o n g t o a d o u b l y -

    l i n k e d l i s t i n c a l l w h e e l , m i g h t a l s o b e l o n g t o a

    d o u b l y - l i n k e d l i s t i n c a l l h a s h ( t h e h a s h t a b l e ) .

    t i m e o u t ( ) a l w a y s i n s e r t s t h e n e w c a l l o u t i n t o t h e

    h a s h t a b l e , a n d u n t i m e o u t ( ) a l w a y s r e m o v e s i t ,

    b u t s o f t c l o c k ( ) m u s t c h e c k t o s e e w h e t h e r a n

    e x p i r i n g c a l l o u t i s i n t h e h a s h t a b l e b e f o r e r e m o v -

    i n g i t . F o r t u n a t e l y , i t n e e d n o t c o m p u t e t h e h a s h

    f u n c t i o n t o d o t h i s ; i t c a n m e r e l y c h e c k t h e l i n k s

    i n t h e t h e c a l l o u t s t r u c t u r e .

    T h e h a s h f u n c t i o n w a s c h o s e n t o b e f a s t t o c o m -

    p u t e , b u t s t i l l p r o v i d e a f a i r l y e v e n d i s t r i b u t i o n

    a m o n g t h e b u c k e t s . c a l l h a s h s i z e i s c o n s t r a i n e d

    t o b e a p o w e r o f 2 , e q u a l t o 2

    c a l l h a s h b i t s

    B o t h t h e f u n c a n d a r g p o i n t e r s a r e l i k e l y t o b e

    l o n g w o r d - a l i g n e d , s o t h e l o w e s t 2 b i t s o f e a c h a r e

    n o t u s e d . T h e l o w e r b i t s o f f u n c t i o n p o i n t e r s a r e

    l i k e l y t o b e m o r e r a n d o m t h a n t h e h i g h e r b i t s , s o

    t h e n e x t h i g h e r c a l l h a s h b i t s b i t s o f f u n c a r e

    u s e d . F o r d a t a p o i n t e r s , t h e l o w b i t s m i g h t b e

    c o n s t a n t ( i n t h e c a s e o f p o i n t e r s t o l a r g e a l i g n e d

    s t r u c t u r e s , s u c h a s m b u f s ) o r t h e y m i g h t b e t h e

    o n l y b i t s t h a t a r e s i g n i c a n t ( i n t h e c a s e o f p o i n t -

    e r s i n t o a n a r r a y , f o r e x a m p l e ) . T h e r e f o r e , w e u s e

    n o t o n l y t h e n e x t h i g h e r c a l l h a s h b i t s b i t s f r o m

    a r g , b u t a l s o t h e n e x t h i g h e r c a l l h a s h b i t s b i t s

    a b o v e t h o s e . T h e t h r e e b i t s t r i n g s , e a c h o f l e n g t h

    c a l l h a s h b i t s , a r e a l i g n e d a n d X O R e d t o p r o d u c e

    t h e i n d e x i n t o t h e h a s h t a b l e . T h e c o m p u t a t i o n r e -

    q u i r e s 3 s h i f t s a n d 3 b o o l e a n o p e r a t i o n s .

    F o r t h e n e w s e t c a l l o u t ( ) i n t e r f a c e , t h e d e -

    s i g n o f t h e h a n d l e w a s n o t t r i v i a l . A s i m p l e

    p o i n t e r t o a c a l l o u t s t r u c t u r e w o u l d n o t b e s a f e ,

    b e c a u s e t h o s e s t r u c t u r e s g e t r e c y c l e d . B e t w e e n

    t h e t i m e s e t c a l l o u t ( ) r e t u r n s a p o i n t e r a n d t h e

    t i m e u n s e t c a l l o u t ( ) i s p a s s e d t h a t p o i n t e r , t h e

    c a l l o u t c o u l d h a v e e x p i r e d a n d b e e n r e u s e d , i n

    w h i c h c a s e t h e c a l l t o u n s e t c a l l o u t ( ) w i l l c a n -

    c e l s o m e o n e e l s e ' s c a l l o u t . T h e s o l u t i o n w a s t o

    g i v e e a c h c a l l o u t s t r u c t u r e a n I D t h a t g e t s i n -

    c r e m e n t e d e a c h t i m e t h e c a l l o u t i s c a n c e l e d b y

    u n s e t c a l l o u t ( ) . T h e I D i s i n c l u d e d i n t h e h a n -

    d l e , s o t h a t u n s e t c a l l o u t ( ) c a n c o m p a r e t h e

    I D s b e f o r e c a n c e l i n g t h e c a l l o u t . T h e s i z e o f t h e

    I D m u s t b e l a r g e e n o u g h t h a t i t w i l l n e v e r w r a p

    a r o u n d . 3 2 b i t s w a s d e e m e d i n s u c i e n t . B u t t h e

    h a n d l e a l s o n e e d s t o i n c l u d e a \ p o i n t e r " t o t h e

    c a l l o u t s t r u c t u r e , a n d a r e a l p o i n t e r i s o v e r k i l l .

    S i n c e a l l o f t h e c a l l o u t s t r u c t u r e s a r e a l l o c a t e d

    a s a s i n g l e a r r a y a t b o o t t i m e , w e o n l y n e e d a n i n -

    d e x i n t o t h i s a r r a y , w h i c h t a k e s c a l l o u t b i t s b i t s

    ( t h i s i s m u c h l e s s t h a n 3 2 ) . S o a c a l l o u t h a n d l e

    s t r u c t u r e c o n t a i n s t w o u n s i g n e d l o n g s , l o a n d h i

    T h e l o w e s t c a l l o u t b i t s b i t s o f h i a r e t h e i n -

    d e x i n t o t h e c a l l o u t a r r a y , a n d a l l r e m a i n i n g b i t s

    a r e u s e d f o r t h e I D . I n c r e m e n t i n g t h e I D a m o u n t s

    t o i n c r e m e n t i n g l o , a n d i f t h e r e s u l t i s z e r o ,

    a d d i n g c a l l o u t s i z e = 2

    c a l l o u t b i t s

    t o h i . E a c h

    c a l l o u t s t r u c t u r e c o n t a i n s a f u l l c a l l o u t h a n d l e

    s t r u c t u r e , w i t h t h e l o w e s t c a l l o u t b i t s b i t s o f h i

    i n i t i a l i z e d a t b o o t t i m e , s o t h a t u n s e t c a l l o u t ( )

    m a y c o m p a r e t h e e n t i r e h a n d l e , r a t h e r t h a n j u s t

    t h e I D p o r t i o n .

    T h e o n l y r e m a i n i n g w r i n k l e i n t h e i m p l e m e n t a -

    t i o n i s m o t i v a t e d b y t h e d e s i r e t o l i m i t t h e t i m e

    t h a t i n t e r r u p t s m a y b e d i s a b l e d . t i m e o u t ( ) a n d

    u n t i m e o u t ( ) , w h i c h u s e t h e h a s h t a b l e , c a n n o t

    g u a r a n t e e a l i m i t o n t h e t i m e t h a t i n t e r r u p t s a r e

    d i s a b l e d , b u t s e t c a l l o u t ( ) a n d u n s e t c a l l o u t ( )

    c a n ( a n d d o ) . h a r d c l o c k ( ) a l w a y s t a k e s c o n s t a n t

    t i m e .

    6

    T h e r e m a i n i n g c o n c e r n i s s o f t c l o c k ( )

    w h i c h m u s t l o c k o u t i n t e r r u p t s w h i l e i t i s m a -

    n i p u l a t i n g t h e c a l l w h e e l s t r u c t u r e . W h i l e i t

    i s t r a v e r s i n g a l i s t ( w h i c h c o u l d b e l o n g i n t h e

    w o r s t c a s e ) , i t c a n n o t a l l o w i t s e l f t o b e i n t e r -

    r u p t e d b y u n t i m e o u t ( ) o r u n s e t c a l l o u t ( ) , b e -

    c a u s e t h o s e f u n c t i o n s m i g h t r e m o v e a c a l l o u t

    s t r u c t u r e r i g h t o u t f r o m u n d e r s o f t c l o c k ( ) . T h i s

    p r o b l e m w a s e l i m i n a t e d b y a b i t o f u n h o l y d a t a -

    s h a r i n g b e t w e e n s o f t c l o c k ( ) a n d u n t i m e o u t ( )

    a n d u n s e t c a l l o u t ( ) A s s o f t c l o c k ( ) t r a -

    v e r s e s a l i s t , i t u s e s a l o c a l p o i n t e r i n t o t h e

    l i s t . W h e n e v e r i t w i s h e s t o e n a b l e i n t e r r u p t s

    b r i e y , i t r s t c o p i e s i t s l o c a l p o i n t e r i n t o t h e

    g l o b a l v a r i a b l e n e x t s o f t c h e c k , t h e n e n a b l e s i n -

    t e r r u p t s , t h e n d i s a b l e s i n t e r r u p t s , t h e n c o p i e s

    n e x t s o f t c h e c k b a c k i n t o i t s l o c a l p o i n t e r . W h e n -

    e v e r u n t i m e o u t ( ) o r u n s e t c a l l o u t ( ) c a n c e l s a

    c a l l o u t , i t c h e c k s t o s e e w h e t h e r n e x t s o f t c h e c k

    6

    F o r i t s c a l l o u t - r e l a t e d d u t i e s , t h a t i s .

  • 8/3/2019 Timer Wheel

    9/13

    8 C o s t e l l o a n d V a r g h e s e

    p o i n t s a t t h e s t r u c t u r e j u s t r e m o v e d , a n d i f s o ,

    i t s e t s n e x t s o f t c h e c k t o p o i n t t o t h e n e x t s t r u c -

    t u r e i n t h e l i s t . s o f t c l o c k ( ) k e e p s t r a c k o f t h e

    n u m b e r o f s t e p s i t h a s t a k e n s i n c e i t l a s t e n -

    a b l e d i n t e r r u p t s , a n d w h e n e v e r t h e c o u n t r e a c h e s

    M A X S O F T C L O C K S T E P S , i t b r i e y e n a b l e s t h e m .

    T h e r e f o r e , s o f t c l o c k ( ) n e v e r d i s a b l e s i n t e r r u p t s

    f o r m o r e t h a n a c o n s t a n t a m o u n t o f t i m e . T h e r e

    a r e n o g u a r a n t e e s o n t h e t i m e l i n e s s o f c a l l o u t e x p i -

    r a t i o n s , b u t t h e r e n e v e r w e r e i n t h e o l d i m p l e m e n -

    t a t i o n e i t h e r .

    5 . M u l t i p l e T i m e r s

    T e s t i n g t h e p e r f o r m a n c e o f t h e n e w c a l l o u t i m p l e -

    m e n t a t i o n w o u l d b e e a s i e s t t o d o i n a u s e r - l e v e l

    p r o c e s s . A u s e r p r o c e s s c a n c a u s e c a l l o u t s t o b e

    s e t , c a n c e l e d , a n d e x p i r e d v i a t h e i n t e r v a l t i m e r f a -

    c i l i t y , t h r o u g h t h e g e t i t i m e r ( ) a n d s e t i t i m e r ( )

    s y s t e m c a l l s .

    U n f o r t u n a t e l y , t h e e x i s t i n g i n t e r v a l t i m e r f a c i l -

    i t y a l l o w s e a c h p r o c e s s o n l y o n e o u t s t a n d i n g r e a l -

    t i m e t i m e r , w h i c h m e a n s o n e o u t s t a n d i n g c a l l o u t .

    T h e r s t t e s t s u s e d m u l t i p l e p r o c e s s e s t o a c h i e v e

    m u l t i p l e o u t s t a n d i n g c a l l o u t s , b u t t h e r e w e r e m y s -

    t e r i o u s p r o b l e m s w h e n e v e r m o r e t h a n 8 0 p r o c e s s e s

    w e r e s p a w n e d , n o m a t t e r h o w h i g h M A X U S E R S w a s

    s e t .

    W h i l e t h i s w a s a p r a g m a t i c r e a s o n , w e a l s o b e -

    l i e v e t h a t u s e r s w i l l b e n e t f r o m t h e a b i l i t y t o a l -

    l o w e a c h p r o c e s s t o h a v e m u l t i p l e o u t s t a n d i n g r e a l -

    t i m e t i m e r s . O u r e x t e n s i o n s i n v o l v e d a d d i n g a n e w

    t i m e r t y p e t a g , I T I M E R M U L T I R E A L , a n d o v e r l o a d -

    i n g t h e s e m a n t i c s o f t h e o t h e r a r g u m e n t s p a s s e d t o

    g e t i t i m e r ( ) a n d s e t i t i m e r ( )

    T h e d e t a i l s o f t h e i n t e r f a c e e x t e n s i o n s a r e d e -

    s c r i b e d i n F i g u r e s 6 a n d 7 . T h e e x t e n d e d i n t e r f a c e

    a l l o w s t h e u s e r p r o c e s s t o c r e a t e m a n y r e a l - t i m e

    t i m e r s , w h i c h h a v e 6 4 - b i t k e r n e l - c h o s e n h a n d l e s a s -

    s o c i a t e d w i t h t h e m , a s w e l l a s 6 4 - b i t u s e r - c h o s e n

    l a b e l s . T h e u s e r p r o c e s s c a n c h a n g e t h e v a l u e s

    a n d l a b e l s o f e x i s t i n g t i m e r s , a n d d e s t r o y e x i s t i n g

    t i m e r s . W h e n e v e r a t i m e r e x p i r e s , t h e t i m e r i s p u t

    i n a q u e u e , a n d a S I G A L R M i s s e n t t o t h e p r o c e s s .

    T h e p r o c e s s c a n p o p a n e x p i r e d t i m e r o o f t h i s

    q u e u e a n d o b t a i n b o t h i t s h a n d l e a n d i t s l a b e l .

    T h e i m p l e m e n t a t i o n o f t h e e x t e n d e d t i m e r f a c i l -

    i t y r e q u i r e d m u c h n e w c o d e i n t h e g e t i t i m e r ( )

    a n d s e t i t i m e r ( ) s y s t e m c a l l s , o f c o u r s e . A l s o ,

    t w o n e w p o i n t e r m e m b e r s w e r e a d d e d t o t h e p r o c

    s t r u c t u r e t o k e e p t r a c k o f r u n n i n g a n d q u e u e d

    t i m e r s b e l o n g i n g t o t h e p r o c e s s e s .

    7

    S i n c e e a c h

    t i m e r i s r e p r e s e n t e d b y a n m r t i m e r s t r u c t u r e a l l o -

    c a t e d f r o m a s h a r e d p o o l , c o d e n e e d e d t o b e a d d e d

    t o e x i t ( ) t o f r e e a n y t i m e r s s t i l l b e l o n g i n g t o t h e

    d y i n g p r o c e s s . E a c h m r t i m e r s t r u c t u r e c o n t a i n s

    a p o i n t e r t o t h e p r o c e s s t h a t o w n s i t , s o o n e p r o -

    c e s s c a n n o t f o r g e h a n d l e s a n d t r i c k t h e k e r n e l i n t o

    m a n i p u l a t i n g t i m e r s b e l o n g i n g t o a n o t h e r p r o c e s s .

    T h e k e r n e l m a y b e c o n g u r e d a t c o m p i l e - t i m e

    t o u s e e i t h e r t h e t i m e o u t ( ) i n t e r f a c e o r t h e

    s e t c a l l o u t ( ) i n t e r f a c e f o r t h e I T I M E R M U L T I R E A L

    f a c i l i t y .

    6 . P e r f o r m a n c e

    T h r e e k e r n e l s w e r e t e s t e d o n a S u n 4 / 3 6 0 . A l l

    i n c l u d e d t h e I T I M E R M U L T I R E A L f a c i l i t y . I n o n e

    k e r n e l , i t u s e d t h e t i m e o u t ( ) i n t e r f a c e t o t h e o l d

    c a l l o u t f a c i l i t y . I n a n o t h e r k e r n e l , i t u s e d t h e

    t i m e o u t ( ) i n t e r f a c e t o t h e n e w c a l l o u t f a c i l i t y . I n

    t h e l a s t k e r n e l , i t u s e d t h e s e t c a l l o u t ( ) i n t e r f a c e

    t o t h e n e w c a l l o u t f a c i l i t y .

    I n e a c h t e s t , o n e p r o c e s s c r e a t e d a n u m b e r o f

    o u t s t a n d i n g t i m e r s s e t f o r r a n d o m t i m e s f a r i n

    t h e f u t u r e , c a u s i n g a n u m b e r o f o u t s t a n d i n g c a l l -

    o u t s . I t t h e n c r e a t e d o n e m o r e t i m e r , a n d r e -

    p e a t e d l y s e t i t f o r a r a n d o m t i m e f a r t h e r i n t h e

    f u t u r e t h a n t h e o t h e r s , c a u s i n g r e p e a t e d c a l l s t o

    u n t i m e o u t ( ) a n d t i m e o u t ( ) ( o r u n s e t c a l l o u t ( )

    a n d s e t c a l l o u t ( ) , d e p e n d i n g o n w h i c h k e r n e l w a s

    b e i n g u s e d ) . T h e r e s u l t s s h o w t h a t t h e t i m e f o r

    t h e o r i g i n a l c a l l o u t f a c i l i t y i n c r e a s e s l i n e a r l y w i t h

    t h e n u m b e r o f o u t s t a n d i n g c a l l o u t s , w h e r e a s t h e

    t i m e f o r t h e r e p l a c e m e n t c a l l o u t f a c i l i t y i s c o n s t a n t

    w i t h r e s p e c t t o t h e n u m b e r o f o u t s t a n d i n g c a l l o u t s ,

    f o r b o t h t h e o l d i n t e r f a c e ( u s i n g h a s h i n g ) a n d t h e

    n e w i n t e r f a c e ( u s i n g h a n d l e s ) . ( S e e F i g u r e 8 a n d

    T a b l e 1 . ) T h e n e w i n t e r f a c e p e r f o r m s v e r y s l i g h t l y

    b e t t e r , a n d p r o v i d e s g u a r a n t e e d c o n s t a n t t i m e o p -

    e r a t i o n s , b u t t h e o l d i n t e r f a c e i s n e e d e d f o r c o m -

    p a t i b i l i t y w i t h t h e r e s t o f t h e k e r n e l .

    7

    I t w o u l d h a v e b e e n e a s i e r t o u s e t h r e e p o i n t e r s , b u t

    t h e r e w e r e a l r e a d y 8 b y t e s o f p a d d i n g i n t h e s t r u c t u r e . B y

    u s i n g o n l y t w o p o i n t e r s , i t w a s p o s s i b l e t o a d d t h e m e m b e r s

    w i t h o u t c h a n g i n g t h e s i z e o f t h e s t r u c t u r e .

  • 8/3/2019 Timer Wheel

    10/13

    R e d e s i g n i n g t h e B S D C a l l o u t a n d T i m e r F a c i l i t i e s 9

    T h e e x i s t i n g i n t e r f a c e , s e t i t i m e r ( I T I M E R R E A L , v a l u e , o v a l u e ) , s e t s t h e p r o c e s s ' s r e a l - t i m e i n t e r -

    v a l t i m e r t o v a l u e - > i t v a l u e , p u t t i n g t h e f o r m e r c o n t e n t s i n t o o v a l u e f o v a l u e i s n o t N U L L . T h e

    t i m e r d e c r e m e n t s i n r e a l t i m e , c a u s i n g a S I G A L R M w h e n i t r e a c h e s z e r o . I f v a l u e - > i t i n t e r v a l w a s

    n o t z e r o , t h e t i m e r r e l o a d s w i t h t h a t v a l u e , o t h e r w i s e i t s t o p s .

    T h e n e w i n t e r f a c e , s e t i t i m e r ( I T I M E R M U L T I R E A L , v a l u e , o v a l u e ) , b e h a v e s s i m i l a r l y , b u t w i t h t h e

    f o l l o w i n g d i e r e n c e s :

    o v a l u e m u s t n o t b e N U L L ; i t m u s t p o i n t t o a s t r u c t i t i m e r v a l

    I f v a l u e - > i t v a l u e i s n o t z e r o , a n d o v a l u e - > i t v a l u e s f - 1 , - 1 g , t h i s i s a c r e a t e - n e w - t i m e r

    o p e r a t i o n . o v a l u e - > i t i n t e r v a l m u s t a l r e a d y b e s e t t o a n a r b i t r a r y u s e r - c h o s e n \ l a b e l " f o r

    t h e n e w t i m e r . o v a l u e - > i t v a l u e w i l l b e o v e r w r i t t e n w i t h a k e r n e l - c h o s e n \ h a n d l e " f o r t h e

    t i m e r . T h e t i m e r w i l l b e i n i t i a l i z e d w i t h v a l u e

    I f v a l u e - > i t v a l u e i s n o t z e r o , a n d o v a l u e - > i t v a l u e i s n o t f - 1 , - 1 g , t h i s i s a r e s e t - e x i s t i n g -

    t i m e r o p e r a t i o n . o v a l u e - > i t v a l u e i s i n t e r p r e t e d a s a t i m e r h a n d l e , a n d o v a l u e - > i t i n t e r v a l

    m u s t a l r e a d y b e s e t t o a n a r b i t r a r y u s e r - c h o s e n l a b e l , w h i c h m a y d i e r f r o m t h e e x i s t i n g t i m e r ' s

    c u r r e n t l a b e l . T h e e x i s t i n g t i m e r i s r e m o v e d f r o m t h e e x p i r e d t i m e r q u e u e ( s e e g e t i t i m e r ( ) )

    i f n e c e s s a r y , a n d i t s v a l u e a n d l a b e l a r e o v e r w r i t t e n w i t h v a l u e a n d o v a l u e - > i t i n t e r v a l A s

    w i t h I T I M E R R E A L o v a l u e i s o v e r w r i t t e n w i t h t h e f o r m e r v a l u e o f t h e t i m e r . I f t h e h a n d l e i n

    o v a l u e - > i t v a l u e d i d n o t r e f e r t o a n e x i s t i n g t i m e r , - 1 i s r e t u r n e d a n d e r r n o i s s e t t o E I N V A L

    I f v a l u e - > i t v a l u e i s z e r o , t h i s i s a c a n c e l - t i m e r o p e r a t i o n . v a l u e - > i t i n t e r v a l a n d

    o v a l u e - > i t i n t e r v a l a r e i g n o r e d . o v a l u e - > i t v a l u e i s i n t e r p r e t e d a s a t i m e r h a n d l e . I f t h e

    h a n d l e i s v a l i d a n d t h e t i m e r e x i s t s , i t i s d e s t r o y e d , a n d i t s n a l v a l u e i s s t o r e d i n o v a l u e

    O t h e r w i s e , - 1 i s r e t u r n e d a n d e r r n o i s s e t t o E I N V A L . N o t e t h a t t i m e r s i n t h e e x p i r e d q u e u e ( s e e

    g e t i t i m e r ( ) ) a r e s t i l l c o n s i d e r e d t o e x i s t .

    F i g u r e 6 : E x t e n s i o n s t o s e t i t i m e r ( )

    T h e e x i s t i n g i n t e r f a c e , g e t i t i m e r ( I T I M E R R E A L , v a l u e ) , w r i t e s t h e c u r r e n t c o n t e n t s o f t h e p r o c e s s ' s

    r e a l - t i m e i n t e r v a l t i m e r i n t o v a l u e

    T h e n e w i n t e r f a c e , g e t i t i m e r ( I T I M E R M U L T I R E A L , v a l u e ) , b e h a v e s s i m i l a r l y , b u t w i t h t h e f o l l o w i n g

    d i e r e n c e s :

    v a l u e - > i t v a l u e m u s t b e s e t b y t h e u s e r b e f o r e t h e c a l l . v a l u e - > i t i n t e r v a l i s i g n o r e d .

    I f v a l u e - > i t v a l u e s f - 1 , - 1 g , t h i s i s a r e a p - e x p i r e d - t i m e r o p e r a t i o n . A s t i m e r s e x p i r e , t h e y

    a r e e n q u e u e d . T h i s c a l l r e m o v e s t h e t i m e r a t t h e h e a d o f t h e q u e u e , w r i t e s i t s h a n d l e i n t o

    v a l u e - > i t v a l u e , a n d w r i t e s i t s l a b e l i n t o v a l u e - > i t i n t e r v a l . I f t h e t i m e r i s n o t s e t u p t o

    r e l o a d , i t i s d e s t r o y e d , o t h e r w i s e i t s t a r t s r u n n i n g a g a i n ( i t s n e x t e x p i r e t i m e i s b a s e d o n i t l a s t

    e x p i r e t i m e , n o t t h e t i m e a t w h i c h i t w a s r e a p e d ) . I f t h e q u e u e i s e m p t y , - 1 i s r e t u r n e d a n d

    e r r n o i s s e t t o E A G A I N . W h e n a p r o c e s s e x i t s , a l l o f i t s r u n n i n g a n d q u e u e d t i m e r s a r e d e s t r o y e d .

    I t i s i m p o l i t e f o r a l o n g - l i v e d p r o c e s s t o l e t t i m e r s e x p i r e a n d n e i t h e r r e a p t h e m n o r c a n c e l t h e m ,

    b e c a u s e t h a t w a s t e s s y s t e m r e s o u r c e s .

    I n a l l o t h e r c a s e s , v a l u e - > i t v a l u e i s i n t e r p r e t e d a s a t i m e r h a n d l e . I f t h e h a n d l e i s v a l i d

    a n d t h e t i m e r e x i s t s , v a l u e i s o v e r w r i t t e n w i t h t h e c u r r e n t t i m e r v a l u e . O t h e r w i s e , i t i s l e f t

    u n t o u c h e d , - 1 i s r e t u r n e d , a n d e r r n o i s s e t t o E I N V A L

    F i g u r e 7 : E x t e n s i o n s t o g e t i t i m e r ( )

  • 8/3/2019 Timer Wheel

    11/13

    1 0 C o s t e l l o a n d V a r g h e s e

    0

    2

    4

    6

    8

    10

    12

    14

    0 200 400 600 800 1000

    elapsedtime(seconds)for10,0

    00set/canceliterations

    number of outstanding timers

    Set/cancel time vs. number of outstanding timers

    new callout implementation with handlesold callout implementation

    new callout implementation with hash table

    F i g u r e 8 : R e a l - t i m e p e r f o r m a n c e c o m p a r i s o n o f c a l l o u t i m p l e m e n t a t i o n s .

    T a b l e 1 : S e l e c t e d d a t a p o i n t s f r o m t h e g r a p h o f F i g u r e 8 .

    n u m b e r o f o u t s t a n d i n g t i m e r s

    k e r n e l 0 2 0 0 4 0 0 6 0 0 8 0 0 1 0 0 0

    o l d c a l l o u t 1 . 3 6 7 3 . 9 6 9 6 . 6 3 8 9 . 4 0 4 1 2 . 0 1 7 1 4 . 6 0 8

    n e w c a l l o u t w i t h h a s h t a b l e 1 . 3 6 6 1 . 3 6 0 1 . 3 7 7 1 . 3 6 3 1 . 3 7 9 1 . 3 6 4

    n e w c a l l o u t w i t h h a n d l e s 1 . 3 1 9 1 . 3 2 5 1 . 3 2 9 1 . 3 2 7 1 . 3 2 5 1 . 3 2 9

    T h e e x a c t n u m b e r o f o u t s t a n d i n g c a l l o u t s c a n -

    n o t b e k n o w n e x a c t l y , b e c a u s e o t h e r p a r t s o f t h e

    k e r n e l a l s o u s e c a l l o u t s . H o w e v e r , a s e a r c h t h r o u g h

    t h e k e r n e l c o d e o n l y r e v e a l e d a b o u t 5 o r 6 o f t h e m ,

    b e i n g u s e d b y R P C , N F S , a n d T C P .

    T a b l e 2 s h o w s t h e n u m b e r o f i n s t r u c t i o n s r e -

    q u i r e d f o r t h e e x e c u t i o n o f e a c h f u n c t i o n . T h e

    l o n g e s t p a t h s w e r e c o u n t e d , e x c e p t t h a t i n -

    s t r u c t i o n s f o r c h a n g i n g t h e h i m e m b e r o f a

    c a l l o u t h a n d l e s t r u c t u r e w e r e n e v e r c o u n t e d , b e -

    c a u s e t h a t h a p p e n s i n o n l y o n e o f e v e r y 2

    3 2

    c a s e s .

    T h e c o m p i l e r u s e d w a s g c c 2 . 4 . 5 f o r S P A R C ( w h i c h

    c a m e w i t h N e t B S D ) w i t h t h e - O 2 o p t i o n .

    T h e p e r f o r m a n c e o f t h e n e w h a r d c l o c k ( ) a n d

    s o f t c l o c k ( ) w e r e n o t t e s t e d , b u t t h e i n s t r u c t i o n

    c o u n t s s u g g e s t t h a t h a r d c l o c k ( ) p e r f o r m s a b o u t

    t h e s a m e a s b e f o r e , w h i l e s o f t c l o c k ( ) i s a b o u t

    h a l f a s f a s t a s b e f o r e ( g i v e n t h a t u s u a l l y i = 1

    j = 0 , a n d k + m + n 1 )

    T h e m e m o r y u s a g e o f t h e n e w c a l l o u t f a c i l i t y

    i s w i t h i n a c o n s t a n t f a c t o r o f t h e o r i g i n a l . O r i g i -

  • 8/3/2019 Timer Wheel

    12/13

    R e d e s i g n i n g t h e B S D C a l l o u t a n d T i m e r F a c i l i t i e s 1 1

    T a b l e 2 : I n s t r u c t i o n c o u n t s f o r c a l l o u t f u n c t i o n s .

    i n s t r u c t i o n c o u n t

    f u n c t i o n n e w v e r s i o n o r i g i n a l

    h a r d c l o c k 3 7 3 4 + 1 1 v

    s o f t c l o c k 2 7 + 2 0 i + 1 5 j + 2 7 + 2 8 e

    1 2 k + 5 4 m + 3 7 n

    t i m e o u t 8 1 4 6 + 1 1 t

    u n t i m e o u t 8 0 + 1 1 h 4 5 + 1 1 t

    s e t c a l l o u t 6 0

    u n s e t c a l l o u t 5 5

    e c a l l o u t s e x p i r e .

    h c a l l o u t s i n a c a l l h a s h b u c k e t d o n o t m a t c h .

    i s o f t c l o c k i s i n c r e m e n t e d i t i m e s .

    j M A X S O F T C L O C K S T E P S i s r e a c h e d j t i m e s .

    k u n e x p i r e d c a l l o u t s a r e t r a v e r s e d .

    m h a s h e d c a l l o u t s e x p i r e .

    n n o n - h a s h e d c a l l o u t s e x p i r e .

    t c a l l o u t s a r e s k i p p e d i n a s e a r c h o f c a l l t o d o

    v c a l l o u t s a r e o v e r d u e a t s t a r t o f c a l l t o d o

    n a l l y , n c a l l o u t s t r u c t u r e s r e q u i r e d 4 n l o n g w o r d s .

    T h e n e w i m p l e m e n t a t i o n n e e d s 9 n l o n g w o r d s f o r

    t h e m , p l u s n t o 2 n f o r t h e c a l l w h e e l a r r a y , p l u s

    2 n t o 4 n f o r t h e c a l l h a s h a r r a y ( u n l e s s t h e v a s t

    m a j o r i t y o f t h e c a l l o u t s t r u c t u r e s a r e i n t e n d e d

    f o r u s e w i t h t h e s e t c a l l o u t ( ) i n t e r f a c e , i n w h i c h

    c a s e c a l l h a s h i s v e r y s m a l l ) .

    T h e I T I M E R M U L T I R E A L f a c i l i t y r e q u i r e s t e n

    l o n g w o r d s p e r t i m e r , p l u s t w o p e r p r o c e s s .

    7 . F u t u r e W o r k

    C u r r e n t l y , t h e k e r n e l p a n i c s i f i t r u n s o u t o f c a l l -

    o u t s t r u c t u r e s . T h e r e w a s a c o m m e n t i n t h e o l d

    c a l l o u t c o d e s a y i n g t h a t n e w c a l l o u t s t r u c t u r e s

    s h o u l d b e a l l o c a t e d d y n a m i c a l l y , a n d w e w o u l d

    l i k e t o f u l l l t h a t w i s h . W e w i l l h a v e t o e n l a r g e

    t h e c a l l o u t h a n d l e s t r u c t u r e , b e c a u s e w e w i l l n o

    l o n g e r b e a b l e t o u s e a n i n d e x i n t o a s i n g l e c a l l o u t

    a r r a y | w e w i l l h a v e t o u s e a n h o n e s t - t o - g o o d n e s s

    p o i n t e r . T h e I D w i l l t h e n h a v e t w o u n s i g n e d l o n g s

    a l l t o i t s e l f .

    T h e r e i s a c a v e a t : i n c r e a s i n g t h e m a x i m u m

    p o s s i b l e n u m b e r o f o u t s t a n d i n g c a l l o u t s w i t h o u t

    i n c r e a s i n g t h e s i z e o f c a l l w h e e l o r c a l l h a s h

    c o u l d d e g r a d e p e r f o r m a n c e , b e c a u s e t h e a v e r a g e

    l i s t l e n g t h s c o u l d i n c r e a s e . A l l o w i n g c a l l w h e e l

    a n d c a l l h a s h t o g r o w d y n a m i c a l l y i s c o n c e i v a b l e ,

    b u t p r o b a b l y n o t w o r t h t h e e o r t .

    W e w o u l d a l s o l i k e t o i m p r o v e t h e a p p e a r a n c e o f

    t h e I T I M E R M U L T I R E A L f a c i l i t y . A l t h o u g h i t s d e -

    s i g n i s f u n c t i o n a l l y c l e a n , t h e o v e r l o a d i n g o f t h e

    v a l u e a n d o v a l u e p a r a m e t e r s i s d i s t a s t e f u l . W e

    w o u l d l i k e t o h i d e t h i s o v e r l o a d i n g f r o m t h e u s e r ,

    o r a t l e a s t p r o v i d e a l t e r n a t e n a m e s f o r s t r u c t u r e

    m e m b e r s w h i c h c o r r e s p o n d t o t h e i r u s a g e .

    F i n a l l y , w e h a v e j u s t l e a r n e d , t o o u r d i s m a y ,

    t h a t a f t e r w e d e c i d e d t o u s e t h e t w o l o n g w o r d s

    o f p a d d i n g i n t h e p r o c s t r u c t u r e t o s u p p o r t

    I T I M E R M U L T I R E A L , t h e N e t B S D a u t h o r s c l a i m e d

    o n e o f t h o s e l o n g w o r d s f o r a n o t h e r p u r p o s e . T h i s

    c o n i c t w i l l h a v e t o b e r e s o l v e d , p r o b a b l y b y e n -

    l a r g i n g t h e s t r u c t u r e .

    8 . C o n c l u s i o n

    W e h a v e d e s c r i b e d a n e w i m p l e m e n t a t i o n o f t h e

    N e t B S D t i m e r f a c i l i t y t h a t a p p e a r s t o b e m o r e

    s c a l a b l e , r o b u s t , a n d e x i b l e t h a n t h e c u r r e n t

    N e t B S D i m p l e m e n t a t i o n . I t i s s c a l a b l e ( s e e

    F i g u r e 8 ) i n t h a t t h e o v e r h e a d t o s t a r t , s t o p , o r

    m a i n t a i n t i m e r s d o e s n o t d e p e n d o n t h e n u m -

    b e r o f o u t s t a n d i n g t i m e r s . I t i s r o b u s t i n t h a t

    w e c a n p r e c i s e l y b o u n d t h e a m o u n t o f t i m e i n -

    t e r r u p t s a r e l o c k e d o u t i n t e r m s o f a p a r a m e t e r ,

    M A X S O F T C L O C K S T E P S . I t i s e x i b l e i n t h a t u s e r

    p r o c e s s e s a r e a l l o w e d t o h a v e m u l t i p l e o u t s t a n d i n g

    t i m e r s . T h e n e w i m p l e m e n t a t i o n i s f u l l y c o m p a t -

    i b l e w i t h e x i s t i n g s o f t w a r e b e c a u s e e x i s t i n g i n t e r -

    f a c e s a r e s u p p o r t e d . H o w e v e r , a p p l i c a t i o n s t h a t

    r e q u i r e s l i g h t l y b e t t e r p e r f o r m a n c e ( h a n d l e s f o r

    d e l e t i n g c a l l o u t s ) o r e x i b i l i t y ( m o r e t h a n o n e o u t -

    s t a n d i n g t i m e r ) m u s t u s e t h e n e w i n t e r f a c e s . T h e

    i m p l e m e n t a t i o n d o e s n o t i n c u r a n y e x t r a c o s t f o r

    t h e s e n e w f e a t u r e s , a n d t h e c o d e e x p a n s i o n i s s m a l l

    ( 4 6 8 l i n e s t o t a l

    8

    ) . T h e s o f t w a r e i s a v a i l a b l e f o r u s e

    o r e x p e r i m e n t a t :

    h t t p : / / w w w . c s . w u s t l . e d u / ~ a m c / r e s e a r c h / t i m e r /

    A c k n o w l e d g e m e n t s : W e w i s h t o t h a n k R o n

    M i n n i c h a n d C h u c k C r a n o r f o r t h e i r h e l p f u l c o m -

    m e n t s o n t h i s p a p e r .

    8

    A s o f t h i s w r i t i n g . W e r e s e r v e t h e r i g h t t o f u r t h e r d e -

    v e l o p t h e c o d e !

  • 8/3/2019 Timer Wheel

    13/13

    1 2 C o s t e l l o a n d V a r g h e s e

    R e f e r e n c e s

    B r o 8 8 ] R . B r o w n . C a l e n d a r q u e u e s : A f a s t O ( 1 )

    p r i o r i t y q u e u e i m p l e m e n t a t i o n f o r t h e s i m -

    u l a t i o n e v e n t s e t p r o b l e m . C o m m u n i c a -

    t i o n s o f t h e A C M , 3 1 ( 1 0 ) : 1 2 2 0 { 1 2 2 7 , O c -

    t o b e r 1 9 8 8 .

    C J R S 8 9 ] D . D . C l a r k , V . J a c o b s o n , J . R o m k e y , a n d

    H . S a l w e n . A n a n a l y s i s o f T C P p r o -

    c e s s i n g o v e r h e a d . I E E E C o m m u n i c a t i o n s

    2 7 ( 6 ) : 2 3 { 2 9 , J u n e 1 9 8 9 .

    D a v 8 9 ] G . D a v i s o n . C a l e n d a r p ' s a n d q ' s . C o m m u -

    n i c a t i o n s o f t h e A C M , 3 2 ( 1 0 ) : 1 2 4 1 { 1 2 4 2 ,

    O c t o b e r 1 9 8 9 .

    T N M L 9 3 ] C . T h e k k a t h , T . N g u y e n , E . M o y , a n d

    E . L a z o w s k a . I m p l e m e n t i n g n e t w o r k p r o -

    t o c o l s a t u s e r l e v e l . I E E E T r a n s a c t i o n s o n

    N e t w o r k i n g , 1 ( 5 ) : 5 5 4 { 5 6 4 , O c t o b e r 1 9 9 3 .

    V L 8 7 ] G . V a r g h e s e a n d A . L a u c k . H a s h e d a n d h i -

    e r a r c h i c a l t i m i n g w h e e l s : D a t a s t r u c t u r e s

    f o r t h e e c i e n t i m p l e m e n t a t i o n o f a t i m e r

    f a c i l i t y . I n P r o c e e d i n g s o f t h e 1 1 t h A C M

    S y m p o s i u m o n O p e r a t i n g S y s t e m s P r i n c i -

    p l e s , p a g e s 1 7 1 { 1 8 0 , N o v e m b e r 1 9 8 7 .