hardirq.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * This file is subject to the terms and conditions of the GNU General Public
  3.  * License.  See the file "COPYING" in the main directory of this archive
  4.  * for more details.
  5.  *
  6.  * Copyright (C) 1997, 1998, 1999, 2000, 2001 by Ralf Baechle
  7.  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8.  * Copyright (C) 2001 MIPS Technologies, Inc.
  9.  */
  10. #ifndef _ASM_HARDIRQ_H
  11. #define _ASM_HARDIRQ_H
  12. #include <linux/config.h>
  13. #include <linux/threads.h>
  14. #include <linux/irq.h>
  15. #include <linux/spinlock.h>
  16. typedef struct {
  17. unsigned int __softirq_pending;
  18. unsigned int __local_irq_count;
  19. unsigned int __local_bh_count;
  20. unsigned int __syscall_count;
  21. struct task_struct * __ksoftirqd_task; /* waitqueue is too large */
  22. } ____cacheline_aligned irq_cpustat_t;
  23. #include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
  24. /*
  25.  * Are we in an interrupt context? Either doing bottom half
  26.  * or hardware interrupt processing?
  27.  */
  28. #define in_interrupt() ({ int __cpu = smp_processor_id(); 
  29. (local_irq_count(__cpu) + local_bh_count(__cpu) != 0); })
  30. #define in_irq() (local_irq_count(smp_processor_id()) != 0)
  31. #ifndef CONFIG_SMP
  32. #define hardirq_trylock(cpu) (local_irq_count(cpu) == 0)
  33. #define hardirq_endlock(cpu) do { } while (0)
  34. #define irq_enter(cpu, irq) (local_irq_count(cpu)++)
  35. #define irq_exit(cpu, irq) (local_irq_count(cpu)--)
  36. #define synchronize_irq() barrier();
  37. #else
  38. #include <asm/atomic.h>
  39. #include <linux/spinlock.h>
  40. #include <asm/smp.h>
  41. extern int global_irq_holder;
  42. extern spinlock_t global_irq_lock;
  43. static inline int irqs_running (void)
  44. {
  45. int i;
  46. for (i = 0; i < smp_num_cpus; i++)
  47. if (local_irq_count(i))
  48. return 1;
  49. return 0;
  50. }
  51. static inline void release_irqlock(int cpu)
  52. {
  53. /* if we didn't own the irq lock, just ignore.. */
  54. if (global_irq_holder == cpu) {
  55. global_irq_holder = NO_PROC_ID;
  56. spin_unlock(&global_irq_lock);
  57. }
  58. }
  59. static inline int hardirq_trylock(int cpu)
  60. {
  61. return !local_irq_count(cpu) && !spin_is_locked(&global_irq_lock);
  62. }
  63. #define hardirq_endlock(cpu) do { } while (0)
  64. static inline void irq_enter(int cpu, int irq)
  65. {
  66. ++local_irq_count(cpu);
  67. while (spin_is_locked(&global_irq_lock))
  68. barrier();
  69. }
  70. static inline void irq_exit(int cpu, int irq)
  71. {
  72. --local_irq_count(cpu);
  73. }
  74. extern void synchronize_irq(void);
  75. #endif /* CONFIG_SMP */
  76. #endif /* _ASM_HARDIRQ_H */