Changeset 3313 for trunk/src/kmk/w32
- Timestamp:
- Mar 16, 2020, 3:31:38 AM (5 years ago)
- Location:
- trunk/src/kmk/w32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/w32/winchildren.c
r3224 r3313 334 334 /** Pointer to childcare workers. */ 335 335 static PWINCHILDCAREWORKER *g_papChildCareworkers = NULL; 336 /** The group index for the worker allocator. 337 * This is ever increasing and must be modded by g_cProcessorGroups. */ 338 static unsigned g_idxProcessorGroupAllocator = 0; 339 /** The processor in group index for the worker allocator. */ 340 static unsigned g_idxProcessorInGroupAllocator = 0; 336 /** The processor group allocator state. */ 337 static MKWINCHILDCPUGROUPALLOCSTATE g_ProcessorGroupAllocator; 341 338 /** Number of processor groups in the system. */ 342 339 static unsigned g_cProcessorGroups = 1; … … 468 465 pacProcessorsInGroup[iGroup] = g_pfnGetActiveProcessorCount(iGroup); 469 466 470 /* We shift the starting group with the make nesting level as part of 471 our very simple distribution strategy. */ 472 g_idxProcessorGroupAllocator = makelevel; 467 MkWinChildInitCpuGroupAllocator(&g_ProcessorGroupAllocator); 473 468 } 474 469 else … … 2635 2630 2636 2631 /** 2632 * Initializes the processor group allocator. 2633 * 2634 * @param pState The allocator to initialize. 2635 */ 2636 void MkWinChildInitCpuGroupAllocator(PMKWINCHILDCPUGROUPALLOCSTATE pState) 2637 { 2638 /* We shift the starting group with the make nesting level as part of 2639 our very simple distribution strategy. */ 2640 pState->idxGroup = makelevel; 2641 pState->idxProcessorInGroup = 0; 2642 } 2643 2644 /** 2645 * Allocate CPU group for the next child process. 2646 * 2647 * @returns CPU group. 2648 * @param pState The allocator state. Must be initialized by 2649 * MkWinChildInitCpuGroupAllocator(). 2650 */ 2651 unsigned int MkWinChildAllocateCpuGroup(PMKWINCHILDCPUGROUPALLOCSTATE pState) 2652 { 2653 unsigned int iGroup = 0; 2654 if (g_cProcessorGroups > 1) 2655 { 2656 unsigned int cMaxInGroup; 2657 unsigned int cInGroup; 2658 2659 iGroup = pState->idxGroup % g_cProcessorGroups; 2660 2661 /* Advance. We employ a very simple strategy that does 50% in 2662 each group for each group cycle. Odd processor counts are 2663 caught in odd group cycles. The init function selects the 2664 starting group based on make nesting level to avoid stressing 2665 out the first group. */ 2666 cInGroup = ++pState->idxProcessorInGroup; 2667 cMaxInGroup = g_pacProcessorsInGroup[iGroup]; 2668 if ( !(cMaxInGroup & 1) 2669 || !((pState->idxGroup / g_cProcessorGroups) & 1)) 2670 cMaxInGroup /= 2; 2671 else 2672 cMaxInGroup = cMaxInGroup / 2 + 1; 2673 if (cInGroup >= cMaxInGroup) 2674 { 2675 pState->idxProcessorInGroup = 0; 2676 pState->idxGroup++; 2677 } 2678 } 2679 return iGroup; 2680 } 2681 2682 /** 2637 2683 * Creates another childcare worker. 2638 2684 * … … 2654 2700 { 2655 2701 /* Before we start the thread, assign it to a processor group. */ 2656 if (g_cProcessorGroups > 1) 2657 { 2658 unsigned int cMaxInGroup; 2659 unsigned int cInGroup; 2660 unsigned int iGroup = g_idxProcessorGroupAllocator % g_cProcessorGroups; 2661 pWorker->iProcessorGroup = iGroup; 2662 2663 /* Advance. We employ a very simple strategy that does 50% in 2664 each group for each group cycle. Odd processor counts are 2665 caught in odd group cycles. The init function selects the 2666 starting group based on make nesting level to avoid stressing 2667 out the first group. */ 2668 cInGroup = ++g_idxProcessorInGroupAllocator; 2669 cMaxInGroup = g_pacProcessorsInGroup[iGroup]; 2670 if ( !(cMaxInGroup & 1) 2671 || !((g_idxProcessorGroupAllocator / g_cProcessorGroups) & 1)) 2672 cMaxInGroup /= 2; 2673 else 2674 cMaxInGroup = cMaxInGroup / 2 + 1; 2675 if (cInGroup >= cMaxInGroup) 2676 { 2677 g_idxProcessorInGroupAllocator = 0; 2678 g_idxProcessorGroupAllocator++; 2679 } 2680 } 2702 pWorker->iProcessorGroup = MkWinChildAllocateCpuGroup(&g_ProcessorGroupAllocator); 2681 2703 2682 2704 /* Try start the thread. */ … … 3414 3436 * that completed children is the typical source of these tokens (esp. for kmk). 3415 3437 * 3416 * @returns Zero if completedchildren, event handle if waiting is required.3438 * @returns Zero if no active children, event handle if waiting is required. 3417 3439 */ 3418 3440 intptr_t MkWinChildGetCompleteEventHandle(void) -
trunk/src/kmk/w32/winchildren.h
r3200 r3313 26 26 #ifndef INCLUDED_WINCHILDREN_H 27 27 #define INCLUDED_WINCHILDREN_H 28 29 /** Child processor group allocator state. */ 30 typedef struct MKWINCHILDCPUGROUPALLOCSTATE 31 { 32 /** The group index for the worker allocator. 33 * This is ever increasing and must be modded by g_cProcessorGroups. */ 34 unsigned int idxGroup; 35 /** The processor in group index for the worker allocator. */ 36 unsigned int idxProcessorInGroup; 37 } MKWINCHILDCPUGROUPALLOCSTATE; 38 /** Pointer to a CPU group allocator state. */ 39 typedef MKWINCHILDCPUGROUPALLOCSTATE *PMKWINCHILDCPUGROUPALLOCSTATE; 28 40 29 41 #ifdef DECLARE_HANDLE … … 68 80 int MkWinChildCreate(char **papszArgs, char **papszEnv, const char *pszShell, struct child *pMkChild, pid_t *pPid); 69 81 int MkWinChildCreateWithStdOutPipe(char **papszArgs, char **papszEnv, int fdErr, pid_t *pPid, int *pfdReadPipe); 82 void MkWinChildInitCpuGroupAllocator(PMKWINCHILDCPUGROUPALLOCSTATE pState); 83 unsigned int MkWinChildAllocateCpuGroup(PMKWINCHILDCPUGROUPALLOCSTATE pState); 84 70 85 #ifdef KMK 71 86 struct KMKBUILTINENTRY; … … 86 101 char **papszEnvVars, const char *pszCwd, BOOL pafReplace[3], HANDLE pahReplace[3]); 87 102 # endif 88 #endif 103 #endif /* KMK */ 89 104 int MkWinChildKill(pid_t pid, int iSignal, struct child *pMkChild); 90 105 int MkWinChildWait(int fBlock, pid_t *pPid, int *piExitCode, int *piSignal, int *pfCoreDumped, struct child **ppMkChild);
Note:
See TracChangeset
for help on using the changeset viewer.