| 
									
										
										
										
											2010-09-17 15:36:40 -07:00
										 |  |  | #ifndef _ASM_X86_MWAIT_H
 | 
					
						
							|  |  |  | #define _ASM_X86_MWAIT_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 15:08:36 +01:00
										 |  |  | #include <linux/sched.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-17 15:36:40 -07:00
										 |  |  | #define MWAIT_SUBSTATE_MASK		0xf
 | 
					
						
							|  |  |  | #define MWAIT_CSTATE_MASK		0xf
 | 
					
						
							|  |  |  | #define MWAIT_SUBSTATE_SIZE		4
 | 
					
						
							| 
									
										
										
										
											2013-02-01 23:37:30 -05:00
										 |  |  | #define MWAIT_HINT2CSTATE(hint)		(((hint) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK)
 | 
					
						
							|  |  |  | #define MWAIT_HINT2SUBSTATE(hint)	((hint) & MWAIT_CSTATE_MASK)
 | 
					
						
							| 
									
										
										
										
											2010-09-17 15:36:40 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define CPUID_MWAIT_LEAF		5
 | 
					
						
							|  |  |  | #define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1
 | 
					
						
							|  |  |  | #define CPUID5_ECX_INTERRUPT_BREAK	0x2
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MWAIT_ECX_INTERRUPT_BREAK	0x1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 15:08:36 +01:00
										 |  |  | static inline void __monitor(const void *eax, unsigned long ecx, | 
					
						
							|  |  |  | 			     unsigned long edx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* "monitor %eax, %ecx, %edx;" */ | 
					
						
							|  |  |  | 	asm volatile(".byte 0x0f, 0x01, 0xc8;" | 
					
						
							|  |  |  | 		     :: "a" (eax), "c" (ecx), "d"(edx)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void __mwait(unsigned long eax, unsigned long ecx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* "mwait %eax, %ecx;" */ | 
					
						
							|  |  |  | 	asm volatile(".byte 0x0f, 0x01, 0xc9;" | 
					
						
							|  |  |  | 		     :: "a" (eax), "c" (ecx)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * This uses new MONITOR/MWAIT instructions on P4 processors with PNI, | 
					
						
							|  |  |  |  * which can obviate IPI to trigger checking of need_resched. | 
					
						
							|  |  |  |  * We execute MONITOR against need_resched and enter optimized wait state | 
					
						
							|  |  |  |  * through MWAIT. Whenever someone changes need_resched, we would be woken | 
					
						
							|  |  |  |  * up from MWAIT (without an IPI). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * New with Core Duo processors, MWAIT can take some hints based on CPU | 
					
						
							|  |  |  |  * capability. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!current_set_polling_and_test()) { | 
					
						
							| 
									
										
										
										
											2014-06-18 00:06:23 +02:00
										 |  |  | 		if (static_cpu_has_bug(X86_BUG_CLFLUSH_MONITOR)) { | 
					
						
							| 
									
										
										
										
											2013-12-19 11:58:16 -08:00
										 |  |  | 			mb(); | 
					
						
							| 
									
										
										
										
											2013-12-12 15:08:36 +01:00
										 |  |  | 			clflush((void *)¤t_thread_info()->flags); | 
					
						
							| 
									
										
										
										
											2013-12-19 11:58:16 -08:00
										 |  |  | 			mb(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-12 15:08:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		__monitor((void *)¤t_thread_info()->flags, 0, 0); | 
					
						
							|  |  |  | 		if (!need_resched()) | 
					
						
							|  |  |  | 			__mwait(eax, ecx); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-20 12:22:37 +01:00
										 |  |  | 	current_clr_polling(); | 
					
						
							| 
									
										
										
										
											2013-12-12 15:08:36 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-17 15:36:40 -07:00
										 |  |  | #endif /* _ASM_X86_MWAIT_H */
 |