Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Kernel Programming

26,360 views

Published on

Miscellaneous Programming APIs in Linux Kernel

Published in: Technology, Business
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I am suffering form worst financial positions i have no money to pay rent or utility bills, My friend told me about this website for some money. I start broken hart but i was surprised to see the results. Now within a month i am making $125 per hour. I recommend all of you who want to make hand some earning to join the link... ♥♥♥ http://t.cn/AisJWYf4
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ♥♥♥ http://bit.ly/36cXjBY ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❤❤❤ http://bit.ly/36cXjBY ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Kernel Programming

  1. 1. © 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Programming
  2. 2. 2© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? How to do programming in “Kernel C” for Achieving Concurrency Keeping Time Providing Delays Timer Control
  3. 3. 3© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Concurrency
  4. 4. 4© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Concurrency with Locking Mutexes Header: <linux/mutex.h> Type: struct mutex APIs DEFINE_MUTEX mutex_is_locked mutex_lock, mutex_trylock, mutex_unlock Semaphores Header: <linux/semaphore.h> Type: struct semaphore APIs sema_init down, down_trylock, down_interruptible, up
  5. 5. 5© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Concurrency w/ Locking (cont.) Spin Locks Header <linux/spinlock.h> Type: spinlock_t APIs spin_lock_init spin_[try]lock, spin_unlock Reader-Writer Locks Header: <linux/spinlock.h> Type: rwlock_t APIs read_lock, read_unlock write_lock, write_unlock
  6. 6. 6© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Concurrency without Locking Atomic Variables Header: <asm-generic/atomic.h> Type: atomic_t Macros ATOMIC_INIT atomic_read, atomic_set atomic_add, atomic_sub, atomic_inc, atomic_dec atomic_xchg
  7. 7. 7© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Concurrency w/o Locking (cont.) Atomic Bit Operations Header: <linux/bitops.h> APIs rol8, rol16, rol32, ror8, ror16, ror32 find_first_bit, find_first_zero_bit find_last_bit find_next_bit, find_next_zero_bit Header: <asm-generic/bitops.h> APIs set_bit, clear_bit, change_bit test_and_set_bit, test_and_clear_bit, test_and_change_bit
  8. 8. 8© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Wait Queues Wait Queues Header: <linux/wait.h> Wait Queue Head APIs DECLARE_WAIT_QUEUE_HEAD(wq); wait_event_interruptible(wq, cond); wait_event_interruptible_timeout(wq, cond, timeout); wake_up_interruptible(&wq); ... (non-interruptible set) Wait Queue APIs DECLARE_WAITQUEUE(w, current); add_wait_queue(&wq, &w); remove_wait_queue(&wq, &w);
  9. 9. 9© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Time Keeping
  10. 10. 10© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Time since Bootup tick – Kernel's unit of time. Also called jiffy HZ – ticks per second Defined in Header: <linux/param.h> Typically, 1000 for desktops, 100 for embedded systems 1 tick = 1ms (desktop), 10ms (embedded systems) Variables: jiffies & jiffies_64 Header: <linux/jiffies.h> APIs time_after, time_before, time_in_range, ... get_jiffies_64, ... msec_to_jiffies, timespec_to_jiffies, timeval_to_jiffies, … jiffies_to_msec, jiffies_to_timespec, jiffies_to_timeval, ...
  11. 11. 11© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Time since Bootup (cont.) Platform specific “Time Stamp Counter” On x86 Header: <asm/msr.h> API: rdtsc(ul low_tsc_ticks, ul high_tsc_ticks); Getting it generically Header: <linux/timex.h> API: read_current_timer(unsigned long *timer_val);
  12. 12. 12© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Absolute Time Header: <linux/time.h> APIs mktime(y, m, d, h, m, s) – Seconds since Epoch void do_gettimeofday(struct timeval *tv); struct timespec current_kernel_time(void);
  13. 13. 13© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Delays
  14. 14. 14© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Long Delays Busy wait: cpu_relax while (time_before(jiffies, j1)) cpu_relax(); Yielding: schedule/schedule_timeout while (time_before(jiffies, j1)) schedule();
  15. 15. 15© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Short Delays but Busy Waiting Header: <linux/delay.h> Arch. specific Header: <asm/delay.h> APIs void ndelay(unsigned long ndelays); void udelay(unsigned long udelays); void mdelay(unsigned long mdelays);
  16. 16. 16© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Long Delays: Back to Yielding Header: <linux/delay.h> APIs void msleep(unsigned int millisecs); unsigned long msleep_interruptible(unsigned int millisecs); void ssleep(unsigned int secs);
  17. 17. 17© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Timers
  18. 18. 18© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Timers Back end of the various delays Header: <linux/timer.h> Type: struct timer_list APIs void init_timer(struct timer_list *); /* Nullifies */ struct timer_list TIMER_INITIALIZER(f, t, p); void add_timer(struct timer_list *); void del_timer(struct timer_list *); int mod_timer(struct timer_list *, unsigned long); int del_timer_sync(struct timer_list *);
  19. 19. 19© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Tasklets Timers without specific Timing Header: <linux/interrupt.h> Type: struct tasklet_struct APIs void tasklet_init(struct tasklet_struct *t, void (*func) (unsigned long), unsigned long data); void tasklet_kill(struct tasklet_struct *t); DECLARE_TASKLET(name, func, data); tasklet_enable(t), tasklet_disable(t) tasklet_[hi_]schedule(t);
  20. 20. 20© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Work Queues In context of “Special Kernel Thread” Header: <linux/workqueue.h> Types: struct workqueue_struct, struct work_struct Work Queue APIs q = create_workqueue(name); q = create_singlethread_workqueue(name); flush_workqueue(q); destroy_workqueue(q); Work APIs DECLARE_WORK(w, void (*function)(void *), void *data); INIT_WORK(w, void (*function)(void *), void *data); Combined APIs int queue_work(q, &w); int queue_delayed_work(q, &w, d); int cancel_delayed_work(&w); Global Shared Work Queue API schedule_work(&w);
  21. 21. 21© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Helper Interfaces
  22. 22. 22© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Other Helper Interfaces in Latest Kernels User Mode Helper Linked Lists Hash Lists Notifier Chains Completion Interface Kthread Helpers
  23. 23. 23© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved.
  24. 24. 24© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? How to do programming in “Kernel C” for Achieving Concurrency With & without Locking Wait Queues Keeping Time Relative & Absolute Providing Delays Long and Short Busy Wait and Yielding Timer Control Kernel Timers Tasklets Work Queues
  25. 25. 25© 2010-15 Sysplay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?

×