ast.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989 Carnegie Mellon University.
  4. * Copyright (c) 1993,1994 The University of Utah and
  5. * the Computer Systems Laboratory (CSL).
  6. * All rights reserved.
  7. *
  8. * Permission to use, copy, modify and distribute this software and its
  9. * documentation is hereby granted, provided that both the copyright
  10. * notice and this permission notice appear in all copies of the
  11. * software, derivative works or modified versions, and any portions
  12. * thereof, and that both notices appear in supporting documentation.
  13. *
  14. * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF
  15. * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
  16. * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
  17. * THIS SOFTWARE.
  18. *
  19. * Carnegie Mellon requests users of this software to return to
  20. *
  21. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  22. * School of Computer Science
  23. * Carnegie Mellon University
  24. * Pittsburgh PA 15213-3890
  25. *
  26. * any improvements or extensions that they make and grant Carnegie Mellon
  27. * the rights to redistribute these changes.
  28. */
  29. /*
  30. * kern/ast.h: Definitions for Asynchronous System Traps.
  31. */
  32. #ifndef _KERN_AST_H_
  33. #define _KERN_AST_H_
  34. /*
  35. * A CPU takes an AST when it is about to return to user code.
  36. * Instead of going back to user code, it calls ast_taken.
  37. * Machine-dependent code is responsible for maintaining
  38. * a set of reasons for an AST, and passing this set to ast_taken.
  39. */
  40. #include "cpu_number.h"
  41. #include <kern/macros.h>
  42. #include <machine/ast.h>
  43. /*
  44. * Bits for reasons
  45. */
  46. #define AST_ZILCH 0x0
  47. #define AST_HALT 0x1
  48. #define AST_TERMINATE 0x2
  49. #define AST_BLOCK 0x4
  50. #define AST_NETWORK 0x8
  51. #define AST_NETIPC 0x10
  52. #define AST_SCHEDULING (AST_HALT|AST_TERMINATE|AST_BLOCK)
  53. /*
  54. * Per-thread ASTs are reset at context-switch time.
  55. * machine/ast.h can define MACHINE_AST_PER_THREAD.
  56. */
  57. #ifndef MACHINE_AST_PER_THREAD
  58. #define MACHINE_AST_PER_THREAD 0
  59. #endif
  60. #define AST_PER_THREAD (AST_HALT | AST_TERMINATE | MACHINE_AST_PER_THREAD)
  61. typedef unsigned long ast_t;
  62. extern volatile ast_t need_ast[NCPUS];
  63. #ifdef MACHINE_AST
  64. /*
  65. * machine/ast.h is responsible for defining aston and astoff.
  66. */
  67. #else /* MACHINE_AST */
  68. #define aston(mycpu)
  69. #define astoff(mycpu)
  70. #endif /* MACHINE_AST */
  71. extern void ast_taken(void);
  72. /*
  73. * ast_needed, ast_on, ast_off, ast_context, and ast_propagate
  74. * assume splsched. mycpu is always cpu_number(). It is an
  75. * argument in case cpu_number() is expensive.
  76. */
  77. #define ast_needed(mycpu) need_ast[mycpu]
  78. #define ast_on(mycpu, reasons) \
  79. MACRO_BEGIN \
  80. if ((need_ast[mycpu] |= (reasons)) != AST_ZILCH) \
  81. { aston(mycpu); } \
  82. MACRO_END
  83. #define ast_off(mycpu, reasons) \
  84. MACRO_BEGIN \
  85. if ((need_ast[mycpu] &= ~(reasons)) == AST_ZILCH) \
  86. { astoff(mycpu); } \
  87. MACRO_END
  88. #define ast_propagate(thread, mycpu) ast_on((mycpu), (thread)->ast)
  89. #define ast_context(thread, mycpu) \
  90. MACRO_BEGIN \
  91. if ((need_ast[mycpu] = \
  92. (need_ast[mycpu] &~ AST_PER_THREAD) | (thread)->ast) \
  93. != AST_ZILCH) \
  94. { aston(mycpu); } \
  95. else \
  96. { astoff(mycpu); } \
  97. MACRO_END
  98. #define thread_ast_set(thread, reason) (thread)->ast |= (reason)
  99. #define thread_ast_clear(thread, reason) (thread)->ast &= ~(reason)
  100. #define thread_ast_clear_all(thread) (thread)->ast = AST_ZILCH
  101. /*
  102. * NOTE: if thread is the current thread, thread_ast_set should
  103. * be followed by ast_propagate().
  104. */
  105. extern void ast_init (void);
  106. extern void ast_check (void);
  107. #endif /* _KERN_AST_H_ */